From 47b79ce8ea56ecdd2c3862ce21ce8d86e4cf0344 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 22 Dec 2015 00:04:48 +0100 Subject: [PATCH] Compost shows the amount of items in the HUD now --- .../blocks/BlockCompost.java | 29 ++++++++++++++++++- .../blocks/render/model/ModelCompost.java | 26 ++++++++++------- .../tile/TileEntityCompost.java | 20 ++++--------- 3 files changed, 50 insertions(+), 25 deletions(-) diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/BlockCompost.java b/src/main/java/ellpeck/actuallyadditions/blocks/BlockCompost.java index 280fb2bb1..e4c930d7b 100644 --- a/src/main/java/ellpeck/actuallyadditions/blocks/BlockCompost.java +++ b/src/main/java/ellpeck/actuallyadditions/blocks/BlockCompost.java @@ -13,27 +13,34 @@ package ellpeck.actuallyadditions.blocks; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import ellpeck.actuallyadditions.blocks.base.BlockContainerBase; +import ellpeck.actuallyadditions.booklet.page.BookletPage; import ellpeck.actuallyadditions.items.ItemFertilizer; import ellpeck.actuallyadditions.items.ItemMisc; import ellpeck.actuallyadditions.items.metalists.TheMiscItems; import ellpeck.actuallyadditions.tile.TileEntityCompost; import ellpeck.actuallyadditions.util.AssetUtil; +import ellpeck.actuallyadditions.util.StringUtil; import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.EnumRarity; import net.minecraft.item.ItemStack; +import net.minecraft.profiler.Profiler; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; import java.util.List; -public class BlockCompost extends BlockContainerBase{ +public class BlockCompost extends BlockContainerBase implements IHudDisplay{ public BlockCompost(String name){ super(Material.wood, name); @@ -98,6 +105,7 @@ public class BlockCompost extends BlockContainerBase{ if(!player.capabilities.isCreativeMode){ player.inventory.getCurrentItem().stackSize--; } + tile.sendUpdate(); } //Add Fertilizer to player's inventory @@ -109,6 +117,7 @@ public class BlockCompost extends BlockContainerBase{ player.getCurrentEquippedItem().stackSize += tile.slots[0].stackSize; } tile.slots[0] = null; + tile.sendUpdate(); } } return true; @@ -141,4 +150,22 @@ public class BlockCompost extends BlockContainerBase{ public EnumRarity getRarity(ItemStack stack){ return EnumRarity.uncommon; } + + @Override + public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, MovingObjectPosition posHit, Profiler profiler, ScaledResolution resolution){ + TileEntity tile = minecraft.theWorld.getTileEntity(posHit.blockX, posHit.blockY, posHit.blockZ); + if(tile instanceof TileEntityCompost){ + ItemStack slot = ((TileEntityCompost)tile).getStackInSlot(0); + String strg; + if(slot == null){ + strg = "Empty"; + } + else{ + strg = slot.getItem().getItemStackDisplayName(slot); + + BookletPage.renderItem(null, slot, resolution.getScaledWidth()/2+15, resolution.getScaledHeight()/2-29, 1F); + } + minecraft.fontRenderer.drawStringWithShadow(EnumChatFormatting.YELLOW+""+EnumChatFormatting.ITALIC+strg, resolution.getScaledWidth()/2+35, resolution.getScaledHeight()/2-25, StringUtil.DECIMAL_COLOR_WHITE); + } + } } diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/render/model/ModelCompost.java b/src/main/java/ellpeck/actuallyadditions/blocks/render/model/ModelCompost.java index 4a48dbb3f..f96b201e2 100644 --- a/src/main/java/ellpeck/actuallyadditions/blocks/render/model/ModelCompost.java +++ b/src/main/java/ellpeck/actuallyadditions/blocks/render/model/ModelCompost.java @@ -10,8 +10,10 @@ package ellpeck.actuallyadditions.blocks.render.model; +import ellpeck.actuallyadditions.items.InitItems; import ellpeck.actuallyadditions.tile.TileEntityCompost; import net.minecraft.client.model.ModelRenderer; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; public class ModelCompost extends ModelBaseAA{ @@ -70,17 +72,21 @@ public class ModelCompost extends ModelBaseAA{ @Override public void renderExtra(float f, TileEntity tile){ - int meta = tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord); - if(meta > 0 && meta <= TileEntityCompost.AMOUNT){ - int heightToDisplay = meta*13/TileEntityCompost.AMOUNT; - if(heightToDisplay > 13){ - heightToDisplay = 13; - } + if(tile instanceof TileEntityCompost){ + ItemStack stack = ((TileEntityCompost)tile).getStackInSlot(0); + if(stack != null){ + if(stack.getItem() == InitItems.itemFertilizer){ + this.innerDone.render(f); + } + else{ + int heightToDisplay = stack.stackSize*13/TileEntityCompost.AMOUNT; + if(heightToDisplay > 13){ + heightToDisplay = 13; + } - this.innerRawList[heightToDisplay-1].render(f); - } - else if(meta == TileEntityCompost.AMOUNT+1){ - this.innerDone.render(f); + this.innerRawList[heightToDisplay-1].render(f); + } + } } } } diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityCompost.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityCompost.java index 7cd6217ac..d2e1557fa 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityCompost.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityCompost.java @@ -30,19 +30,6 @@ public class TileEntityCompost extends TileEntityInventoryBase{ public void updateEntity(){ super.updateEntity(); if(!worldObj.isRemote){ - - if(this.slots[0] != null && this.slots[0].stackSize > 0){ - int toSet = this.slots[0].stackSize+(this.slots[0].getItem() instanceof ItemFertilizer ? 1 : 0); - if(worldObj.getBlockMetadata(xCoord, yCoord, zCoord) != toSet){ - worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, toSet, 2); - } - } - else{ - if(worldObj.getBlockMetadata(xCoord, yCoord, zCoord) != 0){ - worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 2); - } - } - boolean theFlag = this.conversionTime > 0; if(this.slots[0] != null && !(this.slots[0].getItem() instanceof ItemFertilizer) && this.slots[0].stackSize >= AMOUNT){ this.conversionTime++; @@ -57,9 +44,14 @@ public class TileEntityCompost extends TileEntityInventoryBase{ } } + @Override + public boolean shouldSyncSlots(){ + return true; + } + @Override public void writeSyncableNBT(NBTTagCompound compound, boolean sync){ - super.readSyncableNBT(compound, sync); + super.writeSyncableNBT(compound, sync); compound.setInteger("ConversionTime", this.conversionTime); }