Fixed ocelots sitting on chests; cleaned up the main mod file
This commit is contained in:
parent
4cec58ab39
commit
895cf66788
|
|
@ -4,11 +4,10 @@ import static net.minecraftforge.common.util.ForgeDirection.DOWN;
|
||||||
import static net.minecraftforge.common.util.ForgeDirection.UP;
|
import static net.minecraftforge.common.util.ForgeDirection.UP;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockContainer;
|
import net.minecraft.block.BlockContainer;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
|
|
@ -17,6 +16,7 @@ import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
|
import net.minecraft.entity.passive.EntityOcelot;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
|
|
@ -24,10 +24,14 @@ import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
import net.minecraft.util.IIcon;
|
import net.minecraft.util.IIcon;
|
||||||
import net.minecraft.util.MathHelper;
|
import net.minecraft.util.MathHelper;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
|
@ -81,8 +85,8 @@ public class BlockIronChest extends BlockContainer {
|
||||||
return IronChestType.makeEntity(metadata);
|
return IronChestType.makeEntity(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
@Override
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
public IIcon getIcon(int i, int j)
|
public IIcon getIcon(int i, int j)
|
||||||
{
|
{
|
||||||
if (j < IronChestType.values().length)
|
if (j < IronChestType.values().length)
|
||||||
|
|
@ -102,27 +106,74 @@ public class BlockIronChest extends BlockContainer {
|
||||||
items.add(stack);
|
items.add(stack);
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int i1, float f1, float f2, float f3)
|
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int i1, float f1, float f2, float f3)
|
||||||
{
|
{
|
||||||
TileEntity te = world.getTileEntity(i, j, k);
|
|
||||||
|
|
||||||
if (te == null || !(te instanceof TileEntityIronChest))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.isSideSolid(i, j + 1, k, ForgeDirection.DOWN))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.isRemote)
|
if (world.isRemote)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
|
IInventory iinventory = chestInventory(world, i, j, k);
|
||||||
|
|
||||||
|
if (iinventory != null && world.getTileEntity(i, j, k) instanceof TileEntityIronChest)
|
||||||
|
player.openGui(IronChest.instance, ((TileEntityIronChest) world.getTileEntity(i, j, k)).getType().ordinal(), world, i, j, k);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IInventory chestInventory(World world, int i, int j, int k)
|
||||||
|
{
|
||||||
|
TileEntity object = (TileEntityIronChest)world.getTileEntity(i, j, k);
|
||||||
|
|
||||||
|
if (object == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else if (world.isSideSolid(i, j + 1, k, DOWN))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else if (isOcelotOnChest(world, i, j, k))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else if (world.getBlock(i - 1, j, k) == this && (world.isSideSolid(i - 1, j + 1, k, DOWN) || isOcelotOnChest(world, i - 1, j, k)))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else if (world.getBlock(i + 1, j, k) == this && (world.isSideSolid(i + 1, j + 1, k, DOWN) || isOcelotOnChest(world, i + 1, j, k)))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else if (world.getBlock(i, j, k - 1) == this && (world.isSideSolid(i, j + 1, k - 1, DOWN) || isOcelotOnChest(world, i, j, k - 1)))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else if (world.getBlock(i, j, k + 1) == this && (world.isSideSolid(i, j + 1, k + 1, DOWN) || isOcelotOnChest(world, i, j, k + 1)))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return (IInventory)object;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isOcelotOnChest(World world, int i, int j, int k)
|
||||||
|
{
|
||||||
|
Iterator iterator = world.getEntitiesWithinAABB(EntityOcelot.class, AxisAlignedBB.getAABBPool().getAABB((double)i, (double)(j + 1), (double)k, (double)(i + 1), (double)(j + 2), (double)(k + 1))).iterator();
|
||||||
|
EntityOcelot entityocelot1;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (!iterator.hasNext())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
EntityOcelot entityocelot = (EntityOcelot)iterator.next();
|
||||||
|
entityocelot1 = (EntityOcelot)entityocelot;
|
||||||
|
}
|
||||||
|
while (!entityocelot1.isSitting());
|
||||||
|
|
||||||
player.openGui(IronChest.instance, ((TileEntityIronChest) te).getType().ordinal(), world, i, j, k);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -218,7 +269,6 @@ public class BlockIronChest extends BlockContainer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
|
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
|
||||||
{
|
{
|
||||||
|
|
@ -265,6 +315,7 @@ public class BlockIronChest extends BlockContainer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final ForgeDirection[] validRotationAxes = new ForgeDirection[] { UP, DOWN };
|
private static final ForgeDirection[] validRotationAxes = new ForgeDirection[] { UP, DOWN };
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ForgeDirection[] getValidRotations(World worldObj, int x, int y, int z)
|
public ForgeDirection[] getValidRotations(World worldObj, int x, int y, int z)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ public enum ChestChangerType {
|
||||||
return this.target.ordinal();
|
return this.target.ordinal();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemChestChanger buildItem(Configuration cfg)
|
public ItemChestChanger buildItem()
|
||||||
{
|
{
|
||||||
item = new ItemChestChanger(this);
|
item = new ItemChestChanger(this);
|
||||||
GameRegistry.registerItem(item, itemName);
|
GameRegistry.registerItem(item, itemName);
|
||||||
|
|
@ -70,11 +70,11 @@ public enum ChestChangerType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void buildItems(Configuration cfg)
|
public static void buildItems()
|
||||||
{
|
{
|
||||||
for (ChestChangerType type : values())
|
for (ChestChangerType type : values())
|
||||||
{
|
{
|
||||||
type.buildItem(cfg);
|
type.buildItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,59 +1,33 @@
|
||||||
package cpw.mods.ironchest;
|
package cpw.mods.ironchest;
|
||||||
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.common.config.Configuration;
|
|
||||||
import org.apache.logging.log4j.Level;
|
|
||||||
import cpw.mods.fml.common.FMLLog;
|
|
||||||
import cpw.mods.fml.common.Mod;
|
import cpw.mods.fml.common.Mod;
|
||||||
import cpw.mods.fml.common.Mod.EventHandler;
|
import cpw.mods.fml.common.Mod.EventHandler;
|
||||||
import cpw.mods.fml.common.Mod.Instance;
|
import cpw.mods.fml.common.Mod.Instance;
|
||||||
import cpw.mods.fml.common.SidedProxy;
|
import cpw.mods.fml.common.SidedProxy;
|
||||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
|
||||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
|
||||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
|
|
||||||
@Mod(modid = "IronChest", name = "Iron Chests", dependencies = "required-after:Forge@[7.0,);required-after:FML@[5.0.5,)")
|
@Mod(modid = "IronChest", name = "Iron Chests", dependencies = "required-after:Forge@[7.0,);required-after:FML@[5.0.5,)")
|
||||||
public class IronChest {
|
public class IronChest {
|
||||||
public static BlockIronChest ironChestBlock;
|
public static BlockIronChest ironChestBlock;
|
||||||
|
|
||||||
@SidedProxy(clientSide = "cpw.mods.ironchest.client.ClientProxy", serverSide = "cpw.mods.ironchest.CommonProxy")
|
@SidedProxy(clientSide = "cpw.mods.ironchest.client.ClientProxy", serverSide = "cpw.mods.ironchest.CommonProxy")
|
||||||
public static CommonProxy proxy;
|
public static CommonProxy proxy;
|
||||||
|
|
||||||
@Instance("IronChest")
|
@Instance("IronChest")
|
||||||
public static IronChest instance;
|
public static IronChest instance;
|
||||||
public static boolean CACHE_RENDER = true;
|
|
||||||
public static boolean OCELOTS_SITONCHESTS = true;
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent event)
|
public void load(FMLInitializationEvent e)
|
||||||
{
|
{
|
||||||
Version.init(event.getVersionProperties());
|
ChestChangerType.buildItems();
|
||||||
event.getModMetadata().version = Version.fullVersionString();
|
|
||||||
Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
|
|
||||||
try
|
|
||||||
{
|
|
||||||
cfg.load();
|
|
||||||
ChestChangerType.buildItems(cfg);
|
|
||||||
CACHE_RENDER = cfg.get(Configuration.CATEGORY_GENERAL, "cacheRenderingInformation", true).getBoolean(true);
|
|
||||||
OCELOTS_SITONCHESTS = cfg.get(Configuration.CATEGORY_GENERAL, "ocelotsSitOnChests", true).getBoolean(true);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
FMLLog.log(Level.ERROR, e, "IronChest has a problem loading its configuration");
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (cfg.hasChanged())
|
|
||||||
cfg.save();
|
|
||||||
}
|
|
||||||
ironChestBlock = new BlockIronChest();
|
ironChestBlock = new BlockIronChest();
|
||||||
GameRegistry.registerBlock(ironChestBlock, ItemIronChest.class, "BlockIronChest");
|
GameRegistry.registerBlock(ironChestBlock, ItemIronChest.class, "BlockIronChest");
|
||||||
PacketHandler.INSTANCE.ordinal();
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
PacketHandler.INSTANCE.ordinal();
|
||||||
public void load(FMLInitializationEvent evt)
|
|
||||||
{
|
|
||||||
for (IronChestType typ : IronChestType.values())
|
for (IronChestType typ : IronChestType.values())
|
||||||
{
|
{
|
||||||
GameRegistry.registerTileEntityWithAlternatives(typ.clazz, "IronChest."+typ.name(), typ.name());
|
GameRegistry.registerTileEntityWithAlternatives(typ.clazz, "IronChest."+typ.name(), typ.name());
|
||||||
|
|
@ -63,16 +37,6 @@ 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());
|
|
||||||
// }
|
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void modsLoaded(FMLPostInitializationEvent evt)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
package cpw.mods.ironchest;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* @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);
|
|
||||||
}
|
|
||||||
*/}
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
package cpw.mods.ironchest;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
import net.minecraft.entity.ai.EntityAIOcelotSit;
|
|
||||||
import net.minecraft.entity.ai.EntityAITasks;
|
|
||||||
import net.minecraft.entity.passive.EntityOcelot;
|
|
||||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
|
||||||
|
|
||||||
public class OcelotsSitOnChestsHandler {
|
|
||||||
@SubscribeEvent
|
|
||||||
public void changeSittingTaskForOcelots(LivingEvent.LivingUpdateEvent evt)
|
|
||||||
{
|
|
||||||
if (evt.entityLiving.ticksExisted < 5 && evt.entityLiving instanceof EntityOcelot)
|
|
||||||
{
|
|
||||||
EntityOcelot ocelot = (EntityOcelot) evt.entityLiving;
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
List<EntityAITasks.EntityAITaskEntry> tasks = ocelot.tasks.taskEntries;
|
|
||||||
|
|
||||||
for (int i = 0; i < tasks.size(); i++)
|
|
||||||
{
|
|
||||||
EntityAITasks.EntityAITaskEntry task = tasks.get(i);
|
|
||||||
if (task.priority == 6 && (task.action instanceof EntityAIOcelotSit) && !(task.action instanceof IronChestAIOcelotSit))
|
|
||||||
{
|
|
||||||
task.action = new IronChestAIOcelotSit(ocelot, 0.4F);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue