Ocelots on chests time
This commit is contained in:
parent
958f8466d4
commit
8d2a21f082
|
@ -11,19 +11,12 @@
|
||||||
package cpw.mods.ironchest.client;
|
package cpw.mods.ironchest.client;
|
||||||
|
|
||||||
import net.minecraft.src.ChestItemRenderHelper;
|
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.minecraft.src.World;
|
||||||
import net.minecraftforge.client.MinecraftForgeClient;
|
import net.minecraftforge.client.MinecraftForgeClient;
|
||||||
import cpw.mods.fml.client.FMLClientHandler;
|
import cpw.mods.fml.client.FMLClientHandler;
|
||||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
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.CommonProxy;
|
||||||
import cpw.mods.ironchest.IronChestType;
|
import cpw.mods.ironchest.IronChestType;
|
||||||
import cpw.mods.ironchest.TileEntityIronChest;
|
|
||||||
|
|
||||||
public class ClientProxy extends CommonProxy {
|
public class ClientProxy extends CommonProxy {
|
||||||
@Override
|
@Override
|
||||||
|
@ -33,11 +26,6 @@ public class ClientProxy extends CommonProxy {
|
||||||
MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/item_textures.png");
|
MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/item_textures.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isRemote() {
|
|
||||||
return ModLoader.getMinecraftInstance().theWorld.isRemote;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerTileEntitySpecialRenderer(IronChestType typ) {
|
public void registerTileEntitySpecialRenderer(IronChestType typ) {
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer(typ.clazz, new TileEntityIronChestRenderer());
|
ClientRegistry.bindTileEntitySpecialRenderer(typ.clazz, new TileEntityIronChestRenderer());
|
||||||
|
|
|
@ -11,12 +11,12 @@
|
||||||
package cpw.mods.ironchest.client;
|
package cpw.mods.ironchest.client;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.GL_COMPILE_AND_EXECUTE;
|
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.glColor4f;
|
||||||
import static org.lwjgl.opengl.GL11.glDisable;
|
import static org.lwjgl.opengl.GL11.glDisable;
|
||||||
import static org.lwjgl.opengl.GL11.glEnable;
|
import static org.lwjgl.opengl.GL11.glEnable;
|
||||||
import static org.lwjgl.opengl.GL11.glEndList;
|
import static org.lwjgl.opengl.GL11.glEndList;
|
||||||
import static org.lwjgl.opengl.GL11.glGenLists;
|
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.glNewList;
|
||||||
import static org.lwjgl.opengl.GL11.glPopMatrix;
|
import static org.lwjgl.opengl.GL11.glPopMatrix;
|
||||||
import static org.lwjgl.opengl.GL11.glPushMatrix;
|
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.glScalef;
|
||||||
import static org.lwjgl.opengl.GL11.glTranslatef;
|
import static org.lwjgl.opengl.GL11.glTranslatef;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import org.lwjgl.opengl.GL11;
|
import java.util.Random;
|
||||||
|
|
||||||
import net.minecraft.src.Block;
|
import net.minecraft.src.Block;
|
||||||
import net.minecraft.src.EntityItem;
|
import net.minecraft.src.EntityItem;
|
||||||
|
@ -39,14 +37,16 @@ import net.minecraft.src.RenderBlocks;
|
||||||
import net.minecraft.src.Tessellator;
|
import net.minecraft.src.Tessellator;
|
||||||
import net.minecraft.src.TileEntity;
|
import net.minecraft.src.TileEntity;
|
||||||
import net.minecraft.src.TileEntitySpecialRenderer;
|
import net.minecraft.src.TileEntitySpecialRenderer;
|
||||||
import net.minecraftforge.client.ForgeHooksClient;
|
|
||||||
import net.minecraftforge.client.IItemRenderer;
|
import net.minecraftforge.client.IItemRenderer;
|
||||||
import net.minecraftforge.client.MinecraftForgeClient;
|
import net.minecraftforge.client.MinecraftForgeClient;
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import cpw.mods.fml.client.FMLClientHandler;
|
import cpw.mods.fml.client.FMLClientHandler;
|
||||||
|
import cpw.mods.ironchest.IronChest;
|
||||||
import cpw.mods.ironchest.IronChestType;
|
import cpw.mods.ironchest.IronChestType;
|
||||||
import cpw.mods.ironchest.MappableItemStackWrapper;
|
import cpw.mods.ironchest.MappableItemStackWrapper;
|
||||||
import cpw.mods.ironchest.TileEntityIronChest;
|
import cpw.mods.ironchest.TileEntityIronChest;
|
||||||
import cpw.mods.ironchest.IronChest;
|
|
||||||
|
|
||||||
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
||||||
private static Map<MappableItemStackWrapper, Integer> renderList = new HashMap<MappableItemStackWrapper, Integer>();
|
private static Map<MappableItemStackWrapper, Integer> renderList = new HashMap<MappableItemStackWrapper, Integer>();
|
||||||
|
|
|
@ -23,11 +23,6 @@ public class CommonProxy implements IGuiHandler {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRemote()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerTileEntitySpecialRenderer(IronChestType typ)
|
public void registerTileEntitySpecialRenderer(IronChestType typ)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.lang.reflect.Method;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import net.minecraftforge.common.Configuration;
|
import net.minecraftforge.common.Configuration;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import cpw.mods.fml.common.FMLLog;
|
import cpw.mods.fml.common.FMLLog;
|
||||||
import cpw.mods.fml.common.Mod;
|
import cpw.mods.fml.common.Mod;
|
||||||
import cpw.mods.fml.common.Mod.Init;
|
import cpw.mods.fml.common.Mod.Init;
|
||||||
|
@ -74,6 +75,10 @@ public class IronChest {
|
||||||
ChestChangerType.generateRecipes();
|
ChestChangerType.generateRecipes();
|
||||||
NetworkRegistry.instance().registerGuiHandler(instance, proxy);
|
NetworkRegistry.instance().registerGuiHandler(instance, proxy);
|
||||||
proxy.registerRenderInformation();
|
proxy.registerRenderInformation();
|
||||||
|
if (OCELOTS_SITONCHESTS)
|
||||||
|
{
|
||||||
|
MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostInit
|
@PostInit
|
||||||
|
|
|
@ -1,138 +1,19 @@
|
||||||
package cpw.mods.ironchest;
|
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.EntityAIOcelotSit;
|
||||||
import net.minecraft.src.EntityOcelot;
|
import net.minecraft.src.EntityOcelot;
|
||||||
import net.minecraft.src.TileEntityChest;
|
|
||||||
import net.minecraft.src.World;
|
import net.minecraft.src.World;
|
||||||
|
|
||||||
public class IronChestAIOcelotSit extends EntityAIBase {
|
public class IronChestAIOcelotSit extends EntityAIOcelotSit {
|
||||||
private EntityOcelot ocelot;
|
public IronChestAIOcelotSit(EntityOcelot par1EntityOcelot, float par2) {
|
||||||
private final float speed;
|
super(par1EntityOcelot, par2);
|
||||||
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 IronChestAIOcelotSit(EntityOcelot par1EntityOcelot, float par2, EntityAIOcelotSit sitAI) {
|
@Override
|
||||||
this.ocelot = par1EntityOcelot;
|
protected boolean isSittableBlock(World world, int x, int y, int z) {
|
||||||
this.speed = par2;
|
if (world.getBlockId(x, y, z) == IronChest.ironChestBlock.blockID) {
|
||||||
this.sitAI = sitAI;
|
return true;
|
||||||
this.setMutexBits(5);
|
}
|
||||||
if (!grabbedMethod) {
|
return super.isSittableBlock(world, x, y, z);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,6 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package cpw.mods.ironchest;
|
package cpw.mods.ironchest;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import net.minecraft.src.ItemBlock;
|
import net.minecraft.src.ItemBlock;
|
||||||
import net.minecraft.src.ItemStack;
|
import net.minecraft.src.ItemStack;
|
||||||
|
|
||||||
|
|
|
@ -2,27 +2,29 @@ package cpw.mods.ironchest;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import cpw.mods.fml.common.ReflectionHelper;
|
import net.minecraft.src.EntityAITaskEntry;
|
||||||
import net.minecraft.src.EntityAIBase;
|
|
||||||
import net.minecraft.src.EntityAIOcelotSit;
|
|
||||||
import net.minecraft.src.EntityAITasks;
|
|
||||||
import net.minecraft.src.EntityLiving;
|
|
||||||
import net.minecraft.src.EntityOcelot;
|
import net.minecraft.src.EntityOcelot;
|
||||||
import net.minecraft.src.World;
|
import net.minecraftforge.event.ForgeSubscribe;
|
||||||
import net.minecraft.src.forge.IEntityLivingHandler;
|
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||||
import net.minecraft.src.forge.adaptors.EntityLivingHandlerAdaptor;
|
import net.minecraftforge.event.entity.living.LivingSpecialSpawnEvent;
|
||||||
|
|
||||||
public class OcelotsSitOnChestsHandler extends EntityLivingHandlerAdaptor {
|
public class OcelotsSitOnChestsHandler {
|
||||||
private static EntityAIOcelotSit aiTask = new EntityAIOcelotSit(null, 0);
|
@ForgeSubscribe
|
||||||
@Override
|
public void changeSittingTaskForOcelots(LivingEvent.LivingUpdateEvent evt) {
|
||||||
public boolean onEntityLivingUpdate(EntityLiving entity) {
|
if (evt.entityLiving instanceof EntityOcelot && evt.entityLiving.ticksExisted < 5)
|
||||||
if (entity.ticksExisted<2 && entity instanceof EntityOcelot) {
|
{
|
||||||
EntityOcelot ocelot = (EntityOcelot) entity;
|
EntityOcelot ocelot = (EntityOcelot) evt.entityLiving;
|
||||||
EntityAITasks ocelotTasks = ReflectionHelper.getPrivateValue(EntityLiving.class, ocelot, "tasks");
|
@SuppressWarnings("unchecked")
|
||||||
List taskList = ReflectionHelper.getPrivateValue(EntityAITasks.class, ocelotTasks, "tasksToDo");
|
List<EntityAITaskEntry> tasks = ocelot.tasks.field_75782_a;
|
||||||
taskList.remove(5);
|
|
||||||
ocelotTasks.addTask(6, new IronChestAIOcelotSit(ocelot, 0.4F, aiTask));
|
for (int i=0; i<tasks.size(); i++)
|
||||||
}
|
{
|
||||||
return false;
|
EntityAITaskEntry task = tasks.get(i);
|
||||||
}
|
if (task.priority == 6 && !(task.action instanceof IronChestAIOcelotSit))
|
||||||
|
{
|
||||||
|
task.action = new IronChestAIOcelotSit(ocelot, 0.4F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,25 +10,22 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package cpw.mods.ironchest;
|
package cpw.mods.ironchest;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import net.minecraft.src.NetworkManager;
|
||||||
|
import net.minecraft.src.Packet;
|
||||||
|
import net.minecraft.src.Packet250CustomPayload;
|
||||||
|
import net.minecraft.src.TileEntity;
|
||||||
|
import net.minecraft.src.World;
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
import cpw.mods.fml.common.network.IPacketHandler;
|
import cpw.mods.fml.common.network.IPacketHandler;
|
||||||
import cpw.mods.fml.common.network.Player;
|
import cpw.mods.fml.common.network.Player;
|
||||||
|
|
||||||
import net.minecraft.src.NetworkManager;
|
|
||||||
import net.minecraft.src.Packet;
|
|
||||||
import net.minecraft.src.Packet1Login;
|
|
||||||
import net.minecraft.src.Packet250CustomPayload;
|
|
||||||
import net.minecraft.src.TileEntity;
|
|
||||||
import net.minecraft.src.World;
|
|
||||||
|
|
||||||
public class PacketHandler implements IPacketHandler {
|
public class PacketHandler implements IPacketHandler {
|
||||||
@Override
|
@Override
|
||||||
public void onPacketData(NetworkManager network, Packet250CustomPayload packet, Player player) {
|
public void onPacketData(NetworkManager network, Packet250CustomPayload packet, Player player) {
|
||||||
|
|
Loading…
Reference in New Issue