Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Odd world.isRemote difference between two custom machines


Recommended Posts

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, 8));

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());

}

 

}

 

 

 

Link to post
Share on other sites

Well, I looked through your code. the only relevant references to world.isRemote was in your setRotatedMetadata methods. said methods are only called from onBlockAdded. onBlockAdded is only called on serverside, so in your relevant situation, world.isRemote should ALWAYS be false. are you sure you are getting otherwise? if so, then something is very wrong.

If I ever say something stupid, or simply incorrect, please excuse me. I don't know anything about 1.8 modding, and I don't know much about entities either, But I try to help when I can.

Link to post
Share on other sites

As I said, the problem seems to be in TileEntity_ImmersionTank's updateEntity function.  I had a set of statements which would toggle the fluid in the Immersion Tank between water and lava every time the updateEntity function was called, and these statements worked when they were put at the beginning of the updateEntity function, before any other code.  Once they were put in the if (!world.isRemote) block, they stopped working.  So I'm fairly certain that I'm getting true at that point.

Link to post
Share on other sites

I think the change made your TileEntity have the appearance of not working, since unless you have a packet handler notifying the client of changes, the client is going to be unaware of any of the changes made to the TileEntity serverside.

 

Effectively, your updateEntity logic doesn't happen on the client, and unless you have a packet handler to let the client know about these state changes, it will look (from the client perspective) like it isn't working anymore.

Link to post
Share on other sites

I've been trying to implement some kind of packet handling in case this is the issue but I can't find a decent packet handling tutorial anywhere.  I keep finding outdated and contradictory information and I don't know which directions to follow and which ones not to for my particular Minecraft and Forge versions.

 

I have Minecraft 1.7.2, Forge 10.12.1.1060, FML 7.2.156.1060, MCP 9.01-pre

Link to post
Share on other sites

TileEntities already have packet communication built into them.

 

	@Override
public Packet getDescriptionPacket() {
	NBTTagCompound nbtTag = new NBTTagCompound();
	writeToNBT(nbtTag);
	return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbtTag);
}

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
	readFromNBT(packet.func_148857_g());
}

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to post
Share on other sites

And why would you NOT save those variables to NBT?  Do you want them to get reset when you save and exit?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to post
Share on other sites

And why would you NOT save those variables to NBT?  Do you want them to get reset when you save and exit?

Yes, they absolutely should be written to NBT - I'm only commenting on Trekkie's onUpdate method as it currently exists in the top post. (Did you look at it?) I had no way of knowing whether the mod had some kind of external custom packet handler for synching these values not shown in the original post, hence my wording.

 

To recap, for Trekkie's benefit:

- Only side-local fields are being modified

