Skip to content
Permalink
Browse files

Fruit Tree Cleanup

Fruit tree wood growth is now based on year length. Trunk blocks take 1.5 months to grow (at least 6 months from planting until first branch appears), and additional branches take 1 month to grow. Leaf blocks can grow every 2 days regardless of year length.
Fruit trees cannot grow during winter months, but will make up for the lost time in the spring.
Branches will not grow unless the trunk is at the maximum height of 4 blocks.
Newly generated wood blocks use the leaf timer of the block they were generated from, instead of the current time, so they will grow leaves quicker.

Extra: Food and Thirst no longer deplete while debug mode is enabled. Disabling debug mode will make up for lost time. Change field in code to true to revert this change.
  • Loading branch information...
Kittychanley committed Nov 12, 2015
1 parent b661998 commit c7aac651159121f9196accf77d572c4d9ae60aaa
@@ -6,7 +6,6 @@
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@@ -20,11 +19,7 @@

import com.bioxx.tfc.Reference;
import com.bioxx.tfc.Blocks.BlockTerraContainer;
import com.bioxx.tfc.Core.TFC_Climate;
import com.bioxx.tfc.Core.TFC_Core;
import com.bioxx.tfc.Core.TFC_Time;
import com.bioxx.tfc.Food.FloraIndex;
import com.bioxx.tfc.Food.FloraManager;
import com.bioxx.tfc.TileEntities.TEFruitTreeWood;
import com.bioxx.tfc.api.TFCBlocks;
import com.bioxx.tfc.api.TFCItems;
@@ -52,7 +47,7 @@ public int damageDropped(int j)
}

