Jump to content

Recommended Posts

Posted

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

}

 

}

 

 

 

Posted

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.

Posted

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.

Posted

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.

Posted

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

Posted

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.

Posted

Trekkie is only modifying variables local to the side's TileEntity in his updateEntity method - the builtin isn't going to synch those values unless it is actually written to NBT, no?

Posted

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.

Posted

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.

Posted

I haven't worked with NBT stuff before, so I'm not sure how to use them.  I'm guessing to get my problem fixed, I need to use the functions Draco mentioned, but is there anything more I need to do?

Posted

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.

Posted

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.

 

 

Posted

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.

Posted

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.

Posted

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

}

   

 

}

 

 

 

Posted
 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.

Posted

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

 

 

Posted

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.

Posted

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.

Posted

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.

Posted

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

 

 

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.