- The TE's NBT isn't being notified of this, (hence the builtin handling Draco mentioned isn't being used)

- There is no custom packet handling synching the values, hence the block has the appearance of "not working" client side

- Therefore you need some kind of packet handling to notify each side of changes.

Link to post
Share on other sites

You will have to implement the read/write to/from NBT methods as well.  NBT isn't hard, just take the nbt and use the getInt or setInt functions (or other types as needed).  You can save any primitive type inside NBT, as well as other NBT tags.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to post
Share on other sites

What about more complex data types, like ItemStacks and FluidStacks?  I seem to be having trouble with those.

 

This is the code I have for my NBT functions so far:

[spoiler=NBT Functions]

    public void readFromNBT(NBTTagCompound tag)

    {

        super.readFromNBT(tag);

        itemStacks[0].readFromNBT(tag.getCompoundTag("slot0Stack"));

        itemStacks[1].readFromNBT(tag.getCompoundTag("slot1Stack"));

        itemStacks[2].readFromNBT(tag.getCompoundTag("slot2Stack"));

        theFluid.readFromNBT(tag.getCompoundTag("fluidStack"));

        progress = tag.getInteger("progress");

    }

 

    public void writeToNBT(NBTTagCompound tag)

    {

    super.writeToNBT(tag);

    tag.setTag("slot0Stack", itemStacks[0].stackTagCompound);

    tag.setTag("slot1Stack", itemStacks[1].stackTagCompound);

    tag.setTag("slot2Stack", itemStacks[2].stackTagCompound);

    tag.setTag("fluidStack", theFluid.getFluid().tag);

    tag.setLong("progress", progress);

    }

 

 

 

Am I doing this completely wrong?

 

Edit: I was having a null pointer exception, but I think I figured it out.

 

Now that I've got the NBT and packet functions added, do I need to call any of them manually?  It seems my updateEntity() function is still not working, so some of the functions aren't being called automatically.

 

 

Link to post
Share on other sites

ItemStack has a writeToNBT method, which returns NBT, which is savable into NBT.

 

Here's how it's usually done.

 

@Override
    public void readFromNBT(NBTTagCompound tc) {
        super.readFromNBT(tc);
        NBTTagList nbttaglist = tc.getTagList("Items", 10);
        inventory = new ItemStack[getSizeInventory()];

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
            int j = nbttagcompound1.getByte("Slot") & 255;

            if (j >= 0 && j < inventory.length)
            {
                inventory[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
            }
        }
    }

    @Override
    public void writeToNBT(NBTTagCompound tc) {
        super.writeToNBT(tc);
        NBTTagList nbttaglist = new NBTTagList();

        for (int i = 0; i < inventory.length; ++i)
        {
            if (inventory[i] != null)
            {
                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                nbttagcompound1.setByte("Slot", (byte)i);
                inventory[i].writeToNBT(nbttagcompound1);
                nbttaglist.appendTag(nbttagcompound1);
            }
        }
    }

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to post
Share on other sites

Are there any functions I have to call manually in my code when things need to get saved and updated?

 

Call manually?  No.*

Implement?  Yes.

 

*Note: There are some functions that are helpful to call manually in certain circumstances, but not technically required.

 

Whenever your TE's data changes (item is added/removed, etc.)

 

if (worldObj != null) {
    worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); //tells the server that the client needs an update
}
markDirty(); //tells the server that a change that will require saving has occurred.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to post
Share on other sites

This is the TileEntity file I have now.  Right now items are not being kept between exiting the world and going back in.  This is the only file that has changed other than registering the tile entity with the main mod file.

 

[spoiler=TileEntity]

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.nbt.NBTTagCompound;

import net.minecraft.nbt.NBTTagList;

import net.minecraft.network.NetworkManager;

import net.minecraft.network.Packet;

import net.minecraft.network.play.server.S35PacketUpdateTileEntity;

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;

 

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

theFluid.setFluid(new FluidStack(FluidRegistry.WATER, 1000));

itemStacks[1] = new ItemStack(Blocks.cobblestone, 1);

 

if (worldObj != null)

{

worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);

}

markDirty();

 

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();

        if (worldObj != null)

        {

        worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);

        }

        markDirty();

    }

   

    }

    else if (this.progress != 0)

    {

    this.progress = 0;

    if (worldObj != null)

    {

    worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);

    }

    markDirty();

    }

    if (this.canFill())

    {

    fillTank();

    if (worldObj != null)

    {

    worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);

    }

    markDirty();

    }

    if (this.canDrain())

    {

    drainTank();

    if (worldObj != null)

    {

    worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);

    }

    markDirty();

    }

   

    }

    }

 

    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());

    }

   

    }

    }

   

    public void readFromNBT(NBTTagCompound tag)

    {

        super.readFromNBT(tag);

        NBTTagList nbttaglist = tag.getTagList("Items", 10);

        itemStacks = new ItemStack[getSizeInventory()];

       

        for (int i = 0; i < nbttaglist.tagCount(); ++i)

        {

        NBTTagCompound tag1 = nbttaglist.getCompoundTagAt(i);

        int j = tag1.getByte("Slot") & 255;

       

        if (j >= 0 && j < itemStacks.length)

        {

        itemStacks[j] = ItemStack.loadItemStackFromNBT(tag1);

        }

        }

    }

 

    public void writeToNBT(NBTTagCompound tag)

    {

    super.writeToNBT(tag);

        NBTTagList nbttaglist = new NBTTagList();

 

        for (int i = 0; i < itemStacks.length; ++i)

        {

            if (itemStacks != null)

            {

                NBTTagCompound nbttagcompound1 = new NBTTagCompound();

                nbttagcompound1.setByte("Slot", (byte)i);

                itemStacks.writeToNBT(nbttagcompound1);

                nbttaglist.appendTag(nbttagcompound1);

            }

        }

    }

   

    @Override