@Override
public IIcon getIcon(int i, int j)
public IIcon getIcon(int i, int j)
{
return icons[j];
}
@@ -244,103 +239,127 @@ public void setBlockBoundsBasedOnState(IBlockAccess world, int i, int j, int k)
@Override
public void updateTick(World world, int i, int j, int k, Random rand)
{
FloraManager manager = FloraManager.getInstance();
FloraIndex fi = manager.findMatchingIndex(BlockFruitWood.getType(world.getBlockMetadata(i, j, k)));
// Growth is handled in TEFruitTreeWood
/*if (!world.isRemote)
{
FloraManager manager = FloraManager.getInstance();
FloraIndex fi = manager.findMatchingIndex(BlockFruitWood.getType(world.getBlockMetadata(i, j, k)));
float temp = TFC_Climate.getHeightAdjustedTemp(world, i, j, k);
float temp = TFC_Climate.getHeightAdjustedTemp(world, i, j, k);
if(!world.isRemote && world.getTileEntity(i, j, k) != null &&
if (world.getTileEntity(i, j, k) instanceof TEFruitTreeWood &&
TFC_Time.getSeasonAdjustedMonth(k) < 6 &&
fi != null && temp >= fi.minTemp && temp < fi.maxTemp)
{
TEFruitTreeWood te = (TEFruitTreeWood)world.getTileEntity(i, j, k);
int t = 1;
if(TFC_Time.getSeasonAdjustedMonth(k) < 3)
t = 2;

int leafGrowthRate = 20;
int trunkGrowTime = 30;
int branchGrowTime = 20;

//grow upward
if(te.birthTimeWood + trunkGrowTime < TFC_Time.getTotalDays() &&
te.height < 3 && te.isTrunk && rand.nextInt(16/t) == 0 &&
(world.isAirBlock(i, j+1, k) || world.getBlock(i, j+1, k) == TFCBlocks.fruitTreeLeaves))
{
world.setBlock(i, j+1, k, this, world.getBlockMetadata(i, j, k), 0x2);
((TEFruitTreeWood)world.getTileEntity(i, j+1, k)).setTrunk(true);
((TEFruitTreeWood)world.getTileEntity(i, j+1, k)).setHeight(te.height+1);
((TEFruitTreeWood)world.getTileEntity(i, j+1, k)).setBirth();
((TEFruitTreeWood)world.getTileEntity(i, j, k)).setBirthWood(trunkGrowTime);
}
else if(te.birthTimeWood + branchGrowTime < TFC_Time.getTotalDays() && te.height == 2 && te.isTrunk && rand.nextInt(16/t) == 0 &&
world.getBlock(i, j+1, k) != this)
{
int r = rand.nextInt(4);
if (r == 0 && world.blockExists(i + 1, j, k) && (world.isAirBlock(i + 1, j, k) || world.getBlock(i + 1, j, k) == TFCBlocks.fruitTreeLeaves))
TEFruitTreeWood te = (TEFruitTreeWood) world.getTileEntity(i, j, k);
int t = 1;
if (TFC_Time.getSeasonAdjustedMonth(k) < 3)
t = 2;
int leafGrowthRate = 20;
int trunkGrowTime = 30;
int branchGrowTime = 20;
//grow upward
if (te.birthTimeWood + trunkGrowTime < TFC_Time.getTotalDays() &&
te.height < 3 && te.isTrunk && rand.nextInt(16 / t) == 0 &&
(world.isAirBlock(i, j + 1, k) || world.getBlock(i, j + 1, k) == TFCBlocks.fruitTreeLeaves))
{
world.setBlock(i+1, j, k, this, world.getBlockMetadata(i, j, k), 0x2);
((TEFruitTreeWood)world.getTileEntity(i+1, j, k)).setTrunk(false);
((TEFruitTreeWood)world.getTileEntity(i+1, j, k)).setHeight(te.height);
((TEFruitTreeWood)world.getTileEntity(i+1, j, k)).setBirth();
}
else if (r == 1 && world.blockExists(i, j, k - 1) && (world.isAirBlock(i, j, k - 1) || world.getBlock(i, j, k - 1) == TFCBlocks.fruitTreeLeaves))
{
world.setBlock(i, j, k-1, this, world.getBlockMetadata(i, j, k), 0x2);
((TEFruitTreeWood)world.getTileEntity(i, j, k-1)).setTrunk(false);
((TEFruitTreeWood)world.getTileEntity(i, j, k-1)).setHeight(te.height);
((TEFruitTreeWood)world.getTileEntity(i, j, k-1)).setBirth();
world.setBlock(i, j + 1, k, this, world.getBlockMetadata(i, j, k), 0x2);
if (world.getTileEntity(i, j + 1, k) instanceof TEFruitTreeWood)
{
TEFruitTreeWood trunkTE = ((TEFruitTreeWood) world.getTileEntity(i, j + 1, k));
trunkTE.setTrunk(true);
trunkTE.setHeight(te.height + 1);
trunkTE.initBirth();
te.increaseBirthWood(trunkGrowTime);
}
}
else if (r == 2 && world.blockExists(i - 1, j, k) && (world.isAirBlock(i - 1, j, k) || world.getBlock(i - 1, j, k) == TFCBlocks.fruitTreeLeaves))
else if (te.birthTimeWood + branchGrowTime < TFC_Time.getTotalDays() &&te.height == 2 && te.isTrunk && rand.nextInt(16 / t) == 0 &&
world.getBlock(i, j + 1, k) != this)
{
world.setBlock(i-1, j, k, this, world.getBlockMetadata(i, j, k), 0x2);
((TEFruitTreeWood)world.getTileEntity(i-1, j, k)).setTrunk(false);
((TEFruitTreeWood)world.getTileEntity(i-1, j, k)).setHeight(te.height);
((TEFruitTreeWood)world.getTileEntity(i-1, j, k)).setBirth();
int r = rand.nextInt(4);
if (r == 0 && world.blockExists(i + 1, j, k) && (world.isAirBlock(i + 1, j, k) || world.getBlock(i + 1, j, k) == TFCBlocks.fruitTreeLeaves))
{
world.setBlock(i + 1, j, k, this, world.getBlockMetadata(i, j, k), 0x2);
if (world.getTileEntity(i + 1, j, k) instanceof TEFruitTreeWood)
{
TEFruitTreeWood branchTE = ((TEFruitTreeWood) world.getTileEntity(i + 1, j, k));
branchTE.setTrunk(false);
branchTE.setHeight(te.height);
branchTE.initBirth();
}
}
else if (r == 1 && world.blockExists(i, j, k - 1) && (world.isAirBlock(i, j, k - 1) || world.getBlock(i, j, k - 1) == TFCBlocks.fruitTreeLeaves))
{
world.setBlock(i, j, k - 1, this, world.getBlockMetadata(i, j, k), 0x2);
if (world.getTileEntity(i, j, k - 1) instanceof TEFruitTreeWood)
{
TEFruitTreeWood branchTE = ((TEFruitTreeWood) world.getTileEntity(i, j, k - 1));
branchTE.setTrunk(false);
branchTE.setHeight(te.height);
branchTE.initBirth();
}
}
else if (r == 2 && world.blockExists(i - 1, j, k) && (world.isAirBlock(i - 1, j, k) || world.getBlock(i - 1, j, k) == TFCBlocks.fruitTreeLeaves))
{
world.setBlock(i - 1, j, k, this, world.getBlockMetadata(i, j, k), 0x2);
if (world.getTileEntity(i - 1, j, k) instanceof TEFruitTreeWood)
{
TEFruitTreeWood branchTE = (TEFruitTreeWood) world.getTileEntity(i - 1, j, k);
branchTE.setTrunk(false);
branchTE.setHeight(te.height);
branchTE.initBirth();
}
}
else if (r == 3 && world.blockExists(i, j, k + 1) && (world.isAirBlock(i, j, k + 1) || world.getBlock(i, j, k + 1) == TFCBlocks.fruitTreeLeaves))
{
world.setBlock(i, j, k + 1, this, world.getBlockMetadata(i, j, k), 0x2);
if (world.getTileEntity(i, j, k + 1) instanceof TEFruitTreeWood)
{
TEFruitTreeWood branchTE = (TEFruitTreeWood) world.getTileEntity(i, j, k + 1);
branchTE.setTrunk(false);
branchTE.setHeight(te.height);
branchTE.initBirth();
}
}
te.increaseBirthWood(branchGrowTime);
}
else if (r == 3 && world.blockExists(i, j, k + 1) && (world.isAirBlock(i, j, k + 1) || world.getBlock(i, j, k + 1) == TFCBlocks.fruitTreeLeaves))
else if (te.birthTimeWood + 1 < TFC_Time.getTotalDays() && rand.nextInt(leafGrowthRate) == 0 && world.getBlock(i, j + 2, k) != this)
{
world.setBlock(i, j, k+1, this, world.getBlockMetadata(i, j, k), 0x2);
((TEFruitTreeWood)world.getTileEntity(i, j, k+1)).setTrunk(false);
((TEFruitTreeWood)world.getTileEntity(i, j, k+1)).setHeight(te.height);
((TEFruitTreeWood)world.getTileEntity(i, j, k+1)).setBirth();
if (world.isAirBlock(i, j + 1, k) && world.isAirBlock(i, j + 2, k) && BlockFruitLeaves.canStay(world, i, j + 1, k)) //above
world.setBlock(i, j + 1, k, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
else if (world.blockExists(i + 1, j, k) && world.isAirBlock(i + 1, j, k) && world.isAirBlock(i + 1, j + 1, k) && BlockFruitLeaves.canStay(world, i + 1, j, k)) //+x
world.setBlock(i + 1, j, k, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
else if (world.blockExists(i - 1, j, k) && world.isAirBlock(i - 1, j, k) && world.isAirBlock(i - 1, j + 1, k) && BlockFruitLeaves.canStay(world, i - 1, j, k)) //-x
world.setBlock(i - 1, j, k, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
else if (world.blockExists(i, j, k + 1) && world.isAirBlock(i, j, k + 1) && world.isAirBlock(i, j + 1, k + 1) && BlockFruitLeaves.canStay(world, i, j, k + 1)) //+z
world.setBlock(i, j, k + 1, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
else if (world.blockExists(i, j, k - 1) && world.isAirBlock(i, j, k - 1) && world.isAirBlock(i, j + 1, k - 1) && BlockFruitLeaves.canStay(world, i, j, k - 1)) //-z
world.setBlock(i, j, k - 1, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
else if (world.blockExists(i + 1, j, k - 1) && world.isAirBlock(i + 1, j, k - 1) && world.isAirBlock(i + 1, j + 1, k - 1) && BlockFruitLeaves.canStay(world, i + 1, j, k - 1)) //+x/-z
world.setBlock(i + 1, j, k - 1, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
else if (world.blockExists(i + 1, j, k + 1) && world.isAirBlock(i + 1, j, k + 1) && world.isAirBlock(i + 1, j + 1, k + 1) && BlockFruitLeaves.canStay(world, i + 1, j, k + 1)) //+x/+z
world.setBlock(i + 1, j, k + 1, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
else if (world.blockExists(i - 1, j, k - 1) && world.isAirBlock(i - 1, j, k - 1) && world.isAirBlock(i - 1, j + 1, k - 1) && BlockFruitLeaves.canStay(world, i - 1, j, k - 1)) //-x/-z
world.setBlock(i - 1, j, k - 1, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
else if (world.blockExists(i - 1, j, k + 1) && world.isAirBlock(i - 1, j, k + 1) && world.isAirBlock(i - 1, j + 1, k + 1) && BlockFruitLeaves.canStay(world, i - 1, j, k + 1)) //-x/+z
world.setBlock(i - 1, j, k + 1, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
}

((TEFruitTreeWood)world.getTileEntity(i, j, k)).setBirthWood(branchGrowTime);
}
else if(te.birthTimeWood + 1 < TFC_Time.getTotalDays() && rand.nextInt(leafGrowthRate) == 0 && world.getBlock(i, j+2, k) != this)
{
if (world.isAirBlock(i, j + 1, k) && world.isAirBlock(i, j + 2, k) && BlockFruitLeaves.canStay(world, i, j + 1, k))//above
world.setBlock(i, j+1, k, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
else if (world.blockExists(i + 1, j, k) && world.isAirBlock(i + 1, j, k) && world.isAirBlock(i + 1, j + 1, k) && BlockFruitLeaves.canStay(world, i + 1, j, k)) //+x
world.setBlock(i+1, j, k, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
else if (world.blockExists(i - 1, j, k) && world.isAirBlock(i - 1, j, k) && world.isAirBlock(i - 1, j + 1, k) && BlockFruitLeaves.canStay(world, i - 1, j, k)) //-x
world.setBlock(i-1, j, k, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
else if (world.blockExists(i, j, k + 1) && world.isAirBlock(i, j, k + 1) && world.isAirBlock(i, j + 1, k + 1) && BlockFruitLeaves.canStay(world, i, j, k + 1)) //+z
world.setBlock(i, j, k+1, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
else if (world.blockExists(i, j, k - 1) && world.isAirBlock(i, j, k - 1) && world.isAirBlock(i, j + 1, k - 1) && BlockFruitLeaves.canStay(world, i, j, k - 1)) //-z
world.setBlock(i, j, k-1, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
else if (world.blockExists(i + 1, j, k - 1) && world.isAirBlock(i + 1, j, k - 1) && world.isAirBlock(i + 1, j + 1, k - 1) && BlockFruitLeaves.canStay(world, i + 1, j, k - 1)) //+x/-z
world.setBlock(i+1, j, k-1, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
else if (world.blockExists(i + 1, j, k + 1) && world.isAirBlock(i + 1, j, k + 1) && world.isAirBlock(i + 1, j + 1, k + 1) && BlockFruitLeaves.canStay(world, i + 1, j, k + 1)) //+x/+z
world.setBlock(i+1, j, k+1, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
else if (world.blockExists(i - 1, j, k - 1) && world.isAirBlock(i - 1, j, k - 1) && world.isAirBlock(i - 1, j + 1, k - 1) && BlockFruitLeaves.canStay(world, i - 1, j, k - 1)) //-x/-z
world.setBlock(i-1, j, k-1, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
else if (world.blockExists(i - 1, j, k + 1) && world.isAirBlock(i - 1, j, k + 1) && world.isAirBlock(i - 1, j + 1, k + 1) && BlockFruitLeaves.canStay(world, i - 1, j, k + 1)) //-x/+z
world.setBlock(i-1, j, k+1, TFCBlocks.fruitTreeLeaves, world.getBlockMetadata(i, j, k), 0x2);
}
}
}*/
}

