Jump to content

[1.7.10] [SOLVED] Custom Block Renderer Not Updating Block


TrekkieCub314

Recommended Posts

So I have a machine block that has textures for when the machine is running and when it is not.  Rather than use two separate blocks to represent these states like the vanilla furnace does, I use a custom block renderer that checks an integer in the block's corresponding tile entity to accomplish this.  It works for the most part, except that the block's texture won't update unless I break a different block (tall grass, dirt, etc).  It seems like it's a really basic fix, but I'm not sure what I need to add.

 

I've included all the classes relevant to the block in case any of them need to be modified.

 

package com.trekkiecub.hodgepodge.init;

import com.trekkiecub.hodgepodge.mod_TrekkieCubHodgePodge;
import com.trekkiecub.hodgepodge.proxy.Proxy_Client;

import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;

public class Block_Slicer extends Block_Machine{

protected Block_Slicer(Material p_i45386_1_) {
	super(p_i45386_1_);
	// TODO Auto-generated constructor stub
}

@Override public int getRenderType()
{
	return Proxy_Client.renderType_Slicer;
}

@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(mod_TrekkieCubHodgePodge.MODID, 0, world, x, y, z);
	return true;
}

@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
	// TODO Auto-generated method stub
	return new TileEntity_Slicer();
}

}

 

package com.trekkiecub.hodgepodge.init;

import java.util.Random;

import com.trekkiecub.hodgepodge.proxy.Proxy_Client;

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

public class Block_Machine extends BlockContainer {
public IIcon front_on, front_off, front, top, side;

@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.front = reg.registerIcon("trekkiecub_techythings:invisible");
	this.top = reg.registerIcon(this.textureName + "_top");
	this.side = reg.registerIcon(this.textureName + "_side");
}

@Override public boolean renderAsNormalBlock()
{
	return false;
}

@Override public boolean canRenderInPass(int pass)
{
	Proxy_Client.renderPass = pass;
	return true;
}

@Override
public void onBlockAdded(World world, int xcoord, int ycoord, int zcoord)
{
	super.onBlockAdded(world, xcoord, ycoord, zcoord);
	setRotatedMetadata(world, xcoord, ycoord, zcoord);
	System.out.println("X: " + xcoord + ", Y: " + ycoord + ", Z: " + 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 IIcon getIcon(int dir, int meta)
{

	if (meta > 5)
		meta = 5;

	if (dir == 4 && meta == 0)
	{
		return this.front;
	}
	else if (meta == -1)
	{
		return this.front_off;
	}
	else if (meta == -2)
	{
		return this.front_on;
	}
	if (dir == 1)
		return this.top;
	if (dir == meta)
	{
		return this.front;
	}

	return this.side;
}

@Override public int getRenderBlockPass() {return 1;}

protected Block_Machine(Material p_i45386_1_) {
	super(p_i45386_1_);
	// TODO Auto-generated constructor stub
}

@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 p_149915_1_, int p_149915_2_) {
	// TODO Auto-generated method stub
	return null;
}

}

 

package com.trekkiecub.hodgepodge.init;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
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;

public class TileEntity_Slicer extends TileEntity implements IInventory{
private ItemStack[] itemStacks;
private Map recipeList = new HashMap();
public int processTime;
public final int TICKS_DONE = 100;

class recipeEntry
{
	Item output_one, output_two;
	double quantity;

