Skip to content

Commit

Permalink
Dandelifeon border cell exploit fix (#4648)
Browse files Browse the repository at this point in the history
Fixing the "exploit" by requiring cells to have a powered parent in order to qualify as a boundary cell. (fixes #4353)
  • Loading branch information
NEstoll authored May 25, 2024
1 parent bded481 commit ee77979
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,29 @@ 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) {
if (!ticked) {
flowerCoords = flower.getEffectivePos();
validCoords = getBlockPos();
}
}

public void update(Level level) {
if (nextGeneration == Cell.DEAD) {
level.removeBlock(getBlockPos(), false);
}
generation = nextGeneration;
}

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() {
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) {
int diameter = radius * 2;

for (int i = 0; i <= diameter; i++) {
for (int j = 0; j <= diameter; j++) {
BlockPos pos = getEffectivePos().offset(-radius + i, 0, -radius + j);
BlockEntity tile = getLevel().getBlockEntity(pos);
if (tile instanceof CellularBlockEntity) {
((CellularBlockEntity) (tile)).claim(this);
}
}
}
}
}
}
Expand Down Expand Up @@ -166,15 +178,15 @@ public CellTable(int range, DandelifeonBlockEntity dandie) {
for (int i = -1; i <= diameter; i++) {
for (int j = -1; j <= diameter; j++) {
BlockPos pos = center.offset(-range + i, 0, -range + j);
cells[i + 1][j + 1] = getCellGeneration(pos, dandie);
cells[i + 1][j + 1] = getCellGeneration(pos, dandie, onBoundary(i, j));
}
}
}

private static int getCellGeneration(BlockPos pos, DandelifeonBlockEntity dandie) {
private static int getCellGeneration(BlockPos pos, DandelifeonBlockEntity dandie, boolean onBoundary) {
BlockEntity tile = dandie.getLevel().getBlockEntity(pos);
if (tile instanceof CellularBlockEntity cell) {
return cell.isSameFlower(dandie) ? cell.getGeneration() : Cell.boundaryPunish(cell.getGeneration());
return onBoundary ? (cell.hasPoweredParent(dandie.getLevel()) ? Cell.boundaryPunish(cell.getGeneration()) : Cell.DEAD) : cell.getGeneration();
}

return Cell.DEAD;
Expand All @@ -184,6 +196,10 @@ public boolean inBounds(int x, int z) {
return x >= 0 && z >= 0 && x < diameter && z < diameter;
}

private boolean onBoundary(int x, int z) {
return x == -1 || z == -1 || x == diameter || z == diameter;
}

public int getAdjCells(int x, int z) {
int count = 0;
for (int[] shift : ADJACENT_BLOCKS) {
Expand Down

0 comments on commit ee77979

Please sign in to comment.