summaryrefslogtreecommitdiff
path: root/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityHandPedestal.java
diff options
context:
space:
mode:
authorOnyxDarkKnight <sor1n.iliutza16@gmail.com>2015-08-13 21:12:11 +0100
committerOnyxDarkKnight <sor1n.iliutza16@gmail.com>2015-08-13 21:12:11 +0100
commit0ef6a00aa79f022e5bd56b3f77e6861bbecf6d94 (patch)
tree03966c83cd16d1912ec1596d83f89f251cc35f83 /src/main/java/darkknight/jewelrycraft/tileentity/TileEntityHandPedestal.java
parent921f1ba6f30e66c80c803618ebff496778e78970 (diff)
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...
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/tileentity/TileEntityHandPedestal.java')
-rw-r--r--src/main/java/darkknight/jewelrycraft/tileentity/TileEntityHandPedestal.java348
1 files changed, 167 insertions, 181 deletions
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