Jump to content

Value over what it should be, but when I exit and enter the GUI again it fixes


tattyseal

Recommended Posts

Hello, so I want my TileEntity to consume items from the chest slots and convert them into the item or block in the top slot, but, when it consumes them it will say 92 or 88 or something random instead of 64 and make more items than it should, but if I right click on the block again the value goes to what it should be.

 

TileEntity

 

 

package org.tattyseal.exchange.tile;

 

import modmuss50.mods.transcraft.TileEntitys.TileBase;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.inventory.IInventory;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.nbt.NBTTagList;

 

import org.tattyseal.exchange.common.ValueConfig;

 

import cpw.mods.fml.common.network.PacketDispatcher;

 

public class TileEnergyExchanger extends TileBase implements IInventory

{

public ItemStack[] items;

 

public int eValue;

public int targetEValue;

 

public static final int firstSlot = 9;

public static final int lastSlot = 62;

 

public TileEnergyExchanger()

{

eValue = 0;

targetEValue = 0;

items = new ItemStack[9*7 + 1];

}

 

@Override

public void updateEntity()

{

super.updateEntity();

PacketDispatcher.sendPacketToAllInDimension(getDescriptionPacket(), worldObj.provider.dimensionId);

 

 

if(getStackInSlot(lastSlot + 1) != null)

{

if(ValueConfig.eValues.containsKey(getStackInSlot(lastSlot + 1).itemID))

{

targetEValue = ValueConfig.eValues.get(getStackInSlot(lastSlot + 1).itemID);

}

else

{

targetEValue = 0;

}

}

else

{

targetEValue = 0;

}

 

for(int slot = firstSlot; slot <= lastSlot - 1; slot++)

{

if(getStackInSlot(slot) != null)

{

if(ValueConfig.eValues.containsKey(getStackInSlot(slot).itemID))

{

ItemStack stack = getStackInSlot(slot);

 

for(int i = 0; i < stack.stackSize; i = i + 1)

{

eValue += ValueConfig.eValues.get(stack.itemID);

decrStackSize(slot, 1);

}

break;

}

else

{

 

}

}

}

 

if(eValue >= targetEValue)

{

if(getStackInSlot(lastSlot + 1) != null)

{

if(getStackInSlot(lastSlot + 1).stackSize != 64)

{

eValue -= targetEValue;

getStackInSlot(lastSlot + 1).stackSize += 1;

}

}

}

}

 

@Override

public int getSizeInventory()

{

return items.length;

}

 

@Override

public ItemStack getStackInSlot(int i)

{

return items;

}

 

@Override

public ItemStack decrStackSize(int slot, int count)

{

ItemStack item = getStackInSlot(slot);

 

if(item != null)

{

if(item.stackSize <= count)

{

setInventorySlotContents(slot, null);

}

else

{

item = item.splitStack(count);

onInventoryChanged();

}

}

 

return item;

}

 

public ItemStack incrStackSize(int slot, int count)

{

ItemStack item = getStackInSlot(slot);

 

if(item != null)

{

if(item.stackSize >= count)

{

setInventorySlotContents(slot, null);

}

else

{

item.stackSize++;

onInventoryChanged();

}

}

 

return item;

}

 

@Override

public ItemStack getStackInSlotOnClosing(int i)

{

return null;

}

 

@Override

public void setInventorySlotContents(int i, ItemStack itemstack)

{

items = itemstack;

 

if(itemstack != null && itemstack.stackSize  > getInventoryStackLimit())

{

itemstack.stackSize = getInventoryStackLimit();

}

 

onInventoryChanged();

}

 

@Override

public String getInvName()

{

return "exchange.exchanger";

}

 

@Override

public boolean isInvNameLocalized()

{

return true;

}

 

@Override

public int getInventoryStackLimit()

{

return 64;

}

 

@Override

public boolean isUseableByPlayer(EntityPlayer entityplayer)

{

return true;

}

 

@Override

public void openChest() {}

 

@Override

public void closeChest() {}

 

@Override

public boolean isItemValidForSlot(int i, ItemStack itemstack)

{

return true;

}

 

@Override

public void writeToNBT(NBTTagCompound nbt)

{

super.writeToNBT(nbt);

NBTTagList nbtItems = new NBTTagList();

 

for(int i = 0; i < getSizeInventory(); i++)

{

ItemStack stack = getStackInSlot(i);

 

if(stack != null)

{

NBTTagCompound item = new NBTTagCompound();

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

stack.writeToNBT(item);

nbtItems.appendTag(item);

}

}

 

nbt.setTag("Items", nbtItems);

}

 

@Override

public void readFromNBT(NBTTagCompound nbt)

{

super.readFromNBT(nbt);

 

NBTTagList items = nbt.getTagList("Items");

 

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

{

NBTTagCompound item = (NBTTagCompound) items.tagAt(i);

int slot = item.getByte("Slot");

 

if(slot >= 0 && slot < getSizeInventory())

{

setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item));

}

}

}

 

@Override

public void writeCustomNBT(NBTTagCompound cmp)

