Fxied concurrent mod exc when breaking a drawer, closes #71

This commit is contained in:
Buuz135 2022-08-14 15:59:14 +02:00
parent 19c6898ad0
commit a38c2a773a
3 changed files with 16 additions and 11 deletions

View File

@ -12,7 +12,7 @@ buildscript {
apply plugin: 'net.minecraftforge.gradle'
group = 'com.buuz135'
version = '1.18.2-1.0.1'
version = '1.18.2-1.0.2'
java {
archivesBaseName = 'functionalstorage'

View File

@ -1,7 +1,6 @@
package com.buuz135.functionalstorage.block;
import com.buuz135.functionalstorage.FunctionalStorage;
import com.buuz135.functionalstorage.block.tile.CompactingDrawerTile;
import com.buuz135.functionalstorage.block.tile.ControllableDrawerTile;
import com.buuz135.functionalstorage.block.tile.DrawerControllerTile;
import com.hrznstudio.titanium.block.RotatableBlock;
@ -14,13 +13,14 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.NotNull;
import java.util.Optional;
import java.util.ArrayList;
public class DrawerControllerBlock extends RotatableBlock<DrawerControllerTile> {
@ -54,14 +54,17 @@ public class DrawerControllerBlock extends RotatableBlock<DrawerControllerTile>
@Override
public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
TileUtil.getTileEntity(worldIn, pos, DrawerControllerTile.class).ifPresent(drawerControllerTile -> {
drawerControllerTile.getConnectedDrawers().getConnectedDrawers().stream()
.map(BlockPos::of)
.map(blockPos -> TileUtil.getTileEntity(worldIn, blockPos, ControllableDrawerTile.class))
.filter(Optional::isPresent)
.map(Optional::get)
.forEach(controllableDrawerTile -> controllableDrawerTile.setControllerPos(null));
});
if (!state.is(newState.getBlock())) {
TileUtil.getTileEntity(worldIn, pos, DrawerControllerTile.class).ifPresent(drawerControllerTile -> {
for (Long connectedDrawer : new ArrayList<>(drawerControllerTile.getConnectedDrawers().getConnectedDrawers())) {
BlockEntity blockEntity = worldIn.getBlockEntity(BlockPos.of(connectedDrawer));
if (blockEntity instanceof DrawerControllerTile) continue;
if (blockEntity instanceof ControllableDrawerTile controllableDrawerTile) {
controllableDrawerTile.setControllerPos(null);
}
}
});
}
super.onRemove(state, worldIn, pos, newState, isMoving);
}

View File

@ -136,6 +136,7 @@ public class DrawerControllerTile extends ControllableDrawerTile<DrawerControlle
if (isServer()) {
for (Long connectedDrawer : new ArrayList<>(this.connectedDrawers.getConnectedDrawers())) {
BlockEntity blockEntity = this.level.getBlockEntity(BlockPos.of(connectedDrawer));
if (blockEntity instanceof DrawerControllerTile) continue;
if (blockEntity instanceof ControllableDrawerTile) {
((ControllableDrawerTile<?>) blockEntity).setLocked(this.isLocked());
}
@ -149,6 +150,7 @@ public class DrawerControllerTile extends ControllableDrawerTile<DrawerControlle
if (isServer()) {
for (Long connectedDrawer : new ArrayList<>(this.connectedDrawers.getConnectedDrawers())) {
BlockEntity blockEntity = this.level.getBlockEntity(BlockPos.of(connectedDrawer));
if (blockEntity instanceof DrawerControllerTile) continue;
if (blockEntity instanceof ControllableDrawerTile) {
((ControllableDrawerTile<?>) blockEntity).getDrawerOptions().setActive(action, this.getDrawerOptions().isActive(action));
((ControllableDrawerTile<?>) blockEntity).markForUpdate();