Jump to content

Recommended Posts

Posted

I am trying to have a furnace-type container that renders three ItemStacks above it based on what is in the container. Everything works as intended except the ItemStacks on the top of the container will only update whenever you open the container. I have tried using World.markBlockForUpdate(...) but that doesn't seem to help at all. I am rendering the ItemStacks in the TileEntity's render method. Source is located below for the classes. If you need any more information please let me know. Thanks!

 

Block

 

public class BlockInfuser extends BlockContainer {

private final Random random = new Random();
    private final boolean isActive;
    private static boolean field_149934_M;

public BlockInfuser(boolean isActive) {
	super(Material.iron);
	if(isActive) this.setBlockName("infuser_on");
	else this.setBlockName("infuser");
	this.setHardness(5.0F);
	this.setResistance(10.0F);
	this.setHarvestLevel("pickaxe", 0);
	if(!isActive) this.setCreativeTab(Zether.zetherTab);
	this.isActive = isActive;
}

@Override
public int getRenderType() {
	return -1;
}

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

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

@Override
public void registerBlockIcons(IIconRegister icon) {
	this.blockIcon = icon.registerIcon(Zether.modid + ":blackQuartsBlock");
}

    public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
    {
        return Item.getItemFromBlock(Zether.infuser);
    }

    /**
     * Called whenever the block is added into the world. Args: world, x, y, z
     */
    public void onBlockAdded(World world, int p_149726_2_, int p_149726_3_, int p_149726_4_)
    {
        super.onBlockAdded(world, p_149726_2_, p_149726_3_, p_149726_4_);
        this.func_149930_e(world, p_149726_2_, p_149726_3_, p_149726_4_);
    }

    private void func_149930_e(World p_149930_1_, int p_149930_2_, int p_149930_3_, int p_149930_4_)
    {
        if (!p_149930_1_.isRemote)
        {
            Block block = p_149930_1_.getBlock(p_149930_2_, p_149930_3_, p_149930_4_ - 1);
            Block block1 = p_149930_1_.getBlock(p_149930_2_, p_149930_3_, p_149930_4_ + 1);
            Block block2 = p_149930_1_.getBlock(p_149930_2_ - 1, p_149930_3_, p_149930_4_);
            Block block3 = p_149930_1_.getBlock(p_149930_2_ + 1, p_149930_3_, p_149930_4_);
            byte b0 = 3;

            if (block.func_149730_j() && !block1.func_149730_j())
            {
                b0 = 3;
            }

            if (block1.func_149730_j() && !block.func_149730_j())
            {
                b0 = 2;
            }

            if (block2.func_149730_j() && !block3.func_149730_j())
            {
                b0 = 5;
            }

            if (block3.func_149730_j() && !block2.func_149730_j())
            {
                b0 = 4;
            }

            p_149930_1_.setBlockMetadataWithNotify(p_149930_2_, p_149930_3_, p_149930_4_, b0, 2);
        }
    }
    
    public int getBlockMetadata(World world, int x, int y, int z) {
	return this.getDamageValue(world, x, y, z);
    }

    /**
     * Called upon block activation (right click on the block.)
     */
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
    {
        if(!player.isSneaking()){
        	player.openGui(Zether.instance, Zether.guiIdInfuser, world, x, y, z);
        	return true;
        }else{
        	return false;
        }
    }

    /**
     * Update which block the infuser is using depending on whether or not it is burning
     */
    public static void updateInfuserBlockState(boolean p_149931_0_, World p_149931_1_, int p_149931_2_, int p_149931_3_, int p_149931_4_)
    {
        int l = p_149931_1_.getBlockMetadata(p_149931_2_, p_149931_3_, p_149931_4_);
        TileEntity tileentity = p_149931_1_.getTileEntity(p_149931_2_, p_149931_3_, p_149931_4_);
        field_149934_M = true;

        if (p_149931_0_)
        {
            p_149931_1_.setBlock(p_149931_2_, p_149931_3_, p_149931_4_, Zether.infuser_on);
        }
        else
        {
            p_149931_1_.setBlock(p_149931_2_, p_149931_3_, p_149931_4_, Zether.infuser);
        }

        field_149934_M = false;
        p_149931_1_.setBlockMetadataWithNotify(p_149931_2_, p_149931_3_, p_149931_4_, l, 2);

        if (tileentity != null)
        {
            tileentity.validate();
            p_149931_1_.setTileEntity(p_149931_2_, p_149931_3_, p_149931_4_, tileentity);
        }
        p_149931_1_.markBlockForUpdate(p_149931_2_, p_149931_3_, p_149931_4_);
    }