public Packet getDescriptionPacket() {

NBTTagCompound nbtTag = new NBTTagCompound();

writeToNBT(nbtTag);

return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbtTag);

}

 

@Override

public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {

readFromNBT(packet.func_148857_g());

}

   

 

}

 

 

 

Link to post
Share on other sites
 public void writeToNBT(NBTTagCompound tag)
    {
       super.writeToNBT(tag);
        NBTTagList nbttaglist = new NBTTagList();

        for (int i = 0; i < itemStacks.length; ++i)
        {
            if (itemStacks[i] != null)
            {
                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                nbttagcompound1.setByte("Slot", (byte)i);
                itemStacks[i].writeToNBT(nbttagcompound1);
                nbttaglist.appendTag(nbttagcompound1);
            }
        }
    }

 

At what point were you planning on adding

nbttaglist

to

tag

?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to post
Share on other sites

It seems I'm still having some interesting problems.  I was having problems equating item stacks but that has now been resolved.  Fluids are being input into the machine correctly, but when I go to the GUI, the items appear to be invisible.  I can click on the locations where the items are supposed to be at and get the items, but they don't appear in the GUI.  Items are still not being saved when exiting the world.

 

My NBT and Update functions are the only ones that changed

 

[spoiler=NBT and Update functions]

    public void writeToNBT(NBTTagCompound tag)
    {
    	super.writeToNBT(tag);
        NBTTagList nbttaglist = new NBTTagList();

        for (int i = 0; i < itemStacks.length; ++i)
        {
            if (itemStacks[i] != null)
            {
                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                nbttagcompound1.setByte("Slot", (byte)i);
                itemStacks[i].writeToNBT(nbttagcompound1);
                nbttaglist.appendTag(nbttagcompound1);
            }
        }
        tag.setTag("Items", nbttaglist);
        tag.setInteger("progress", progress);
        if (theFluid.getFluid() == null || theFluid.getFluidAmount() == 0)
        {
        	tag.setInteger("FluidID", -1);
        }
        else
        	tag.setInteger("FluidID", theFluid.getFluid().fluidID);
        tag.setInteger("FluidAmount", theFluid.getFluidAmount());
    }

 

 

Link to post
Share on other sites

What is this?

itemStacks.writeToNBT(nbttagcompound1);

 

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to post
Share on other sites

What is this?

itemStacks.writeToNBT(nbttagcompound1);

 

Because he didn't wrap it in a [nobbc]

[/nobbc] tag, the [nobbc][i][/nobbc] got dropped.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to post
Share on other sites

show also your readFromNBT function.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to post
Share on other sites

Sorry about that.  Meant to include that with the update statement if the spoiler thing in the previous post didn't indicate that.

