Skip to content

Commit

Permalink
fix quantum mechanical behavior of planters (hopefully)
Browse files Browse the repository at this point in the history
  • Loading branch information
eerussianguy committed Sep 11, 2022
1 parent 223afd9 commit 5b430d1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, FLBee
public FLBeehiveBlockEntity(BlockPos pos, BlockState state)
{
super(FLBlockEntities.BEEHIVE.get(), pos, state, defaultInventory(SLOTS), NAME);
lastPlayerTick = lastAreaTick = Calendars.SERVER.getTicks();
lastPlayerTick = Integer.MIN_VALUE;
lastAreaTick = Calendars.SERVER.getTicks();
cachedBees = new IBee[] {null, null, null, null};
honey = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, Large
private float growth;

private float nitrogen, phosphorous, potassium, water;
private long lastPlayerTick;
private long lastUpdateTick;
private long lastGrowthTick;
private boolean climateValid;
private int tier;

Expand All @@ -54,12 +55,13 @@ public LargePlanterBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState
{
super(type, pos, state, inventoryFactory, defaultName);
cachedPlant = null;
lastPlayerTick = Calendars.SERVER.getTicks();
climateValid = false;
growth = 0;
water = 0;
tier = 0;
nitrogen = phosphorous = potassium = 0;
lastUpdateTick = Integer.MIN_VALUE;
lastGrowthTick = Calendars.SERVER.getTicks();
}

@Override
Expand Down Expand Up @@ -99,24 +101,36 @@ protected void updateBlockState(BlockState state)
}
}

public long getLastGrowthTick()
{
return lastGrowthTick;
}

public void setLastGrowthTick(long lastGrowthTick)
{
this.lastGrowthTick = lastGrowthTick;
}

@Override
public long getLastUpdateTick()
{
return lastPlayerTick;
return lastUpdateTick;
}

@Override
public void setLastUpdateTick(long ticks)
{
lastPlayerTick = ticks;
lastUpdateTick = ticks;
markForSync();
}

@Override
public void loadAdditional(CompoundTag nbt)
{
super.loadAdditional(nbt);
climateValid = nbt.getBoolean("valid");
lastPlayerTick = nbt.getLong("lastPlayerTick");
lastUpdateTick = nbt.getLong("lastUpdateTick");
lastGrowthTick = nbt.getLong("lastGrowthTick");
climateValid = nbt.getBoolean("climateValid");
nitrogen = nbt.getFloat("n");
phosphorous = nbt.getFloat("p");
Expand All @@ -138,7 +152,8 @@ public void saveAdditional(CompoundTag nbt)
{
super.saveAdditional(nbt);
nbt.putBoolean("valid", climateValid);
nbt.putLong("lastPlayerTick", lastPlayerTick);
nbt.putLong("lastUpdateTick", lastUpdateTick);
nbt.putLong("lastGrowthTick", lastGrowthTick);
nbt.putBoolean("climateValid", climateValid);
nbt.putFloat("n", nitrogen);
nbt.putFloat("p", phosphorous);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public record GreenhouseInfo(GreenhouseType type, Set<BlockPos> positions) { }

public static boolean growthTick(Level level, BlockPos pos, BlockState state, LargePlanterBlockEntity planter)
{
final long firstTick = planter.getLastUpdateTick(), thisTick = Calendars.SERVER.getTicks();
final long firstTick = planter.getLastGrowthTick(), thisTick = Calendars.SERVER.getTicks();
long tick = firstTick + UPDATE_INTERVAL, lastTick = firstTick;
for (; tick < thisTick; tick += UPDATE_INTERVAL)
{
Expand Down Expand Up @@ -192,7 +192,7 @@ public static boolean growthTickStep(Level level, Random random, long fromTick,
planter.setGrowth(slot, 0);
}
}
planter.setLastUpdateTick(calendar.getTicks());
planter.setLastGrowthTick(calendar.getTicks());
planter.markForSync();
planter.afterGrowthTickStep(growing);
return true;
Expand Down

0 comments on commit 5b430d1

Please sign in to comment.