Guest User

GUI Energie

a guest
May 2nd, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.29 KB | None | 0 0
  1. package firstetestmod;
  2.  
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.init.Items;
  5. import net.minecraft.inventory.ISidedInventory;
  6. import net.minecraft.item.Item;
  7. import net.minecraft.item.ItemStack;
  8. import net.minecraft.item.crafting.FurnaceRecipes;
  9. import net.minecraft.nbt.NBTTagCompound;
  10. import net.minecraft.nbt.NBTTagList;
  11. import net.minecraft.tileentity.TileEntity;
  12. import net.minecraftforge.oredict.OreDictionary;
  13. import cpw.mods.fml.relauncher.Side;
  14. import cpw.mods.fml.relauncher.SideOnly;
  15.  
  16. public class TileEntityMatterMachine extends TileEntity implements ISidedInventory{
  17. private static final int[] slots_bottom = new int[] {0};
  18. private static final int[] slots_sides = new int[] {1};
  19.  
  20. /**
  21. * The ItemStacks that hold the items currently being used in the furnace
  22. */
  23. private ItemStack[] slots = new ItemStack[2];
  24.  
  25. /** the speed of this furnace, 200 is normal / how many ticks it takes : 30 ticks = 1 second */
  26. public int maceratingSpeed = 400;
  27.  
  28. /** The number of ticks that the furnace will keep burning */
  29. public int power;
  30. public int maxPower = 30000;
  31.  
  32. /** The number of ticks that the current item has been cooking for */
  33. public int cookTime;
  34.  
  35. private String field_94130_e;
  36. private String MatterMachineName;
  37. public void MatterMachineName(String string){
  38. this.MatterMachineName = string;
  39. }
  40.  
  41. /**
  42. * Returns the number of slots in the inventory.
  43. */
  44. public int getSizeInventory()
  45. {
  46. return this.slots.length;
  47. }
  48.  
  49. /**
  50. * Returns the stack in slot i
  51. */
  52. public ItemStack getStackInSlot(int par1)
  53. {
  54. return this.slots[par1];
  55. }
  56.  
  57. /**
  58. * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a
  59. * new stack.
  60. */
  61. public ItemStack decrStackSize(int par1, int par2)
  62. {
  63. if (this.slots[par1] != null)
  64. {
  65. ItemStack itemstack;
  66.  
  67. if (this.slots[par1].stackSize <= par2)
  68. {
  69. itemstack = this.slots[par1];
  70. this.slots[par1] = null;
  71. return itemstack;
  72. }
  73. else
  74. {
  75. itemstack = this.slots[par1].splitStack(par2);
  76.  
  77. if (this.slots[par1].stackSize == 0)
  78. {
  79. this.slots[par1] = null;
  80. }
  81.  
  82. return itemstack;
  83. }
  84. }
  85. else
  86. {
  87. return null;
  88. }
  89. }
  90.  
  91. /**
  92. * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
  93. * like when you close a workbench GUI.
  94. */
  95. public ItemStack getStackInSlotOnClosing(int par1)
  96. {
  97. if (this.slots[par1] != null)
  98. {
  99. ItemStack itemstack = this.slots[par1];
  100. this.slots[par1] = null;
  101. return itemstack;
  102. }else{
  103. return null;
  104. }
  105. }
  106.  
  107. /**
  108. * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
  109. */
  110. public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
  111. {
  112. this.slots[par1] = par2ItemStack;
  113.  
  114. if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
  115. {
  116. par2ItemStack.stackSize = this.getInventoryStackLimit();
  117. }
  118. }
  119.  
  120. /**
  121. * Returns the name of the inventory.
  122. */
  123. public String getInvName()
  124. {
  125. return this.isInvNameLocalized() ? this.field_94130_e : "container.MatterMachine";
  126. }
  127.  
  128. /**
  129. * If this returns false, the inventory name will be used as an unlocalized name, and translated into the player's
  130. * language. Otherwise it will be used directly.
  131. */
  132. public boolean isInvNameLocalized()
  133. {
  134. return this.field_94130_e != null && this.field_94130_e.length() > 0;
  135. }
  136.  
  137. @Override
  138. public String getInventoryName()
  139. {
  140. return this.hasCustomInventoryName() ? this.field_94130_e : "container.MatterMachine";
  141. }
  142.  
  143. public boolean isInventoryName()
  144. {
  145. return this.field_94130_e != null && this.field_94130_e.length() > 0;
  146. }
  147. /**
  148. * Sets the custom display name to use when opening a GUI linked to this tile entity.
  149. */
  150. public void setGuiDisplayName(String par1Str)
  151. {
  152. this.field_94130_e = par1Str;
  153. }
  154.  
  155. /**
  156. * Reads a tile entity from NBT.
  157. */
  158. public void readFromNBT(NBTTagCompound par1NBTTagCompound)
  159. {
  160. super.readFromNBT(par1NBTTagCompound);
  161. NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items", 10);
  162. this.slots = new ItemStack[this.getSizeInventory()];
  163.  
  164. for (int i = 0; i < nbttaglist.tagCount(); ++i)
  165. {
  166. NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.getCompoundTagAt(i);
  167. byte b0 = nbttagcompound1.getByte("Slot");
  168.  
  169. if (b0 >= 0 && b0 < this.slots.length)
  170. {
  171. this.slots[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
  172. }
  173. }
  174.  
  175. this.power = par1NBTTagCompound.getShort("power");
  176. this.cookTime = par1NBTTagCompound.getShort("CookTime");
  177.  
  178. if (par1NBTTagCompound.hasKey("container.MatterMachineName"))
  179. {
  180. this.MatterMachineName = par1NBTTagCompound.getString("container.MatterMachineName");
  181. }
  182. }
  183.  
  184. /**
  185. * Writes a tile entity to NBT.
  186. */
  187. public void writeToNBT(NBTTagCompound par1NBTTagCompound)
  188. {
  189. super.writeToNBT(par1NBTTagCompound);
  190. par1NBTTagCompound.setShort("power", (short)this.power);
  191. par1NBTTagCompound.setShort("CookTime", (short)this.cookTime);
  192. NBTTagList nbttaglist = new NBTTagList();
  193.  
  194. for (int i = 0; i < this.slots.length; ++i)
  195. {
  196. if (this.slots[i] != null)
  197. {
  198. NBTTagCompound nbttagcompound1 = new NBTTagCompound();
  199. nbttagcompound1.setByte("Slot", (byte)i);
  200. this.slots[i].writeToNBT(nbttagcompound1);
  201. nbttaglist.appendTag(nbttagcompound1);
  202. }
  203. }
  204.  
  205. par1NBTTagCompound.setTag("Items", nbttaglist);
  206.  
  207. if (this.isInventoryName())
  208. {
  209. par1NBTTagCompound.setString("container.MatterMachineName", this.MatterMachineName);
  210. }
  211. }
  212.  
  213. /**
  214. * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
  215. * this more of a set than a get?*
  216. */
  217. public int getInventoryStackLimit()
  218. {
  219. return 64;
  220. }
  221.  
  222. @SideOnly(Side.CLIENT)
  223.  
  224. /**
  225. * Returns an integer between 0 and the passed value representing how close the current item is to being completely
  226. * cooked
  227. */
  228. public int getCookProgressScaled(int par1)
  229. {
  230. return this.cookTime * par1 / this.maceratingSpeed;
  231. }
  232.  
  233. public int getPowerRemainingScaled(int par1){
  234. return this.power * par1 / this.maxPower;
  235. }
  236.  
  237. /**
  238. * Returns true if the furnace is currently burning
  239. */
  240. public boolean hasPower()
  241. {
  242. return this.power > 0;
  243. }
  244.  
  245. public boolean isMacerating(){
  246. return this.cookTime > 0;
  247. }
  248.  
  249. /**
  250. * Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner uses this to count
  251. * ticks and creates a new spawn inside its implementation.
  252. */
  253. public void updateEntity(){
  254. boolean flag = this.power > 0;
  255. boolean flag1 = false;
  256.  
  257. if (hasPower() && isMacerating()){
  258. this.power--;
  259. }
  260.  
  261. if (!this.worldObj.isRemote){
  262. if (this.power < this.maxPower && this.getItemPower(this.slots[1]) > 0){
  263. this.power += getItemPower(this.slots[1]);
  264.  
  265. flag1 = true;
  266.  
  267. if (this.slots[1] != null){
  268. this.slots[1].stackSize--;
  269.  
  270. if (this.slots[1].stackSize == 0){
  271. this.slots[1] = this.slots[1].getItem().getContainerItem(slots[1]);
  272. }
  273. }
  274. }
  275.  
  276. if (this.hasPower() && this.canSmelt())
  277. {
  278. ++this.cookTime;
  279.  
  280. if (this.cookTime == this.maceratingSpeed)
  281. {
  282. this.cookTime = 0;
  283.  
  284. flag1 = true;
  285. }
  286. }
  287. else
  288. {
  289. this.cookTime = 0;
  290. }
  291.  
  292. if (flag != this.power > 0)
  293. {
  294. flag1 = true;
  295. MatterMachine.updateFurnaceBlockState(this.power > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
  296. }
  297. }
  298.  
  299. if (flag1){
  300. this.markDirty();
  301. }
  302. }
  303.  
  304.  
  305.  
  306. /**
  307. * Returns true if the furnace can smelt an item, i.e. has a source item, destination stack isn't full, etc.
  308. */
  309. private boolean canSmelt(){
  310. boolean flag3 = this.power >= 1000;
  311. if (!this.hasPower()){
  312. return false;
  313. }else if(this.hasPower() && !flag3) {
  314. return false;
  315. }else
  316. {
  317. if(flag3) {
  318. MatterMachineRecipe.getMatter();
  319. return true;
  320. }
  321. return false;
  322.  
  323. }
  324. }
  325.  
  326. /**
  327. * Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack
  328. */
  329. //CANSMELTITEM LEL
  330.  
  331.  
  332. /**
  333. * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't
  334. * fuel
  335. */
  336. public static int getItemPower(ItemStack itemstack){
  337. if (itemstack == null){
  338. return 0;
  339. }else{
  340. Item item = itemstack.getItem();
  341.  
  342. if (item == Items.redstone) return 10;
  343. if (item == Items.nether_star) return 50;
  344. if (item == firsttestmodmain.LacirisItem) return 500;
  345. if (item == firsttestmodmain.UniversalMatter)return 1000;
  346. return 0;
  347. }
  348. }
  349.  
  350.  
  351. /**
  352. * Return true if item is a fuel source (getItempower() > 0).
  353. */
  354. public static boolean isItemFuel(ItemStack par0ItemStack)
  355. {
  356. return getItemPower(par0ItemStack) > 0;
  357. }
  358.  
  359. /**
  360. * Do not make give this method the name canInteractWith because it clashes with Container
  361. */
  362. public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
  363. {
  364. return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
  365. }
  366.  
  367. public void openChest() {}
  368.  
  369. public void closeChest() {}
  370.  
  371. /**
  372. * Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
  373. */
  374. public boolean isItemValidForSlot(int par1, ItemStack par2ItemStack)
  375. {
  376. return par1 == 2 ? false : (par1 == 1 ? isItemFuel(par2ItemStack) : true);
  377. }
  378.  
  379. /**
  380. * Returns an array containing the indices of the slots that can be accessed by automation on the given side of this
  381. * block.
  382. */
  383. public int[] getAccessibleSlotsFromSide(int par1)
  384. {
  385. return par1 == 0 ? slots_bottom : par1 == 1 ? slots_sides : slots_sides;
  386. }
  387.  
  388. /**
  389. * Returns true if automation can insert the given item in the given slot from the given side. Args: Slot, item,
  390. * side
  391. */
  392. public boolean canInsertItem(int par1, ItemStack par2ItemStack, int par3)
  393. {
  394. return this.isItemValidForSlot(par1, par2ItemStack);
  395. }
  396.  
  397. /**
  398. * Returns true if automation can extract the given item in the given slot from the given side. Args: Slot, item,
  399. * side
  400. */
  401.  
  402.  
  403.  
  404. @Override
  405. public boolean hasCustomInventoryName() {
  406. // TODO Auto-generated method stub
  407. return false;
  408. }
  409.  
  410. @Override
  411. public void openInventory() {
  412. // TODO Auto-generated method stub
  413.  
  414. }
  415.  
  416. @Override
  417. public void closeInventory() {
  418. // TODO Auto-generated method stub
  419.  
  420. }
  421.  
  422. @Override
  423. public boolean canExtractItem(int p_102008_1_, ItemStack p_102008_2_,
  424. int p_102008_3_) {
  425.  
  426. return false;
  427. }
  428. }
Add Comment
Please, Sign In to add comment