Now I am very confused.Do I keep all the other code in my TE and add the class to it? then call world#notifyblockupdate in that class. I am sorry I am not understanding what it is I need to do.
Okay, so I am able to get it synced at the start of the client and when placing an item by adding to the TE
public ItemStack getStack() {
return stack;
}
public void setStack(ItemStack stack)
{
this.stack = stack;
markDirty();
if (worldObj != null)
{
IBlockState state = worldObj.getBlockState(getPos());
worldObj.notifyBlockUpdate(getPos(), state, state, 3);
}
}
@Override
public NBTTagCompound getUpdateTag() {
// getUpdateTag() is called whenever the chunkdata is sent to the
// client. In contrast getUpdatePacket() is called when the tile entity
// itself wants to sync to the client. In many cases you want to send
// over the same information in getUpdateTag() as in getUpdatePacket().
return writeToNBT(new NBTTagCompound());
}
@Override
public SPacketUpdateTileEntity getUpdatePacket() {
// Prepare a packet for syncing our TE to the client. Since we only have to sync the stack
// and that's all we have we just write our entire NBT here. If you have a complex
// tile entity that doesn't need to have all information on the client you can write
// a more optimal NBT here.
NBTTagCompound nbtTag = new NBTTagCompound();
this.writeToNBT(nbtTag);
return new SPacketUpdateTileEntity(getPos(), 1, nbtTag);
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
// Here we get the packet from the server and read it into our client side tile entity
this.readFromNBT(packet.getNbtCompound());
}
and changing the block to
if (te.getStackInSlot(0) == null) {
if (player.getHeldItem(hand) != null) {
// There is no item in the pedestal and the player is holding an item. We move that item
// to the pedestal
te.setInventorySlotContents(0,player.getHeldItem(hand));
te.setStack(player.getHeldItem(hand));
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
// Make sure the client knows about the changes in the player inventory
player.openContainer.detectAndSendChanges();
}
} else
{
// There is a stack in the pedestal. In this case we remove it and try to put it in the
// players inventory if there is room
ItemStack stack = te.getStackInSlot(0);
te.setInventorySlotContents(0,null);
te.setStack(null);
if (!player.inventory.addItemStackToInventory(stack) ) {
// Not possible. Throw item in the world
EntityItem entityItem = new EntityItem(world, pos.getX(), pos.getY()+1, pos.getZ(), stack);
world.spawnEntityInWorld(entityItem);
}
else
{
player.openContainer.detectAndSendChanges();
}
}
but when removing an item from the pedestal it is still not syncing.
So I made a pedestal using a TESR following a tutorial, idea was simple enough, right click to add or remove an item that is then rendered as a tileentity. got it working no problem, I then decide I want to on shift right click have a gui. Got that working but now there is a new problem, if you exit MC or if you right click it doesn't update the state of the rendered TE. So if you open the gui place a sword in the inv it appears on the pedestal, if you then right click removing the sword it still appears rendered above the pedestal. I'm at a loss as to where I went wrong.
I am working on a second furnace that is almost a copy paste of the first furnace. only difference? 2 inputs instead of 1, but for some reason the second furnace will not save NBT data...
public class TEFurnaceCopperAlloy extends TileEntityLockable implements ITickable, ISidedInventory
{
private static final int[] SLOTS_TOP = new int[] {0, 3};
private static final int[] SLOTS_BOTTOM = new int[] {2, 1};
private static final int[] SLOTS_SIDES = new int[] {1};
/** The ItemStacks that hold the items currently being used in the furnace */
private ItemStack[] furnaceItemStacks = new ItemStack[4];
/** The number of ticks that the furnace will keep burning */
private int furnaceBurnTime;
/** The number of ticks that a fresh copy of the currently-burning item would keep the furnace burning for */
private int currentItemBurnTime;
private int cookTime;
private int totalCookTime;
private String furnaceCustomName;
/**
* Returns the number of slots in the inventory.
*/
public int getSizeInventory()
{
return this.furnaceItemStacks.length;
}
/**
* Returns the stack in the given slot.
*/
//@Nullable
public ItemStack getStackInSlot(int index)
{
return this.furnaceItemStacks[index];
}
/**
* Removes up to a specified number of items from an inventory slot and returns them in a new stack.
*/
//@Nullable
public ItemStack decrStackSize(int index, int count)
{
return ItemStackHelper.getAndSplit(this.furnaceItemStacks, index, count);
}
/**
* Removes a stack from the given slot and returns it.
*/
//@Nullable
public ItemStack removeStackFromSlot(int index)
{
return ItemStackHelper.getAndRemove(this.furnaceItemStacks, index);
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
*/
public void setInventorySlotContents(int index, ItemStack stack)
{
/**
* Get the name of this object. For players this returns their username
*/
public String getName()
{
return this.hasCustomName() ? this.furnaceCustomName : "Copper Furnace";
}
/**
* Returns true if this thing is named
*/
public boolean hasCustomName()
{
return this.furnaceCustomName != null && !this.furnaceCustomName.isEmpty();
}
public void setCustomInventoryName(String p_145951_1_)
{
this.furnaceCustomName = p_145951_1_;
}
public static void func_189676_a(DataFixer p_189676_0_)
{
p_189676_0_.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackDataLists("Furnace", new String[] {"Items"}));
}
@Override
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
NBTTagList nbttaglist = compound.getTagList("Items", 10);
this.furnaceItemStacks = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound.getByte("Slot");
if (compound.hasKey("CustomName", 8))
{
this.furnaceCustomName = compound.getString("CustomName");
}
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
compound.setInteger("BurnTime", this.furnaceBurnTime);
compound.setInteger("CookTime", this.cookTime);
compound.setInteger("CookTimeTotal", this.totalCookTime);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.furnaceItemStacks.length; ++i)
{
if (this.furnaceItemStacks != null)
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte)i);
this.furnaceItemStacks.writeToNBT(nbttagcompound);
nbttaglist.appendTag(nbttagcompound);
}
}
compound.setTag("Items", nbttaglist);
if (this.hasCustomName())
{
compound.setString("CustomName", this.furnaceCustomName);
}
return compound;
}
/**
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
*/
public int getInventoryStackLimit()
{
return 64;
}
/**
* Time to cook, lower = faster, default 200
*/
public int getCookTime(ItemStack stack)
{
return 155;
}
/**
* Returns true if the furnace can smelt an item, i.e. has a source item, destination stack isn't full, etc.
*/
private boolean canSmelt()
{
if (this.furnaceItemStacks[0] == null)
{
return false;
}
else
{
ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.furnaceItemStacks[0]);
if (itemstack == null) return false;
if (this.furnaceItemStacks[2] == null) return true;
if (!this.furnaceItemStacks[2].isItemEqual(itemstack)) return false;
int result = furnaceItemStacks[2].stackSize + itemstack.stackSize;
return result <= getInventoryStackLimit() && result <= this.furnaceItemStacks[2].getMaxStackSize(); //Forge BugFix: Make it respect stack sizes properly.
}
}
/**
* Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack
*/
public void smeltItem()
{
if (this.canSmelt())
{
ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.furnaceItemStacks[0]);
if (this.furnaceItemStacks[2] == null)
{
this.furnaceItemStacks[2] = itemstack.copy();
}
else if (this.furnaceItemStacks[2].getItem() == itemstack.getItem())
{
this.furnaceItemStacks[2].stackSize += itemstack.stackSize; // Forge BugFix: Results may have multiple items
}
/**
* Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't
* fuel
*/
public static int getItemBurnTime(ItemStack stack)
{
if (stack == null)
{
return 0;
}
else
{
Item item = stack.getItem();
if (block.getDefaultState().getMaterial() == Material.WOOD)
{
return 300;
}
if (block == Blocks.COAL_BLOCK)
{
return 16000;
}
}
if (item instanceof ItemTool && "WOOD".equals(((ItemTool)item).getToolMaterialName())) return 200;
if (item instanceof ItemSword && "WOOD".equals(((ItemSword)item).getToolMaterialName())) return 200;
if (item instanceof ItemHoe && "WOOD".equals(((ItemHoe)item).getMaterialName())) return 200;
if (item == Items.STICK) return 100;
if (item == Items.COAL) return 1600;
if (item == Items.LAVA_BUCKET) return 20000;
if (item == Item.getItemFromBlock(Blocks.SAPLING)) return 100;
if (item == Items.BLAZE_ROD) return 2400;
return net.minecraftforge.fml.common.registry.GameRegistry.getFuelValue(stack);
}
}
public static boolean isItemFuel(ItemStack stack)
{
/**
* Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't
* fuel
*/
return getItemBurnTime(stack) > 0;
}
/**
* Do not make give this method the name canInteractWith because it clashes with Container
*/
public boolean isUseableByPlayer(EntityPlayer player)
{
return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
}
public void openInventory(EntityPlayer player)
{
}
public void closeInventory(EntityPlayer player)
{
}
/**
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
*/
public boolean isItemValidForSlot(int index, ItemStack stack)
{
if (index == 2)
{
return false;
}
else if (index != 1)
{
return true;
}
else
{
ItemStack itemstack = this.furnaceItemStacks[1];
return isItemFuel(stack) || SlotFurnaceFuel.isBucket(stack) && (itemstack == null || itemstack.getItem() != Items.BUCKET);
}
}
/**
* Returns true if automation can insert the given item in the given slot from the given side.
*/
public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction)
{
return this.isItemValidForSlot(index, itemStackIn);
}
/**
* Returns true if automation can extract the given item in the given slot from the given side.
*/
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction)
{
if (direction == EnumFacing.DOWN && index == 1)
{
Item item = stack.getItem();
public String getGuiID()
{
return "minecraft:furnace";
}
public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
{
return new ContainerFurnace(playerInventory, this);
}
public int getField(int id)
{
switch (id)
{
case 0:
return this.furnaceBurnTime;
case 1:
return this.currentItemBurnTime;
case 2:
return this.cookTime;
case 3:
return this.totalCookTime;
default:
return 0;
}
}
public void setField(int id, int value)
{
switch (id)
{
case 0:
this.furnaceBurnTime = value;
break;
case 1:
this.currentItemBurnTime = value;
break;
case 2:
this.cookTime = value;
break;
case 3:
this.totalCookTime = value;
}
}
public int getFieldCount()
{
return 4;
}
public void clear()
{
for (int i = 0; i < this.furnaceItemStacks.length; ++i)
{
this.furnaceItemStacks = null;
}
}
@Override
public ITextComponent getDisplayName() {
// TODO Auto-generated method stub
return null;
}
@Override
public void markDirty() {
// TODO Auto-generated method stub
}
@Override
public int[] getSlotsForFace(EnumFacing side)
{
return side == EnumFacing.DOWN ? SLOTS_BOTTOM : (side == EnumFacing.UP ? SLOTS_TOP : SLOTS_SIDES);
}
net.minecraftforge.items.IItemHandler handlerTop = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.UP);
net.minecraftforge.items.IItemHandler handlerBottom = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.DOWN);
net.minecraftforge.items.IItemHandler handlerSide = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.WEST);
@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing)
{
if (facing != null && capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
if (facing == EnumFacing.DOWN)
return (T) handlerBottom;
else if (facing == EnumFacing.UP)
return (T) handlerTop;
else
return (T) handlerSide;
return super.getCapability(capability, facing);
}
I am following this tutorial http://modwiki.temporal-reality.com/mw/index.php/Render_Block_TESR_/_OBJ-1.9 and while I can get the pedestal to render, to take my item, and save/ load the nbt the pedestal item does not render and the entity in the pedestal's inv. does not render. any help is greatly appreciated.
Ok, so there was an easy fix, I was not implementing ItemModelProvider but now the call GL11.GL_SMOOTH, GL11.GL_FLAT, and GL11.GL_QUADS are crashing the game.
crash report here: http://pastebin.com/L3ECdbui
OMG. Thank you sooooo much. I got it now.... I was calling Main.proxy.registerItemRenderer(itemblock, 0, name); in the BlockBase class but the furnaces are not extending that class, so I needed to make the same call in the copperFurnace class. Is this the best way to code this or should I be extending the BlockBase class instead of or with the Block class? My BlockBase class extends Block class so I am assuming it would just be easier to extend BlockBase instead of BlockContainer. But I am not sure I understand what you mean when you say I would have to override Block#hasTileEntity(IBlockState)[/i] andBlock#createTileEntity[/i]. Again thank you so much. I know I am a total noob and learning by example may not be the best way but it is what I have got so thank you!
I'm lost, I tried to call ModelLoader.setCustomModelResourceLocation but it doesn't work. where am I suppose to call this? in the block.furnaces.copperFurnace? I also tried Main[/i].proxy.registerItemRenderer(this, 0, name); but it wants to convert the item renderer to type copperFurnace. I'm sorry, I am so very new at this and am still trying to figure everything out. Thank you for your time though, I really appreciate it.
0
I can find it in the world class no problem. but...
This is still giving me errors
0
I am getting the error notifyBlockUpdate is undefined for type World...[/i]
1
1
Have you tried...
0
Now I am very confused.Do I keep all the other code in my TE and add the class to it? then call world#notifyblockupdate in that class. I am sorry I am not understanding what it is I need to do.
0
So do I implement IInventory and IItemHandler and just add the onSlotChanged code to the exsisting code?[/i]
0
Trying to switch to IItemHandler any good resources to learn how to properly implement it?[/i]
0
Where do I call World#notifyBlockUpdate?[/i]
0
Okay, so I am able to get it synced at the start of the client and when placing an item by adding to the TE
public ItemStack getStack() {
return stack;
}
public void setStack(ItemStack stack)
{
this.stack = stack;
markDirty();
if (worldObj != null)
{
IBlockState state = worldObj.getBlockState(getPos());
worldObj.notifyBlockUpdate(getPos(), state, state, 3);
}
}
@Override
public NBTTagCompound getUpdateTag() {
// getUpdateTag() is called whenever the chunkdata is sent to the
// client. In contrast getUpdatePacket() is called when the tile entity
// itself wants to sync to the client. In many cases you want to send
// over the same information in getUpdateTag() as in getUpdatePacket().
return writeToNBT(new NBTTagCompound());
}
@Override
public SPacketUpdateTileEntity getUpdatePacket() {
// Prepare a packet for syncing our TE to the client. Since we only have to sync the stack
// and that's all we have we just write our entire NBT here. If you have a complex
// tile entity that doesn't need to have all information on the client you can write
// a more optimal NBT here.
NBTTagCompound nbtTag = new NBTTagCompound();
this.writeToNBT(nbtTag);
return new SPacketUpdateTileEntity(getPos(), 1, nbtTag);
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
// Here we get the packet from the server and read it into our client side tile entity
this.readFromNBT(packet.getNbtCompound());
}
and changing the block to
if (te.getStackInSlot(0) == null) {
if (player.getHeldItem(hand) != null) {
// There is no item in the pedestal and the player is holding an item. We move that item
// to the pedestal
te.setInventorySlotContents(0,player.getHeldItem(hand));
te.setStack(player.getHeldItem(hand));
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
// Make sure the client knows about the changes in the player inventory
player.openContainer.detectAndSendChanges();
}
} else
{
// There is a stack in the pedestal. In this case we remove it and try to put it in the
// players inventory if there is room
ItemStack stack = te.getStackInSlot(0);
te.setInventorySlotContents(0,null);
te.setStack(null);
if (!player.inventory.addItemStackToInventory(stack) ) {
// Not possible. Throw item in the world
EntityItem entityItem = new EntityItem(world, pos.getX(), pos.getY()+1, pos.getZ(), stack);
world.spawnEntityInWorld(entityItem);
}
else
{
player.openContainer.detectAndSendChanges();
}
}
but when removing an item from the pedestal it is still not syncing.
0
github
logs/fml-client-latest.log\
So I made a pedestal using a TESR following a tutorial, idea was simple enough, right click to add or remove an item that is then rendered as a tileentity. got it working no problem, I then decide I want to on shift right click have a gui. Got that working but now there is a new problem, if you exit MC or if you right click it doesn't update the state of the rendered TE. So if you open the gui place a sword in the inv it appears on the pedestal, if you then right click removing the sword it still appears rendered above the pedestal. I'm at a loss as to where I went wrong.
Pedestal Block Code
Pedestal TE Code
Pedestal TESR
0
I feel so stupid right now... If I had looked at ModTileEntities it would have been staring me in the face... Ugh. Thanks again Choonster!
0
I am working on a second furnace that is almost a copy paste of the first furnace. only difference? 2 inputs instead of 1, but for some reason the second furnace will not save NBT data...
github
package janellope.digicraft.tileentity.furnace;
import janellope.digicraft.block.furnaces.BlockFurnaceCopper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerFurnace;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.inventory.SlotFurnaceFuel;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemTool;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntityLockable;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.datafix.FixTypes;
import net.minecraft.util.datafix.walkers.ItemStackDataLists;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class TEFurnaceCopperAlloy extends TileEntityLockable implements ITickable, ISidedInventory
{
private static final int[] SLOTS_TOP = new int[] {0, 3};
private static final int[] SLOTS_BOTTOM = new int[] {2, 1};
private static final int[] SLOTS_SIDES = new int[] {1};
/** The ItemStacks that hold the items currently being used in the furnace */
private ItemStack[] furnaceItemStacks = new ItemStack[4];
/** The number of ticks that the furnace will keep burning */
private int furnaceBurnTime;
/** The number of ticks that a fresh copy of the currently-burning item would keep the furnace burning for */
private int currentItemBurnTime;
private int cookTime;
private int totalCookTime;
private String furnaceCustomName;
/**
* Returns the number of slots in the inventory.
*/
public int getSizeInventory()
{
return this.furnaceItemStacks.length;
}
/**
* Returns the stack in the given slot.
*/
//@Nullable
public ItemStack getStackInSlot(int index)
{
return this.furnaceItemStacks[index];
}
/**
* Removes up to a specified number of items from an inventory slot and returns them in a new stack.
*/
//@Nullable
public ItemStack decrStackSize(int index, int count)
{
return ItemStackHelper.getAndSplit(this.furnaceItemStacks, index, count);
}
/**
* Removes a stack from the given slot and returns it.
*/
//@Nullable
public ItemStack removeStackFromSlot(int index)
{
return ItemStackHelper.getAndRemove(this.furnaceItemStacks, index);
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
*/
public void setInventorySlotContents(int index, ItemStack stack)
{
boolean flag = stack != null && stack.isItemEqual(this.furnaceItemStacks[index]) && ItemStack.areItemStackTagsEqual(stack, this.furnaceItemStacks[index]);
this.furnaceItemStacks[index] = stack;
if (stack != null && stack.stackSize > this.getInventoryStackLimit())
{
stack.stackSize = this.getInventoryStackLimit();
}
if (index == 0 && !flag)
{
this.totalCookTime = this.getCookTime(stack);
this.cookTime = 0;
this.markDirty();
}
}
/**
* Get the name of this object. For players this returns their username
*/
public String getName()
{
return this.hasCustomName() ? this.furnaceCustomName : "Copper Furnace";
}
/**
* Returns true if this thing is named
*/
public boolean hasCustomName()
{
return this.furnaceCustomName != null && !this.furnaceCustomName.isEmpty();
}
public void setCustomInventoryName(String p_145951_1_)
{
this.furnaceCustomName = p_145951_1_;
}
public static void func_189676_a(DataFixer p_189676_0_)
{
p_189676_0_.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackDataLists("Furnace", new String[] {"Items"}));
}
@Override
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
NBTTagList nbttaglist = compound.getTagList("Items", 10);
this.furnaceItemStacks = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound.getByte("Slot");
if (j >= 0 && j < this.furnaceItemStacks.length)
{
this.furnaceItemStacks[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
}
}
this.furnaceBurnTime = compound.getInteger("BurnTime");
this.cookTime = compound.getInteger("CookTime");
this.totalCookTime = compound.getInteger("CookTimeTotal");
this.currentItemBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
if (compound.hasKey("CustomName", 8))
{
this.furnaceCustomName = compound.getString("CustomName");
}
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
compound.setInteger("BurnTime", this.furnaceBurnTime);
compound.setInteger("CookTime", this.cookTime);
compound.setInteger("CookTimeTotal", this.totalCookTime);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.furnaceItemStacks.length; ++i)
{
if (this.furnaceItemStacks != null)
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte)i);
this.furnaceItemStacks.writeToNBT(nbttagcompound);
nbttaglist.appendTag(nbttagcompound);
}
}
compound.setTag("Items", nbttaglist);
if (this.hasCustomName())
{
compound.setString("CustomName", this.furnaceCustomName);
}
return compound;
}
/**
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
*/
public int getInventoryStackLimit()
{
return 64;
}
/**
* Furnace isBurning
*/
public boolean isBurning()
{
return this.furnaceBurnTime > 0;
}
@SideOnly(Side.CLIENT)
public static boolean isBurning(IInventory inventory)
{
return inventory.getField(0) > 0;
}
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
boolean flag = this.isBurning();
boolean flag1 = false;
if (this.isBurning())
{
--this.furnaceBurnTime;
}
if (!this.worldObj.isRemote)
{
if (this.isBurning() || this.furnaceItemStacks[1] != null && this.furnaceItemStacks[0] != null)
{
if (!this.isBurning() && this.canSmelt())
{
this.furnaceBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
this.currentItemBurnTime = this.furnaceBurnTime;
if (this.isBurning())
{
flag1 = true;
if (this.furnaceItemStacks[1] != null)
{
--this.furnaceItemStacks[1].stackSize;
if (this.furnaceItemStacks[1].stackSize == 0)
{
this.furnaceItemStacks[1] = furnaceItemStacks[1].getItem().getContainerItem(furnaceItemStacks[1]);
}
}
}
}
if (this.isBurning() && this.canSmelt())
{
++this.cookTime;
if (this.cookTime == this.totalCookTime)
{
this.cookTime = 0;
this.totalCookTime = this.getCookTime(this.furnaceItemStacks[0]);
this.smeltItem();
flag1 = true;
}
}
else
{
this.cookTime = 0;
}
}
else if (!this.isBurning() && this.cookTime > 0)
{
this.cookTime = MathHelper.clamp_int(this.cookTime - 2, 0, this.totalCookTime);
}
if (flag != this.isBurning())
{
flag1 = true;
BlockFurnaceCopper.setState(this.isBurning(), this.worldObj, this.pos);
}
}
if (flag1)
{
this.markDirty();
}
}
/**
* Time to cook, lower = faster, default 200
*/
public int getCookTime(ItemStack stack)
{
return 155;
}
/**
* Returns true if the furnace can smelt an item, i.e. has a source item, destination stack isn't full, etc.
*/
private boolean canSmelt()
{
if (this.furnaceItemStacks[0] == null)
{
return false;
}
else
{
ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.furnaceItemStacks[0]);
if (itemstack == null) return false;
if (this.furnaceItemStacks[2] == null) return true;
if (!this.furnaceItemStacks[2].isItemEqual(itemstack)) return false;
int result = furnaceItemStacks[2].stackSize + itemstack.stackSize;
return result <= getInventoryStackLimit() && result <= this.furnaceItemStacks[2].getMaxStackSize(); //Forge BugFix: Make it respect stack sizes properly.
}
}
/**
* Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack
*/
public void smeltItem()
{
if (this.canSmelt())
{
ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.furnaceItemStacks[0]);
if (this.furnaceItemStacks[2] == null)
{
this.furnaceItemStacks[2] = itemstack.copy();
}
else if (this.furnaceItemStacks[2].getItem() == itemstack.getItem())
{
this.furnaceItemStacks[2].stackSize += itemstack.stackSize; // Forge BugFix: Results may have multiple items
}
if (this.furnaceItemStacks[0].getItem() == Item.getItemFromBlock(Blocks.SPONGE) && this.furnaceItemStacks[0].getMetadata() == 1 && this.furnaceItemStacks[1] != null && this.furnaceItemStacks[1].getItem() == Items.BUCKET)
{
this.furnaceItemStacks[1] = new ItemStack(Items.WATER_BUCKET);
}
--this.furnaceItemStacks[0].stackSize;
if (this.furnaceItemStacks[0].stackSize <= 0)
{
this.furnaceItemStacks[0] = null;
}
}
}
/**
* Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't
* fuel
*/
public static int getItemBurnTime(ItemStack stack)
{
if (stack == null)
{
return 0;
}
else
{
Item item = stack.getItem();
if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.AIR)
{
Block block = Block.getBlockFromItem(item);
if (block == Blocks.WOODEN_SLAB)
{
return 150;
}
if (block.getDefaultState().getMaterial() == Material.WOOD)
{
return 300;
}
if (block == Blocks.COAL_BLOCK)
{
return 16000;
}
}
if (item instanceof ItemTool && "WOOD".equals(((ItemTool)item).getToolMaterialName())) return 200;
if (item instanceof ItemSword && "WOOD".equals(((ItemSword)item).getToolMaterialName())) return 200;
if (item instanceof ItemHoe && "WOOD".equals(((ItemHoe)item).getMaterialName())) return 200;
if (item == Items.STICK) return 100;
if (item == Items.COAL) return 1600;
if (item == Items.LAVA_BUCKET) return 20000;
if (item == Item.getItemFromBlock(Blocks.SAPLING)) return 100;
if (item == Items.BLAZE_ROD) return 2400;
return net.minecraftforge.fml.common.registry.GameRegistry.getFuelValue(stack);
}
}
public static boolean isItemFuel(ItemStack stack)
{
/**
* Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't
* fuel
*/
return getItemBurnTime(stack) > 0;
}
/**
* Do not make give this method the name canInteractWith because it clashes with Container
*/
public boolean isUseableByPlayer(EntityPlayer player)
{
return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
}
public void openInventory(EntityPlayer player)
{
}
public void closeInventory(EntityPlayer player)
{
}
/**
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
*/
public boolean isItemValidForSlot(int index, ItemStack stack)
{
if (index == 2)
{
return false;
}
else if (index != 1)
{
return true;
}
else
{
ItemStack itemstack = this.furnaceItemStacks[1];
return isItemFuel(stack) || SlotFurnaceFuel.isBucket(stack) && (itemstack == null || itemstack.getItem() != Items.BUCKET);
}
}
/**
* Returns true if automation can insert the given item in the given slot from the given side.
*/
public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction)
{
return this.isItemValidForSlot(index, itemStackIn);
}
/**
* Returns true if automation can extract the given item in the given slot from the given side.
*/
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction)
{
if (direction == EnumFacing.DOWN && index == 1)
{
Item item = stack.getItem();
if (item != Items.WATER_BUCKET && item != Items.BUCKET)
{
return false;
}
}
return true;
}
public String getGuiID()
{
return "minecraft:furnace";
}
public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
{
return new ContainerFurnace(playerInventory, this);
}
public int getField(int id)
{
switch (id)
{
case 0:
return this.furnaceBurnTime;
case 1:
return this.currentItemBurnTime;
case 2:
return this.cookTime;
case 3:
return this.totalCookTime;
default:
return 0;
}
}
public void setField(int id, int value)
{
switch (id)
{
case 0:
this.furnaceBurnTime = value;
break;
case 1:
this.currentItemBurnTime = value;
break;
case 2:
this.cookTime = value;
break;
case 3:
this.totalCookTime = value;
}
}
public int getFieldCount()
{
return 4;
}
public void clear()
{
for (int i = 0; i < this.furnaceItemStacks.length; ++i)
{
this.furnaceItemStacks = null;
}
}
@Override
public ITextComponent getDisplayName() {
// TODO Auto-generated method stub
return null;
}
@Override
public void markDirty() {
// TODO Auto-generated method stub
}
@Override
public int[] getSlotsForFace(EnumFacing side)
{
return side == EnumFacing.DOWN ? SLOTS_BOTTOM : (side == EnumFacing.UP ? SLOTS_TOP : SLOTS_SIDES);
}
net.minecraftforge.items.IItemHandler handlerTop = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.UP);
net.minecraftforge.items.IItemHandler handlerBottom = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.DOWN);
net.minecraftforge.items.IItemHandler handlerSide = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.WEST);
@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing)
{
if (facing != null && capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
if (facing == EnumFacing.DOWN)
return (T) handlerBottom;
else if (facing == EnumFacing.UP)
return (T) handlerTop;
else
return (T) handlerSide;
return super.getCapability(capability, facing);
}
}
0
I am following this tutorial http://modwiki.temporal-reality.com/mw/index.php/Render_Block_TESR_/_OBJ-1.9 and while I can get the pedestal to render, to take my item, and save/ load the nbt the pedestal item does not render and the entity in the pedestal's inv. does not render. any help is greatly appreciated.
https://github.com/Janellope/DigiCraft
::EDIT::
Ok, so there was an easy fix, I was not implementing ItemModelProvider but now the call GL11.GL_SMOOTH, GL11.GL_FLAT, and GL11.GL_QUADS are crashing the game.
crash report here: http://pastebin.com/L3ECdbui
0
OMG. Thank you sooooo much. I got it now.... I was calling Main.proxy.registerItemRenderer(itemblock, 0, name); in the BlockBase class but the furnaces are not extending that class, so I needed to make the same call in the copperFurnace class. Is this the best way to code this or should I be extending the BlockBase class instead of or with the Block class? My BlockBase class extends Block class so I am assuming it would just be easier to extend BlockBase instead of BlockContainer. But I am not sure I understand what you mean when you say I would have to override Block#hasTileEntity(IBlockState)[/i] andBlock#createTileEntity[/i]. Again thank you so much. I know I am a total noob and learning by example may not be the best way but it is what I have got so thank you!
0
I'm lost, I tried to call ModelLoader.setCustomModelResourceLocation but it doesn't work. where am I suppose to call this? in the block.furnaces.copperFurnace? I also tried Main[/i].proxy.registerItemRenderer(this, 0, name); but it wants to convert the item renderer to type copperFurnace. I'm sorry, I am so very new at this and am still trying to figure everything out. Thank you for your time though, I really appreciate it.