I'm having an odd problem with a couple of machines (well, only one really) that I've added to the game. One is a rock crusher, the other is an immersion tank. The rock crusher is working perfectly, while the immersion tank is having an odd problem. After messing around with the blocks a while, it seems that the problem is in the corresponding TileEntity's updateEntity function. Specifically, when checking to see if the world is remote or not, the rock crusher gets one result whereas the immersion tank gets a different result. I've been looking through the code for all of the files I've made and can't find where the difference between the blocks is at. I thought maybe it was due to how the external textures are being handled by either block (rock crusher is using the vanilla furnace method where the block is replaced with a slightly different block while processing an item, whereas the immersion tank is using a custom renderer), but after modifying the latter to match the former, I'm still having the same problem.
Has this happened to anyone else? Does anyone know how to fix this?
Since I'm not sure where the problem is, I'm including every file even remotely related to the machines.
[spoiler=Block_Rock_Crusher]
package com.trekkiecub.allthethings;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import com.trekkiecub.allthethings.TileEntity_RockCrusher;
public class Block_Rock_Crusher extends BlockContainer {
public IIcon front_on, front_off, top, side;
protected static boolean changing = false;
protected Block_Rock_Crusher(Material p_i45394_1_, boolean working) {
super(p_i45394_1_);
this.changing = working;
}
@Override
public void registerBlockIcons(IIconRegister reg)
{
this.front_on = reg.registerIcon(this.textureName + "_front_on");
this.front_off = reg.registerIcon(this.textureName + "_front_off");
this.top = reg.registerIcon(this.textureName + "_top");
this.side = reg.registerIcon(this.textureName + "_side");
}
@Override
public IIcon getIcon(int dir, int meta)
{
if (meta > 5)
meta = 5;
if (dir == 4 && meta == 0)
{
return (this.lightValue > 0?this.front_on:this.front_off);
}
if (dir == 1)
return this.top;
if (meta == -1 || dir == meta)
{
return (this.lightValue > 0?this.front_on:this.front_off);
}
return this.side;
}
@Override
public void onBlockAdded(World world, int xcoord, int ycoord, int zcoord)
{
super.onBlockAdded(world, xcoord, ycoord, zcoord);
setRotatedMetadata(world, xcoord, ycoord, zcoord);
}
public void onBlockPlacedBy(World world, int xcoord, int ycoord, int zcoord, EntityLivingBase player, ItemStack theBlock)
{
int direction = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
switch (direction)
{
case 0:
world.setBlockMetadataWithNotify(xcoord, ycoord, zcoord, 2, 2);
break;
case 1:
world.setBlockMetadataWithNotify(xcoord, ycoord, zcoord, 5, 2);
break;
case 2:
world.setBlockMetadataWithNotify(xcoord, ycoord, zcoord, 3, 2);
break;
case 3:
world.setBlockMetadataWithNotify(xcoord, ycoord, zcoord, 4, 2);
break;
}
}
private void setRotatedMetadata(World world, int xcoord, int ycoord, int zcoord)
{
if (!world.isRemote)
{
Block north = world.getBlock(xcoord, ycoord, zcoord-1);
Block south = world.getBlock(xcoord, ycoord, zcoord+1);
Block east = world.getBlock(xcoord-1, ycoord, zcoord);
Block west = world.getBlock(xcoord+1, ycoord, zcoord);
byte newMeta = 3;
if (north.func_149730_j() && !south.func_149730_j())
{
newMeta = 3;
}
if (south.func_149730_j() && !north.func_149730_j())
{
newMeta = 2;
}
if (east.func_149730_j() && !west.func_149730_j())
{
newMeta = 5;
}
if (west.func_149730_j() && !east.func_149730_j())
{
newMeta = 4;
}
world.setBlockMetadataWithNotify(xcoord, ycoord, zcoord, newMeta, 2);
}
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int metadata, float a, float b, float c)
{
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (tileEntity == null || player.isSneaking())
return false;
player.openGui("TrekkieCub_AllTheThings", 0, world, x, y, z);
return true;
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int par6)
{
dropItems(world, x, y, z);
super.breakBlock(world, x, y, z, block, par6);
}
private void dropItems(World world, int x, int y, int z)
{
Random rand = new Random();
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (!(tileEntity instanceof IInventory))
{
return;
}
IInventory inventory = (IInventory) tileEntity;
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
ItemStack item = inventory.getStackInSlot(i);
if (item != null && item.stackSize > 0)
{
float randX = rand.nextFloat() * 0.8F + 0.1F;
float randY = rand.nextFloat() * 0.8F + 0.1F;
float randZ = rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, x+randX, y+randY, z+randZ, new ItemStack(item.getItem(), item.stackSize, item.getItemDamage()));
if (item.hasTagCompound())
{
entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy());
}
float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntityInWorld(entityItem);
item.stackSize = 0;
}
}
}
@Override
public TileEntity createNewTileEntity(World var1, int var2) {
// TODO Auto-generated method stub
return new TileEntity_RockCrusher();
}
public static void updateCrusherStatus(boolean turnOn, World world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z);
TileEntity tileEnt = world.getTileEntity(x, y, z);
world.removeTileEntity(x, y, z);
changing = true;
if (turnOn)
{
world.setBlock(x, y, z, mod_TCAllTheThings.dummy_Rock_Crusher);
}
else
{
world.setBlock(x, y, z, mod_TCAllTheThings.Rock_Crusher);
}
changing = false;
world.setBlockMetadataWithNotify(x, y, z, meta, 2);
if (tileEnt != null)
{
tileEnt.validate();
world.setTileEntity(x, y, z, tileEnt);
}
}
}
[spoiler=TileEntity_RockCrusher]
package com.trekkiecub.allthethings;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class TileEntity_RockCrusher extends TileEntity implements IInventory, ISidedInventory {
private ItemStack[] itemStacks;
private int[] slots_top = new int[] {0};
private int[] slots_bottom = new int[] {1,2,3};
private int[] slots_side = new int[] {1,2,3};
private Map crushingList = new HashMap();
public int crushTime;
class crushEntry {
Item out_pri, out_sec, out_tert;
double numResources;
public crushEntry(Item out_pri, Item out_sec, Item out_tert, double numResources)
{
this.out_pri = out_pri;
this.out_sec = out_sec;
this.out_tert = out_tert;
this.numResources = numResources;
}
public void setResources(int num)
{
this.numResources = num;
}
}
public TileEntity_RockCrusher() {
itemStacks = new ItemStack[4];
crushingList.put(Items.diamond_axe, new crushEntry(Items.diamond, mod_TCAllTheThings.Shard_Diamond, mod_TCAllTheThings.Powdered_Diamond, 3));
crushingList.put(Items.diamond_boots, new crushEntry(Items.diamond, mod_TCAllTheThings.Shard_Diamond, mod_TCAllTheThings.Powdered_Diamond, 4));
crushingList.put(Items.diamond_chestplate, new crushEntry(Items.diamond, mod_TCAllTheThings.Shard_Diamond, mod_TCAllTheThings.Powdered_Diamond, );
crushingList.put(Items.diamond_helmet, new crushEntry(Items.diamond, mod_TCAllTheThings.Shard_Diamond, mod_TCAllTheThings.Powdered_Diamond, 5));
crushingList.put(Items.diamond_hoe, new crushEntry(Items.diamond, mod_TCAllTheThings.Shard_Diamond, mod_TCAllTheThings.Powdered_Diamond, 2));
crushingList.put(Items.diamond_horse_armor, new crushEntry(Items.diamond, mod_TCAllTheThings.Shard_Diamond, mod_TCAllTheThings.Powdered_Diamond, 6));
crushingList.put(Items.diamond_leggings, new crushEntry(Items.diamond, mod_TCAllTheThings.Shard_Diamond, mod_TCAllTheThings.Powdered_Diamond, 7));
crushingList.put(Items.diamond_pickaxe, new crushEntry(Items.diamond, mod_TCAllTheThings.Shard_Diamond, mod_TCAllTheThings.Powdered_Diamond, 3));
crushingList.put(Items.diamond_shovel, new crushEntry(Items.diamond, mod_TCAllTheThings.Shard_Diamond, mod_TCAllTheThings.Powdered_Diamond, 1));
crushingList.put(Items.diamond_sword, new crushEntry(Items.diamond, mod_TCAllTheThings.Shard_Diamond, mod_TCAllTheThings.Powdered_Diamond, 2));
crushingList.put(Items.diamond, new crushEntry(null, mod_TCAllTheThings.Shard_Diamond, mod_TCAllTheThings.Powdered_Diamond, 1));
crushingList.put(mod_TCAllTheThings.Shard_Diamond, new crushEntry(null, null, mod_TCAllTheThings.Powdered_Diamond, 0.25));
}
@Override
public int getSizeInventory() {
// TODO Auto-generated method stub
return itemStacks.length;
}
@Override
public ItemStack getStackInSlot(int var1) {
// TODO Auto-generated method stub
return itemStacks[var1];
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
// TODO Auto-generated method stub
ItemStack stack = getStackInSlot(slot);
if (stack != null)
{
if (stack.stackSize <= amount)
{
setInventorySlotContents(slot, null);
}
else
{
stack = stack.splitStack(amount);
if (stack.stackSize == 0)
{
setInventorySlotContents(slot, null);
}
}
}
return stack;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
ItemStack stack = getStackInSlot(slot);
if (stack != null)
{
setInventorySlotContents(slot, null);
}
return stack;
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
itemStacks[slot] = stack;
if (stack != null && stack.stackSize > getInventoryStackLimit())
{
stack.stackSize = getInventoryStackLimit();
}
}
@Override
public String getInventoryName() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean hasCustomInventoryName() {
// TODO Auto-generated method stub
return false;
}
@Override
public int getInventoryStackLimit() {
// TODO Auto-generated method stub
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
// TODO Auto-generated method stub
return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this &&
player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
}
@Override
public void openInventory() {
// TODO Auto-generated method stub
}
@Override
public void closeInventory() {
// TODO Auto-generated method stub
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
switch (slot)
{
case 0: //Input
{
if (crushingList.get(stack.getItem()) != null)
{
return true;
}
else
return false;
}
default:
return false;
}
}
/**
* Returns an integer between 0 and the passed value representing how close the current item is to being completely
* cooked
*/
@SideOnly(Side.CLIENT)
public int getCrushProgressScaled(int p_145953_1_)
{
return this.crushTime * p_145953_1_ / 200;
}
public boolean isWorking()
{
return this.crushTime > 0;
}
@Override
public void updateEntity()
{
if (!this.worldObj.isRemote)
{
if (this.canProcess())
{
this.crushTime++;
if (this.crushTime == 200)
{
this.crushTime = 0;
this.processItem();
Block_Rock_Crusher.updateCrusherStatus(false, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
}
else if (this.crushTime == 1)
{
Block_Rock_Crusher.updateCrusherStatus(true, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
}
}
else
this.crushTime = 0;
}
}
private boolean canProcess()
{
if (this.itemStacks[0] == null)
{
return false;
}
else
{
// Get the crushEntry for the corresponding item in the input slot
crushEntry resultEntry = (crushEntry) crushingList.get(this.itemStacks[0].getItem());
// Return can't crush if the item doesn't have a recipe
if (resultEntry == null) return false;
// Create temporary new resource amounts
int newResourceAmount = (int) (resultEntry.numResources * 4);
if (this.itemStacks[0].getItem().getMaxDamage() != 0)
{
float percentDamaged = (float) this.itemStacks[0].getItemDamage() / this.itemStacks[0].getItem().getMaxDamage();
newResourceAmount = MathHelper.floor_float((1 - percentDamaged) * newResourceAmount);
}
boolean firstPasses, secondPasses, thirdPasses;
if (resultEntry.out_pri == null)
{
firstPasses = true;
}
else
{
if (this.itemStacks[1] == null || (this.itemStacks[1].getItem() == resultEntry.out_pri && this.itemStacks[1].stackSize + (newResourceAmount - newResourceAmount%4)/4 <= this.itemStacks[1].getMaxStackSize()))
{
firstPasses = true;
}
else
return false;
}
if (this.itemStacks[2] == null || resultEntry.out_sec == null)
{
secondPasses = true;
}
else if (this.itemStacks[2].getItem() == resultEntry.out_sec && newResourceAmount + this.itemStacks[2].stackSize <= this.itemStacks[2].getMaxStackSize())
{
secondPasses = true;
}
else
return false;
if (this.itemStacks[3] == null || resultEntry.out_tert == null)
{
thirdPasses = true;
}
else if (this.itemStacks[3].getItem() == resultEntry.out_tert && newResourceAmount + this.itemStacks[3].stackSize <= this.itemStacks[3].getMaxStackSize())
{
thirdPasses = true;
}
else
return false;
return firstPasses && secondPasses && thirdPasses;
}
}
public void processItem()
{
if (this.canProcess())
{
Random rand = new Random();
// Get the crush entry for the corresponding item in the input slot
crushEntry result = ((crushEntry) crushingList.get(this.itemStacks[0].getItem()));
// Create temporary new resource amounts
int newResourceAmount = (int) (result.numResources * 4);
if (this.itemStacks[0].getItem().getMaxDamage() != 0)
{
float percentDamaged = (float) this.itemStacks[0].getItemDamage() / this.itemStacks[0].getItem().getMaxDamage();
newResourceAmount = MathHelper.floor_float((1 - percentDamaged) * newResourceAmount);
}
boolean spawnedPrimary = false;
int chance;
for (int p = 0; p < newResourceAmount; p++)
{
spawnedPrimary = false;
if (p%4 == 0 && result.out_pri != null)
{
chance = rand.nextInt(4);
if (chance == 0)
{
if (this.itemStacks[1] == null)
{
this.itemStacks[1] = new ItemStack(result.out_pri, 1);
}
else
{
this.itemStacks[1].stackSize += 1;
}
p += 3; // This forces an increment of 4 instead of 1
spawnedPrimary = true;
}
}
if (!spawnedPrimary)
{
chance = rand.nextInt(4);
if (chance == 0 && result.out_sec != null)
{
if (this.itemStacks[2] == null)
{
this.itemStacks[2] = new ItemStack(result.out_sec, 1);
}
else
this.itemStacks[2].stackSize += 1;
}
else if (result.out_tert != null)
{
if (this.itemStacks[3] == null)
{
this.itemStacks[3] = new ItemStack(result.out_tert, 1);
}
else
this.itemStacks[3].stackSize += 1;
}
}
}
this.itemStacks[0].stackSize--;
if (this.itemStacks[0].stackSize <= 0)
{
this.itemStacks[0] = null;
}
}
}
@Override
public int[] getAccessibleSlotsFromSide(int par1)
{
return par1 == 0 ? slots_bottom : (par1 == 1 ? slots_top : slots_side);
}
@Override
public boolean canInsertItem(int par1, ItemStack par2ItemStack, int par3)
{
return this.isItemValidForSlot(par1, par2ItemStack);
}
@Override
public boolean canExtractItem(int var1, ItemStack var2, int var3) {
if (var1 == 0 || var3 == 1)
{
return false;
}
return true;
}
}
[spoiler=Container_Rock_Crusher]
package com.trekkiecub.allthethings;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotFurnace;
import net.minecraft.item.ItemStack;
public class Container_RockCrusher extends Container {
protected TileEntity_RockCrusher tileEntity;
int prevCrushTime = 0;
public Container_RockCrusher(InventoryPlayer inventoryPlayer, TileEntity_RockCrusher rcE)
{
tileEntity = rcE;
addSlotToContainer(new Slot(tileEntity, 0, 56, 35));
for (int i = 0; i < 3; i++)
{
addSlotToContainer(new SlotFurnace(inventoryPlayer.player, tileEntity, i+1, 116, 17 + i*18));
}
bindPlayerInventory(inventoryPlayer);
}
@Override
public void addCraftingToCrafters(ICrafting craftingThing)
{
super.addCraftingToCrafters(craftingThing);
craftingThing.sendProgressBarUpdate(this, 0, this.tileEntity.crushTime);
}
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
for (int i = 0; i < this.crafters.size(); ++i)
{
ICrafting icrafting = (ICrafting)this.crafters.get(i);
if (this.prevCrushTime != this.tileEntity.crushTime)
{
icrafting.sendProgressBarUpdate(this, 0, this.tileEntity.crushTime);
}
}
this.prevCrushTime = this.tileEntity.crushTime;
}
@SideOnly(Side.CLIENT)
public void updateProgressBar(int par1, int par2)
{
this.tileEntity.crushTime = par2;
}
@Override
public boolean canInteractWith(EntityPlayer var1) {
// TODO Auto-generated method stub
return tileEntity.isUseableByPlayer(var1);
}
protected void bindPlayerInventory(InventoryPlayer invPlayer)
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 9; j++)
{
addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (int i = 0; i < 9; i++)
{
addSlotToContainer(new Slot(invPlayer, i, 8+i*18, 142));
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot)
{
ItemStack stack = null;
Slot slotObject = (Slot) inventorySlots.get(slot);
if (slotObject != null && slotObject.getHasStack())
{
ItemStack stackInSlot = slotObject.getStack();
stack = stackInSlot.copy();
if (slot < 9)
{
if (!this.mergeItemStack(stackInSlot, 0, 35, true))
{
return null;
}
}
else if (!this.mergeItemStack(stackInSlot, 0, 9, false))
{
return null;
}
if (stackInSlot.stackSize == 0)
{
slotObject.putStack(null);
}
else
{
slotObject.onSlotChanged();
}
if (stackInSlot.stackSize == stack.stackSize)
{
return null;
}
slotObject.onPickupFromSlot(player, stackInSlot);
}
return stack;
}
}
[spoiler=Gui_RockCrusher]
package com.trekkiecub.allthethings;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class Gui_RockCrusher extends GuiContainer {
private TileEntity_RockCrusher tileCrusher;
public Gui_RockCrusher(InventoryPlayer inventoryPlayer, TileEntity_RockCrusher tileRockCrusher) {
super(new Container_RockCrusher(inventoryPlayer, tileRockCrusher));
this.tileCrusher = tileRockCrusher;
}
@Override
protected void drawGuiContainerForegroundLayer(int param1, int param2)
{
fontRendererObj.drawString("Rock Crusher", 8, 6, 4210752);
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize-96+2, 4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2,
int var3) {
this.mc.renderEngine.bindTexture(new ResourceLocation("trekkiecub:textures/gui/rock_crusher.png"));
int x = (this.width - this.xSize)/2;
int y = (this.height - this.ySize)/2;
this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize);
int i1 = this.tileCrusher.getCrushProgressScaled(24);
this.drawTexturedModalRect(x + 79, y + 34, 176, 14, i1 + 1, 16);
FluidStack afluid = new FluidStack(FluidRegistry.WATER, 1000);
mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
GL11.glColor3f(1.0F, 1.0F, 1.0F);
this.drawTexturedModelRectFromIcon(x+5, y+20, afluid.getFluid().getIcon(afluid), 20, 20);
}
}
[spoiler=Block_Immersion_Tank]
package com.trekkiecub.allthethings;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
public class Block_Immersion_Tank extends BlockContainer {
public IIcon front_trans, front_fluid, top, side;
protected Block_Immersion_Tank(Material p_i45386_1_) {
super(p_i45386_1_);
// TODO Auto-generated constructor stub
}
@Override
public void registerBlockIcons(IIconRegister reg)
{
this.front_trans = reg.registerIcon(this.textureName + "_front_transparent");
this.front_fluid = reg.registerIcon(this.textureName + "_front_default");
this.top = reg.registerIcon(this.textureName + "_top");
this.side = reg.registerIcon(this.textureName + "_side");
}
@Override public boolean renderAsNormalBlock()
{
return false;
}
@Override public int getRenderType()
{
return Proxy_Client.immersionTankRenderType;
}
@Override public boolean canRenderInPass(int pass)
{
Proxy_Client.renderPass = pass;
return true;
}
@Override public int getRenderBlockPass() {return 1;}
@Override
public IIcon getIcon(int dir, int meta)
{
if (meta > 5)
meta = 5;
if (dir == 4 && meta == 0)
{
//return (this.lightValue > 0?this.front_on:this.front_off);
return this.front_trans;
}
if (dir == 1)
return this.top;
if (meta == -1 || dir == meta)
{
//return (this.lightValue > 0?this.front_on:this.front_off);
return this.front_trans;
}
return this.side;
}
@Override
public void onBlockAdded(World world, int xcoord, int ycoord, int zcoord)
{
super.onBlockAdded(world, xcoord, ycoord, zcoord);
setRotatedMetadata(world, xcoord, ycoord, zcoord);
}
public void onBlockPlacedBy(World world, int xcoord, int ycoord, int zcoord, EntityLivingBase player, ItemStack theBlock)
{
int direction = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
switch (direction)
{
case 0:
world.setBlockMetadataWithNotify(xcoord, ycoord, zcoord, 2, 2);
break;
case 1:
world.setBlockMetadataWithNotify(xcoord, ycoord, zcoord, 5, 2);
break;
case 2:
world.setBlockMetadataWithNotify(xcoord, ycoord, zcoord, 3, 2);
break;
case 3:
world.setBlockMetadataWithNotify(xcoord, ycoord, zcoord, 4, 2);
break;
}
}
private void setRotatedMetadata(World world, int xcoord, int ycoord, int zcoord)
{
if (!world.isRemote)
{
Block north = world.getBlock(xcoord, ycoord, zcoord-1);
Block south = world.getBlock(xcoord, ycoord, zcoord+1);
Block east = world.getBlock(xcoord-1, ycoord, zcoord);
Block west = world.getBlock(xcoord+1, ycoord, zcoord);
byte newMeta = 3;
if (north.func_149730_j() && !south.func_149730_j())
{
newMeta = 3;
}
if (south.func_149730_j() && !north.func_149730_j())
{
newMeta = 2;
}
if (east.func_149730_j() && !west.func_149730_j())
{
newMeta = 5;
}
if (west.func_149730_j() && !east.func_149730_j())
{
newMeta = 4;
}
world.setBlockMetadataWithNotify(xcoord, ycoord, zcoord, newMeta, 2);
}
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int metadata, float a, float b, float c)
{
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (tileEntity == null || player.isSneaking())
return false;
player.openGui("TrekkieCub_AllTheThings", 1, world, x, y, z);
return true;
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int par6)
{
dropItems(world, x, y, z);
super.breakBlock(world, x, y, z, block, par6);
}
private void dropItems(World world, int x, int y, int z)
{
Random rand = new Random();
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (!(tileEntity instanceof IInventory))
{
return;
}
IInventory inventory = (IInventory) tileEntity;
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
ItemStack item = inventory.getStackInSlot(i);
if (item != null && item.stackSize > 0)
{
float randX = rand.nextFloat() * 0.8F + 0.1F;
float randY = rand.nextFloat() * 0.8F + 0.1F;
float randZ = rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, x+randX, y+randY, z+randZ, new ItemStack(item.getItem(), item.stackSize, item.getItemDamage()));
if (item.hasTagCompound())
{
entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy());
}
float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntityInWorld(entityItem);
item.stackSize = 0;
}
}
}
@Override
public TileEntity createNewTileEntity(World var1, int var2) {
// TODO Auto-generated method stub
return new TileEntity_ImmersionTank();
}
public static void updateTank(World world, int x, int y, int z)
{
TileEntity entity = world.getTileEntity(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
world.removeTileEntity(x, y, z);
world.setBlock(x, y, z, mod_TCAllTheThings.Immersion_Tank);
world.setBlockMetadataWithNotify(x, y, z, meta, 2);
if (entity != null)
{
entity.validate();
world.setTileEntity(x, y, z, entity);
}
world.markBlockForUpdate(x, y, z);
}
}
[spoiler=TileEntity_ImmersionTank]
package com.trekkiecub.allthethings;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import com.trekkiecub.allthethings.TileEntity_RockCrusher.crushEntry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
public class TileEntity_ImmersionTank extends TileEntity implements IInventory, ISidedInventory {
private ItemStack[] itemStacks;
private FluidTank theFluid;
private ArrayList processingEntries = new ArrayList();
private ArrayList fillList = new ArrayList();
private ArrayList drainList = new ArrayList();
public int progress, soakTime;
public boolean fluidToggle = false;
class soakEntry {
ItemStack item_in;
FluidStack fluid_in;
ItemStack item_out;
FluidStack fluid_out;
int num_ticks;
public soakEntry (ItemStack item_in, ItemStack item_out, FluidStack fluid_in, FluidStack fluid_out, int num_ticks)
{
this.item_in = item_in;
this.item_out = item_out;
this.fluid_in = fluid_in;
this.fluid_out = fluid_out;
this.num_ticks = 200;
}
public soakEntry()
{
this.item_in = null;
this.item_out = null;
this.fluid_in = null;
this.fluid_out = null;
this.num_ticks = 200;
}
public ItemStack getItemInput() {return this.item_in;}
public ItemStack getItemOutput() {return this.item_out;}
public FluidStack getFluidInput() {return this.fluid_in;}
public FluidStack getFluidOutput() {return this.fluid_out;}
}
class fillEntry {
ItemStack item_input;
FluidStack fluid_input;
FluidStack fluid_output;
ItemStack item_output;
public fillEntry (ItemStack item_in, ItemStack item_out, FluidStack fluid_out)
{
this.item_input = item_in;
this.item_output = item_out;
this.fluid_input = null;
this.fluid_output = fluid_out;
}
}
class drainEntry {
ItemStack item_input;
FluidStack fluid_input;
FluidStack fluid_output;
ItemStack item_output;
public drainEntry (ItemStack item_in, ItemStack item_out, FluidStack fluid_in)
{
this.item_input = item_in;
this.item_output = item_out;
this.fluid_input = fluid_in;
this.fluid_output = null;
}
}
public TileEntity_ImmersionTank()
{
itemStacks = new ItemStack[3];
theFluid = new FluidTank(1000);
fillList.add(new fillEntry(new ItemStack(Items.water_bucket, 1), new ItemStack(Items.bucket, 1), new FluidStack(FluidRegistry.WATER, 1000)));
processingEntries.add(new soakEntry(new ItemStack(Blocks.cobblestone, 1), new ItemStack(Blocks.mossy_cobblestone, 1), new FluidStack(FluidRegistry.WATER, 1000), null, 200));
}
public FluidStack getFluid()
{
return this.theFluid.getFluid();
}
public void setFluid(FluidStack newFluid)
{
this.theFluid.setFluid(newFluid);
}
@Override public int[] getAccessibleSlotsFromSide(int var1) {
// TODO Auto-generated method stub
return null;
}
@Override public boolean canInsertItem(int var1, ItemStack var2, int var3) {
// TODO Auto-generated method stub
return false;
}
@Override public boolean canExtractItem(int var1, ItemStack var2, int var3) {
// TODO Auto-generated method stub
return false;
}
@Override public int getSizeInventory() {
return itemStacks.length;
}
@Override public ItemStack getStackInSlot(int var1) {
return itemStacks[var1];
}
@Override public ItemStack decrStackSize(int slot, int amount) {
ItemStack stack = getStackInSlot(slot);
if (stack != null)
{
if (stack.stackSize <= amount)
{
setInventorySlotContents(slot, null);
}
else
{
stack = stack.splitStack(amount);
if (stack.stackSize == 0)
{
setInventorySlotContents(slot, null);
}
}
}
return stack;
}
@Override public ItemStack getStackInSlotOnClosing(int slot) {
ItemStack stack = getStackInSlot(slot);
if (stack != null)
{
setInventorySlotContents(slot, null);
}
return stack;
}
@Override public void setInventorySlotContents(int slot, ItemStack stack) {
itemStacks[slot] = stack;
if (stack != null && stack.stackSize > getInventoryStackLimit())
{
stack.stackSize = getInventoryStackLimit();
}
}
@Override public String getInventoryName() {
// TODO Auto-generated method stub
return null;
}
@Override public boolean hasCustomInventoryName() {
// TODO Auto-generated method stub
return false;
}
@Override public int getInventoryStackLimit() { return 64; }
@Override public boolean isUseableByPlayer(EntityPlayer player) {
return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this &&
player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
}
@Override public void openInventory() { }
@Override public void closeInventory() { }
@Override public boolean isItemValidForSlot(int slot, ItemStack stack) {
switch (slot)
{
case 0:
fillEntry fill = null;
// Get the crushEntry for the corresponding item in the input slot
for (int p = 0; p < fillList.size() && fill == null; p++)
{
if (((fillEntry) fillList.get(p)).item_input == this.itemStacks[0])
{
fill = (fillEntry) fillList.get(p);
}
}
// Return can't crush if the item doesn't have a recipe
if (fill == null) return false;
else return true;
case 1:
return true;
case 2:
drainEntry drain = null;
for (int p = 0; p < drainList.size() && drain == null; p++)
{
drainEntry currentEntry = (drainEntry) drainList.get(p);
if (currentEntry.item_input == this.itemStacks[2] && currentEntry.fluid_input == this.theFluid.getFluid())
{
drain = currentEntry;
}
}
if (drain == null) return false;
else return true;
default:
return false;
}
}
@SideOnly(Side.CLIENT)
public int getSoakProgressScaled(int newMax)
{
if (this.soakTime == 0) {return 0;}
return this.progress * newMax / soakTime;
}
@SideOnly(Side.CLIENT)
public int getFluidAmountScaled(int newMax)
{
if (this.theFluid.getFluid() == null)
return 0;
return this.theFluid.getFluidAmount() * newMax / this.theFluid.getCapacity();
}
@Override public void updateEntity()
{
if (!this.worldObj.isRemote)
{
if (this.canProcess())
{
this.progress++;
if (this.progress == soakTime)
{
this.progress = 0;
this.soakTime = 1;
this.processItem();
}
}
else
this.progress = 0;
if (this.canFill())
{
fillTank();
}
if (this.canDrain())
{
drainTank();
}
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
}
private boolean canFill()
{
if (this.itemStacks[0] == null || (this.theFluid.getFluid() != null && this.theFluid.getFluidAmount() != 0))
{
return false;
}
else
{
fillEntry fill = null;
for (int p = 0; p < fillList.size() && fill == null; p++)
{
fillEntry currentEntry = (fillEntry) fillList.get(p);
if (currentEntry.item_input == this.itemStacks[0])
{
fill = currentEntry;
}
}
if (fill == null) return false;
else return true;
}
}
private boolean canDrain()
{
if (this.itemStacks[2] == null || this.theFluid.getFluid() == null || this.theFluid.getFluidAmount() == 0)
{
return false;
}
else
{
drainEntry drain = null;
for (int p = 0; p < drainList.size() && drain == null; p++)
{
drainEntry currentEntry = (drainEntry) drainList.get(p);
if (currentEntry.item_input == this.itemStacks[2] && currentEntry.fluid_input == this.theFluid.getFluid())
{
drain = currentEntry;
}
}
if (drain == null) return false;
else return true;
}
}
private boolean canProcess()
{
if (this.itemStacks[1] == null)
{
return false;
}
else
{
// Get the crushEntry for the corresponding item in the input slot
soakEntry resultEntry = null;
for (int p = 0; p < processingEntries.size() && resultEntry == null; p++)
{
if (((soakEntry) processingEntries.get(p)).getItemInput() == this.itemStacks[1])
{
if (((soakEntry) processingEntries.get(p)).getFluidInput() == this.theFluid.getFluid())
{
resultEntry = (soakEntry) processingEntries.get(p);
}
}
}
// Return can't crush if the item doesn't have a recipe
if (resultEntry == null) return false;
else return true;
}
}
public void fillTank()
{
if (this.canFill())
{
fillEntry fill = null;
for (int p = 0; p < fillList.size() && fill == null; p++)
{
fillEntry currentEntry = (fillEntry) fillList.get(p);
if (currentEntry.item_input == this.itemStacks[0])
{
fill = currentEntry;
}
}
if (fill != null)
{
this.theFluid.setFluid(fill.fluid_output);
this.itemStacks[0] = fill.item_output;
}
}
}
public void drainTank()
{
if (this.canDrain())
{
drainEntry drain = null;
for (int p = 0; p < drainList.size() && drain == null; p++)
{
drainEntry currentEntry = (drainEntry) drainList.get(p);
if (currentEntry.item_input == this.itemStacks[2] && currentEntry.fluid_input == this.theFluid.getFluid())
{
drain = currentEntry;
}
}
if (drain != null)
{
this.theFluid.setFluid(null);
this.itemStacks[0] = drain.item_output;
}
}
}
public void processItem()
{
if (this.canProcess())
{
// Get the correct soak entry for the inputs
soakEntry resultEntry = null;
for (int p = 0; p < processingEntries.size() && resultEntry == null; p++)
{
if (((soakEntry) processingEntries.get(p)).getItemInput() == this.itemStacks[1])
{
if (((soakEntry) processingEntries.get(p)).getFluidInput() == this.theFluid.getFluid())
{
resultEntry = (soakEntry) processingEntries.get(p);
}
}
}
if (resultEntry != null)
{
this.itemStacks[1] = resultEntry.getItemOutput();
this.theFluid.setFluid(resultEntry.getFluidOutput());
}
}
}
}
[spoiler=Container_ImmersionTank]
package com.trekkiecub.allthethings;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class Container_ImmersionTank extends Container{
protected TileEntity_ImmersionTank tileEntity;
int prevProgress = 0;
public Container_ImmersionTank(InventoryPlayer invPlay, TileEntity_ImmersionTank tile)
{
this.tileEntity = tile;
addSlotToContainer(new Slot(tileEntity, 0, 16, 37));
addSlotToContainer(new Slot(tileEntity, 1, 80, 37));
addSlotToContainer(new Slot(tileEntity, 2, 145, 37));
bindPlayerInventory(invPlay);
}
protected void bindPlayerInventory(InventoryPlayer invPlayer)
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 9; j++)
{
addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (int i = 0; i < 9; i++)
{
addSlotToContainer(new Slot(invPlayer, i, 8+i*18, 142));
}
}
@Override public void addCraftingToCrafters(ICrafting craftingThing)
{
super.addCraftingToCrafters(craftingThing);
craftingThing.sendProgressBarUpdate(this, 0, this.tileEntity.progress);
}
@Override public void detectAndSendChanges()
{
super.detectAndSendChanges();
for (int i = 0; i < this.crafters.size(); ++i)
{
ICrafting icrafting = (ICrafting)this.crafters.get(i);
if (this.prevProgress != this.tileEntity.progress)
{
icrafting.sendProgressBarUpdate(this, 0, this.tileEntity.progress);
}
}
this.prevProgress = this.tileEntity.progress;
}
@SideOnly(Side.CLIENT)
public void updateProgressBar(int par1, int par2)
{
this.tileEntity.progress = par2;
}
@Override public boolean canInteractWith(EntityPlayer var1) {
// TODO Auto-generated method stub
return tileEntity.isUseableByPlayer(var1);
}
@Override public ItemStack transferStackInSlot(EntityPlayer player, int slot)
{
ItemStack stack = null;
Slot slotObject = (Slot) inventorySlots.get(slot);
if (slotObject != null && slotObject.getHasStack())
{
ItemStack stackInSlot = slotObject.getStack();
stack = stackInSlot.copy();
if (slot < 3)
{
if (!this.mergeItemStack(stackInSlot, 0, 35, true))
{
return null;
}
}
else if (!this.mergeItemStack(stackInSlot, 0, 9, false))
{
return null;
}
if (stackInSlot.stackSize == 0)
{
slotObject.putStack(null);
}
else
slotObject.onSlotChanged();
if (stackInSlot.stackSize == stack.stackSize)
{
return null;
}
slotObject.onPickupFromSlot(player, stackInSlot);
}
return stack;
}
}
[spoiler=Gui_ImmersionTank]
package com.trekkiecub.allthethings;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
public class Gui_ImmersionTank extends GuiContainer {
private TileEntity_ImmersionTank tileTank;
public Gui_ImmersionTank(InventoryPlayer invPlayer, TileEntity_ImmersionTank tileImmTank)
{
super(new Container_ImmersionTank(invPlayer, tileImmTank));
this.tileTank = tileImmTank;
}
@Override protected void drawGuiContainerForegroundLayer(int param1, int param2)
{
fontRendererObj.drawString("Immersion Tank", 8, 6, 4210752);
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize-96+2, 4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
this.mc.renderEngine.bindTexture(new ResourceLocation("trekkiecub:textures/gui/immersion_tank.png"));
int x = (this.width - this.xSize)/2;
int y = (this.height - this.ySize)/2;
this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize);
// Soak Progress Bar
int startPoint = this.tileTank.getSoakProgressScaled(54);
this.drawTexturedModalRect(x+62, x+69, 2, 176, startPoint+1, 5);
// Fluid
FluidStack fluid = tileTank.getFluid();
IIcon drawThis;
if (fluid == null)
{
drawThis = FluidRegistry.WATER.getStillIcon();
}
else
drawThis = fluid.getFluid().getStillIcon();
mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
GL11.glColor3f(1.0F,1.0F,1.0F);
int rectHeight = this.tileTank.getFluidAmountScaled(37);
this.drawTexturedModelRectFromIcon(x+65, y+27+(37-rectHeight), drawThis, 48, rectHeight); // max 63
this.mc.renderEngine.bindTexture(new ResourceLocation("trekkiecub:textures/gui/immersion_tank.png"));
GL11.glColor3f(1.0F, 1.0F, 1.0F);
this.drawTexturedModalRect(x+79, y+36, 79, 36, 18, 18);
}
}
[spoiler=Render_Immersion_Tank]
package com.trekkiecub.allthethings;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.init.Blocks;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidRegistry;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import com.trekkiecub.allthethings.Block_Immersion_Tank;
public class Render_Immersion_Tank implements ISimpleBlockRenderingHandler {
@Override
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
// TODO Auto-generated method stub
}
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
if (Proxy_Client.renderPass == 0)
{
IIcon newIcon;
TileEntity_ImmersionTank tileEnt = (TileEntity_ImmersionTank) world.getTileEntity(x, y, z);
if (tileEnt.getFluid() == null || tileEnt.getFluid().amount == 0)
{
newIcon = ((Block_Immersion_Tank) block).front_fluid;
}
else
newIcon = tileEnt.getFluid().getFluid().getStillIcon();
renderer.renderFaceXNeg(block, x, y, z, newIcon);
renderer.renderFaceXPos(block, x, y, z, newIcon);
renderer.renderFaceZNeg(block, x, y, z, newIcon);
renderer.renderFaceZPos(block, x, y, z, newIcon);
renderer.renderFaceYNeg(block, x, y, z, newIcon);
renderer.renderFaceYPos(block, x, y, z, newIcon);
//renderer.renderStandardBlock(Blocks.flowing_water, x, y, z);
}
else
{
renderer.renderStandardBlock(mod_TCAllTheThings.Immersion_Tank, x, y, z);
}
return true;
}
@Override
public boolean shouldRender3DInInventory(int modelId) {
// TODO Auto-generated method stub
return false;
}
@Override
public int getRenderId() {
return Proxy_Client.immersionTankRenderType;
}
}
[spoiler=GuiHandler]
package com.trekkiecub.allthethings;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;
public class GuiHandler implements IGuiHandler{
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity tileEntity = world.getTileEntity(x, y, z);
switch (ID)
{
case 0:
return (tileEntity instanceof TileEntity_RockCrusher ? new Container_RockCrusher(player.inventory, (TileEntity_RockCrusher) tileEntity) : null);
case 1:
return (tileEntity instanceof TileEntity_ImmersionTank ? new Container_ImmersionTank(player.inventory, (TileEntity_ImmersionTank) tileEntity) : null);
default:
return null;
}
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity tileEntity = world.getTileEntity(x, y, z);
switch (ID)
{
case 0:
return (tileEntity instanceof TileEntity_RockCrusher ? new Gui_RockCrusher(player.inventory, (TileEntity_RockCrusher) tileEntity) : null);
case 1:
return (tileEntity instanceof TileEntity_ImmersionTank ? new Gui_ImmersionTank(player.inventory, (TileEntity_ImmersionTank) tileEntity) : null);
}
return null;
}
}
[spoiler=Proxy_Client]
package com.trekkiecub.allthethings;
import cpw.mods.fml.client.registry.RenderingRegistry;
public class Proxy_Client extends Proxy_Common {
public static int renderPass;
public static int immersionTankRenderType;
@Override
public void registerRenderThings()
{
immersionTankRenderType = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerEntityRenderingHandler(Entity_Mummy.class, new Render_Mummy(new Model_Mummy(), 0.5f));
RenderingRegistry.registerBlockHandler(new Render_Immersion_Tank());
}
}
[spoiler=Proxy_Common]
package com.trekkiecub.allthethings;
public class Proxy_Common {
public void registerRenderThings() { }
}
[spoiler=Main mod file]
package com.trekkiecub.allthethings;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.biome.BiomeGenBase;
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.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.network.NetworkRegistry;
@Mod(modid="TrekkieCub_AllTheThings", name = "Trekkie Cub's All The Things", version = "alpha")
public class mod_TCAllTheThings {
//
// Create an instance of the mod
//
@Instance("mod_TCAllTheThings")
public static mod_TCAllTheThings instance;
//
// Creative Mode Tab
//
public static CreativeTabs allTheThingsTab = new CreativeTabs("allTheThings"){
@Override
public Item getTabIconItem() {
return Items.emerald;
}
};
//
// Item Declarations
//
public static Item Paper_Bowl, Shard_Diamond, Shard_Stone, Powdered_Diamond, Powdered_Stone, Fried_Egg, Burial_Wraps;
//
// Block Declarations
//
public static Block Rock_Crusher, dummy_Rock_Crusher, Immersion_Tank;
//
// Proxy Definitions
//
@SidedProxy(clientSide = "com.trekkiecub.allthethings.Proxy_Client", serverSide = "com.trekkiecub.allthethings.Proxy_Common")
public static Proxy_Common commonProxy;
public static Proxy_Client clientProxy;
//
// Pre-Initialization Event
//
@EventHandler
public void preInit(FMLPreInitializationEvent e) {
clientProxy = new Proxy_Client();
//
// Constants
//
int ID_Mummy = EntityRegistry.findGlobalUniqueEntityId();
//
// Item Definitions
//
Paper_Bowl = new Item_Paper_Bowl().setCreativeTab(allTheThingsTab).setUnlocalizedName("paper_bowl").setTextureName("trekkiecub:paper_bowl");
Shard_Diamond = new Item_Shard_Diamond();
Shard_Stone = new Item_Shard_Stone().setCreativeTab(allTheThingsTab).setUnlocalizedName("shard_stone").setTextureName("trekkiecub:shard_rock");
Powdered_Diamond = new Item_Powdered_Diamond().setCreativeTab(allTheThingsTab).setUnlocalizedName("powdered_diamond").setTextureName("trekkiecub:powdered_diamond");
Powdered_Stone = new Item_Powdered_Stone().setCreativeTab(allTheThingsTab).setUnlocalizedName("powdered_stone").setTextureName("trekkiecub:powdered_stone");
Fried_Egg = new Item_Fried_Egg(6, 0.6F).setCreativeTab(allTheThingsTab).setUnlocalizedName("fried_egg").setTextureName("trekkiecub:fried_egg");
Burial_Wraps = new Item_Burial_Wraps().setCreativeTab(allTheThingsTab).setUnlocalizedName("burial_wraps").setTextureName("trekkiecub:burial_wraps");
//
// Item Registry
//
GameRegistry.registerItem(Paper_Bowl, "paper_bowl");
GameRegistry.registerItem(Shard_Diamond, "shard_diamond");
GameRegistry.registerItem(Powdered_Diamond, "powdered_diamond");
GameRegistry.registerItem(Powdered_Stone, "powdered_stone");
GameRegistry.registerItem(Shard_Stone, "shard_stone");
GameRegistry.registerItem(Fried_Egg, "fried_egg");
GameRegistry.registerItem(Burial_Wraps, "burial_wraps");
//
// Block Definitions
//
Rock_Crusher = new Block_Rock_Crusher(Material.rock, false).setStepSound(Block.soundTypeStone).setBlockName("block_rock_crusher").setCreativeTab(allTheThingsTab).setBlockTextureName("trekkiecub:rock_crusher");
dummy_Rock_Crusher = new Block_Rock_Crusher(Material.rock, true).setStepSound(Block.soundTypeStone).setBlockName("block_rock_crusher").setBlockTextureName("trekkiecub:rock_crusher").setLightLevel((float)1/15);
Immersion_Tank = new Block_Immersion_Tank(Material.rock).setStepSound(Block.soundTypeStone).setBlockName("block_immersion_tank").setCreativeTab(allTheThingsTab).setBlockTextureName("trekkiecub:immersion_tank");
//
// Block Registry
//
GameRegistry.registerBlock(Rock_Crusher, "block_rock_crusher");
GameRegistry.registerBlock(dummy_Rock_Crusher, "lit_block_rock_crusher");
GameRegistry.registerBlock(Immersion_Tank, "block_immersion_tank");
//
// Entity Registry
//
EntityRegistry.registerGlobalEntityID(Entity_Mummy.class, "Mummy", ID_Mummy);
EntityRegistry.registerModEntity(Entity_Mummy.class, "Mummy", ID_Mummy, this, 80, 1, true);
EntityRegistry.addSpawn(Entity_Mummy.class, 2, 0, 1, EnumCreatureType.monster, BiomeGenBase.desert);
EntityList.entityEggs.put(Integer.valueOf(ID_Mummy), new EntityList.EntityEggInfo(ID_Mummy, 0xe9e5c3, 0xc6c57b));
//
// Crafting Recipes
//
GameRegistry.addRecipe(new ItemStack(Paper_Bowl, 10), "p p", " p ", 'p', Items.paper);
GameRegistry.addRecipe(new ItemStack(Rock_Crusher), "cpc", "p p", "cpc", 'c', Blocks.cobblestone, 'p', Blocks.piston);
GameRegistry.addRecipe(new ItemStack(Items.spawn_egg, 1, 50), "ggg", "geg", "ggg", 'g', Items.gunpowder, 'e', Items.egg);
GameRegistry.addRecipe(new ItemStack(Items.spawn_egg, 1, ID_Mummy), "www", "wew", "www", 'w', Burial_Wraps, 'e', Items.egg);
GameRegistry.addRecipe(new ItemStack(Immersion_Tank), "i i", "ici", "iii", 'i', Items.iron_ingot, 'c', Blocks.chest);
GameRegistry.addShapelessRecipe(new ItemStack(Immersion_Tank), new ItemStack(Blocks.cauldron), new ItemStack(Blocks.chest));
//
// Smelting Recipes
//
GameRegistry.addSmelting(Items.egg, new ItemStack(Fried_Egg), 0);
//
// Proxy Functions
//
clientProxy.registerRenderThings();
}
//
// Initialization Event
//
@EventHandler
public void Init(FMLInitializationEvent e) {
}
//
// Post-Initialization Event
//
@EventHandler
public void postInit(FMLPostInitializationEvent e) {
//
// Network Registry
//
NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler());
}
}