public void surroundWithLeaves(World world, int i, int j, int k)
/*public void surroundWithLeaves(World world, int i, int j, int k)
{
for (int y = 0; y <= 1; y++)
{
for (int x = 1; x >= -1; x--)
{
for (int z = 1; z >= -1; z--)
{
if(world.isAirBlock(i+x, j+y, k+z) && (world.isAirBlock(i+x, j+y+1, k+z) || world.isAirBlock(i+x, j+y+2, k+z)))
if(world.isAirBlock(i+x, j+y, k+z) && (world.isAirBlock(i+x, j+y+1, k+z) || world.isAirBlock(i+x, j+y+2, k+z)))
{
int meta = world.getBlockMetadata(i, j, k);
Block block = meta < 8 ? TFCBlocks.fruitTreeLeaves : TFCBlocks.fruitTreeLeaves2;
@@ -351,7 +370,7 @@ public void surroundWithLeaves(World world, int i, int j, int k)
}
}
}
}
}*/

public static String getType(int meta)
{
@@ -380,7 +399,7 @@ public TileEntity createNewTileEntity(World var1, int var2)
public void breakBlock(World world, int x, int y, int z, Block block, int metadata)
{
if(!world.isRemote && checkOut(world,x,y-1,z,metadata) && world.getTileEntity(x, y-1, z) != null)
((TEFruitTreeWood)world.getTileEntity(x, y-1, z)).setBirth();
((TEFruitTreeWood)world.getTileEntity(x, y-1, z)).initBirth();
super.breakBlock(world, x, y, z, block, metadata);
}

@@ -24,6 +24,8 @@

public class FoodStatsTFC
{
private boolean updateStats = !TFCOptions.enableDebugMode; // Replace with true to allow stat depleting with debug mode enabled

/** The player's food level. This measures how much food the player can handle.*/
public float stomachLevel = 24;
private float stomachMax = 24.0f;
@@ -41,7 +43,7 @@

public long soberTime;

/**This is how full the player is from the food that they've eaten.
/**This is how full the player is from the food that they've eaten.
* It could also be how happy they are with what they've eaten*/
private float satisfaction;

@@ -97,7 +99,7 @@ public void onUpdate(EntityPlayer player)
this.waterTimer = TFC_Time.startTime;
}

if (TFC_Time.getTotalTicks() - this.foodTimer >= TFC_Time.HOUR_LENGTH && !player.capabilities.isCreativeMode)
if (TFC_Time.getTotalTicks() - this.foodTimer >= TFC_Time.HOUR_LENGTH && !player.capabilities.isCreativeMode && updateStats)
{
this.foodTimer += TFC_Time.HOUR_LENGTH;
float drainMult = 1.0f;
@@ -108,20 +110,20 @@ public void onUpdate(EntityPlayer player)
//Water
if(player.isSprinting())
waterLevel -= 5+(tempWaterMod);
if(!player.capabilities.isCreativeMode)
if (!player.capabilities.isCreativeMode && updateStats)
waterLevel -= bodyTemp.getExtraWater()*drainMult;

//Food
float hunger = (1 + foodExhaustionLevel + bodyTemp.getExtraFood()) * drainMult;
if(this.satisfaction >= hunger)
{
satisfaction -= hunger;
satisfaction -= hunger;
hunger = 0;
foodExhaustionLevel = 0;
}
else
{
hunger -= satisfaction;
hunger -= satisfaction;
satisfaction = 0;
foodExhaustionLevel = 0;
}
@@ -174,7 +176,7 @@ else if(this.satisfaction <= 0)
}*/
}

