Implemented Ocelots sitting on Iron Chests, with configurable chest-blocking behavior (#30)

Co-authored-by: Maya <[email protected]>
This commit is contained in:
Charsy89andMaya authored and GitHub committed 2025-06-28 16:15:16 +00:00
1 parent 40d69a89ab
commit 77cdfe937d
7 files changed
+71 -13

No files matched your search

+1 -1
View File
@@ -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
@@ -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<EntityOcelot> 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;
}
}
@@ -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);
}
@@ -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);
}
}
@@ -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);
}
}
}
@@ -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;
@@ -0,0 +1 @@
public net.minecraft.entity.ai.EntityAIOcelotSit func_151486_a(Lnet/minecraft/world/World;III)Z # isSittableBlock