Skip to content

Commit

Permalink
Add cell check for powered parent, have dandelifeon's claim tiles mor…
Browse files Browse the repository at this point in the history
…e aggressively
  • Loading branch information
nestoll committed May 15, 2024
1 parent 86d9e5b commit eed2ad5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,18 @@ public void setNextGeneration(DandelifeonBlockEntity flower, int gen) {
nextGeneration = gen;
getLevel().scheduleTick(getBlockPos(), BotaniaBlocks.cellBlock, 1);
if (!ticked) {
flowerCoords = flower.getEffectivePos();
validCoords = getBlockPos();
claim(flower);
ticked = true;
} else if (!validCoords.equals(getBlockPos()) || !flowerCoords.equals(flower.getEffectivePos())) {
level.removeBlock(worldPosition, false);
}
}

public void claim(DandelifeonBlockEntity flower) {
flowerCoords = flower.getEffectivePos();
validCoords = getBlockPos();
}

public void update(Level level) {
if (nextGeneration == Cell.DEAD) {
level.removeBlock(getBlockPos(), false);
Expand All @@ -65,6 +69,10 @@ public boolean isSameFlower(DandelifeonBlockEntity flower) {
return !ticked || validCoords.equals(getBlockPos()) && flowerCoords.equals(flower.getEffectivePos());
}

public boolean hasPoweredParent(Level level) {
return flowerCoords != null && level.getBlockEntity(flowerCoords) instanceof DandelifeonBlockEntity && level.hasNeighborSignal(flowerCoords);
}

public int getGeneration() {
return generation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ public void tickFlower() {
if (!getLevel().isClientSide) {
if (getLevel().getGameTime() % SPEED == 0 && getLevel().hasNeighborSignal(getBlockPos())) {
runSimulation();
} else if (getLevel().getGameTime()+1 % SPEED == 0) {
diameter = radius * 2 + 1;

for (int i = -1; i <= diameter; i++) {
for (int j = -1; j <= diameter; j++) {
BlockPos pos = getEffectivePosition().offset(-range + i, 0, -range + j);
BlockEntity tile = dandie.getLevel().getBlockEntity(pos);
if (tile instanceof CellularBlockEntity) {
tile.claim();
}
}
}
}
}
}
Expand Down Expand Up @@ -174,7 +186,7 @@ public CellTable(int range, DandelifeonBlockEntity dandie) {
private static int getCellGeneration(BlockPos pos, DandelifeonBlockEntity dandie) {
BlockEntity tile = dandie.getLevel().getBlockEntity(pos);
if (tile instanceof CellularBlockEntity cell) {
return cell.isSameFlower(dandie) ? cell.getGeneration() : Cell.boundaryPunish(cell.getGeneration());
return cell.isSameFlower(dandie) ? cell.getGeneration() : (cell.hasPoweredParent(dandie.getLevel()) ? Cell.boundaryPunish(cell.getGeneration()) : Cell.DEAD);
}

return Cell.DEAD;
Expand Down

0 comments on commit eed2ad5

Please sign in to comment.