	public recipeEntry(Item output_one, Item output_two, double quantity)
	{
		this.output_one = output_one;
		this.output_two = output_two;
		this.quantity = quantity;
	}
	public void setQuantity(double quant)
	{
		this.quantity = quant;
	}
}

public TileEntity_Slicer()
{
	itemStacks = new ItemStack[3];

	recipeList.put(Items.iron_ingot, new recipeEntry(ItemInit.Half_Ingot_Iron, ItemInit.Half_Ingot_Iron, 1));
	recipeList.put(ItemInit.Half_Ingot_Iron, new recipeEntry(ItemInit.Quarter_Ingot_Iron, ItemInit.Quarter_Ingot_Iron, 1));
}

@Override
public int getSizeInventory() {
	return itemStacks.length;
}

@Override
public ItemStack getStackInSlot(int slot) {
	if (slot < 0 || slot >= this.getSizeInventory())
        return null;
    return this.itemStacks[slot];
}

@Override
public ItemStack decrStackSize(int slot, int amount) {
	ItemStack stack = getStackInSlot(slot);
	if (stack != null)
	{
		if (stack.stackSize <= amount)
		{
			setInventorySlotContents(slot, null);
			markDirty();
		}
		else
		{
			stack = stack.splitStack(amount);
			if(stack.stackSize == 0)
			{
				setInventorySlotContents(slot, null);
			}
			this.markDirty();
		}
	}
	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 (slot < 0 || slot >= this.getSizeInventory())
	{
		return;
	}
	if (stack != null && stack.stackSize > getInventoryStackLimit())
	{
		stack.stackSize = getInventoryStackLimit();
	}

	if (stack != null && stack.stackSize == 0)
	{
		stack = null;
	}
	this.itemStacks[slot] = stack;
	this.markDirty();
}

@Override
public String getInventoryName() {
	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() {
	// 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:
		{
			return (recipeList.get(stack.getItem()) != null);
		}
		default: return false;
	}
}

@SideOnly(Side.CLIENT)
public int getProgressScaled(int somenum)
{
	return this.processTime * somenum / TICKS_DONE;
}

public boolean isWorking() {return this.processTime > 0;}

public void updateEntity()
{
	if (!this.worldObj.isRemote)
    	{
    		if (this.canProcess())
    		{
    			this.processTime++;
    			
    			if (this.processTime >= TICKS_DONE)
    			{
    				this.processTime = 0;
    				this.processItem();
    			}
    			worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
    			markDirty();
    		}
    		else
    		{
    			this.processTime = 0;
    			worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
    			markDirty();
    		}

    	}
    	super.updateEntity();
}

private boolean canProcess()
    {
    	if (this.itemStacks[0] == null)
    	{
    		return false;
    	}
    	else
    	{
    		// Get the crushEntry for the corresponding item in the input slot
    		recipeEntry resultEntry = (recipeEntry) recipeList.get(this.itemStacks[0].getItem());
    		
    		// Return can't crush if the item doesn't have a recipe
    		if (resultEntry == null) return false;
    		
    		boolean firstPasses, secondPasses, thirdPasses;
    		
    		if (this.itemStacks[1] == null || resultEntry.output_two == null)
    		{
    			firstPasses = true;
    		}
    		else if (this.itemStacks[1].getItem() == resultEntry.output_two && this.itemStacks[1].stackSize + 1 <= this.itemStacks[1].getMaxStackSize())
    		{
    			firstPasses = true;
    		}
    		else
    		{
    			return false;
    		}
    		
    		if (this.itemStacks[2] == null || resultEntry.output_two == null)
    		{
    			secondPasses = true;
    		}
    		else if (this.itemStacks[2].getItem() == resultEntry.output_two && 1 + this.itemStacks[2].stackSize <= this.itemStacks[2].getMaxStackSize())
    		{
    			secondPasses = true;
    		}
    		else
    		{
    			return false;
    		}
    		
    		
       		return firstPasses && secondPasses;
    	}
    }