[spoiler=writeNBT]

    public void writeToNBT(NBTTagCompound tag)
    {
    	super.writeToNBT(tag);
        NBTTagList nbttaglist = new NBTTagList();

        for (int i = 0; i < itemStacks.length; ++i)
        {
            if (itemStacks[i] != null)
            {
                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                nbttagcompound1.setByte("Slot", (byte)i);
                itemStacks[i].writeToNBT(nbttagcompound1);
                nbttaglist.appendTag(nbttagcompound1);
            }
        }
        tag.setTag("Items", nbttaglist);
        tag.setInteger("progress", progress);
        if (theFluid.getFluid() == null || theFluid.getFluidAmount() == 0)
        {
        	tag.setInteger("FluidID", -1);
        }
        else
        	tag.setInteger("FluidID", theFluid.getFluid().fluidID);
        tag.setInteger("FluidAmount", theFluid.getFluidAmount());
    }

 

 

[spoiler=ReadNBT]

    public void readFromNBT(NBTTagCompound tag)
    {
        super.readFromNBT(tag);
        NBTTagList nbttaglist = tag.getTagList("Items", 3);
        itemStacks = new ItemStack[getSizeInventory()];
        progress = tag.getInteger("progress");
        if (tag.getInteger("FluidID") >= 0)
        {
        	Fluid storedFluid = FluidRegistry.getFluid(tag.getInteger("FluidID"));
        	int fluidAmt = tag.getInteger("FluidAmount");
            theFluid.setFluid(new FluidStack(storedFluid, fluidAmt));
        }
        
        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
        	NBTTagCompound tag1 = nbttaglist.getCompoundTagAt(i);
        	int j = tag1.getByte("Slot") & 255;
        	
        	if (j >= 0 && j < itemStacks.length)
        	{
        		itemStacks[j] = ItemStack.loadItemStackFromNBT(tag1);
        	}
        }
        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
    }

 

 

Some of the code from updateEntity() was commented out so I could test stuff.  This is what is running.

[spoiler=updateEntity]

    @Override public void updateEntity()
    {
    	if (!this.worldObj.isRemote)
    	{
    		if (this.canFill())
    		{
    			fillTank();
    		}
    		if (theFluid != null && theFluid.getFluid() != null && theFluid.getFluidAmount() > 0)
    		{
    			itemStacks[2] = new ItemStack(Items.cake);
    		}
		if (this.worldObj != null)
		{
			this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
		}
		markDirty();
    	}
}

 

 

Link to post
Share on other sites

