Fxied concurrent mod exc when breaking a drawer, closes #71
This commit is contained in:
parent
19c6898ad0
commit
a38c2a773a
|
@ -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'
|
||||||
|
|
|
@ -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) {
|
||||||
TileUtil.getTileEntity(worldIn, pos, DrawerControllerTile.class).ifPresent(drawerControllerTile -> {
|
if (!state.is(newState.getBlock())) {
|
||||||
drawerControllerTile.getConnectedDrawers().getConnectedDrawers().stream()
|
TileUtil.getTileEntity(worldIn, pos, DrawerControllerTile.class).ifPresent(drawerControllerTile -> {
|
||||||
.map(BlockPos::of)
|
for (Long connectedDrawer : new ArrayList<>(drawerControllerTile.getConnectedDrawers().getConnectedDrawers())) {
|
||||||
.map(blockPos -> TileUtil.getTileEntity(worldIn, blockPos, ControllableDrawerTile.class))
|
BlockEntity blockEntity = worldIn.getBlockEntity(BlockPos.of(connectedDrawer));
|
||||||
.filter(Optional::isPresent)
|
if (blockEntity instanceof DrawerControllerTile) continue;
|
||||||
.map(Optional::get)
|
if (blockEntity instanceof ControllableDrawerTile controllableDrawerTile) {
|
||||||
.forEach(controllableDrawerTile -> controllableDrawerTile.setControllerPos(null));
|
controllableDrawerTile.setControllerPos(null);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
super.onRemove(state, worldIn, pos, newState, isMoving);
|
super.onRemove(state, worldIn, pos, newState, isMoving);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user