Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minecraft.src;
- public class TileEntityPamCrop extends TileEntity
- {
- public TileEntityPamCrop()
- {
- }
- public void readFromNBT(NBTTagCompound nbttagcompound)
- {
- //Load the data
- super.readFromNBT(nbttagcompound);
- CropID = nbttagcompound.getShort("CropID");
- GrowthStage = nbttagcompound.getShort("GrowthStage");
- }
- public void writeToNBT(NBTTagCompound nbttagcompound)
- {
- //Save the data
- super.writeToNBT(nbttagcompound);
- nbttagcompound.setShort("CropID", (short) CropID);
- nbttagcompound.setShort("GrowthStage", (short) GrowthStage);
- }
- public void invalidate()
- {
- super.invalidate();
- //Called from our block removal
- int MaxStage = GrowthStageCount[CropID] - 1;
- int SeedsCount = 0;
- int HarvestCount = 0;
- //1/2 chance of adding 1 seed to all drops
- if (worldObj.rand.nextInt(1) == 0)
- {
- SeedsCount++;
- }
- //1/2 chance of adding 1 more for partialy grown crops
- if (GrowthStage > 0)
- {
- if (worldObj.rand.nextInt(2) == 0)
- {
- SeedsCount++;
- }
- }
- //Harvest Stage
- if (GrowthStage == MaxStage)
- {
- //Must Drop at least 1 seed
- if (SeedsCount < 1)
- {
- SeedsCount = 1;
- }
- SeedsCount += worldObj.rand.nextInt(2); //Can add 1 or 2 more seeds
- HarvestCount = 1; //We have a harvest
- }
- //With all the drop counts asside, lets drop that amount.
- if (CropID < SeedDrops.length && SeedsCount > 0)
- {
- DropItem(SeedDrops[CropID],SeedsCount);
- }
- if (CropID < HarvestDrops.length && HarvestCount > 0)
- {
- DropItem(HarvestDrops[CropID],HarvestCount);
- }
- }
- public void DropItem(int Item, int Count)
- {
- float f = 0.7F;
- double d = (double)(worldObj.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
- double d1 = (double)(worldObj.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
- double d2 = (double)(worldObj.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
- EntityItem entityitem = new EntityItem(worldObj, (double)xCoord + d, (double)yCoord + d1, (double)zCoord + d2, new ItemStack(Item,Count,0));
- entityitem.delayBeforeCanPickup = 10;
- worldObj.entityJoinedWorld(entityitem);
- return;
- }
- public void setCropID(int ID)
- {
- //used by the seed item
- CropID = ID;
- }
- public int getCropID()
- {
- //Base value for fetching other values
- return CropID;
- }
- public void addGrowthStage()
- {
- //Run this instead of metadata functions
- if (CropID < GrowthStageCount.length) /* Check if the CropID is in range to avoid a crash */
- {
- 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. */
- {
- GrowthStage++;
- }
- }
- worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlockId(xCoord, yCoord, zCoord)); //Updates the block so it displays properly
- }
- public void setGrowthStage(int Stage)
- {
- //In case you need an override
- if (CropID < GrowthStageCount.length)
- {
- int MaxStage = GrowthStageCount[CropID] - 1; //Make sure we don't get above max
- if (Stage > MaxStage)
- {
- GrowthStage = MaxStage;
- } else {
- GrowthStage = Stage;
- }
- }
- worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlockId(xCoord, yCoord, zCoord));
- }
- public void applyBonemeal()
- {
- //Set it to the Max Stage
- if (CropID < GrowthStageCount.length)
- {
- int MaxStage = GrowthStageCount[CropID] - 1; //Make sure we don't get above max
- GrowthStage = MaxStage;
- }
- worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlockId(xCoord, yCoord, zCoord));
- }
- public int getGrowthStage()
- {
- //In case you need to check the stage
- return GrowthStage;
- }
- public int getTextureID()
- {
- //This will be used the the renderblocks hook
- if (CropID < TextureBases.length)
- {
- return TextureBases[CropID] + GrowthStage; //Base texture with stage shift
- }
- return 0; //something happened wrong
- }
- private int CropID = 0; //This will be set in a custom seed item during placement
- private int GrowthStage = 0; //should always start at 0
- private int[] TextureBases = {0,//Tomato
- 16,//Potato
- 32,//Lettuce
- 48,//Onion
- 64,//Carrot
- 80,//Corn
- 96,//Strawberry
- 112,//Grape
- 128,//Peanut
- 144,//Cucumber
- 160,//Spice
- 176,//Rice
- 192,//Beans
- 208,//Bellpepper
- 224,//Eggplant
- 240,//Tea
- 8,//Coffee
- 24,//Beet
- 40,//Broccoli
- 56,//Sweet Potato
- 72,//Peas
- 88,//Pineapple
- 104,//Turnip
- 200,//Blueberry
- 216,//Blackberry
- 232,//Raspberry
- 248,/*Kiwi*/};
- /*Each line has a different index to start on. Our getTextureID() will return
- * the base texture with growth stage added so it goes to the next texture
- * in the sheet. TNT is the tiny stage, TNT Top is the medium stage, and TNT Side
- * is the harvest stage. TextureBases[CropID] will return the appropriate line for the ID.
- */
- private int[] GrowthStageCount = {8,//Tomato
- 8,//Potato
- 8,//Lettuce
- 8,//Onion
- 8,//Carrot
- 8,//Corn
- 8,//Strawberry
- 8,//Grape
- 8,//Peanut
- 8,//Cucumber
- 8,//Spice
- 8,//Rice
- 8,//Beans
- 8,//Bellpepper
- 8,//Eggplant
- 8,//Tea
- 8,//Coffee
- 8,//Beet
- 8,//Broccoli
- 8,//Sweet Potato
- 8,//Peas
- 8,//Pineapple
- 8,//Turnip
- 8,//Blueberry
- 8,//Blackberry
- 8,//Raspberry
- 8,/*Kiwi*/};
- //There are 8 default wheat stages. We will put 8 for CropID 3 so we can go through all stages.
- private int[] SeedDrops = {mod_Pamfood.tomatoseedItem.shiftedIndex,
- mod_Pamfood.potatoseedItem.shiftedIndex,
- mod_Pamfood.lettuceseedItem.shiftedIndex,
- mod_Pamfood.onionseedItem.shiftedIndex,
- mod_Pamfood.carrotseedItem.shiftedIndex,
- mod_Pamfood.cornseedItem.shiftedIndex,
- mod_Pamfood.strawberryseedItem.shiftedIndex,
- mod_Pamfood.grapeseedItem.shiftedIndex,
- mod_Pamfood.peanutseedItem.shiftedIndex,
- mod_Pamfood.cucumberseedItem.shiftedIndex,
- mod_Pamfood.spiceseedItem.shiftedIndex,
- mod_Pamfood.riceseedItem.shiftedIndex,
- mod_Pamfood.beansseedItem.shiftedIndex,
- mod_Pamfood.bellpepperseedItem.shiftedIndex,
- mod_Pamfood.eggplantseedItem.shiftedIndex,
- mod_Pamfood.teaseedItem.shiftedIndex,
- mod_Pamfood.coffeeseedItem.shiftedIndex,
- mod_Pamfood.beetseedItem.shiftedIndex,
- mod_Pamfood.broccoliseedItem.shiftedIndex,
- mod_Pamfood.sweetpotatoseedItem.shiftedIndex,
- mod_Pamfood.peasseedItem.shiftedIndex,
- mod_Pamfood.pineappleseedItem.shiftedIndex,
- mod_Pamfood.turnipseedItem.shiftedIndex,
- mod_Pamfood.blueberryseedItem.shiftedIndex,
- mod_Pamfood.blackberryseedItem.shiftedIndex,
- mod_Pamfood.raspberryseedItem.shiftedIndex,
- mod_Pamfood.kiwiseedItem.shiftedIndex};
- //These are seed drops in the same array format. Just fill it with Item/Block IDs.
- private int[] HarvestDrops = {mod_Pamfood.tomatoItem.shiftedIndex,
- mod_Pamfood.potatoItem.shiftedIndex,
- mod_Pamfood.lettuceItem.shiftedIndex,
- mod_Pamfood.onionItem.shiftedIndex,
- mod_Pamfood.carrotItem.shiftedIndex,
- mod_Pamfood.cornItem.shiftedIndex,
- mod_Pamfood.strawberryItem.shiftedIndex,
- mod_Pamfood.grapeItem.shiftedIndex,
- mod_Pamfood.peanutItem.shiftedIndex,
- mod_Pamfood.cucumberItem.shiftedIndex,
- mod_Pamfood.peppercornItem.shiftedIndex,
- mod_Pamfood.riceItem.shiftedIndex,
- mod_Pamfood.beansItem.shiftedIndex,
- mod_Pamfood.bellpepperItem.shiftedIndex,
- mod_Pamfood.eggplantItem.shiftedIndex,
- mod_Pamfood.teaItem.shiftedIndex,
- mod_Pamfood.coffeeItem.shiftedIndex,
- mod_Pamfood.beetItem.shiftedIndex,
- mod_Pamfood.broccoliItem.shiftedIndex,
- mod_Pamfood.sweetpotatoItem.shiftedIndex,
- mod_Pamfood.peasItem.shiftedIndex,
- mod_Pamfood.pineappleItem.shiftedIndex,
- mod_Pamfood.turnipItem.shiftedIndex,
- mod_Pamfood.blueberryItem.shiftedIndex,
- mod_Pamfood.blackberryItem.shiftedIndex,
- mod_Pamfood.raspberryItem.shiftedIndex,
- mod_Pamfood.kiwiItem.shiftedIndex};
- //Same thing as above but it will drop when harvested at the final stage.
- }
Add Comment
Please, Sign In to add comment