Skip to content

Commit

Permalink
Improve and fix some DoubleChest behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Phoenix616 committed Jan 11, 2025
1 parent 481f630 commit 10d4507
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.List;

import static com.Acrobot.Breeze.Utils.ImplementationAdapter.getHolder;
import static com.Acrobot.Breeze.Utils.ImplementationAdapter.getLeftSide;
import static com.Acrobot.Breeze.Utils.ImplementationAdapter.getRightSide;

/**
* @author Acrobot
Expand All @@ -46,11 +48,11 @@ public static void onInventoryOpen(InventoryOpenEvent event) {
List<Block> containers = new ArrayList<>();

if (holder instanceof DoubleChest) {
InventoryHolder leftSide = ((DoubleChest) holder).getLeftSide();
InventoryHolder leftSide = getLeftSide((DoubleChest) holder, false);
if (leftSide instanceof BlockState) {
containers.add(((BlockState) leftSide).getBlock());
}
InventoryHolder rightSide = ((DoubleChest) holder).getRightSide();
InventoryHolder rightSide = getRightSide((DoubleChest) holder, false);
if (rightSide instanceof BlockState) {
containers.add(((BlockState) rightSide).getBlock());
}
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/com/Acrobot/ChestShop/Utils/uBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.ArrayList;
import java.util.List;

import static com.Acrobot.Breeze.Utils.ImplementationAdapter.getLeftSide;
import static com.Acrobot.Breeze.Utils.ImplementationAdapter.getRightSide;
import static com.Acrobot.Breeze.Utils.ImplementationAdapter.getState;

/**
Expand Down Expand Up @@ -178,15 +180,15 @@ public static List<Sign> findConnectedShopSigns(InventoryHolder chestShopInvento
List<Sign> result = new ArrayList<>();

if (chestShopInventoryHolder instanceof DoubleChest) {
BlockState leftChestSide = (BlockState) ((DoubleChest) chestShopInventoryHolder).getLeftSide();
BlockState rightChestSide = (BlockState) ((DoubleChest) chestShopInventoryHolder).getRightSide();
InventoryHolder leftChestSide = getLeftSide((DoubleChest) chestShopInventoryHolder, false);
InventoryHolder rightChestSide = getRightSide((DoubleChest) chestShopInventoryHolder, false);

if (leftChestSide == null || rightChestSide == null) {
if (!(leftChestSide instanceof BlockState) || !(rightChestSide instanceof BlockState)) {
return result;
}

Block leftChest = leftChestSide.getBlock();
Block rightChest = rightChestSide.getBlock();
Block leftChest = ((BlockState) leftChestSide).getBlock();
Block rightChest = ((BlockState) rightChestSide).getBlock();

if (ChestShopSign.isShopBlock(leftChest)) {
result.addAll(uBlock.findConnectedShopSigns(leftChest));
Expand Down Expand Up @@ -318,6 +320,6 @@ public static boolean couldBeShopContainer(Block block) {

public static boolean couldBeShopContainer(InventoryHolder holder) {
return (holder instanceof Container && couldBeShopContainer(((Container) holder).getBlock()))
|| (holder instanceof DoubleChest && couldBeShopContainer(((DoubleChest) holder).getLeftSide()));
|| (holder instanceof DoubleChest && couldBeShopContainer(getLeftSide((DoubleChest) holder, false)));
}
}

0 comments on commit 10d4507

Please sign in to comment.