Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.13 KB | None | 0 0
  1. package com.vognersmods.fleshworks;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import java.util.Random;
  6.  
  7. import org.apache.logging.log4j.Level;
  8. import org.apache.logging.log4j.LogManager;
  9. import org.apache.logging.log4j.Logger;
  10.  
  11. import cpw.mods.fml.common.FMLLog;
  12. import cpw.mods.fml.common.registry.GameRegistry;
  13. import cpw.mods.fml.relauncher.Side;
  14. import cpw.mods.fml.relauncher.SideOnly;
  15. import net.minecraft.block.Block;
  16. import net.minecraft.block.material.Material;
  17. import net.minecraft.entity.Entity;
  18. import net.minecraft.entity.effect.EntityLightningBolt;
  19. import net.minecraft.entity.player.EntityPlayer;
  20. import net.minecraft.init.Blocks;
  21. import net.minecraft.init.Items;
  22. import net.minecraft.inventory.ISidedInventory;
  23. import net.minecraft.item.Item;
  24. import net.minecraft.item.ItemBlock;
  25. import net.minecraft.item.ItemHoe;
  26. import net.minecraft.item.ItemStack;
  27. import net.minecraft.item.ItemSword;
  28. import net.minecraft.item.ItemTool;
  29. import net.minecraft.nbt.NBTTagCompound;
  30. import net.minecraft.nbt.NBTTagList;
  31. import net.minecraft.tileentity.TileEntity;
  32. import net.minecraft.util.AxisAlignedBB;
  33. import net.minecraft.world.World;
  34.  
  35. public class TileEntityBolus extends TileEntity implements ISidedInventory {
  36.  
  37. public Logger logger = LogManager.getLogger();
  38. public ItemStack[] bolusItemStacks = new ItemStack[18];
  39. public int furnaceBurnTime;
  40. /** The number of ticks that a fresh copy of the currently-burning item would keep the furnace burning for */
  41. public int currentItemBurnTime = 300;
  42. /** The number of ticks that the current item has been cooking for */
  43. public int furnaceCookTime;
  44. public int field_145926_a;
  45. public float field_145933_i;
  46. public float field_145931_j;
  47. public float field_145932_k;
  48. public float field_145929_l;
  49. public float field_145930_m;
  50. public float field_145927_n;
  51. public float field_145928_o;
  52. public float field_145925_p;
  53. public float field_145924_q;
  54. private static Random rand = new Random();//field_145923_r
  55. EntityPlayer entityplayer;
  56. public boolean atRest;
  57. int ticker = 0;//used to time texture animation
  58. boolean canGrumble;
  59.  
  60. public TileEntityBolus(World world, int meta){
  61. this.blockMetadata = meta;
  62. this.worldObj = world;
  63. if(world.isRemote){
  64. switch(meta){
  65. case 2: {
  66. this.field_145924_q = -1.57F;//CORRECT-ISH
  67. //System.out.println("-1.57, " + meta);
  68. break;
  69. }
  70. case 3:{
  71. this.field_145924_q = 1.57F;//CORRECT-ISH
  72. //System.out.println("1.57, " + meta);
  73. break;
  74. }
  75. case 4: {
  76. this.field_145924_q = 3.14F;//CORRECT-ISH
  77. //System.out.println("3.14, " + meta);
  78.  
  79. break;
  80. }
  81. case 5: {
  82. this.field_145924_q = 0.0F; //CORRECT, with the other values it jerks from 0.0 to the value I specified
  83. //System.out.println("0.0, " + meta);
  84. break;
  85. }
  86. default:
  87. System.out.println("TEBolus: Unexpeected metadata, " + meta);
  88. break;
  89. }
  90. }
  91. //remove lightning rod
  92. this.worldObj.setBlockToAir(xCoord, yCoord+1, zCoord);
  93. this.worldObj.setBlockToAir(xCoord, yCoord+2, zCoord);
  94. }
  95.  
  96. public TileEntityBolus(){
  97. //nullary constructor necessary for FML reflection
  98. }
  99.  
  100. @Override
  101. public void updateEntity(){
  102. super.updateEntity();
  103.  
  104. /*for(int i = 0; i < bolusItemStacks.length; i++){
  105. System.out.print("slot " + i + ", ");
  106. if(i == 17){
  107. System.out.print("\n");
  108. }
  109. if(bolusItemStacks[i] != null){
  110. System.out.println("\n\n\n\nNon-null item stack found: \n\n\n\n" + bolusItemStacks[i].getDisplayName());
  111. }
  112. }*/
  113.  
  114.  
  115. this.field_145927_n = this.field_145930_m;
  116. this.field_145925_p = this.field_145928_o;
  117. entityplayer = this.worldObj.getClosestPlayer((double)((float)this.xCoord + 0.5F), (double)((float)this.yCoord + 0.5F), (double)((float)this.zCoord + 0.5F), 6.0D);
  118.  
  119. if (entityplayer != null) {
  120. if(canGrumble){
  121. grumble();
  122. canGrumble = false;
  123. }
  124. atRest = false;
  125. double d0 = entityplayer.posX - (double)((float)this.xCoord + 0.5F);//difference between
  126. double d1 = entityplayer.posZ - (double)((float)this.zCoord + 0.5F);
  127. this.field_145924_q = (float)Math.atan2(d1, d0);//probable rotation angle
  128.  
  129. } else {
  130. if(!canGrumble)
  131. canGrumble = true;
  132. atRest = true;
  133. if(worldObj.isRemote){
  134. switch(getBlockMetadata()){
  135. case 2: {
  136. field_145924_q = -1.57F;
  137. break;
  138. }
  139. case 3: {
  140. field_145924_q = 1.57F;
  141. break;
  142. }
  143. case 4: {
  144. field_145924_q = 3.14F;
  145. break;
  146. }
  147. case 5: {
  148. field_145924_q = 0.0F;
  149. break;
  150. }
  151. default:
  152. System.out.println("Unexpected metadata: " + getBlockMetadata());
  153. break;
  154. }
  155. }
  156. }
  157.  
  158. if(atRest){ //close eye
  159. if(ticker >= 0){
  160. ticker--;
  161. }
  162.  
  163. } else { //open eye
  164. if(ticker <= 2){
  165. ticker++;
  166. }
  167. }
  168.  
  169. //begin wrap-arounds
  170. while (this.field_145928_o >= (float)Math.PI)
  171. {
  172. this.field_145928_o -= ((float)Math.PI * 2F);
  173. }
  174.  
  175. while (this.field_145928_o < -(float)Math.PI)
  176. {
  177. this.field_145928_o += ((float)Math.PI * 2F);
  178. }
  179.  
  180. while (this.field_145924_q >= (float)Math.PI)
  181. {
  182. this.field_145924_q -= ((float)Math.PI * 2F);
  183. }
  184.  
  185. while (this.field_145924_q < -(float)Math.PI)
  186. {
  187. this.field_145924_q += ((float)Math.PI * 2F);
  188. }
  189. //end wrap-arounds
  190.  
  191. float f2;
  192.  
  193. for (f2 = this.field_145924_q - this.field_145928_o; f2 >= (float)Math.PI; f2 -= ((float)Math.PI * 2F))
  194. {
  195. ;
  196. }
  197.  
  198. while (f2 < -(float)Math.PI)
  199. {
  200. f2 += ((float)Math.PI * 2F);
  201. }
  202.  
  203. this.field_145928_o += f2 * 0.4F;
  204.  
  205. ++this.field_145926_a;
  206. this.field_145931_j = this.field_145933_i;
  207. float f = (this.field_145932_k - this.field_145933_i) * 0.4F;
  208. float f3 = 0.2F;
  209.  
  210. if (f < -f3)
  211. {
  212. f = -f3;
  213. }
  214.  
  215. if (f > f3)
  216. {
  217. f = f3;
  218. }
  219.  
  220. this.field_145929_l += (f - this.field_145929_l) * 0.9F;
  221. this.field_145933_i += this.field_145929_l;
  222.  
  223.  
  224.  
  225.  
  226. //START FURNACE-EY SHIT
  227.  
  228. boolean flag = this.furnaceBurnTime > 0;
  229. boolean flag1 = false;
  230.  
  231. if (this.furnaceBurnTime > 0)
  232. {
  233. --this.furnaceBurnTime;
  234. }
  235.  
  236. if (!this.worldObj.isRemote)
  237. {
  238. if (this.furnaceBurnTime != 0 || this.bolusItemStacks[1] != null && this.bolusItemStacks[0] != null)
  239. {
  240. if (this.furnaceBurnTime == 0)
  241. {
  242. this.currentItemBurnTime = this.furnaceBurnTime = getItemBurnTime(this.bolusItemStacks[1]);
  243.  
  244. if (this.furnaceBurnTime > 0)
  245. {
  246. flag1 = true;
  247.  
  248. if (this.bolusItemStacks[1] != null)
  249. {
  250. --this.bolusItemStacks[1].stackSize;
  251.  
  252. if (this.bolusItemStacks[1].stackSize == 0)
  253. {
  254. this.bolusItemStacks[1] = bolusItemStacks[1].getItem().getContainerItem(bolusItemStacks[1]);
  255. }
  256. }
  257. }
  258. }
  259.  
  260. if (this.isBurning())
  261. {
  262. ++this.furnaceCookTime;
  263.  
  264. if (this.furnaceCookTime == 200)
  265. {
  266. this.furnaceCookTime = 0;
  267. this.smeltItem();
  268. flag1 = true;
  269. }
  270. }
  271. else
  272. {
  273. this.furnaceCookTime = 0;
  274. }
  275. }
  276. }
  277. this.markDirty();
  278. worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
  279. }
  280.  
  281. @Override
  282. public AxisAlignedBB getRenderBoundingBox()
  283. {
  284. AxisAlignedBB bb = INFINITE_EXTENT_AABB;
  285. bb = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1.6, zCoord + 1);
  286. return bb;
  287. }
  288.  
  289. public void grumble(){
  290. //randomize pitch a bit at some point
  291. worldObj.playSound((double)xCoord, (double)yCoord, (double)zCoord, "fw:grumble", 0.2F, 1.3F, false);
  292. }
  293.  
  294.  
  295. // -=-=Begin furnace-like stuff//-=-=
  296.  
  297. /**
  298. * Returns an integer between 0 and the passed value representing how close the current item is to being completely
  299. * cooked
  300. */
  301. @SideOnly(Side.CLIENT)
  302. public int getCookProgressScaled(int p_145953_1_)
  303. {
  304. return this.furnaceCookTime * p_145953_1_ / 200;
  305. }
  306.  
  307. /**
  308. * Returns an integer between 0 and the passed value representing how much burn time is left on the current fuel
  309. * item, where 0 means that the item is exhausted and the passed value means that the item is fresh
  310. */
  311. @SideOnly(Side.CLIENT)
  312. public int getBurnTimeRemainingScaled(int p_145955_1_)
  313. {
  314. if (this.currentItemBurnTime == 0)
  315. {
  316. this.currentItemBurnTime = 200;
  317. }
  318.  
  319. return this.furnaceBurnTime * p_145955_1_ / this.currentItemBurnTime;
  320. }
  321.  
  322. /**
  323. * Furnace isBurning
  324. */
  325. public boolean isBurning()
  326. {
  327. return this.furnaceBurnTime > 0;
  328. }
  329.  
  330. //IF OUTPUT SLOTS ARE FULL, THROW RESULT ON GROUND
  331. public ItemStack smeltItem(){
  332. System.out.println("\nSMELTING RESULT CHECKING IN\n");
  333. return null;
  334.  
  335. }
  336.  
  337.  
  338. /**
  339. * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't
  340. * fuel
  341. *
  342. * In short, any kind of meaty mob drop will work.
  343. *
  344. * Flesh blocks only burn for 1/4 of the time as one of these items as the bolus has already eaten them once.
  345. * Cooked meat is only half as effective.
  346. *
  347. *
  348. */
  349. public static int getItemBurnTime(ItemStack itemStack)
  350. {
  351. if (itemStack == null)
  352. {
  353. return 0;
  354. }
  355. else
  356. {
  357. Item item = itemStack.getItem();
  358.  
  359. if (item instanceof ItemBlock && Block.getBlockFromItem(item) != FleshWorks.blockFlesh || item instanceof ItemBlock && Block.getBlockFromItem(item) != FleshWorks.blockBolus )
  360. {
  361. return 75;
  362. }
  363.  
  364. //raw: , spider eye, raw pork, raw beef, raw fish, raw chicken, slimeball RETURN 300
  365. if (item == Items.rotten_flesh) return 300;
  366. if (item == Items.spider_eye) return 300;
  367. if (item == Items.porkchop) return 300;
  368. if (item == Items.beef) return 300;
  369. if (item == Items.fish) return 300;
  370. if (item == Items.chicken) return 300;
  371. if (item == Items.slime_ball) return 300;
  372. //cooked: chicken, fish, steak RETURN 150
  373. if (item == Items.cooked_beef) return 150;
  374. if (item == Items.cooked_chicken) return 150;
  375. if (item == Items.cooked_fished) return 150;
  376. if (item == Items.cooked_porkchop) return 150;
  377. return 0;
  378.  
  379.  
  380. }
  381. }
  382.  
  383.  
  384. public void readFromNBT(NBTTagCompound saveData)
  385. {
  386. super.readFromNBT(saveData);
  387. System.out.println("\n\t\tREAD CHECKING IN\n");
  388. NBTTagList nbttaglist = saveData.getTagList("Items", 10);
  389. this.bolusItemStacks = new ItemStack[this.getSizeInventory()];
  390.  
  391. for (int i = 0; i < nbttaglist.tagCount(); ++i)
  392. {
  393. NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
  394. byte b0 = nbttagcompound1.getByte("Slot");
  395.  
  396. if (b0 >= 0 && b0 < this.bolusItemStacks.length)
  397. {
  398. this.bolusItemStacks[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
  399. if(bolusItemStacks[b0] == null){
  400. System.out.println("Reading NULL item stack " + b0 + ",\t");
  401. } else {
  402. System.out.println("Reading item stack " + b0 + ", " + bolusItemStacks[b0].getDisplayName() + ",\t");
  403. }
  404.  
  405. }
  406. }
  407.  
  408. this.furnaceBurnTime = saveData.getShort("BurnTime");
  409. this.furnaceCookTime = saveData.getShort("CookTime");
  410. }
  411.  
  412. public void writeToNBT(NBTTagCompound saveData)
  413. {
  414. super.writeToNBT(saveData);
  415. System.out.println("\n\t\tWRITE CHECKING IN\n");
  416.  
  417. saveData.setShort("BurnTime", (short)this.furnaceBurnTime);
  418. saveData.setShort("CookTime", (short)this.furnaceCookTime);
  419. NBTTagList nbttaglist = new NBTTagList();
  420.  
  421. for (int i = 0; i < this.bolusItemStacks.length; ++i)
  422. {
  423. if(bolusItemStacks[i] == null){
  424. System.out.println("Saving NULL item stack " + i + ",\t");
  425. } else {
  426. System.out.println("Saving item stack " + i + ", " + bolusItemStacks[i].getDisplayName() + ",\t");
  427. }
  428. if (this.bolusItemStacks[i] != null)
  429. {
  430. System.out.println("Saving " + this.bolusItemStacks[i].getDisplayName());
  431.  
  432. NBTTagCompound nbttagcompound1 = new NBTTagCompound();
  433. nbttagcompound1.setByte("Slot", (byte)i);
  434. this.bolusItemStacks[i].writeToNBT(nbttagcompound1);
  435. nbttaglist.appendTag(nbttagcompound1);
  436. }
  437. }
  438.  
  439. saveData.setTag("Items", nbttaglist);
  440. }
  441.  
  442. public static boolean isItemFuel(ItemStack p_145954_0_)
  443. {
  444. /**
  445. * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't
  446. * fuel
  447. */
  448. return getItemBurnTime(p_145954_0_) > 0;
  449. }
  450.  
  451.  
  452. /*
  453. * ISidedInventory start
  454. *
  455. * I've disabled all automation-related things. Most automation (aside from feeding it) is simply not practical
  456. * due to the effect it has on its surroundings.
  457. *
  458. * */
  459.  
  460. @Override
  461. public int getSizeInventory() {
  462. return this.bolusItemStacks.length;
  463. }
  464.  
  465. @Override
  466. public ItemStack getStackInSlot(int p_70301_1_) {
  467. return this.bolusItemStacks[p_70301_1_];
  468. }
  469.  
  470. @Override
  471. /**
  472. * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a
  473. * new stack.
  474. */
  475. public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_)
  476. {
  477. if (this.bolusItemStacks[p_70298_1_] != null)
  478. {
  479. ItemStack itemstack;
  480.  
  481. if (this.bolusItemStacks[p_70298_1_].stackSize <= p_70298_2_)
  482. {
  483. itemstack = this.bolusItemStacks[p_70298_1_];
  484. this.bolusItemStacks[p_70298_1_] = null;
  485. return itemstack;
  486. }
  487. else
  488. {
  489. itemstack = this.bolusItemStacks[p_70298_1_].splitStack(p_70298_2_);
  490.  
  491. if (this.bolusItemStacks[p_70298_1_].stackSize == 0)
  492. {
  493. this.bolusItemStacks[p_70298_1_] = null;
  494. }
  495.  
  496. return itemstack;
  497. }
  498. }
  499. else
  500. {
  501. return null;
  502. }
  503. }
  504.  
  505. @Override
  506. public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
  507. if (this.bolusItemStacks[p_70304_1_] != null)
  508. {
  509. ItemStack itemstack = this.bolusItemStacks[p_70304_1_];
  510. //this.bolusItemStacks[p_70304_1_] = null;
  511. return itemstack;
  512. }
  513. else
  514. {
  515. return null;
  516. }
  517. }
  518.  
  519. @Override
  520. /**
  521. * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
  522. */
  523. public void setInventorySlotContents(int slotIndex, ItemStack itemStack)
  524. {
  525. this.bolusItemStacks[slotIndex] = itemStack;
  526.  
  527. if (itemStack != null)
  528. {
  529. System.out.println("\n\tSlot " + slotIndex + " getting filled with " + itemStack.getDisplayName() + "; double check: this.bolusItemStacks[slotIndex].getDisplayName()..." + this.bolusItemStacks[slotIndex].getDisplayName());
  530. } else {
  531. System.out.println("SETTING NULL ITEM TO SLOT " + slotIndex);
  532. }
  533.  
  534.  
  535. if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit())
  536. {
  537. itemStack.stackSize = this.getInventoryStackLimit();
  538. }
  539.  
  540. markDirty();
  541. worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
  542. }
  543.  
  544. @Override
  545. public String getInventoryName() {
  546. return null;
  547. }
  548.  
  549. @Override
  550. public boolean hasCustomInventoryName() {
  551. return false;
  552. }
  553.  
  554. @Override
  555. public int getInventoryStackLimit() {
  556. return 64;
  557. }
  558.  
  559. @Override
  560. public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
  561. return true;
  562. }
  563.  
  564. @Override
  565. public void openInventory() {}
  566.  
  567. @Override
  568. public void closeInventory() {}
  569.  
  570. @Override// hm...
  571. public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
  572. return true;
  573. }
  574.  
  575. @Override
  576. public int[] getAccessibleSlotsFromSide(int p_94128_1_) {
  577. return null;
  578. }
  579.  
  580. @Override
  581. public boolean canInsertItem(int p_102007_1_, ItemStack p_102007_2_, int p_102007_3_) {
  582. return false;
  583. }
  584.  
  585. @Override
  586. public boolean canExtractItem(int p_102008_1_, ItemStack p_102008_2_, int p_102008_3_) {
  587. return false;
  588. }
  589. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement