Updated ocelot handling

This commit is contained in:
Taylor Shuler 2014-07-30 13:58:46 -04:00
parent a36beb09c8
commit 6bb69755ab
7 changed files with 396 additions and 429 deletions

View File

@ -26,6 +26,7 @@ repositories {
dirs "repo"
}
}
// IronChest uses git tagging to mark major versions. This sets up the project version to that version data
def versionInfo = getGitVersion()
version = "${versionInfo['IronChest.version']}"
@ -38,11 +39,11 @@ archivesBaseName = "ironchest"
// Setup the forge minecraft plugin data. Specify the preferred forge/minecraft version here
minecraft {
version = "1.7.10-10.13.0.1150"
runDir = "eclipse/assets"
}
// This wrangles the resources for the jar files- stuff like textures and languages
processResources
{
processResources {
// we're omitting the .xcf files - they're development only
exclude '**/*.xcf'
// we only want to do search/replace stuff in mcmod.info, nothing else
@ -74,7 +75,6 @@ processResources
jar {
classifier = 'universal'
version = "${project.minecraft.version}-${project.version}"
}
println "FISHBUM ${jar.version}"
@ -165,8 +165,7 @@ uploadArchives {
}
// This is a special task for pulling the version information from git and the environment (for BUILD_NUMBER)
def getGitVersion()
{
def getGitVersion() {
def out = [:]
// call git command.

View File

@ -14,11 +14,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;
@ -27,6 +26,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;
@ -34,20 +34,20 @@ 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;
public class BlockIronChest extends BlockContainer {
private Random random;
@SideOnly(Side.CLIENT)
private IIcon[][] icons;
public BlockIronChest()
{
super(Material.iron);
@ -91,8 +91,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)
@ -112,27 +112,68 @@ 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)
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
{
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)
{
return true;
}
else
{
IInventory iinventory = chestInventory(world, i, j, k);
if (iinventory != null)
{
player.openGui(IronChest.instance, ((TileEntityIronChest) world.getTileEntity(i, j, k)).getType().ordinal(), world, i, j, k);
}
return true;
}
}
public IInventory chestInventory(World world, int i, int j, int k)
{
TileEntity chest = (TileEntityIronChest)world.getTileEntity(i, j, k);
if (chest == null
|| world.isSideSolid(i, j + 1, k, DOWN)
|| isOcelotMounted(world, i, j, k)
|| world.getBlock(i - 1, j, k) == this && (world.isSideSolid(i - 1, j + 1, k, DOWN)
|| isOcelotMounted(world, i - 1, j, k))
|| world.getBlock(i + 1, j, k) == this && (world.isSideSolid(i + 1, j + 1, k, DOWN)
|| isOcelotMounted(world, i + 1, j, k))
|| world.getBlock(i, j, k - 1) == this && (world.isSideSolid(i, j + 1, k - 1, DOWN)
|| isOcelotMounted(world, i, j, k - 1))
|| world.getBlock(i, j, k + 1) == this && (world.isSideSolid(i, j + 1, k + 1, DOWN)
|| isOcelotMounted(world, i, j, k + 1)))
{
return null;
}
else
{
return (IInventory)chest;
}
}
private static boolean isOcelotMounted(World world, int i, int j, int k)
{
Iterator iterator = world.getEntitiesWithinAABB(EntityOcelot.class, AxisAlignedBB.getBoundingBox((double)i, (double)(j + 1), (double)k, (double)(i + 1), (double)(j + 2), (double)(k + 1))).iterator();
EntityOcelot entityocelot;
do
{
if (!iterator.hasNext())
{
return false;
}
Entity entity = (Entity)iterator.next();
entityocelot = (EntityOcelot)entity;
}
while (!entityocelot.isSitting());
player.openGui(IronChest.instance, ((TileEntityIronChest) te).getType().ordinal(), world, i, j, k);
return true;
}
@ -228,7 +269,6 @@ public class BlockIronChest extends BlockContainer {
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
@ -274,11 +314,10 @@ 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)
{
return validRotationAxes;
return new ForgeDirection[] { UP, DOWN };
}
@Override

View File

@ -12,14 +12,15 @@ 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;
@ -27,12 +28,13 @@ import cpw.mods.fml.common.registry.GameRegistry;
@Mod(modid = "IronChest", name = "Iron Chests", dependencies = "required-after:Forge@[10.10,);required-after:FML@[7.2,)")
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)
@ -45,7 +47,6 @@ public class IronChest {
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)
{
@ -73,16 +74,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)
{
}
}

View File

@ -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);
}
*/}

View File

@ -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);
}
}
}
}
}

View File

@ -9,12 +9,7 @@ package cpw.mods.ironchest;
import java.util.Properties;
public class Version {
private static String major;
private static String minor;
private static String rev;
private static String build;
@SuppressWarnings("unused")
private static String mcversion;
private static String major, minor, rev, build, mcversion;
static void init(Properties properties)
{

View File

@ -18,11 +18,11 @@ import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glRotatef;
import static org.lwjgl.opengl.GL11.glScalef;
import static org.lwjgl.opengl.GL11.glTranslatef;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import net.minecraft.client.model.ModelChest;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
@ -30,18 +30,19 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.primitives.SignedBytes;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.MappableItemStackWrapper;
import cpw.mods.ironchest.TileEntityIronChest;
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
@SuppressWarnings("unused")
private static Map<MappableItemStackWrapper, Integer> renderList = new HashMap<MappableItemStackWrapper, Integer>();
private ModelChest model;
private static Map<IronChestType, ResourceLocation> locations;
static {
Builder<IronChestType, ResourceLocation> builder = ImmutableMap.<IronChestType,ResourceLocation>builder();
for (IronChestType typ : IronChestType.values()) {
@ -49,11 +50,8 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
}
locations = builder.build();
}
private Random random;
@SuppressWarnings("unused")
private RenderBlocks renderBlocks;
private RenderItem itemRenderer;
private static float[][] shifts = { { 0.3F, 0.45F, 0.3F }, { 0.7F, 0.45F, 0.3F }, { 0.3F, 0.45F, 0.7F }, { 0.7F, 0.45F, 0.7F }, { 0.3F, 0.1F, 0.3F },
@ -63,7 +61,6 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
{
model = new ModelChest();
random = new Random();
renderBlocks = new RenderBlocks();
itemRenderer = new RenderItem() {
@Override
public byte getMiniBlockCount(ItemStack stack, byte original) {
@ -176,6 +173,4 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
{
render((TileEntityIronChest) tileentity, x, y, z, partialTick);
}
private ModelChest model;
}