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 java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
|
|
@ -17,6 +16,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;
|
||||
|
|
@ -24,10 +24,14 @@ 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;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
|
|
@ -81,8 +85,8 @@ public class BlockIronChest extends BlockContainer {
|
|||
return IronChestType.makeEntity(metadata);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon(int i, int j)
|
||||
{
|
||||
if (j < IronChestType.values().length)
|
||||
|
|
@ -102,31 +106,78 @@ public class BlockIronChest extends BlockContainer {
|
|||
items.add(stack);
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
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))
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (world.isSideSolid(i, j + 1, k, ForgeDirection.DOWN))
|
||||
public IInventory chestInventory(World world, int i, int j, int k)
|
||||
{
|
||||
TileEntity object = (TileEntityIronChest)world.getTileEntity(i, j, k);
|
||||
|
||||
if (object == null)
|
||||
{
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (world.isRemote)
|
||||
else if (world.isSideSolid(i, j + 1, k, DOWN))
|
||||
{
|
||||
return true;
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void onBlockAdded(World world, int i, int j, int k)
|
||||
{
|
||||
super.onBlockAdded(world, i, j, k);
|
||||
|
|
@ -218,7 +269,6 @@ public class BlockIronChest extends BlockContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@SideOnly(Side.CLIENT)
|
||||
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 };
|
||||
|
||||
@Override
|
||||
public ForgeDirection[] getValidRotations(World worldObj, int x, int y, int z)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public enum ChestChangerType {
|
|||
return this.target.ordinal();
|
||||
}
|
||||
|
||||
public ItemChestChanger buildItem(Configuration cfg)
|
||||
public ItemChestChanger buildItem()
|
||||
{
|
||||
item = new ItemChestChanger(this);
|
||||
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())
|
||||
{
|
||||
type.buildItem(cfg);
|
||||
type.buildItem();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,59 +1,33 @@
|
|||
package cpw.mods.ironchest;
|
||||
|
||||
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.EventHandler;
|
||||
import cpw.mods.fml.common.Mod.Instance;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
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.registry.GameRegistry;
|
||||
|
||||
@Mod(modid = "IronChest", name = "Iron Chests", dependencies = "required-after:Forge@[7.0,);required-after:FML@[5.0.5,)")
|
||||
public class IronChest {
|
||||
public static BlockIronChest ironChestBlock;
|
||||
|
||||
@SidedProxy(clientSide = "cpw.mods.ironchest.client.ClientProxy", serverSide = "cpw.mods.ironchest.CommonProxy")
|
||||
public static CommonProxy proxy;
|
||||
|
||||
@Instance("IronChest")
|
||||
public static IronChest instance;
|
||||
public static boolean CACHE_RENDER = true;
|
||||
public static boolean OCELOTS_SITONCHESTS = true;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
public void load(FMLInitializationEvent e)
|
||||
{
|
||||
Version.init(event.getVersionProperties());
|
||||
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();
|
||||
ChestChangerType.buildItems();
|
||||
|
||||
ironChestBlock = new BlockIronChest();
|
||||
GameRegistry.registerBlock(ironChestBlock, ItemIronChest.class, "BlockIronChest");
|
||||
|
||||
PacketHandler.INSTANCE.ordinal();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void load(FMLInitializationEvent evt)
|
||||
{
|
||||
for (IronChestType typ : IronChestType.values())
|
||||
{
|
||||
GameRegistry.registerTileEntityWithAlternatives(typ.clazz, "IronChest."+typ.name(), typ.name());
|
||||
|
|
@ -63,16 +37,6 @@ public class IronChest {
|
|||
ChestChangerType.generateRecipes();
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
|
||||
proxy.registerRenderInformation();
|
||||
// if (OCELOTS_SITONCHESTS)
|
||||
// {
|
||||
// MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler());
|
||||
// }
|
||||
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