diff --git a/src/main/java/com/buuz135/functionalstorage/block/tile/DrawerControllerTile.java b/src/main/java/com/buuz135/functionalstorage/block/tile/DrawerControllerTile.java index a17bb71..c740972 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/tile/DrawerControllerTile.java +++ b/src/main/java/com/buuz135/functionalstorage/block/tile/DrawerControllerTile.java @@ -1,16 +1,12 @@ package com.buuz135.functionalstorage.block.tile; import com.buuz135.functionalstorage.FunctionalStorage; -import com.buuz135.functionalstorage.block.DrawerControllerBlock; import com.buuz135.functionalstorage.block.config.FunctionalStorageConfig; -import com.buuz135.functionalstorage.inventory.BigInventoryHandler; import com.buuz135.functionalstorage.inventory.ControllerInventoryHandler; import com.buuz135.functionalstorage.item.ConfigurationToolItem; import com.buuz135.functionalstorage.item.LinkingToolItem; -import com.buuz135.functionalstorage.item.UpgradeItem; import com.hrznstudio.titanium.annotation.Save; import com.hrznstudio.titanium.block.BasicTileBlock; -import com.hrznstudio.titanium.component.inventory.InventoryComponent; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -36,7 +32,7 @@ import java.util.HashMap; import java.util.List; import java.util.UUID; -public class DrawerControllerTile extends ControllableDrawerTile{ +public class DrawerControllerTile extends ControllableDrawerTile { private static HashMap INTERACTION_LOGGER = new HashMap<>(); @@ -65,7 +61,7 @@ public class DrawerControllerTile extends ControllableDrawerTile(this.connectedDrawers.getConnectedDrawers())) { BlockEntity blockEntity = this.level.getBlockEntity(BlockPos.of(connectedDrawer)); - if (blockEntity instanceof ControllableDrawerTile){ + if (blockEntity instanceof ControllableDrawerTile) { ((ControllableDrawerTile) blockEntity).setLocked(this.isLocked()); } } @@ -129,10 +126,10 @@ public class DrawerControllerTile extends ControllableDrawerTile(this.connectedDrawers.getConnectedDrawers())) { BlockEntity blockEntity = this.level.getBlockEntity(BlockPos.of(connectedDrawer)); - if (blockEntity instanceof ControllableDrawerTile){ + if (blockEntity instanceof ControllableDrawerTile) { ((ControllableDrawerTile) blockEntity).getDrawerOptions().setActive(action, this.getDrawerOptions().isActive(action)); ((ControllableDrawerTile) blockEntity).markForUpdate(); } @@ -150,16 +147,18 @@ public class DrawerControllerTile extends ControllableDrawerTile aLong == position.asLong()); - } + if (level.getBlockState(position).is(FunctionalStorage.DRAWER_CONTROLLER.get())) continue; + if (this.getBlockPos().closerThan(position, FunctionalStorageConfig.DRAWER_CONTROLLER_LINKING_RANGE)) { + if (action == LinkingToolItem.ActionMode.ADD) { + if (!connectedDrawers.getConnectedDrawers().contains(position.asLong())) + this.connectedDrawers.getConnectedDrawers().add(position.asLong()); + } + } + if (action == LinkingToolItem.ActionMode.REMOVE) { + this.connectedDrawers.getConnectedDrawers().removeIf(aLong -> aLong == position.asLong()); + } } this.connectedDrawers.rebuild(); markForUpdate(); @@ -190,13 +189,13 @@ public class DrawerControllerTile extends ControllableDrawerTile(); - if (level != null && !level.isClientSide()){ + if (level != null && !level.isClientSide()) { for (Long connectedDrawer : this.connectedDrawers) { BlockPos pos = BlockPos.of(connectedDrawer); BlockEntity entity = level.getBlockEntity(pos); - if (entity instanceof ControllableDrawerTile){ + if (entity instanceof ControllableDrawerTile) { this.handlers.add(((ControllableDrawerTile) entity).getStorage()); } }