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' apply plugin: 'net.minecraftforge.gradle'
group = 'com.buuz135' group = 'com.buuz135'
version = '1.18.2-1.0.1' version = '1.18.2-1.0.2'
java { java {
archivesBaseName = 'functionalstorage' archivesBaseName = 'functionalstorage'

View File

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

View File

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