Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Dandelifeon to respect enchanted soil #4660

Open
wants to merge 8 commits into
base: 1.20.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public final void setFloating(boolean floating) {
this.isFloating = floating;
}

private boolean isOnSpecialSoil() {
public boolean isOnSpecialSoil() {
if (isFloating()) {
return false;
} else {
Expand Down
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 hasPoweredParent(Level level) {
return flowerCoords != null && level.getBlockEntity(flowerCoords) instanceof DandelifeonBlockEntity && level.hasNeighborSignal(flowerCoords);
public boolean hasActiveParent(DandelifeonBlockEntity dandie) {
return flowerCoords != null && dandie.getLevel().getBlockEntity(flowerCoords) instanceof DandelifeonBlockEntity parent && dandie.getLevel().hasNeighborSignal(flowerCoords) && (!dandie.overgrowthBoost || parent.isOnSpecialSoil());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This or-check at the end is weird to me. It's true if the flower it's being transferred to is not boosted, or if the current flower is boosted. (Did i get that right?) So this returns true when both are boosted or neither are boosted, and false if the old flower is not boosted and the new one is. But if the old flower is boosted and the new one is not, this will still return true, right? Which we don't want, right?

It would also be nice if these variable names better reflected which flower it's coming from and which flower it's going to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is always called by the new flower, so we only need to make sure that either this is a normal tick (we aren't in an overgrowth tick), or that the other flower is also enchanted, and therefor will tick as well. This means that adjacent flowers will only share cells on ticks where they both are ticking. If the old flower is boosted and the new one isn't, then the new one won't be ticked, so this will never be called, and thus the return value doesn't matter.

}

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().hasNeighborSignal(getBlockPos())) {
if (shouldTick(getLevel().getGameTime())) {
runSimulation();
} else if ((getLevel().getGameTime() + 1) % SPEED == 0) {
} 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 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.hasPoweredParent(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