Basically this thread has something with container code, so it'll be okay to post here.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • 1.7 is no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • So I downloaded the 1.7.10-Forge10. 13.4.1614-1.7.10 and the MCHeli mod. It all went well when suddenly it said it was shutting down the internal server. It kicked me out of Minecraft and gave me this (scroll down to see it) I restarted my computer, I opened it without the MCHeli mod. But it all ended up the same.   ---- Minecraft Crash Report ---- // Hey, that tickles! Hehehe! Time: 6/24/21 5:12 PM Description: Unexpected error java.lang.IndexOutOfBoundsException     at java.nio.Buffer.checkIndex(Buffer.java:540)     at java.nio.DirectIntBufferU.get(DirectIntBufferU.java:253)     at net.minecraft.client.renderer.RenderGlobal.func_72712_a(RenderGlobal.java:350)     at net.minecraft.client.renderer.RenderGlobal.func_72732_a(RenderGlobal.java:294)     at net.minecraft.client.Minecraft.func_71353_a(Minecraft.java:2216)     at net.minecraft.client.Minecraft.func_71403_a(Minecraft.java:2146)     at net.minecraft.client.network.NetHandlerPlayClient.func_147282_a(NetHandlerPlayClient.java:240)     at net.minecraft.network.play.server.S01PacketJoinGame.func_148833_a(SourceFile:70)     at net.minecraft.network.play.server.S01PacketJoinGame.func_148833_a(SourceFile:13)     at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:212)     at net.minecraft.client.Minecraft.func_71407_l(Minecraft.java:2061)     at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:973)     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:898)     at net.minecraft.client.main.Main.main(SourceFile:148)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)     at net.minecraft.launchwrapper.Launch.main(Launch.java:28) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace:     at java.nio.Buffer.checkIndex(Buffer.java:540)     at java.nio.DirectIntBufferU.get(DirectIntBufferU.java:253)     at net.minecraft.client.renderer.RenderGlobal.func_72712_a(RenderGlobal.java:350)     at net.minecraft.client.renderer.RenderGlobal.func_72732_a(RenderGlobal.java:294)     at net.minecraft.client.Minecraft.func_71353_a(Minecraft.java:2216)     at net.minecraft.client.Minecraft.func_71403_a(Minecraft.java:2146)     at net.minecraft.client.network.NetHandlerPlayClient.func_147282_a(NetHandlerPlayClient.java:240)     at net.minecraft.network.play.server.S01PacketJoinGame.func_148833_a(SourceFile:70)     at net.minecraft.network.play.server.S01PacketJoinGame.func_148833_a(SourceFile:13)     at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:212) -- Affected level -- Details:     Level name: MpServer     All players: 0 total; []     Chunk stats: MultiplayerChunkCache: 0, 0     Level seed: 0     Level generator: ID 00 - default, ver 1. Features enabled: false     Level generator options:      Level spawn location: World: (8,64,8), Chunk: (at 8,4,8 in 0,0; contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)     Level time: 0 game time, 0 day time     Level dimension: 0     Level storage version: 0x00000 - Unknown?     Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)     Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false     Forced entities: 0 total; []     Retry entities: 0 total; []     Server brand: ~~ERROR~~ NullPointerException: null     Server type: Integrated singleplayer server Stacktrace:     at net.minecraft.client.multiplayer.WorldClient.func_72914_a(WorldClient.java:373)     at net.minecraft.client.Minecraft.func_71396_d(Minecraft.java:2444)     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:927)     at net.minecraft.client.main.Main.main(SourceFile:148)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)     at net.minecraft.launchwrapper.Launch.main(Launch.java:28) -- System Details -- Details:     Minecraft Version: 1.7.10     Operating System: Windows 10 (amd64) version 10.0     Java Version: 1.8.0_51, Oracle Corporation     Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation     Memory: 205831808 bytes (196 MB) / 536870912 bytes (512 MB) up to 2147483648 bytes (2048 MB)     JVM Flags: 8 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xmx2G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M     AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used     IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95     FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1614 4 mods loaded, 4 mods active     States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored     UCHIJAAAA    mcp{9.05} [Minecraft Coder Pack] (minecraft.jar)      UCHIJAAAA    FML{7.10.99.99} [Forge Mod Loader] (forge-1.7.10-10.13.4.1614-1.7.10.jar)      UCHIJAAAA    Forge{10.13.4.1614} [Minecraft Forge] (forge-1.7.10-10.13.4.1614-1.7.10.jar)      UCHIJAAAA    mcheli{1.0.3} [MC Helicopter] (mcheli)      GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.6.0 NVIDIA 462.30' Renderer: 'GeForce RTX 2080 Ti/PCIe/SSE2'     Launched Version: 1.7.10-Forge10.13.4.1614-1.7.10     LWJGL: 2.9.1     OpenGL: GeForce RTX 2080 Ti/PCIe/SSE2 GL version 4.6.0 NVIDIA 462.30, NVIDIA Corporation     GL Caps: Using GL 1.3 multitexturing. Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported. Anisotropic filtering is supported and maximum anisotropy is 16. Shaders are available because OpenGL 2.1 is supported.     Is Modded: Definitely; Client brand changed to 'fml,forge'     Type: Client (map_client.txt)     Resource Packs: []     Current Language: English (US)     Profiler Position: N/A (disabled)     Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used     Anisotropic Filtering: Off (1)
    • 1.12 is no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • I can't seem to find any QNAP server packages for Minecraft Forge 1.12.2. I'm very inexperienced in this field and would be extremely grateful if anyone would provide a way for me to run a server on my NAS, which runs Linux QNAP. If to help me more information is required, then i'll be more than glad to provide it.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.