    public void processItem()
    {
    	if (this.canProcess())
    	{
    		Random rand = new Random();
    		// Get the crush entry for the corresponding item in the input slot
    		recipeEntry result = ((recipeEntry) recipeList.get(this.itemStacks[0].getItem()));
    		
    		if (result.output_one != null)
    		{
    			if (this.itemStacks[1] == null)
    			{
    				this.itemStacks[1] = new ItemStack(result.output_one, 1);
    			}
    			else
    			{
    				this.itemStacks[1].stackSize += 1;
    			}
    		}
    		if (result.output_two != null)
    		{
    			if (this.itemStacks[2] == null)
    			{
    				this.itemStacks[2] = new ItemStack(result.output_two, 1);
    			}
    			else
    			{
    				this.itemStacks[2].stackSize += 1;
    			}
    		}
    		
    		this.itemStacks[0].stackSize--;
    		if (this.itemStacks[0].stackSize <= 0)
    		{
    			this.itemStacks[0] = null;
    		}
    		
    		
    	}
    }

    @Override
    public void readFromNBT(NBTTagCompound tag)
    {
        super.readFromNBT(tag);
        NBTTagList nbttaglist = tag.getTagList("Items", 10);
        this.processTime = tag.getInteger("progress");
        
        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
        	NBTTagCompound tag1 = nbttaglist.getCompoundTagAt(i);
        	int j = tag1.getByte("Slot") & 255;
        	
        	setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(tag1));
        }
        
    }

    @Override
    public void writeToNBT(NBTTagCompound tag)
    {
        super.writeToNBT(tag);
    	tag.setInteger("progress", this.processTime);
    	
        NBTTagList nbttaglist = new NBTTagList();

        for (int i = 0; i < getSizeInventory(); ++i)
        {
            if (getStackInSlot(i) != null)
            {
                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                nbttagcompound1.setByte("Slot", (byte)i);
                getStackInSlot(i).writeToNBT(nbttagcompound1);
                nbttaglist.appendTag(nbttagcompound1);
            }
        }
        tag.setTag("Items", nbttaglist);
    }
    
    @Override
    public Packet getDescriptionPacket()
    {
        return null;
    }
    
    @Override
    public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
    {
    }

}

 


package com.trekkiecub.hodgepodge.rendering;

import org.lwjgl.opengl.GL11;

import com.trekkiecub.hodgepodge.init.BlockInit;
import com.trekkiecub.hodgepodge.init.Block_Slicer;
import com.trekkiecub.hodgepodge.init.TileEntity_Slicer;
import com.trekkiecub.hodgepodge.proxy.Proxy_Client;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;

public class Render_Slicer implements ISimpleBlockRenderingHandler {

@Override
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
	Tessellator tessellator = Tessellator.instance;
	block.setBlockBoundsForItemRender();
        renderer.setRenderBoundsFromBlock(block);
        GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
        GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
        tessellator.startDrawingQuads();
        tessellator.setNormal(0.0F, -1.0F, 0.0F);
        renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 0, 3));
        tessellator.draw();
        
        tessellator.startDrawingQuads();
        tessellator.setNormal(0.0F, 1.0F, 0.0F);
        renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 1, 3));
        tessellator.draw();
        
        tessellator.startDrawingQuads();
        tessellator.setNormal(0.0F, 0.0F, -1.0F);
        renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 2, 3));
        tessellator.draw();
        tessellator.startDrawingQuads();
        tessellator.setNormal(0.0F, 0.0F, 1.0F);
        renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 3, 0));
        tessellator.draw();
        tessellator.startDrawingQuads();
        tessellator.setNormal(-1.0F, 0.0F, 0.0F);
        renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 4, -1));
        tessellator.draw();
        tessellator.startDrawingQuads();
        tessellator.setNormal(1.0F, 0.0F, 0.0F);
        renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 5, 3));
        tessellator.draw();
        GL11.glTranslatef(0.5F, 0.5F, 0.5F);
}

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId,
		RenderBlocks renderer) {
	if (Proxy_Client.renderPass == 0)
	{
		TileEntity_Slicer tileEnt = (TileEntity_Slicer) world.getTileEntity(x, y, z);
		IIcon newIcon;

		if (tileEnt.processTime > 0)
		{
			newIcon = ((Block_Slicer) block).front_on;
		}
		else
			newIcon = ((Block_Slicer) block).front_off;


		GL11.glColor3f(1.0F,1.0F,1.0F);
		Tessellator tess = Tessellator.instance;
		tess.setColorOpaque_F(1.0F, 1.0F, 1.0F);
		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(BlockInit.Machine_Slicer, x, y, z);
	}

	return true;
}

