Guest User

Untitled

a guest
Feb 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.18 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. public class TileEntityPamCrop extends TileEntity
  4. {
  5.  
  6. public TileEntityPamCrop()
  7. {
  8.  
  9. }
  10.  
  11. public void readFromNBT(NBTTagCompound nbttagcompound)
  12. {
  13. //Load the data
  14. super.readFromNBT(nbttagcompound);
  15. CropID = nbttagcompound.getShort("CropID");
  16. GrowthStage = nbttagcompound.getShort("GrowthStage");
  17. }
  18.  
  19. public void writeToNBT(NBTTagCompound nbttagcompound)
  20. {
  21. //Save the data
  22. super.writeToNBT(nbttagcompound);
  23. nbttagcompound.setShort("CropID", (short) CropID);
  24. nbttagcompound.setShort("GrowthStage", (short) GrowthStage);
  25. }
  26.  
  27. public void invalidate()
  28. {
  29. super.invalidate();
  30.  
  31. //Called from our block removal
  32. int MaxStage = GrowthStageCount[CropID] - 1;
  33. int SeedsCount = 0;
  34. int HarvestCount = 0;
  35.  
  36. //1/2 chance of adding 1 seed to all drops
  37. if (worldObj.rand.nextInt(1) == 0)
  38. {
  39. SeedsCount++;
  40. }
  41.  
  42. //1/2 chance of adding 1 more for partialy grown crops
  43. if (GrowthStage > 0)
  44. {
  45. if (worldObj.rand.nextInt(2) == 0)
  46. {
  47. SeedsCount++;
  48. }
  49. }
  50.  
  51. //Harvest Stage
  52. if (GrowthStage == MaxStage)
  53. {
  54. //Must Drop at least 1 seed
  55. if (SeedsCount < 1)
  56. {
  57. SeedsCount = 1;
  58. }
  59.  
  60. SeedsCount += worldObj.rand.nextInt(2); //Can add 1 or 2 more seeds
  61. HarvestCount = 1; //We have a harvest
  62. }
  63.  
  64. //With all the drop counts asside, lets drop that amount.
  65.  
  66. if (CropID < SeedDrops.length && SeedsCount > 0)
  67. {
  68. DropItem(SeedDrops[CropID],SeedsCount);
  69. }
  70.  
  71. if (CropID < HarvestDrops.length && HarvestCount > 0)
  72. {
  73. DropItem(HarvestDrops[CropID],HarvestCount);
  74. }
  75. }
  76.  
  77. public void DropItem(int Item, int Count)
  78. {
  79. float f = 0.7F;
  80. double d = (double)(worldObj.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
  81. double d1 = (double)(worldObj.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
  82. double d2 = (double)(worldObj.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
  83. EntityItem entityitem = new EntityItem(worldObj, (double)xCoord + d, (double)yCoord + d1, (double)zCoord + d2, new ItemStack(Item,Count,0));
  84. entityitem.delayBeforeCanPickup = 10;
  85. worldObj.entityJoinedWorld(entityitem);
  86. return;
  87. }
  88.  
  89. public void setCropID(int ID)
  90. {
  91. //used by the seed item
  92. CropID = ID;
  93. }
  94.  
  95. public int getCropID()
  96. {
  97. //Base value for fetching other values
  98. return CropID;
  99. }
  100.  
  101. public void addGrowthStage()
  102. {
  103. //Run this instead of metadata functions
  104. if (CropID < GrowthStageCount.length) /* Check if the CropID is in range to avoid a crash */
  105. {
  106. if (GrowthStage < GrowthStageCount[CropID] - 1) /* If it hasn't hit the max for that CropID, add a stage. Subtract one because the start stage was already used. */
  107. {
  108. GrowthStage++;
  109. }
  110. }
  111.  
  112. worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlockId(xCoord, yCoord, zCoord)); //Updates the block so it displays properly
  113. }
  114.  
  115. public void setGrowthStage(int Stage)
  116. {
  117. //In case you need an override
  118. if (CropID < GrowthStageCount.length)
  119. {
  120. int MaxStage = GrowthStageCount[CropID] - 1; //Make sure we don't get above max
  121.  
  122. if (Stage > MaxStage)
  123. {
  124. GrowthStage = MaxStage;
  125. } else {
  126. GrowthStage = Stage;
  127. }
  128. }
  129.  
  130. worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlockId(xCoord, yCoord, zCoord));
  131. }
  132.  
  133. public void applyBonemeal()
  134. {
  135. //Set it to the Max Stage
  136. if (CropID < GrowthStageCount.length)
  137. {
  138. int MaxStage = GrowthStageCount[CropID] - 1; //Make sure we don't get above max
  139. GrowthStage = MaxStage;
  140. }
  141.  
  142. worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlockId(xCoord, yCoord, zCoord));
  143. }
  144.  
  145. public int getGrowthStage()
  146. {
  147. //In case you need to check the stage
  148. return GrowthStage;
  149. }
  150.  
  151. public int getTextureID()
  152. {
  153. //This will be used the the renderblocks hook
  154. if (CropID < TextureBases.length)
  155. {
  156. return TextureBases[CropID] + GrowthStage; //Base texture with stage shift
  157. }
  158. return 0; //something happened wrong
  159. }
  160.  
  161. private int CropID = 0; //This will be set in a custom seed item during placement
  162. private int GrowthStage = 0; //should always start at 0
  163.  
  164. private int[] TextureBases = {0,//Tomato
  165. 16,//Potato
  166. 32,//Lettuce
  167. 48,//Onion
  168. 64,//Carrot
  169. 80,//Corn
  170. 96,//Strawberry
  171. 112,//Grape
  172. 128,//Peanut
  173. 144,//Cucumber
  174. 160,//Spice
  175. 176,//Rice
  176. 192,//Beans
  177. 208,//Bellpepper
  178. 224,//Eggplant
  179. 240,//Tea
  180. 8,//Coffee
  181. 24,//Beet
  182. 40,//Broccoli
  183. 56,//Sweet Potato
  184. 72,//Peas
  185. 88,//Pineapple
  186. 104,//Turnip
  187. 200,//Blueberry
  188. 216,//Blackberry
  189. 232,//Raspberry
  190. 248,/*Kiwi*/};
  191.  
  192. /*Each line has a different index to start on. Our getTextureID() will return
  193. * the base texture with growth stage added so it goes to the next texture
  194. * in the sheet. TNT is the tiny stage, TNT Top is the medium stage, and TNT Side
  195. * is the harvest stage. TextureBases[CropID] will return the appropriate line for the ID.
  196. */
  197.  
  198. private int[] GrowthStageCount = {8,//Tomato
  199. 8,//Potato
  200. 8,//Lettuce
  201. 8,//Onion
  202. 8,//Carrot
  203. 8,//Corn
  204. 8,//Strawberry
  205. 8,//Grape
  206. 8,//Peanut
  207. 8,//Cucumber
  208. 8,//Spice
  209. 8,//Rice
  210. 8,//Beans
  211. 8,//Bellpepper
  212. 8,//Eggplant
  213. 8,//Tea
  214. 8,//Coffee
  215. 8,//Beet
  216. 8,//Broccoli
  217. 8,//Sweet Potato
  218. 8,//Peas
  219. 8,//Pineapple
  220. 8,//Turnip
  221. 8,//Blueberry
  222. 8,//Blackberry
  223. 8,//Raspberry
  224. 8,/*Kiwi*/};
  225.  
  226. //There are 8 default wheat stages. We will put 8 for CropID 3 so we can go through all stages.
  227.  
  228. private int[] SeedDrops = {mod_Pamfood.tomatoseedItem.shiftedIndex,
  229. mod_Pamfood.potatoseedItem.shiftedIndex,
  230. mod_Pamfood.lettuceseedItem.shiftedIndex,
  231. mod_Pamfood.onionseedItem.shiftedIndex,
  232. mod_Pamfood.carrotseedItem.shiftedIndex,
  233. mod_Pamfood.cornseedItem.shiftedIndex,
  234. mod_Pamfood.strawberryseedItem.shiftedIndex,
  235. mod_Pamfood.grapeseedItem.shiftedIndex,
  236. mod_Pamfood.peanutseedItem.shiftedIndex,
  237. mod_Pamfood.cucumberseedItem.shiftedIndex,
  238. mod_Pamfood.spiceseedItem.shiftedIndex,
  239. mod_Pamfood.riceseedItem.shiftedIndex,
  240. mod_Pamfood.beansseedItem.shiftedIndex,
  241. mod_Pamfood.bellpepperseedItem.shiftedIndex,
  242. mod_Pamfood.eggplantseedItem.shiftedIndex,
  243. mod_Pamfood.teaseedItem.shiftedIndex,
  244. mod_Pamfood.coffeeseedItem.shiftedIndex,
  245. mod_Pamfood.beetseedItem.shiftedIndex,
  246. mod_Pamfood.broccoliseedItem.shiftedIndex,
  247. mod_Pamfood.sweetpotatoseedItem.shiftedIndex,
  248. mod_Pamfood.peasseedItem.shiftedIndex,
  249. mod_Pamfood.pineappleseedItem.shiftedIndex,
  250. mod_Pamfood.turnipseedItem.shiftedIndex,
  251. mod_Pamfood.blueberryseedItem.shiftedIndex,
  252. mod_Pamfood.blackberryseedItem.shiftedIndex,
  253. mod_Pamfood.raspberryseedItem.shiftedIndex,
  254. mod_Pamfood.kiwiseedItem.shiftedIndex};
  255.  
  256. //These are seed drops in the same array format. Just fill it with Item/Block IDs.
  257.  
  258. private int[] HarvestDrops = {mod_Pamfood.tomatoItem.shiftedIndex,
  259. mod_Pamfood.potatoItem.shiftedIndex,
  260. mod_Pamfood.lettuceItem.shiftedIndex,
  261. mod_Pamfood.onionItem.shiftedIndex,
  262. mod_Pamfood.carrotItem.shiftedIndex,
  263. mod_Pamfood.cornItem.shiftedIndex,
  264. mod_Pamfood.strawberryItem.shiftedIndex,
  265. mod_Pamfood.grapeItem.shiftedIndex,
  266. mod_Pamfood.peanutItem.shiftedIndex,
  267. mod_Pamfood.cucumberItem.shiftedIndex,
  268. mod_Pamfood.peppercornItem.shiftedIndex,
  269. mod_Pamfood.riceItem.shiftedIndex,
  270. mod_Pamfood.beansItem.shiftedIndex,
  271. mod_Pamfood.bellpepperItem.shiftedIndex,
  272. mod_Pamfood.eggplantItem.shiftedIndex,
  273. mod_Pamfood.teaItem.shiftedIndex,
  274. mod_Pamfood.coffeeItem.shiftedIndex,
  275. mod_Pamfood.beetItem.shiftedIndex,
  276. mod_Pamfood.broccoliItem.shiftedIndex,
  277. mod_Pamfood.sweetpotatoItem.shiftedIndex,
  278. mod_Pamfood.peasItem.shiftedIndex,
  279. mod_Pamfood.pineappleItem.shiftedIndex,
  280. mod_Pamfood.turnipItem.shiftedIndex,
  281. mod_Pamfood.blueberryItem.shiftedIndex,
  282. mod_Pamfood.blackberryItem.shiftedIndex,
  283. mod_Pamfood.raspberryItem.shiftedIndex,
  284. mod_Pamfood.kiwiItem.shiftedIndex};
  285.  
  286. //Same thing as above but it will drop when harvested at the final stage.
  287.  
  288. }
Add Comment
Please, Sign In to add comment