{

super.writeCustomNBT(cmp);

 

cmp.setInteger("current", eValue);

cmp.setInteger("target", targetEValue);

}

 

@Override

public void readCustomNBT(NBTTagCompound cmp)

{

super.readCustomNBT(cmp);

eValue = cmp.getInteger("current");

targetEValue = cmp.getInteger("target");

}

 

}

 

 

 

 

TileBase

 

 

/**

* This class is part of the mod Transcraft.

*

* Transcraft is Open Source but you cant use any code without permission!

*

*/

 

package modmuss50.mods.transcraft.TileEntitys;

 

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.network.INetworkManager;

import net.minecraft.network.packet.Packet;

import net.minecraft.network.packet.Packet132TileEntityData;

import net.minecraft.tileentity.TileEntity;

 

public class TileBase extends TileEntity {

 

@Override

public void writeToNBT(NBTTagCompound par1nbtTagCompound) {

super.writeToNBT(par1nbtTagCompound);

 

writeCustomNBT(par1nbtTagCompound);

}

 

@Override

public void readFromNBT(NBTTagCompound par1nbtTagCompound) {

super.readFromNBT(par1nbtTagCompound);

 

readCustomNBT(par1nbtTagCompound);

}

 

public void writeCustomNBT(NBTTagCompound cmp) {

// NO-OP

}

 

public void readCustomNBT(NBTTagCompound cmp) {

// NO-OP

}

 

@Override

public Packet getDescriptionPacket() {

NBTTagCompound nbttagcompound = new NBTTagCompound();

writeCustomNBT(nbttagcompound);

return new Packet132TileEntityData(xCoord, yCoord, zCoord, -999, nbttagcompound);

}

 

@Override

public void onDataPacket(INetworkManager manager, Packet132TileEntityData packet) {

super.onDataPacket(manager, packet);

readCustomNBT(packet.data);

worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);

}

}

 

 

 

 

GUI

 

 

package org.tattyseal.exchange.gui;

 

import org.tattyseal.exchange.tile.TileEnergyExchanger;

 

import net.minecraft.client.gui.inventory.GuiContainer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.ResourceLocation;

 

public class GuiExchanger extends GuiContainer

{

public TileEnergyExchanger tile;

public InventoryPlayer inv;

 

private static final ResourceLocation guiTex = new ResourceLocation("exchange", "textures/gui/energyExchanger.png");

 

public GuiExchanger(InventoryPlayer inv, TileEntity tile)

{

super(new ContainerExchanger(inv, tile));

xSize = 176;

ySize = 238;

 

this.tile = (TileEnergyExchanger) tile;

this.inv = inv;

}

 

@Override

protected void drawGuiContainerBackgroundLayer(float f, int x, int y)

{

mc.renderEngine.bindTexture(guiTex);

 

drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);

 

if(tile.targetEValue != 0 && tile.eValue != 0)

{

int width = tile.eValue / tile.targetEValue;

 

drawTexturedModalRect(guiLeft + 28, guiTop + 10, 1, 239, 140 / width, 16);

}

 

drawString(mc.fontRenderer, "Target E Value: " + tile.targetEValue, guiLeft + 50, guiTop + 18, 0x000FFF);

drawString(mc.fontRenderer, "Current E Value: : " + tile.eValue, guiLeft + 50, guiTop + 10, 0x000FFF);

}

}

 

 

 

 

Container

 

 

package org.tattyseal.exchange.gui;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.inventory.Container;

import net.minecraft.inventory.Slot;

import net.minecraft.item.ItemStack;

import net.minecraft.tileentity.TileEntity;

 

import org.tattyseal.exchange.tile.TileEnergyExchanger;

 

public class ContainerExchanger extends Container

{

public TileEnergyExchanger tile;

public InventoryPlayer inv;

 

public ContainerExchanger(InventoryPlayer inv, TileEntity tile)

{

super();

this.inv = inv;

this.tile = (TileEnergyExchanger) tile;

 

for(int x = 0; x < 9; x++)

{

addSlotToContainer(new Slot(inv, x, 8 + 18 * x, 214));

}

 

for(int x = 0; x < 9; x++)

{

for(int y = 0; y < 3; y++)

{

addSlotToContainer(new Slot(inv, x + y * 9 + 9, /*X*/ 8 + 18 * x, 72 + y * 18 + 84));

}

}

 

for(int x = 0; x < 9; x++)

{

for(int y = 0; y < 6; y++)

{

addSlotToContainer(new Slot(this.tile, x + y * 9 + 9, 8 + 18 * x, 34 + y * 18));

}

}

 

addSlotToContainer(new Slot(this.tile, 9 * 7, 8, 10));

}

 

@Override

public boolean canInteractWith(EntityPlayer entityplayer)

{

return true;

}

 

@Override

public ItemStack transferStackInSlot(EntityPlayer p, int i)

{

return null;

}

}

 

 

 

 

I cannot see anything wrong! Please Help! :)

Link to comment
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.
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



×
×
  • Create New...

Important Information

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