    /**
     * Returns a new instance of a block's tile entity class. Called on placing the block.
     */
    public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_)
    {
        return new TileEntityInfuser();
    }

    /**
     * Called when the block is placed in the world.
     */
    public void onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_, int p_149689_4_, EntityLivingBase p_149689_5_, ItemStack p_149689_6_)
    {
        int l = MathHelper.floor_double((double)(p_149689_5_.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

        if (l == 0)
        {
            p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 2, 2);
        }

        if (l == 1)
        {
            p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 5, 2);
        }

        if (l == 2)
        {
            p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 3, 2);
        }

        if (l == 3)
        {
            p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, 4, 2);
        }

        if (p_149689_6_.hasDisplayName())
        {
            ((TileEntityInfuser)p_149689_1_.getTileEntity(p_149689_2_, p_149689_3_, p_149689_4_)).func_145951_a(p_149689_6_.getDisplayName());
        }
    }

    public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_)
    {
        if (!field_149934_M)
        {
            TileEntityInfuser TileEntityInfuser = (TileEntityInfuser)p_149749_1_.getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_);

            if (TileEntityInfuser != null)
            {
                for (int i1 = 0; i1 < TileEntityInfuser.getSizeInventory(); ++i1)
                {
                    ItemStack itemstack = TileEntityInfuser.getStackInSlot(i1);

                    if (itemstack != null)
                    {
                        float f = this.random.nextFloat() * 0.8F + 0.1F;
                        float f1 = this.random.nextFloat() * 0.8F + 0.1F;
                        float f2 = this.random.nextFloat() * 0.8F + 0.1F;

                        while (itemstack.stackSize > 0)
                        {
                            int j1 = this.random.nextInt(21) + 10;

                            if (j1 > itemstack.stackSize)
                            {
                                j1 = itemstack.stackSize;
                            }

                            itemstack.stackSize -= j1;
                            EntityItem entityitem = new EntityItem(p_149749_1_, (double)((float)p_149749_2_ + f), (double)((float)p_149749_3_ + f1), (double)((float)p_149749_4_ + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));

                            if (itemstack.hasTagCompound())
                            {
                                entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
                            }

                            float f3 = 0.05F;
                            entityitem.motionX = (double)((float)this.random.nextGaussian() * f3);
                            entityitem.motionY = (double)((float)this.random.nextGaussian() * f3 + 0.2F);
                            entityitem.motionZ = (double)((float)this.random.nextGaussian() * f3);
                            p_149749_1_.spawnEntityInWorld(entityitem);
                        }
                    }
                }

                p_149749_1_.func_147453_f(p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_);
            }
        }

        super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_);
    }

    /**
     * A randomly called display update to be able to add particles or other items for display
     */
    @SideOnly(Side.CLIENT)
    public void randomDisplayTick(World world, int x, int y, int z, Random random)
    {
        if (this.isActive)
        {
        	for(int i = 0; i < 3; i++)
        	world.spawnParticle("portal", x + 0.5, y + 1, z + 0.5, random.nextDouble() * (random.nextBoolean() == true ? -1 : 1), random.nextDouble() * (random.nextBoolean() == true ? -1 : 1), random.nextDouble() * (random.nextBoolean() == true ? -1 : 1));
        }
        world.markBlockForUpdate(x, y, z);
    }

    /**
     * If this returns true, then comparators facing away from this block will use the value from
     * getComparatorInputOverride instead of the actual redstone signal strength.
     */
    public boolean hasComparatorInputOverride()
    {
        return true;
    }

    /**
     * If hasComparatorInputOverride returns true, the return value from this is used instead of the redstone signal
     * strength when this block inputs to a comparator.
     */
    public int getComparatorInputOverride(World p_149736_1_, int p_149736_2_, int p_149736_3_, int p_149736_4_, int p_149736_5_)
    {
        return Container.calcRedstoneFromInventory((IInventory)p_149736_1_.getTileEntity(p_149736_2_, p_149736_3_, p_149736_4_));
    }

    /**
     * Gets an item for the block being called on. Args: world, x, y, z
     */
    @SideOnly(Side.CLIENT)
    public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_)
    {
        return Item.getItemFromBlock(Zether.infuser);
    }
}

 

 

