Skip to content

Commit

Permalink
Refactor timing and boost, add shouldTick() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Estoll committed Jul 10, 2024
1 parent 899ede2 commit 3c78bb9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public void update(Level level) {
generation = nextGeneration;
}

public boolean hasActiveParent(Level level) {
return flowerCoords != null && level.getBlockEntity(flowerCoords) instanceof DandelifeonBlockEntity parent && level.hasNeighborSignal(flowerCoords) && ((level.getGameTime() % DandelifeonBlockEntity.SPEED == 0) || parent.overgrowth);
public boolean hasActiveParent(DandelifeonBlockEntity dandie) {
return flowerCoords != null && dandie.getLevel().getBlockEntity(flowerCoords) instanceof DandelifeonBlockEntity parent && dandie.getLevel().hasNeighborSignal(flowerCoords) && parent.overgrowthBoost == dandie.overgrowthBoost;
}

public int getGeneration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
public class DandelifeonBlockEntity extends GeneratingFlowerBlockEntity {
public static final int RANGE = 12;
public static final int SPEED = 10;
public static final int OVERGROWN_SPEED = SPEED / 2;
// private static final int MAX_GENERATIONS = 100;
public static final int MAX_MANA_GENERATIONS = 100;
public static final int MANA_PER_GEN = 60;
Expand Down Expand Up @@ -58,9 +59,9 @@ public void tickFlower() {
super.tickFlower();

if (!getLevel().isClientSide) {
if ((getLevel().getGameTime() % SPEED == 0 || (getLevel().getGameTime() % (SPEED / 2) == 0 && overgrowth)) && getLevel().hasNeighborSignal(getBlockPos())) {
if (shouldTick(getLevel().getGameTime())) {
runSimulation();
} else if ((getLevel().getGameTime() + 1) % SPEED == 0 || ((getLevel().getGameTime() + 1) % (SPEED / 2) == 0 && overgrowth)) {
} else if (shouldTick(getLevel().getGameTime() + 1)) {
int diameter = radius * 2;

for (int i = 0; i <= diameter; i++) {
Expand All @@ -76,6 +77,10 @@ public void tickFlower() {
}
}

private static boolean shouldTick(long gameTime) {
return (gameTime % SPEED == 0 || (gameTime % (OVERGROWN_SPEED) == 0 && overgrowthBoost)) && getLevel().hasNeighborSignal(getBlockPos());
}

private void runSimulation() {
var table = new CellTable(radius, this);
List<LifeUpdate> changes = new ArrayList<>();
Expand Down Expand Up @@ -186,7 +191,7 @@ public CellTable(int range, DandelifeonBlockEntity dandie) {
private static int getCellGeneration(BlockPos pos, DandelifeonBlockEntity dandie, boolean onBoundary) {
BlockEntity tile = dandie.getLevel().getBlockEntity(pos);
if (tile instanceof CellularBlockEntity cell) {
return onBoundary ? (cell.hasActiveParent(dandie.getLevel()) ? Cell.boundaryPunish(cell.getGeneration()) : Cell.DEAD) : cell.getGeneration();
return onBoundary ? (cell.hasActiveParent(dandie) ? Cell.boundaryPunish(cell.getGeneration()) : Cell.DEAD) : cell.getGeneration();
}

return Cell.DEAD;
Expand Down

0 comments on commit 3c78bb9

Please sign in to comment.