@Override
public boolean shouldRender3DInInventory(int modelId) {
	return true;
}

@Override
public int getRenderId() {
	return Proxy_Client.renderType_Slicer;
}

}

 

package com.trekkiecub.hodgepodge.rendering;

import com.trekkiecub.hodgepodge.init.TileEntity_Slicer;

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_Slicer extends Container{
protected TileEntity_Slicer tileEntity;
int prevProcessTime = 0;

public Container_Slicer(InventoryPlayer inventoryPlayer, TileEntity_Slicer rcE)
{
	tileEntity = rcE;
	addSlotToContainer(new Slot(tileEntity, 0, 56, 35));
	addSlotToContainer(new SlotFurnace(inventoryPlayer.player, tileEntity, 1, 116, 26));
	addSlotToContainer(new SlotFurnace(inventoryPlayer.player, tileEntity, 2, 116, 44));

	bindPlayerInventory(inventoryPlayer);
}

@Override
public void addCraftingToCrafters(ICrafting craftingThing)
{
	super.addCraftingToCrafters(craftingThing);
	craftingThing.sendProgressBarUpdate(this, 0, this.tileEntity.processTime);
}

@Override
public void detectAndSendChanges()
{
	super.detectAndSendChanges();

	for (int i = 0; i < this.crafters.size(); ++i)
        {
            ICrafting icrafting = (ICrafting)this.crafters.get(i);

            if (this.prevProcessTime != this.tileEntity.processTime)
            {
            	icrafting.sendProgressBarUpdate(this, 0, this.tileEntity.processTime);
            }
        }
	this.prevProcessTime = this.tileEntity.processTime;

}

@SideOnly(Side.CLIENT)
    public void updateProgressBar(int par1, int par2)
    {
        this.tileEntity.processTime = par2;

    }

@Override
public boolean canInteractWith(EntityPlayer player) {
	return tileEntity.isUseableByPlayer(player);
}

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 fromslot)
{
	ItemStack previous = null;
	Slot slot = (Slot) this.inventorySlots.get(fromslot);

	if (slot != null && slot.getHasStack())
	{
		ItemStack current = slot.getStack();
		previous = current.copy();

		if (fromslot < 3)
		{
			if (!this.mergeItemStack(current, 3, 39, true))
			{
				return null;
			}
		}
		else
		{
			if (!this.mergeItemStack(current, 0, 3, false))
			{
				return null;
			}
		}

		if (current.stackSize == 0)
		{
			slot.putStack(null);
		}

		// Custom Shit

		if (current.stackSize == previous.stackSize)
		{
			return null;
		}
		slot.onPickupFromSlot(player, current);
	}
	return previous;

}

}

 

package com.trekkiecub.hodgepodge.rendering;

import com.trekkiecub.hodgepodge.init.TileEntity_Slicer;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;

public class Gui_Slicer extends GuiContainer{

private TileEntity_Slicer tile_slicer;

public Gui_Slicer(InventoryPlayer inventoryPlayer, TileEntity_Slicer tile_slicer) {
	super(new Container_Slicer(inventoryPlayer, tile_slicer));
	this.tile_slicer = tile_slicer;
}

@Override
protected void drawGuiContainerForegroundLayer(int param1, int param2)
{
	fontRendererObj.drawString("Slicer", 8, 6, 4210752);

	fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize-96+2, 4210752);


}

@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
	this.mc.renderEngine.bindTexture(new ResourceLocation("trekkiecub_techythings:textures/gui/slicer.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.tile_slicer.getProgressScaled(24);
	this.drawTexturedModalRect(x + 79, y + 34, 176, 14, i1 + 1, 16);

}

}

