Compost shows the amount of items in the HUD now

This commit is contained in:
Ellpeck 2015-12-22 00:04:48 +01:00
parent ad23456456
commit 47b79ce8ea
3 changed files with 50 additions and 25 deletions

View file

@ -13,27 +13,34 @@ package ellpeck.actuallyadditions.blocks;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import ellpeck.actuallyadditions.blocks.base.BlockContainerBase; import ellpeck.actuallyadditions.blocks.base.BlockContainerBase;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
import ellpeck.actuallyadditions.items.ItemFertilizer; import ellpeck.actuallyadditions.items.ItemFertilizer;
import ellpeck.actuallyadditions.items.ItemMisc; import ellpeck.actuallyadditions.items.ItemMisc;
import ellpeck.actuallyadditions.items.metalists.TheMiscItems; import ellpeck.actuallyadditions.items.metalists.TheMiscItems;
import ellpeck.actuallyadditions.tile.TileEntityCompost; import ellpeck.actuallyadditions.tile.TileEntityCompost;
import ellpeck.actuallyadditions.util.AssetUtil; import ellpeck.actuallyadditions.util.AssetUtil;
import ellpeck.actuallyadditions.util.StringUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; 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.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.profiler.Profiler;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon; import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.List; import java.util.List;
public class BlockCompost extends BlockContainerBase{ public class BlockCompost extends BlockContainerBase implements IHudDisplay{
public BlockCompost(String name){ public BlockCompost(String name){
super(Material.wood, name); super(Material.wood, name);
@ -98,6 +105,7 @@ public class BlockCompost extends BlockContainerBase{
if(!player.capabilities.isCreativeMode){ if(!player.capabilities.isCreativeMode){
player.inventory.getCurrentItem().stackSize--; player.inventory.getCurrentItem().stackSize--;
} }
tile.sendUpdate();
} }
//Add Fertilizer to player's inventory //Add Fertilizer to player's inventory
@ -109,6 +117,7 @@ public class BlockCompost extends BlockContainerBase{
player.getCurrentEquippedItem().stackSize += tile.slots[0].stackSize; player.getCurrentEquippedItem().stackSize += tile.slots[0].stackSize;
} }
tile.slots[0] = null; tile.slots[0] = null;
tile.sendUpdate();
} }
} }
return true; return true;
@ -141,4 +150,22 @@ public class BlockCompost extends BlockContainerBase{
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.uncommon; 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);
}
}
} }

View file

@ -10,8 +10,10 @@
package ellpeck.actuallyadditions.blocks.render.model; package ellpeck.actuallyadditions.blocks.render.model;
import ellpeck.actuallyadditions.items.InitItems;
import ellpeck.actuallyadditions.tile.TileEntityCompost; import ellpeck.actuallyadditions.tile.TileEntityCompost;
import net.minecraft.client.model.ModelRenderer; import net.minecraft.client.model.ModelRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
public class ModelCompost extends ModelBaseAA{ public class ModelCompost extends ModelBaseAA{
@ -70,17 +72,21 @@ public class ModelCompost extends ModelBaseAA{
@Override @Override
public void renderExtra(float f, TileEntity tile){ public void renderExtra(float f, TileEntity tile){
int meta = tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord); if(tile instanceof TileEntityCompost){
if(meta > 0 && meta <= TileEntityCompost.AMOUNT){ ItemStack stack = ((TileEntityCompost)tile).getStackInSlot(0);
int heightToDisplay = meta*13/TileEntityCompost.AMOUNT; if(stack != null){
if(heightToDisplay > 13){ if(stack.getItem() == InitItems.itemFertilizer){
heightToDisplay = 13; this.innerDone.render(f);
} }
else{
int heightToDisplay = stack.stackSize*13/TileEntityCompost.AMOUNT;
if(heightToDisplay > 13){
heightToDisplay = 13;
}
this.innerRawList[heightToDisplay-1].render(f); this.innerRawList[heightToDisplay-1].render(f);
} }
else if(meta == TileEntityCompost.AMOUNT+1){ }
this.innerDone.render(f);
} }
} }
} }

View file

@ -30,19 +30,6 @@ public class TileEntityCompost extends TileEntityInventoryBase{
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!worldObj.isRemote){ 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; boolean theFlag = this.conversionTime > 0;
if(this.slots[0] != null && !(this.slots[0].getItem() instanceof ItemFertilizer) && this.slots[0].stackSize >= AMOUNT){ if(this.slots[0] != null && !(this.slots[0].getItem() instanceof ItemFertilizer) && this.slots[0].stackSize >= AMOUNT){
this.conversionTime++; this.conversionTime++;
@ -57,9 +44,14 @@ public class TileEntityCompost extends TileEntityInventoryBase{
} }
} }
@Override
public boolean shouldSyncSlots(){
return true;
}
@Override @Override
public void writeSyncableNBT(NBTTagCompound compound, boolean sync){ public void writeSyncableNBT(NBTTagCompound compound, boolean sync){
super.readSyncableNBT(compound, sync); super.writeSyncableNBT(compound, sync);
compound.setInteger("ConversionTime", this.conversionTime); compound.setInteger("ConversionTime", this.conversionTime);
} }