TileEntity

 

public class TileEntityInfuser extends TileEntity implements ISidedInventory
{
    private static final int[] slotsTop = new int[] {0};
    private static final int[] slotsBottom = new int[] {2, 1};
    private static final int[] slotsSides = new int[] {1};
    /**
     * The ItemStacks that hold the items currently being used in the infuser
     */
    private ItemStack[] infuserItemStacks = new ItemStack[3];
    /** The number of ticks that the infuser will keep burning */
    public int infuserBurnTime;
    /**
     * The number of ticks that a fresh copy of the currently-burning item would keep the infuser burning for
     */
    public int currentItemBurnTime;
    /** The number of ticks that the current item has been cooking for */
    public int infuserCookTime;
    private String field_145958_o;
    private static final String __OBFID = "CL_00000357";

    /**
     * Returns the number of slots in the inventory.
     */
    public int getSizeInventory()
    {
        return this.infuserItemStacks.length;
    }

    /**
     * Returns the stack in slot i
     */
    public ItemStack getStackInSlot(int p_70301_1_)
    {
        return this.infuserItemStacks[p_70301_1_];
    }

    /**
     * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a
     * new stack.
     */
    public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_)
    {
        if (this.infuserItemStacks[p_70298_1_] != null)
        {
            ItemStack itemstack;

            if (this.infuserItemStacks[p_70298_1_].stackSize <= p_70298_2_)
            {
                itemstack = this.infuserItemStacks[p_70298_1_];
                this.infuserItemStacks[p_70298_1_] = null;
                return itemstack;
            }
            else
            {
                itemstack = this.infuserItemStacks[p_70298_1_].splitStack(p_70298_2_);

                if (this.infuserItemStacks[p_70298_1_].stackSize == 0)
                {
                    this.infuserItemStacks[p_70298_1_] = null;
                }

                return itemstack;
            }
        }
        else
        {
            return null;
        }
    }

    /**
     * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
     * like when you close a workbench GUI.
     */
    public ItemStack getStackInSlotOnClosing(int p_70304_1_)
    {
        if (this.infuserItemStacks[p_70304_1_] != null)
        {
            ItemStack itemstack = this.infuserItemStacks[p_70304_1_];
            this.infuserItemStacks[p_70304_1_] = null;
            return itemstack;
        }
        else
        {
            return null;
        }
    }

    /**
     * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
     */
    public void setInventorySlotContents(int p_70299_1_, ItemStack p_70299_2_)
    {
        this.infuserItemStacks[p_70299_1_] = p_70299_2_;

        if (p_70299_2_ != null && p_70299_2_.stackSize > this.getInventoryStackLimit())
        {
            p_70299_2_.stackSize = this.getInventoryStackLimit();
        }
    }

    /**
     * Returns the name of the inventory
     */
    public String getInventoryName()
    {
        return this.hasCustomInventoryName() ? this.field_145958_o : "container.infuser";
    }

    /**
     * Returns if the inventory is named
     */
    public boolean hasCustomInventoryName()
    {
        return this.field_145958_o != null && this.field_145958_o.length() > 0;
    }

    public void func_145951_a(String p_145951_1_)
    {
        this.field_145958_o = p_145951_1_;
    }

    public void readFromNBT(NBTTagCompound p_145839_1_)
    {
        super.readFromNBT(p_145839_1_);
        NBTTagList nbttaglist = p_145839_1_.getTagList("Items", 10);
        this.infuserItemStacks = new ItemStack[this.getSizeInventory()];

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

            if (b0 >= 0 && b0 < this.infuserItemStacks.length)
            {
                this.infuserItemStacks[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
            }
        }

        this.infuserBurnTime = p_145839_1_.getShort("BurnTime");
        this.infuserCookTime = p_145839_1_.getShort("CookTime");
        this.currentItemBurnTime = 200;

        if (p_145839_1_.hasKey("CustomName", )
        {
            this.field_145958_o = p_145839_1_.getString("CustomName");
        }
    }

    public void writeToNBT(NBTTagCompound p_145841_1_)
    {
        super.writeToNBT(p_145841_1_);
        p_145841_1_.setShort("BurnTime", (short)this.infuserBurnTime);
        p_145841_1_.setShort("CookTime", (short)this.infuserCookTime);
        NBTTagList nbttaglist = new NBTTagList();

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

        p_145841_1_.setTag("Items", nbttaglist);

        if (this.hasCustomInventoryName())
        {
            p_145841_1_.setString("CustomName", this.field_145958_o);
        }
    }

    /**
     * Returns the maximum stack size for a inventory slot.
     */
    public int getInventoryStackLimit()
    {
        return 64;
    }

    /**
     * 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 getCookProgressScaled(int p_145953_1_)
    {
        return this.infuserCookTime * p_145953_1_ / 200;
    }

    /**
     * Returns an integer between 0 and the passed value representing how much burn time is left on the current fuel
     * item, where 0 means that the item is exhausted and the passed value means that the item is fresh
     */
    @SideOnly(Side.CLIENT)
    public int getBurnTimeRemainingScaled(int p_145955_1_)
    {
        if (this.currentItemBurnTime == 0)
        {
            this.currentItemBurnTime = 200;
        }

        return this.infuserBurnTime * p_145955_1_ / this.currentItemBurnTime;
    }

    /**
     * infuser isBurning
     */
    public boolean isBurning()
    {
        return this.infuserBurnTime > 0;
    }

    public void updateEntity()
    {
        boolean flag = this.infuserBurnTime > 0;
        boolean flag1 = false;

        if (this.infuserBurnTime > 0)
        {
            --this.infuserBurnTime;
        }

        if (!this.worldObj.isRemote)
        {
            if (this.infuserBurnTime != 0 || this.infuserItemStacks[1] != null && this.infuserItemStacks[0] != null)
            {
                if (this.infuserBurnTime == 0 && this.canSmelt())
                {
                    this.currentItemBurnTime = this.infuserBurnTime = 200;

                    if (this.infuserBurnTime > 0)
                    {
                        flag1 = true;

                        if (this.infuserItemStacks[1] != null)
                        {
                            --this.infuserItemStacks[1].stackSize;

                            if (this.infuserItemStacks[1].stackSize == 0)
                            {
                                this.infuserItemStacks[1] = infuserItemStacks[1].getItem().getContainerItem(infuserItemStacks[1]);
                            }
                        }
                    }
                }

                if (this.isBurning() && this.canSmelt())
                {
                    ++this.infuserCookTime;

                    if (this.infuserCookTime == 200)
                    {
                        this.infuserCookTime = 0;
                        this.smeltItem();
                        flag1 = true;
                    }
                }
                else
                {
                    this.infuserCookTime = 0;
                }
            }

            if (flag != this.infuserBurnTime > 0)
            {
                flag1 = true;
                BlockInfuser.updateInfuserBlockState(this.infuserBurnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
            }
        }

        if (flag1)
        {
            this.markDirty();
        }
    }

    /**
     * Returns true if the infuser can smelt an item, i.e. has a source item, destination stack isn't full, etc.
     */
    private boolean canSmelt()
    {
        if (this.infuserItemStacks[0] == null)
        {
            return false;
        }
        else
        {
            ItemStack itemstack = InfuserRecipes.smelting().getInfusingResult(this.infuserItemStacks[0]);
            if (itemstack == null) return false;
            if (this.infuserItemStacks[2] == null) return true;
            if (!this.infuserItemStacks[2].isItemEqual(itemstack)) return false;
            int result = infuserItemStacks[2].stackSize + itemstack.stackSize;
            return result <= getInventoryStackLimit() && result <= this.infuserItemStacks[2].getMaxStackSize(); //Forge BugFix: Make it respect stack sizes properly.
        }
    }

    /**
     * Turn one item from the infuser source stack into the appropriate smelted item in the infuser result stack
     */
    public void smeltItem()
    {
        if (this.canSmelt())
        {
            ItemStack itemstack = InfuserRecipes.smelting().getInfusingResult(this.infuserItemStacks[0]);

            if (this.infuserItemStacks[2] == null)
            {
                this.infuserItemStacks[2] = itemstack.copy();
            }
            else if (this.infuserItemStacks[2].getItem() == itemstack.getItem())
            {
                this.infuserItemStacks[2].stackSize += itemstack.stackSize; // Forge BugFix: Results may have multiple items
            }

            --this.infuserItemStacks[0].stackSize;

            if (this.infuserItemStacks[0].stackSize <= 0)
            {
                this.infuserItemStacks[0] = null;
            }
        }
    }

    public static boolean isItemFuel(ItemStack stack)
    {
        /**
         * Returns the number of ticks that the supplied fuel item will keep the infuser burning, or 0 if the item isn't
         * fuel
         */
        return stack.getItem() == Item.getItemFromBlock(Zether.zetherBrick);
    }

    /**
     * Do not make give this method the name canInteractWith because it clashes with Container
     */
    public boolean isUseableByPlayer(EntityPlayer p_70300_1_)
    {
        return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : p_70300_1_.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
    }

    public void openInventory() {}

    public void closeInventory() {}

    /**
     * Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
     */
    public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_)
    {
        return p_94041_1_ == 2 ? false : (p_94041_1_ == 1 ? isItemFuel(p_94041_2_) : true);
    }

    /**
     * Returns an array containing the indices of the slots that can be accessed by automation on the given side of this
     * block.
     */
    public int[] getAccessibleSlotsFromSide(int p_94128_1_)
    {
        return p_94128_1_ == 0 ? slotsBottom : (p_94128_1_ == 1 ? slotsTop : slotsSides);
    }

    /**
     * Returns true if automation can insert the given item in the given slot from the given side. Args: Slot, item,
     * side
     */
    public boolean canInsertItem(int p_102007_1_, ItemStack p_102007_2_, int p_102007_3_)
    {
        return this.isItemValidForSlot(p_102007_1_, p_102007_2_);
    }

    /**
     * Returns true if automation can extract the given item in the given slot from the given side. Args: Slot, item,
     * side
     */
    public boolean canExtractItem(int p_102008_1_, ItemStack p_102008_2_, int p_102008_3_)
    {
        return p_102008_3_ != 0 || p_102008_1_ != 1 || p_102008_2_.getItem() == Items.bucket;
    }
}

 

 