Link to comment
Share on other sites

Your description packet is null, so the client knows nothing about the server's TileEntity data.

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

 

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

 

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

Link to comment
Share on other sites

I've looked into this a little, and made a few changes to my tile entity class, but they don't seem to be working and I'm not sure what I'm doing wrong.  The issue I mentioned persists.  The major changes I've made are the bottom four functions.

 

package com.trekkiecub.hodgepodge.init;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
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;

public class TileEntity_Slicer extends TileEntity implements IInventory{
private ItemStack[] itemStacks;
private Map recipeList = new HashMap();
public int processTime;
public final int TICKS_DONE = 100;

class recipeEntry
{
	Item output_one, output_two;
	double quantity;

	public recipeEntry(Item output_one, Item output_two, double quantity)
	{
		this.output_one = output_one;
		this.output_two = output_two;
		this.quantity = quantity;
	}
	public void setQuantity(double quant)
	{
		this.quantity = quant;
	}
}

public TileEntity_Slicer()
{
	itemStacks = new ItemStack[3];

	recipeList.put(Items.gold_ingot, new recipeEntry(ItemInit.Half_Ingot_Gold, ItemInit.Half_Ingot_Gold, 1));
	recipeList.put(Items.iron_ingot, new recipeEntry(ItemInit.Half_Ingot_Iron, ItemInit.Half_Ingot_Iron, 1));
	recipeList.put(ItemInit.Half_Ingot_Gold, new recipeEntry(ItemInit.Quarter_Ingot_Gold, ItemInit.Quarter_Ingot_Gold, 1));
	recipeList.put(ItemInit.Half_Ingot_Iron, new recipeEntry(ItemInit.Quarter_Ingot_Iron, ItemInit.Quarter_Ingot_Iron, 1));
}

@Override
public int getSizeInventory() {
	return itemStacks.length;
}

@Override
public ItemStack getStackInSlot(int slot) {
	if (slot < 0 || slot >= this.getSizeInventory())
        return null;
    return this.itemStacks[slot];
}

@Override
public ItemStack decrStackSize(int slot, int amount) {
	ItemStack stack = getStackInSlot(slot);
	if (stack != null)
	{
		if (stack.stackSize <= amount)
		{
			setInventorySlotContents(slot, null);
			markDirty();
		}
		else
		{
			stack = stack.splitStack(amount);
			if(stack.stackSize == 0)
			{
				setInventorySlotContents(slot, null);
			}
			this.markDirty();
		}
	}
	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 (slot < 0 || slot >= this.getSizeInventory())
	{
		return;
	}
	if (stack != null && stack.stackSize > getInventoryStackLimit())
	{
		stack.stackSize = getInventoryStackLimit();
	}

	if (stack != null && stack.stackSize == 0)
	{
		stack = null;
	}
	this.itemStacks[slot] = stack;
	this.markDirty();
}

@Override
public String getInventoryName() {
	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() {
	// 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:
		{
			return (recipeList.get(stack.getItem()) != null);
		}
		default: return false;
	}
}

@SideOnly(Side.CLIENT)
public int getProgressScaled(int somenum)
{
	return this.processTime * somenum / TICKS_DONE;
}

public boolean isWorking() {return this.processTime > 0;}

public void updateEntity()
{
	if (!this.worldObj.isRemote)
    	{
    		if (this.canProcess())
    		{
    			this.processTime++;
    			
    			if (this.processTime >= TICKS_DONE)
    			{
    				this.processTime = 0;
    				this.processItem();
    			}
    			worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
    			markDirty();
    		}
    		else
    		{
    			this.processTime = 0;
    			worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
    			markDirty();
    		}

    	}
    	super.updateEntity();
}

private boolean canProcess()
    {
    	if (this.itemStacks[0] == null)
    	{
    		return false;
    	}
    	else
    	{
    		// Get the crushEntry for the corresponding item in the input slot
    		recipeEntry resultEntry = (recipeEntry) recipeList.get(this.itemStacks[0].getItem());
    		
    		// Return can't crush if the item doesn't have a recipe
    		if (resultEntry == null) return false;
    		
    		boolean firstPasses, secondPasses, thirdPasses;
    		
    		if (this.itemStacks[1] == null || resultEntry.output_two == null)
    		{
    			firstPasses = true;
    		}
    		else if (this.itemStacks[1].getItem() == resultEntry.output_two && this.itemStacks[1].stackSize + 1 <= this.itemStacks[1].getMaxStackSize())
    		{
    			firstPasses = true;
    		}
    		else
    		{
    			return false;
    		}
    		
    		if (this.itemStacks[2] == null || resultEntry.output_two == null)
    		{
    			secondPasses = true;
    		}
    		else if (this.itemStacks[2].getItem() == resultEntry.output_two && 1 + this.itemStacks[2].stackSize <= this.itemStacks[2].getMaxStackSize())
    		{
    			secondPasses = true;
    		}
    		else
    		{
    			return false;
    		}
    		
    		
       		return firstPasses && secondPasses;
    	}
    }