if(!player.capabilities.isCreativeMode)
if (!player.capabilities.isCreativeMode && updateStats)
{
for(;waterTimer < TFC_Time.getTotalTicks(); waterTimer++)
{
@@ -209,7 +211,7 @@ else if(erTFC.getManualShaderBeingUsed() && soberTime <= TFC_Time.getTotalTicks(
}
}

protected void reduceNutrition(float amount)
protected void reduceNutrition(float amount)
{
nutrFruit = Math.max(this.nutrFruit - (amount + foodExhaustionLevel), 0);
nutrVeg = Math.max(this.nutrVeg - (amount + foodExhaustionLevel), 0);
@@ -380,7 +382,7 @@ public long getPlayerFoodSeed()
{
Random r = new Random(getPlayerFoodSeed());
return new int[]
{ 20 + r.nextInt(70), 20 + r.nextInt(70), 20 + r.nextInt(70), 20 + r.nextInt(70), 20 + r.nextInt(70) };
{ 20 + r.nextInt(70), 20 + r.nextInt(70), 20 + r.nextInt(70), 20 + r.nextInt(70), 20 + r.nextInt(70) };
}

public float getTasteFactor(ItemStack food)
@@ -424,7 +426,7 @@ public static int getMaxHealth(EntityPlayer player)
}

/**
*
*
* @return return true if the itemstack should be consumed, else return false
*/
public static boolean reduceFood(ItemStack is, float amount)
@@ -53,7 +53,7 @@ public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world,

((TEFruitTreeWood)world.getTileEntity(x, y + 1, z)).setTrunk(true);
((TEFruitTreeWood)world.getTileEntity(x, y + 1, z)).setHeight(0);
((TEFruitTreeWood)world.getTileEntity(x, y + 1, z)).setBirth();
((TEFruitTreeWood)world.getTileEntity(x, y + 1, z)).initBirth();

stack.stackSize = stack.stackSize - 1;
return true;

0 comments on commit c7aac65

Please sign in to comment.
You can’t perform that action at this time.