Container

 

public class ContainerInfuser extends Container
{
    private TileEntityInfuser tileInfuser;
    private int lastCookTime;
    private int lastBurnTime;
    private int lastItemBurnTime;

    public ContainerInfuser(InventoryPlayer p_i1812_1_, World world, int x, int y, int z)
    {
        this.tileInfuser = (TileEntityInfuser) p_i1812_1_.player.worldObj.getTileEntity(x, y, z);
        this.addSlotToContainer(new Slot(this.tileInfuser, 0, 98, 46));
        this.addSlotToContainer(new Slot(this.tileInfuser, 1, 62, 46));
        this.addSlotToContainer(new SlotFurnace(p_i1812_1_.player, this.tileInfuser, 2, 80, 17));
        int i;

        for (i = 0; i < 3; ++i)
        {
            for (int j = 0; j < 9; ++j)
            {
                this.addSlotToContainer(new Slot(p_i1812_1_, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
            }
        }

        for (i = 0; i < 9; ++i)
        {
            this.addSlotToContainer(new Slot(p_i1812_1_, i, 8 + i * 18, 142));
        }
    }

    public void addCraftingToCrafters(ICrafting p_75132_1_)
    {
        super.addCraftingToCrafters(p_75132_1_);
        p_75132_1_.sendProgressBarUpdate(this, 0, this.tileInfuser.infuserCookTime);
        p_75132_1_.sendProgressBarUpdate(this, 1, this.tileInfuser.infuserBurnTime);
        p_75132_1_.sendProgressBarUpdate(this, 2, this.tileInfuser.currentItemBurnTime);
    }

    /**
     * Looks for changes made in the container, sends them to every listener.
     */
    public void detectAndSendChanges()
    {
        super.detectAndSendChanges();

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

            if (this.lastCookTime != this.tileInfuser.infuserCookTime)
            {
                icrafting.sendProgressBarUpdate(this, 0, this.tileInfuser.infuserCookTime);
            }

            if (this.lastBurnTime != this.tileInfuser.infuserBurnTime)
            {
                icrafting.sendProgressBarUpdate(this, 1, this.tileInfuser.infuserBurnTime);
            }

            if (this.lastItemBurnTime != this.tileInfuser.currentItemBurnTime)
            {
                icrafting.sendProgressBarUpdate(this, 2, this.tileInfuser.currentItemBurnTime);
            }
        }

        this.lastCookTime = this.tileInfuser.infuserCookTime;
        this.lastBurnTime = this.tileInfuser.infuserBurnTime;
        this.lastItemBurnTime = this.tileInfuser.currentItemBurnTime;
    }

    @SideOnly(Side.CLIENT)
    public void updateProgressBar(int p_75137_1_, int p_75137_2_)
    {
        if (p_75137_1_ == 0)
        {
            this.tileInfuser.infuserCookTime = p_75137_2_;
        }

        if (p_75137_1_ == 1)
        {
            this.tileInfuser.infuserBurnTime = p_75137_2_;
        }

        if (p_75137_1_ == 2)
        {
            this.tileInfuser.currentItemBurnTime = p_75137_2_;
        }
    }

    public boolean canInteractWith(EntityPlayer p_75145_1_)
    {
        return this.tileInfuser.isUseableByPlayer(p_75145_1_);
    }

    /**
     * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
     */
    public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_)
    {
        ItemStack itemstack = null;
        Slot slot = (Slot)this.inventorySlots.get(p_82846_2_);

        if (slot != null && slot.getHasStack())
        {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();

            if (p_82846_2_ == 2)
            {
                if (!this.mergeItemStack(itemstack1, 3, 39, true))
                {
                    return null;
                }

                slot.onSlotChange(itemstack1, itemstack);
            }
            else if (p_82846_2_ != 1 && p_82846_2_ != 0)
            {
                if (InfuserRecipes.smelting().getInfusingResult(itemstack1) != null)
                {
                    if (!this.mergeItemStack(itemstack1, 0, 1, false))
                    {
                        return null;
                    }
                }
                else if (TileEntityInfuser.isItemFuel(itemstack1))
                {
                    if (!this.mergeItemStack(itemstack1, 1, 2, false))
                    {
                        return null;
                    }
                }
                else if (p_82846_2_ >= 3 && p_82846_2_ < 30)
                {
                    if (!this.mergeItemStack(itemstack1, 30, 39, false))
                    {
                        return null;
                    }
                }
                else if (p_82846_2_ >= 30 && p_82846_2_ < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(itemstack1, 3, 39, false))
            {
                return null;
            }

            if (itemstack1.stackSize == 0)
            {
                slot.putStack((ItemStack)null);
            }
            else
            {
                slot.onSlotChanged();
            }

            if (itemstack1.stackSize == itemstack.stackSize)
            {
                return null;
            }

            slot.onPickupFromSlot(p_82846_1_, itemstack1);
        }

        return itemstack;
    }
}

 

 

Gui

 

@SideOnly(Side.CLIENT)
public class GuiInfuser extends GuiContainer
{
    private static final ResourceLocation infuserGuiTextures = new ResourceLocation(Zether.modid, "/textures/gui/infuser.png");
    private TileEntityInfuser tileInfuser;

    public GuiInfuser(InventoryPlayer p_i1091_1_, World world, int x, int y, int z)
    {
        super(new ContainerInfuser(p_i1091_1_, world, x, y, z));
        this.tileInfuser = (TileEntityInfuser) world.getTileEntity(x, y, z);
    }

    /**
     * Draw the foreground layer for the GuiContainer (everything in front of the items)
     */
    protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_)
    {
        String s = this.tileInfuser.hasCustomInventoryName() ? this.tileInfuser.getInventoryName() : I18n.format("Infuser");
        this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752);
        this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
    }

    protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_)
    {
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(infuserGuiTextures);
        int k = (this.width - this.xSize) / 2;
        int l = (this.height - this.ySize) / 2;
        this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);

        if (this.tileInfuser.isBurning())
        {
            int i1 = this.tileInfuser.getCookProgressScaled(40);
            this.drawTexturedModalRect(k + 84, l + 75 - i1, 176, 38 - i1, 12, i1 + 1);
        }
    }
}

 

 

 

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.