    public void processItem()
    {
    	if (this.canProcess())
    	{
    		Random rand = new Random();
    		// Get the crush entry for the corresponding item in the input slot
    		recipeEntry result = ((recipeEntry) recipeList.get(this.itemStacks[0].getItem()));
    		
    		if (result.output_one != null)
    		{
    			if (this.itemStacks[1] == null)
    			{
    				this.itemStacks[1] = new ItemStack(result.output_one, 1);
    			}
    			else
    			{
    				this.itemStacks[1].stackSize += 1;
    			}
    		}
    		if (result.output_two != null)
    		{
    			if (this.itemStacks[2] == null)
    			{
    				this.itemStacks[2] = new ItemStack(result.output_two, 1);
    			}
    			else
    			{
    				this.itemStacks[2].stackSize += 1;
    			}
    		}
    		
    		this.itemStacks[0].stackSize--;
    		if (this.itemStacks[0].stackSize <= 0)
    		{
    			this.itemStacks[0] = null;
    		}
    		
    		
    	}
    }

    @Override
    public void readFromNBT(NBTTagCompound tag)
    {
        super.readFromNBT(tag);
        NBTTagList nbttaglist = tag.getTagList("Items", 10);
        this.processTime = tag.getInteger("progress");
        
        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
        	NBTTagCompound tag1 = nbttaglist.getCompoundTagAt(i);
        	int j = tag1.getByte("Slot") & 255;
        	
        	setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(tag1));
        }
        
    }

    @Override
    public void writeToNBT(NBTTagCompound tag)
    {
        super.writeToNBT(tag);
    	tag.setInteger("progress", this.processTime);
    	
        NBTTagList nbttaglist = new NBTTagList();

        for (int i = 0; i < getSizeInventory(); ++i)
        {
            if (getStackInSlot(i) != null)
            {
                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                nbttagcompound1.setByte("Slot", (byte)i);
                getStackInSlot(i).writeToNBT(nbttagcompound1);
                nbttaglist.appendTag(nbttagcompound1);
            }
        }
        tag.setTag("Items", nbttaglist);
    }
    
    public void writeNBTSync(NBTTagCompound tag)
    {
    	tag.setInteger("progress", this.processTime);
    }
    public void readNBTSync(NBTTagCompound tag)
    {
    	this.processTime = tag.getInteger("progress");
    }
    
    @Override
    public Packet getDescriptionPacket()
    {
        NBTTagCompound tagCompound = new NBTTagCompound();
        writeNBTSync(tagCompound);
        return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tagCompound);
    }
    
    @Override
    public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
    {
    	readNBTSync(pkt.func_148857_g());
    }

}

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.