Skip to content

Commit

Permalink
Fix liquid behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Creeperface01 committed Oct 30, 2020
1 parent 9f7eb00 commit 0a7ea6c
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ default BlockState getExtra() {

BlockState getState(int layer);

default int getLiquidLayer() {
BlockState state = getExtra();
if (state == BlockStates.AIR) {
return 0;
}
return 1;
}

default BlockState getLiquid() {
BlockState state = getExtra();
if (state == BlockStates.AIR) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/cloudburstmc/server/block/CloudBlock.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.cloudburstmc.server.block;

import com.nukkitx.math.vector.Vector3i;
import lombok.ToString;
import org.cloudburstmc.server.level.Level;
import org.cloudburstmc.server.level.chunk.Chunk;
import org.cloudburstmc.server.math.Direction;

import static org.cloudburstmc.server.block.BlockTypes.FLOWING_WATER;
import static org.cloudburstmc.server.block.BlockTypes.WATER;

@ToString(exclude = {"level"}, callSuper = true)
public class CloudBlock extends CloudBlockSnapshot implements Block {

public static BlockState[] EMPTY = new BlockState[]{BlockStates.AIR, BlockStates.AIR};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.cloudburstmc.server.block;

import lombok.RequiredArgsConstructor;
import lombok.ToString;

import static com.google.common.base.Preconditions.checkElementIndex;

@RequiredArgsConstructor
@ToString
public class CloudBlockSnapshot implements BlockSnapshot {
private final BlockState[] states;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,16 @@ protected boolean placeBlock(Block block, BlockState newState) {
}

protected boolean placeBlock(Block block, BlockState newState, boolean update) {
val state = block.getState();
val state = block.getLiquid();
BlockBehavior behavior = state.getBehavior();
if (behavior instanceof BlockBehaviorLiquid && ((BlockBehaviorLiquid) behavior).usesWaterLogging()) {
boolean flowing = state.ensureTrait(BlockTraits.IS_FLOWING) || state.ensureTrait(BlockTraits.FLUID_LEVEL) != 0;

if (!flowing && canWaterlogSource(newState) || flowing && canWaterlogFlowing(newState)) {
val newBehavior = newState.getBehavior();
if (!flowing && newBehavior.canWaterlogSource(newState) || flowing && newBehavior.canWaterlogFlowing(newState)) {
block.set(state, 1, true, false);
} else {
block.setExtra(BlockStates.AIR, true, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ protected void checkForHarden(Block block) {
}

@Override
protected void flowIntoBlock(Block block, int newFlowDecay) {
protected void flowIntoBlock(Block block, int newFlowDecay, boolean falling) {
val behavior = block.getState().getBehavior();
if (behavior instanceof BlockBehaviorWater) {
((BlockBehaviorLiquid) behavior).liquidCollide(block, BlockState.get(BlockTypes.STONE));
} else {
super.flowIntoBlock(block, newFlowDecay);
super.flowIntoBlock(block, newFlowDecay, falling);
}
}

Expand Down
Loading

1 comment on commit 0a7ea6c

@lukeeey
Copy link
Member

Choose a reason for hiding this comment

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

Can you please stop mixing in val everywhere

Please sign in to comment.