From 0ef6a00aa79f022e5bd56b3f77e6861bbecf6d94 Mon Sep 17 00:00:00 2001 From: OnyxDarkKnight Date: Thu, 13 Aug 2015 21:12:11 +0100 Subject: Added a new structure, a new curse, achievements, challenges, curses entry in the guide; reworked liquids to be tile entities, cleaned the structures code, potion code and... you know what? I improved and changed so much stuff that I literally forgot what I did... --- .../tileentity/TileEntityHandPedestal.java | 348 ++++++++++----------- 1 file changed, 167 insertions(+), 181 deletions(-) (limited to 'src/main/java/darkknight/jewelrycraft/tileentity/TileEntityHandPedestal.java') diff --git a/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityHandPedestal.java b/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityHandPedestal.java index ee48d08..e4a8602 100644 --- a/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityHandPedestal.java +++ b/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityHandPedestal.java @@ -1,182 +1,168 @@ -package darkknight.jewelrycraft.tileentity; - -import net.minecraft.item.ItemBlock; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.Packet; -import net.minecraft.network.play.server.S35PacketUpdateTileEntity; -import net.minecraft.tileentity.TileEntity; - -/** - * @author Paul Fulham (pau101) - */ -public class TileEntityHandPedestal extends TileEntity -{ - protected boolean isDirty; - protected ItemStack heldItemStack; - /** - * When the hand is open the grip is 0 and is 20 when closed. - */ - private float grip; - private float prevGrip; - private float gripMax; - private float gripScale; - private boolean isHandOpen; - - /** - * - */ - public TileEntityHandPedestal() - { - isDirty = false; - heldItemStack = null; - grip = 0; - gripMax = 20; - gripScale = 1; - isHandOpen = true; - } - - /** - * @param tagCompound - */ - @Override - public void writeToNBT(NBTTagCompound tagCompound) - { - super.writeToNBT(tagCompound); - if (heldItemStack != null){ - NBTTagCompound objectCompound = new NBTTagCompound(); - heldItemStack.writeToNBT(objectCompound); - tagCompound.setTag("object", objectCompound); - } - tagCompound.setBoolean("isHandOpen", isHandOpen); - } - - /** - * @param tagCompound - */ - @Override - public void readFromNBT(NBTTagCompound tagCompound) - { - super.readFromNBT(tagCompound); - if (tagCompound.hasKey("object", 10)) setHeldItemStack(ItemStack.loadItemStackFromNBT(tagCompound.getCompoundTag("object"))); - else removeHeldItemStack(); - isHandOpen = tagCompound.getBoolean("isHandOpen"); - } - - /** - * - */ - @Override - public void updateEntity() - { - super.updateEntity(); - updateGrip(); - if (isDirty){ - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - isDirty = false; - } - } - - /** - * - */ - private void updateGrip() - { - prevGrip = grip; - if (grip > 0 && isHandOpen) grip -= 1 / gripScale; - else if (grip < gripMax && !isHandOpen) grip += 1 / gripScale; - } - - /** - * @return - */ - @Override - public Packet getDescriptionPacket() - { - NBTTagCompound nbttagcompound = new NBTTagCompound(); - writeToNBT(nbttagcompound); - return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, nbttagcompound); - } - - /** - * @param networkManager - * @param packet - */ - @Override - public void onDataPacket(NetworkManager networkManager, S35PacketUpdateTileEntity packet) - { - readFromNBT(packet.func_148857_g()); - worldObj.func_147479_m(xCoord, yCoord, zCoord); - } - - /** - * - */ - @Override - public void markDirty() - { - super.markDirty(); - isDirty = true; - } - - /** - * @return - */ - public ItemStack getHeldItemStack() - { - return heldItemStack; - } - - /** - * @param heldItemStack - */ - public void setHeldItemStack(ItemStack heldItemStack) - { - heldItemStack.stackSize = 1; - this.heldItemStack = heldItemStack; - if (heldItemStack.getItem() instanceof ItemBlock) gripScale = 0.5f; - else gripScale = 1; - } - - /** - * - */ - public void removeHeldItemStack() - { - heldItemStack = null; - } - - /** - * - */ - public void openHand() - { - isHandOpen = true; - } - - /** - * - */ - public void closeHand() - { - isHandOpen = false; - } - - /** - * @param t - * @return - */ - public float getGrip(float t) - { - return (prevGrip * (1 - t) + grip * t) / gripMax; - } - - /** - * @return - */ - public float getGripScale() - { - return gripScale; - } +package darkknight.jewelrycraft.tileentity; + +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; + +/** + * @author Paul Fulham (pau101) + */ +public class TileEntityHandPedestal extends TileEntity { + protected boolean isDirty; + protected ItemStack heldItemStack; + /** + * When the hand is open the grip is 0 and is 20 when closed. + */ + private float grip; + private float prevGrip; + private float gripMax; + private float gripScale; + private boolean isHandOpen; + + /** + * + */ + public TileEntityHandPedestal() { + isDirty = false; + heldItemStack = null; + grip = 0; + gripMax = 20; + gripScale = 1; + isHandOpen = true; + } + + /** + * @param tagCompound + */ + @Override + public void writeToNBT(NBTTagCompound tagCompound) { + super.writeToNBT(tagCompound); + if (heldItemStack != null) { + NBTTagCompound objectCompound = new NBTTagCompound(); + heldItemStack.writeToNBT(objectCompound); + tagCompound.setTag("object", objectCompound); + } + tagCompound.setBoolean("isHandOpen", isHandOpen); + } + + /** + * @param tagCompound + */ + @Override + public void readFromNBT(NBTTagCompound tagCompound) { + super.readFromNBT(tagCompound); + if (tagCompound.hasKey("object", 10)) setHeldItemStack(ItemStack.loadItemStackFromNBT(tagCompound.getCompoundTag("object"))); + else removeHeldItemStack(); + isHandOpen = tagCompound.getBoolean("isHandOpen"); + } + + /** + * + */ + @Override + public void updateEntity() { + super.updateEntity(); + updateGrip(); + if (isDirty) { + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + isDirty = false; + } + } + + /** + * + */ + private void updateGrip() { + prevGrip = grip; + if (grip > 0 && isHandOpen) grip -= 1 / gripScale; + else if (grip < gripMax && !isHandOpen) grip += 1 / gripScale; + } + + /** + * @return + */ + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbttagcompound = new NBTTagCompound(); + writeToNBT(nbttagcompound); + return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, nbttagcompound); + } + + /** + * @param networkManager + * @param packet + */ + @Override + public void onDataPacket(NetworkManager networkManager, S35PacketUpdateTileEntity packet) { + readFromNBT(packet.func_148857_g()); + worldObj.func_147479_m(xCoord, yCoord, zCoord); + } + + /** + * + */ + @Override + public void markDirty() { + super.markDirty(); + isDirty = true; + } + + /** + * @return + */ + public ItemStack getHeldItemStack() { + return heldItemStack; + } + + /** + * @param heldItemStack + */ + public void setHeldItemStack(ItemStack heldItemStack) { + if (heldItemStack != null && heldItemStack.getItem() != null) { + heldItemStack.stackSize = 1; + this.heldItemStack = heldItemStack; + if (heldItemStack.getItem() instanceof ItemBlock) gripScale = 0.5f; + else gripScale = 1; + } + } + + /** + * + */ + public void removeHeldItemStack() { + heldItemStack = null; + } + + /** + * + */ + public void openHand() { + isHandOpen = true; + } + + /** + * + */ + public void closeHand() { + isHandOpen = false; + } + + /** + * @param t + * @return + */ + public float getGrip(float t) { + return (prevGrip * (1 - t) + grip * t) / gripMax; + } + + /** + * @return + */ + public float getGripScale() { + return gripScale; + } } \ No newline at end of file -- cgit v1.2.3