From 77cdfe937d0d0adbc461e05eabce6364a8288d75 Mon Sep 17 00:00:00 2001 From: Charsy89 <28523197+Charsy89@users.noreply.github.com> Date: Sat, 28 Jun 2025 16:15:16 +0000 Subject: [PATCH] Implemented Ocelots sitting on Iron Chests, with configurable chest-blocking behavior (#30) Co-authored-by: Maya <10861407+serenibyss@users.noreply.github.com> --- gradle.properties | 2 +- .../cpw/mods/ironchest/BlockIronChest.java | 32 +++++++++++++++++++ .../java/cpw/mods/ironchest/IronChest.java | 21 +++++++++--- .../mods/ironchest/IronChestAIOcelotSit.java | 22 +++++++++---- .../ironchest/OcelotsSitOnChestsHandler.java | 2 +- .../mods/ironchest/TileEntityIronChest.java | 4 +++ src/main/resources/META-INF/IronChest_at.cfg | 1 + 7 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 src/main/resources/META-INF/IronChest_at.cfg diff --git a/gradle.properties b/gradle.properties index 26ddf05..db04a8f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -80,7 +80,7 @@ apiPackage = # Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/ # There can be multiple files in a space-separated list. # Example value: mymodid_at.cfg nei_at.cfg -accessTransformersFile = +accessTransformersFile = IronChest_at.cfg # Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled! usesMixins = false diff --git a/src/main/java/cpw/mods/ironchest/BlockIronChest.java b/src/main/java/cpw/mods/ironchest/BlockIronChest.java index a73e4a2..82a449b 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,28 @@ public class BlockIronChest extends BlockContainer { return false; } + private static boolean isOcelotSitting(World world, int x, int y, int z) { + if (!IronChest.OCELOTS_BLOCKCHESTS) return false; + + @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; + } + } diff --git a/src/main/java/cpw/mods/ironchest/IronChest.java b/src/main/java/cpw/mods/ironchest/IronChest.java index 97962a7..403c39b 100644 --- a/src/main/java/cpw/mods/ironchest/IronChest.java +++ b/src/main/java/cpw/mods/ironchest/IronChest.java @@ -40,6 +40,7 @@ public class IronChest { @Instance("IronChest") public static IronChest instance; public static boolean OCELOTS_SITONCHESTS = true; + public static boolean OCELOTS_BLOCKCHESTS = true; public static final String VERSION = "GRADLETOKEN_VERSION"; public static boolean TRANSPARENT_RENDER_INSIDE = true; public static double TRANSPARENT_RENDER_DISTANCE = 128D; @@ -56,7 +57,18 @@ public class IronChest { Configuration cfg = new Configuration(event.getSuggestedConfigurationFile()); try { cfg.load(); - OCELOTS_SITONCHESTS = cfg.get(Configuration.CATEGORY_GENERAL, "ocelotsSitOnChests", true).getBoolean(true); + OCELOTS_SITONCHESTS = cfg.get( + Configuration.CATEGORY_GENERAL, + "ocelotsSitOnChests", + true, + "Whether or not to allow Ocelots to sit on Iron Chests.").getBoolean(true); + OCELOTS_BLOCKCHESTS = cfg + .get( + Configuration.CATEGORY_GENERAL, + "ocelotsBlockChests", + true, + "Whether or not Ocelots should prevent opening Iron Chests when sitting on top of them.") + .getBoolean(true); TRANSPARENT_RENDER_INSIDE = cfg .get( Configuration.CATEGORY_GENERAL, @@ -114,10 +126,9 @@ public class IronChest { ChestChangerType.generateRecipes(); NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy); proxy.registerRenderInformation(); - // if (OCELOTS_SITONCHESTS) - // { - // MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler()); - // } + if (OCELOTS_SITONCHESTS) { + MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler()); + } MinecraftForge.EVENT_BUS.register(this); } diff --git a/src/main/java/cpw/mods/ironchest/IronChestAIOcelotSit.java b/src/main/java/cpw/mods/ironchest/IronChestAIOcelotSit.java index 85a68c6..20f42d6 100644 --- a/src/main/java/cpw/mods/ironchest/IronChestAIOcelotSit.java +++ b/src/main/java/cpw/mods/ironchest/IronChestAIOcelotSit.java @@ -1,15 +1,25 @@ package cpw.mods.ironchest; +import net.minecraft.block.Block; import net.minecraft.entity.ai.EntityAIOcelotSit; import net.minecraft.entity.passive.EntityOcelot; +import net.minecraft.world.World; public class IronChestAIOcelotSit extends EntityAIOcelotSit { - public IronChestAIOcelotSit(EntityOcelot par1EntityOcelot, float par2) { - super(par1EntityOcelot, par2); + public IronChestAIOcelotSit(EntityOcelot ocelot, double navigationSpeed) { + super(ocelot, navigationSpeed); } - /* - * @Override protected boolean func_151486_a(World world, int x, int y, int z) { if (world.getBlock(x, y, z) == - * IronChest.ironChestBlock) { return true; } return super.func_151486_a(world, x, y, z); } - */} + @Override + public boolean func_151486_a(World world, int x, int y, int z) { + Block targetBlock = world.getBlock(x, y, z); + if (targetBlock == IronChest.ironChestBlock) { + TileEntityIronChest chest = (TileEntityIronChest) world.getTileEntity(x, y, z); + if (chest.getNumUsingPlayers() == 0) { + return true; + } + } + return super.func_151486_a(world, x, y, z); + } +} diff --git a/src/main/java/cpw/mods/ironchest/OcelotsSitOnChestsHandler.java b/src/main/java/cpw/mods/ironchest/OcelotsSitOnChestsHandler.java index 3294c39..08abc43 100644 --- a/src/main/java/cpw/mods/ironchest/OcelotsSitOnChestsHandler.java +++ b/src/main/java/cpw/mods/ironchest/OcelotsSitOnChestsHandler.java @@ -21,7 +21,7 @@ public class OcelotsSitOnChestsHandler { for (EntityAITasks.EntityAITaskEntry task : tasks) { if (task.priority == 6 && (task.action instanceof EntityAIOcelotSit) && !(task.action instanceof IronChestAIOcelotSit)) { - task.action = new IronChestAIOcelotSit(ocelot, 0.4F); + task.action = new IronChestAIOcelotSit(ocelot, 1.33D); } } } diff --git a/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java b/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java index 809b1d3..f99be1d 100644 --- a/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java +++ b/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java @@ -69,6 +69,10 @@ public class TileEntityIronChest extends TileEntity implements IInventory { return type; } + public int getNumUsingPlayers() { + return numUsingPlayers; + } + @Override public ItemStack getStackInSlot(int i) { inventoryTouched = true; diff --git a/src/main/resources/META-INF/IronChest_at.cfg b/src/main/resources/META-INF/IronChest_at.cfg new file mode 100644 index 0000000..675b55e --- /dev/null +++ b/src/main/resources/META-INF/IronChest_at.cfg @@ -0,0 +1 @@ +public net.minecraft.entity.ai.EntityAIOcelotSit func_151486_a(Lnet/minecraft/world/World;III)Z # isSittableBlock