From d63df23d64e3e07d9b866d938bf67f57a75fbbc7 Mon Sep 17 00:00:00 2001 From: Charsy89 <28523197+Charsy89@users.noreply.github.com> Date: Mon, 23 Jun 2025 02:04:01 -0600 Subject: [PATCH] Prevent opening an Iron Chest if an ocelot is sitting on it! * Matches vanilla behavior. --- .../cpw/mods/ironchest/BlockIronChest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/cpw/mods/ironchest/BlockIronChest.java b/src/main/java/cpw/mods/ironchest/BlockIronChest.java index a73e4a2..696cd41 100644 --- a/src/main/java/cpw/mods/ironchest/BlockIronChest.java +++ b/src/main/java/cpw/mods/ironchest/BlockIronChest.java @@ -22,6 +22,7 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.passive.EntityOcelot; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; @@ -29,6 +30,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.World; @@ -119,6 +121,12 @@ public class BlockIronChest extends BlockContainer { return true; } + if (isOcelotSitting(world, i, j, k)) { + // One or more Ocelots are sitting on this chest. Return true as if the player successfully used the chest, + // but don't open the chest! + return true; + } + player.openGui(IronChest.instance, ((TileEntityIronChest) te).getType().ordinal(), world, i, j, k); return true; } @@ -281,4 +289,19 @@ public class BlockIronChest extends BlockContainer { return false; } + private static boolean isOcelotSitting(World world, int x, int y, int z) { + @SuppressWarnings("unchecked") + List cats = world.getEntitiesWithinAABB(EntityOcelot.class, AxisAlignedBB.getBoundingBox( + (double)x, (double)(y + 1), (double)z, (double)(x + 1), (double)(y + 2), (double)(z + 1))); + for(EntityOcelot cat : cats) { + if(cat.isSitting()) { + // There are cats in the block above this chest and at least one of them is sitting. + return true; + } + } + + // No cats or none of them are sitting. :( + return false; + } + }