Guest User

Untitled

a guest
Dec 10th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. package com.camerpon900.realauto2.blocks.TileEntities;
  2.  
  3. import com.camerpon900.realauto2.blocks.Blocks;
  4. import com.camerpon900.realauto2.utils.WorldHelper;
  5. import net.minecraft.entity.player.EntityPlayer;
  6. import net.minecraft.inventory.ISidedInventory;
  7. import net.minecraft.item.ItemStack;
  8. import net.minecraft.nbt.NBTTagCompound;
  9. import net.minecraft.nbt.NBTTagList;
  10. import net.minecraft.tileentity.TileEntity;
  11. import net.minecraft.world.World;
  12. import net.minecraft.world.biome.BiomeGenDesert;
  13. import net.minecraftforge.common.util.ForgeDirection;
  14.  
  15. public class TileEntityEnergyCube extends TileEntity implements ISidedInventory {
  16.  
  17. private ItemStack[] slots = new ItemStack[2];
  18.  
  19. public int power = 0;
  20. private int maxPower = 5000000;
  21.  
  22. public void updateEntity() {
  23. System.out.println("Slots: " + this.slots.length);
  24. }
  25.  
  26. public void readFromNBT(NBTTagCompound nbt) {
  27. super.readFromNBT(nbt);
  28.  
  29. System.out.println("slots " + this.slots);
  30.  
  31. System.out.println("reading nbt");
  32.  
  33. NBTTagList list = nbt.getTagList("Slots", 10);
  34. NBTTagList powerList = nbt.getTagList("Power",power);
  35. this.slots = new ItemStack[getSizeInventory()];
  36.  
  37. for(int i = 0; i < list.tagCount(); i++) {
  38. NBTTagCompound item = list.getCompoundTagAt(i);
  39. NBTTagCompound power = list.getCompoundTagAt(i);
  40. byte b = item.getByte("Item");
  41. int p = item.getInteger("Power");
  42.  
  43. if (b >= 0 && b < this.slots.length) {
  44. this.slots[b] = ItemStack.loadItemStackFromNBT(item);
  45. }
  46.  
  47. if(p >= 0 && p < this.maxPower) {
  48. this.power = power.getInteger("Power");
  49. }
  50. }
  51. }
  52.  
  53. public void writeToNBT(NBTTagCompound nbt) {
  54. super.writeToNBT(nbt);
  55. System.out.println("Writing To NBT at x: " + xCoord + " y: " + yCoord + " z: " + zCoord);
  56.  
  57. NBTTagList list = new NBTTagList();
  58.  
  59. for(int i = 0; i < slots.length; i++) {
  60. if(this.slots[i] != null) {
  61. NBTTagCompound item = new NBTTagCompound();
  62. item.setByte("Item", (byte)i);
  63. this.slots[i].writeToNBT(item);
  64. list.appendTag(item);
  65. }
  66. }
  67.  
  68. if(power >= 1) {
  69. NBTTagCompound power = new NBTTagCompound();
  70. power.setInteger("Power", this.power);
  71. list.appendTag(power);
  72. }
  73. nbt.setTag("Power", list);
  74. nbt.setTag("Slots", list);
  75. }
  76.  
  77. public int getSizeInventory() {
  78. return this.slots.length;
  79. }
  80.  
  81. public int[] getAccessibleSlotsFromSide(int p_94128_1_) {
  82. return new int[0];
  83. }
  84.  
  85. public boolean canInsertItem(int p_102007_1_, ItemStack p_102007_2_, int p_102007_3_) {
  86. return this.isItemValidForSlot(p_102007_1_,p_102007_2_);
  87. }
  88.  
  89. public boolean canExtractItem(int p_102008_1_, ItemStack p_102008_2_, int p_102008_3_) {
  90. return true;
  91. }
  92.  
  93. public ItemStack getStackInSlot(int i) {
  94. if(i <= 2) {
  95. return this.slots[1];
  96. }
  97. return this.slots[i];
  98. }
  99.  
  100. public ItemStack decrStackSize(int i, int j) {
  101. if(this.slots[i] != null) {
  102. System.out.println(this.slots[i]);
  103. ItemStack itemStack;
  104. if(this.slots[i].stackSize <= j) {
  105. itemStack = this.slots[i];
  106. this.slots[i] = null;
  107. return itemStack;
  108. } else {
  109. itemStack = this.slots[i].splitStack(j);
  110. if(this.slots[i].stackSize == 0) {
  111. this.slots[i] = null;
  112. }
  113. }
  114. return itemStack;
  115. }
  116.  
  117. return null;
  118. }
  119.  
  120. public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
  121. return null;
  122. }
  123.  
  124. public void setInventorySlotContents(int i, ItemStack itemStack) {
  125. this.slots[i] = itemStack;
  126.  
  127. if(itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()) {
  128. itemStack.stackSize = this.getInventoryStackLimit();
  129. }
  130. }
  131.  
  132. public String getInventoryName() {
  133. return null;
  134. }
  135.  
  136. public boolean hasCustomInventoryName() {
  137. return false;
  138. }
  139.  
  140. public int getInventoryStackLimit() {
  141. return 64;
  142. }
  143.  
  144. public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
  145. return true;
  146. }
  147.  
  148. public void openInventory() {
  149.  
  150. }
  151.  
  152. public void closeInventory() {
  153.  
  154. }
  155.  
  156. public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
  157. return true;
  158. }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment