diff --git a/IronChests2/client/cpw/mods/ironchest/client/ClientProxy.java b/IronChests2/client/cpw/mods/ironchest/client/ClientProxy.java index 205156c..e044796 100644 --- a/IronChests2/client/cpw/mods/ironchest/client/ClientProxy.java +++ b/IronChests2/client/cpw/mods/ironchest/client/ClientProxy.java @@ -11,19 +11,12 @@ package cpw.mods.ironchest.client; import net.minecraft.src.ChestItemRenderHelper; -import net.minecraft.src.EntityPlayer; -import net.minecraft.src.ModLoader; -import net.minecraft.src.TileEntity; import net.minecraft.src.World; import net.minecraftforge.client.MinecraftForgeClient; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.client.registry.ClientRegistry; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.network.IGuiHandler; -import cpw.mods.ironchest.ContainerIronChestBase; import cpw.mods.ironchest.CommonProxy; import cpw.mods.ironchest.IronChestType; -import cpw.mods.ironchest.TileEntityIronChest; public class ClientProxy extends CommonProxy { @Override @@ -33,11 +26,6 @@ public class ClientProxy extends CommonProxy { MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/item_textures.png"); } - @Override - public boolean isRemote() { - return ModLoader.getMinecraftInstance().theWorld.isRemote; - } - @Override public void registerTileEntitySpecialRenderer(IronChestType typ) { ClientRegistry.bindTileEntitySpecialRenderer(typ.clazz, new TileEntityIronChestRenderer()); diff --git a/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java b/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java index eee28c3..d4cd0e7 100644 --- a/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java +++ b/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java @@ -11,12 +11,12 @@ package cpw.mods.ironchest.client; import static org.lwjgl.opengl.GL11.GL_COMPILE_AND_EXECUTE; +import static org.lwjgl.opengl.GL11.glCallList; import static org.lwjgl.opengl.GL11.glColor4f; import static org.lwjgl.opengl.GL11.glDisable; import static org.lwjgl.opengl.GL11.glEnable; import static org.lwjgl.opengl.GL11.glEndList; import static org.lwjgl.opengl.GL11.glGenLists; -import static org.lwjgl.opengl.GL11.glCallList; import static org.lwjgl.opengl.GL11.glNewList; import static org.lwjgl.opengl.GL11.glPopMatrix; import static org.lwjgl.opengl.GL11.glPushMatrix; @@ -24,11 +24,9 @@ import static org.lwjgl.opengl.GL11.glRotatef; import static org.lwjgl.opengl.GL11.glScalef; import static org.lwjgl.opengl.GL11.glTranslatef; -import java.util.Random; -import java.util.Map; import java.util.HashMap; - -import org.lwjgl.opengl.GL11; +import java.util.Map; +import java.util.Random; import net.minecraft.src.Block; import net.minecraft.src.EntityItem; @@ -39,14 +37,16 @@ import net.minecraft.src.RenderBlocks; import net.minecraft.src.Tessellator; import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntitySpecialRenderer; -import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.client.IItemRenderer; import net.minecraftforge.client.MinecraftForgeClient; + +import org.lwjgl.opengl.GL11; + import cpw.mods.fml.client.FMLClientHandler; +import cpw.mods.ironchest.IronChest; import cpw.mods.ironchest.IronChestType; import cpw.mods.ironchest.MappableItemStackWrapper; import cpw.mods.ironchest.TileEntityIronChest; -import cpw.mods.ironchest.IronChest; public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer { private static Map renderList = new HashMap(); diff --git a/IronChests2/common/cpw/mods/ironchest/CommonProxy.java b/IronChests2/common/cpw/mods/ironchest/CommonProxy.java index b53c52c..f6d48b8 100644 --- a/IronChests2/common/cpw/mods/ironchest/CommonProxy.java +++ b/IronChests2/common/cpw/mods/ironchest/CommonProxy.java @@ -23,11 +23,6 @@ public class CommonProxy implements IGuiHandler { } - public boolean isRemote() - { - return true; - } - public void registerTileEntitySpecialRenderer(IronChestType typ) { diff --git a/IronChests2/common/cpw/mods/ironchest/IronChest.java b/IronChests2/common/cpw/mods/ironchest/IronChest.java index 153e150..22df701 100644 --- a/IronChests2/common/cpw/mods/ironchest/IronChest.java +++ b/IronChests2/common/cpw/mods/ironchest/IronChest.java @@ -14,6 +14,7 @@ import java.lang.reflect.Method; import java.util.logging.Level; import net.minecraftforge.common.Configuration; +import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.Init; @@ -74,6 +75,10 @@ public class IronChest { ChestChangerType.generateRecipes(); NetworkRegistry.instance().registerGuiHandler(instance, proxy); proxy.registerRenderInformation(); + if (OCELOTS_SITONCHESTS) + { + MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler()); + } } @PostInit diff --git a/IronChests2/common/cpw/mods/ironchest/IronChestAIOcelotSit.java b/IronChests2/common/cpw/mods/ironchest/IronChestAIOcelotSit.java index 4104b36..49d682b 100644 --- a/IronChests2/common/cpw/mods/ironchest/IronChestAIOcelotSit.java +++ b/IronChests2/common/cpw/mods/ironchest/IronChestAIOcelotSit.java @@ -1,138 +1,19 @@ package cpw.mods.ironchest; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import net.minecraft.src.Block; -import net.minecraft.src.BlockBed; -import net.minecraft.src.EntityAIBase; import net.minecraft.src.EntityAIOcelotSit; import net.minecraft.src.EntityOcelot; -import net.minecraft.src.TileEntityChest; import net.minecraft.src.World; -public class IronChestAIOcelotSit extends EntityAIBase { - private EntityOcelot ocelot; - private final float speed; - private int ticksRun = 0; - private int tryTicks = 0; - private int maxTicks = 0; - private int targetX = 0; - private int targetY = 0; - private int targetZ = 0; - private EntityAIOcelotSit sitAI; - private Method isTargetBlockMethod; - private boolean grabbedMethod; +public class IronChestAIOcelotSit extends EntityAIOcelotSit { + public IronChestAIOcelotSit(EntityOcelot par1EntityOcelot, float par2) { + super(par1EntityOcelot, par2); + } - public IronChestAIOcelotSit(EntityOcelot par1EntityOcelot, float par2, EntityAIOcelotSit sitAI) { - this.ocelot = par1EntityOcelot; - this.speed = par2; - this.sitAI = sitAI; - this.setMutexBits(5); - if (!grabbedMethod) { - try { - isTargetBlockMethod = EntityAIOcelotSit.class.getDeclaredMethod("a", World.class, int.class, int.class, int.class); - } catch (Exception e) { - // Can't find it - try { - isTargetBlockMethod = EntityAIOcelotSit.class.getDeclaredMethod("func_50078_a", World.class, int.class, int.class, int.class); - } catch (Exception e1) { - } - } - isTargetBlockMethod.setAccessible(true); - grabbedMethod = true; - } - } - - public boolean shouldExecute() - { - return ocelot.isTamed() && !ocelot.isSitting() && ocelot.getRNG().nextDouble() <= 0.0065D && thereIsChestNearby(); - } - - /** - * Returns whether an in-progress EntityAIBase should continue executing - */ - public boolean continueExecuting() - { - return this.ticksRun <= this.maxTicks && this.tryTicks <= 60 && isBlockAChestBlock(ocelot.worldObj, this.targetX, this.targetY, this.targetZ); - } - - /** - * Execute a one shot task or start executing a continuous task - */ - public void startExecuting() - { - this.ocelot.getNavigator().tryMoveToXYZ((double) ((float) this.targetX) + 0.5D, (double) (this.targetY + 1), (double) ((float) this.targetZ) + 0.5D, - this.speed); - this.ticksRun = 0; - this.tryTicks = 0; - this.maxTicks = this.ocelot.getRNG().nextInt(this.ocelot.getRNG().nextInt(1200) + 1200) + 1200; - this.ocelot.func_50008_ai().setIsSitting(false); - } - - /** - * Resets the task - */ - public void resetTask() - { - this.ocelot.setSitting(false); - } - - /** - * Updates the task - */ - public void updateTask() - { - ++this.ticksRun; - this.ocelot.func_50008_ai().setIsSitting(false); - - if (this.ocelot.getDistanceSq((double) this.targetX, (double) (this.targetY + 1), (double) this.targetZ) > 1.0D) - { - this.ocelot.setSitting(false); - this.ocelot.getNavigator().tryMoveToXYZ((double) ((float) this.targetX) + 0.5D, (double) (this.targetY + 1), (double) ((float) this.targetZ) + 0.5D, - this.speed); - ++this.tryTicks; - } - else if (!this.ocelot.isSitting()) - { - this.ocelot.setSitting(true); - } - else - { - --this.tryTicks; - } - } - - private boolean thereIsChestNearby() { - int searchY = (int) this.ocelot.posY; - double closestChestDistance = Integer.MAX_VALUE; - - for (int searchX = (int) this.ocelot.posX - 8; searchX < this.ocelot.posX + 8; searchX++) { - for (int searchZ = (int) this.ocelot.posZ - 8; searchZ < this.ocelot.posZ + 8; searchZ++) { - if (this.isBlockAChestBlock(this.ocelot.worldObj, searchX, searchY, searchZ) && this.ocelot.worldObj.isAirBlock(searchX, searchY + 1, searchZ)) { - double chestDistance = this.ocelot.getDistanceSq((double) searchX, (double) searchY, (double) searchZ); - - if (chestDistance < closestChestDistance) { - this.targetX = searchX; - this.targetY = searchY; - this.targetZ = searchZ; - closestChestDistance = chestDistance; - } - } - } - } - - return closestChestDistance < Integer.MAX_VALUE; - } - - private boolean isBlockAChestBlock(World world, int x, int y, int z) { - if (world.getBlockId(x, y, z)==IronChest.ironChestBlock.blockID) { - return true; - } - try { - return (Boolean) isTargetBlockMethod.invoke(sitAI, world, x, y, z); - } catch (Exception e) { - } - return false; - } + @Override + protected boolean isSittableBlock(World world, int x, int y, int z) { + if (world.getBlockId(x, y, z) == IronChest.ironChestBlock.blockID) { + return true; + } + return super.isSittableBlock(world, x, y, z); + } } diff --git a/IronChests2/common/cpw/mods/ironchest/ItemIronChest.java b/IronChests2/common/cpw/mods/ironchest/ItemIronChest.java index 53812a2..132887b 100644 --- a/IronChests2/common/cpw/mods/ironchest/ItemIronChest.java +++ b/IronChests2/common/cpw/mods/ironchest/ItemIronChest.java @@ -10,8 +10,6 @@ ******************************************************************************/ package cpw.mods.ironchest; -import java.util.ArrayList; - import net.minecraft.src.ItemBlock; import net.minecraft.src.ItemStack; diff --git a/IronChests2/common/cpw/mods/ironchest/OcelotsSitOnChestsHandler.java b/IronChests2/common/cpw/mods/ironchest/OcelotsSitOnChestsHandler.java index 99cfd07..683a345 100644 --- a/IronChests2/common/cpw/mods/ironchest/OcelotsSitOnChestsHandler.java +++ b/IronChests2/common/cpw/mods/ironchest/OcelotsSitOnChestsHandler.java @@ -2,27 +2,29 @@ package cpw.mods.ironchest; import java.util.List; -import cpw.mods.fml.common.ReflectionHelper; -import net.minecraft.src.EntityAIBase; -import net.minecraft.src.EntityAIOcelotSit; -import net.minecraft.src.EntityAITasks; -import net.minecraft.src.EntityLiving; +import net.minecraft.src.EntityAITaskEntry; import net.minecraft.src.EntityOcelot; -import net.minecraft.src.World; -import net.minecraft.src.forge.IEntityLivingHandler; -import net.minecraft.src.forge.adaptors.EntityLivingHandlerAdaptor; +import net.minecraftforge.event.ForgeSubscribe; +import net.minecraftforge.event.entity.living.LivingEvent; +import net.minecraftforge.event.entity.living.LivingSpecialSpawnEvent; -public class OcelotsSitOnChestsHandler extends EntityLivingHandlerAdaptor { - private static EntityAIOcelotSit aiTask = new EntityAIOcelotSit(null, 0); - @Override - public boolean onEntityLivingUpdate(EntityLiving entity) { - if (entity.ticksExisted<2 && entity instanceof EntityOcelot) { - EntityOcelot ocelot = (EntityOcelot) entity; - EntityAITasks ocelotTasks = ReflectionHelper.getPrivateValue(EntityLiving.class, ocelot, "tasks"); - List taskList = ReflectionHelper.getPrivateValue(EntityAITasks.class, ocelotTasks, "tasksToDo"); - taskList.remove(5); - ocelotTasks.addTask(6, new IronChestAIOcelotSit(ocelot, 0.4F, aiTask)); - } - return false; - } +public class OcelotsSitOnChestsHandler { + @ForgeSubscribe + public void changeSittingTaskForOcelots(LivingEvent.LivingUpdateEvent evt) { + if (evt.entityLiving instanceof EntityOcelot && evt.entityLiving.ticksExisted < 5) + { + EntityOcelot ocelot = (EntityOcelot) evt.entityLiving; + @SuppressWarnings("unchecked") + List tasks = ocelot.tasks.field_75782_a; + + for (int i=0; i