Skip to content

Commit

Permalink
Fixed sapling timestamp resetting when growing into a tree fails due …
Browse files Browse the repository at this point in the history
…to not enough space. Added WAILA message for saplings that do not have enough space to grow. This message will not disappear until the sapling grows into a tree, as we don't want it to constantly scan to see if space has been cleared.
  • Loading branch information
Kittychanley committed Jan 11, 2016
1 parent f933407 commit 01754a3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
40 changes: 25 additions & 15 deletions src/Common/com/bioxx/tfc/Blocks/Flora/BlockSapling.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,23 @@ public void registerBlockIcons(IIconRegister registerer)

}

public void growTree(World world, int i, int j, int k, Random rand)
public void growTree(World world, int i, int j, int k, Random rand, long timestamp)
{
int l = world.getBlockMetadata(i, j, k);
int meta = world.getBlockMetadata(i, j, k);
world.setBlockToAir(i, j, k);
Object obj = TFCBiome.getTreeGen(l, rand.nextBoolean());
WorldGenerator worldGen = TFCBiome.getTreeGen(meta, rand.nextBoolean());

if (obj!= null && !((WorldGenerator) obj).generate(world, rand, i, j, k))
world.setBlock(i, j, k, this, l, 3);
if (worldGen != null && !worldGen.generate(world, rand, i, j, k))
{
world.setBlock(i, j, k, this, meta, 3);
if (world.getTileEntity(i, j, k) instanceof TESapling)
{
TESapling te = (TESapling) world.getTileEntity(i, j, k);
te.growTime = timestamp;
te.enoughSpace = false;
te.markDirty();
}
}
}

@Override
Expand Down Expand Up @@ -123,19 +132,20 @@ else if(meta == 9 || meta == 14|| meta == 15)
@Override
public void updateTick(World world, int i, int j, int k, Random rand)
{
if (world.isRemote)
return;

super.updateTick(world, i, j, k, rand);

if (world.getTileEntity(i, j, k) instanceof TESapling)
if (!world.isRemote)
{
TESapling te = (TESapling) world.getTileEntity(i, j, k);
super.updateTick(world, i, j, k, rand);

if (world.getTileEntity(i, j, k) instanceof TESapling)
{
long timestamp = ((TESapling) world.getTileEntity(i, j, k)).growTime;

if (world.getBlockLightValue(i, j + 1, k) >= 9 && te != null && TFC_Time.getTotalTicks() > te.growTime)
growTree(world, i, j, k, rand);
if (world.getBlockLightValue(i, j + 1, k) >= 9 && TFC_Time.getTotalTicks() > timestamp)
{
growTree(world, i, j, k, rand, timestamp);
}
}
}
//this.checkChange(world, i, j, k);
}

/**
Expand Down
15 changes: 9 additions & 6 deletions src/Common/com/bioxx/tfc/TileEntities/TESapling.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class TESapling extends TileEntity
{
public long growTime;
public boolean enoughSpace = true;

public TESapling()
{
Expand All @@ -21,17 +22,19 @@ public boolean canUpdate()
}

@Override
public void readFromNBT(NBTTagCompound nbttagcompound)
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbttagcompound);
growTime = nbttagcompound.getLong("growTime");
super.readFromNBT(nbt);
growTime = nbt.getLong("growTime");
enoughSpace = nbt.getBoolean("enoughSpace");
}

@Override
public void writeToNBT(NBTTagCompound nbttagcompound)
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbttagcompound);
nbttagcompound.setLong("growTime", growTime);
super.writeToNBT(nbt);
nbt.setLong("growTime", growTime);
nbt.setBoolean("enoughSpace", enoughSpace);
}

@Override
Expand Down
9 changes: 8 additions & 1 deletion src/Common/com/bioxx/tfc/WAILA/WAILAData.java
Original file line number Diff line number Diff line change
Expand Up @@ -1130,10 +1130,17 @@ else if (burnStart > 0)
public List<String> saplingBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config)
{
NBTTagCompound tag = accessor.getNBTData();
Long growTime = tag.getLong("growTime");
boolean enoughSpace = tag.getBoolean("enoughSpace");
long growTime = tag.getLong("growTime");
int days = (int) ((growTime - TFC_Time.getTotalTicks()) / TFC_Time.DAY_LENGTH);
if (days > 0)
{
currenttip.add(days + " " + TFC_Core.translate("gui.daysRemaining"));
}
else if (!enoughSpace)
{
currenttip.add(TFC_Core.translate("gui.enoughSpace"));
}

return currenttip;
}
Expand Down
1 change: 1 addition & 0 deletions src/Resources/assets/terrafirmacraft/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -2598,6 +2598,7 @@ gui.gems=Gems
gui.familiarized=Familiarized
gui.familiarity=Familiarity
gui.baby=Baby
gui.enoughSpace=Clear space for growth
option.tfc.oreQuality=Show ore quality
option.tfc.gender=Show animal gender
option.tfc.familiarToday=Show animal familiarized
Expand Down

0 comments on commit 01754a3

Please sign in to comment.