mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2025-01-25 09:41:32 +01:00
ChestLink Verifier
Fix for ChestLinks not being converted to single chests when a block is on top of the DoubleChest.
This commit is contained in:
parent
dd3d77e85a
commit
8fb9c5c220
@ -5,8 +5,10 @@ import com.jamesdpeters.minecraft.chests.serialize.Config;
|
||||
import com.jamesdpeters.minecraft.chests.storage.chestlink.ChestLinkStorage;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -42,6 +44,8 @@ public class ChestLinkVerifier extends BukkitRunnable {
|
||||
convertToSingleChest(left.getInventory());
|
||||
convertToSingleChest(right.getInventory());
|
||||
}
|
||||
} else {
|
||||
manualCheck(chest);
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,4 +76,36 @@ public class ChestLinkVerifier extends BukkitRunnable {
|
||||
|
||||
return (leftStorage != null) || (rightStorage != null);
|
||||
}
|
||||
|
||||
private void manualCheck(Chest chest){
|
||||
if(chest.getBlockData() instanceof Directional) {
|
||||
Directional directional = (Directional) chest.getBlockData();
|
||||
BlockFace facing = directional.getFacing();
|
||||
BlockFace[] perpendulcarFaces = getPerpendicularFaces(facing);
|
||||
if(perpendulcarFaces == null) return;
|
||||
for (BlockFace perpendicularFace : perpendulcarFaces) {
|
||||
Block toTest = block.getRelative(perpendicularFace);
|
||||
if(toTest.getState() instanceof Chest && Config.getChestLink().getStorage(toTest.getLocation()) != null){
|
||||
convertToSingleChest(chest.getInventory());
|
||||
convertToSingleChest(((Chest) toTest.getState()).getInventory());
|
||||
convertToSingleChest(chest.getInventory());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final BlockFace[] NS = new BlockFace[]{BlockFace.WEST, BlockFace.EAST};
|
||||
private static final BlockFace[] WE = new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH};
|
||||
|
||||
private BlockFace[] getPerpendicularFaces(BlockFace face){
|
||||
switch (face){
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
return NS;
|
||||
case WEST:
|
||||
case EAST:
|
||||
return WE;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -126,6 +126,6 @@ public class AutoCraftingStorage extends AbstractStorage implements Configuratio
|
||||
@Override
|
||||
public void postConfigLoad() {
|
||||
super.postConfigLoad();
|
||||
if(recipeSerializable != null) onItemDisplayUpdate(recipeSerializable.getRecipe().getResult());
|
||||
if(recipeSerializable != null && recipeSerializable.getRecipe() != null) onItemDisplayUpdate(recipeSerializable.getRecipe().getResult());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user