Skip to content

Commit

Permalink
feat: introduce BlockLiquidComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Jun 8, 2024
1 parent b91d3f4 commit 9275844
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.allaymc.api.block.component.common;

import org.allaymc.api.block.component.BlockComponent;

/**
* Allay Project 2024/6/9
*
* @author daoge_cmd
*/
public interface BlockLiquidComponent extends BlockComponent {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.allaymc.api.block.interfaces.liquid;

import org.allaymc.api.block.BlockBehavior;
import org.allaymc.api.block.component.common.BlockLiquidComponent;

/**
* @author daoge_cmd <br>
* Allay Project <br>
*/
public interface BlockFlowingLavaBehavior extends BlockBehavior {
public interface BlockFlowingLavaBehavior extends BlockBehavior, BlockLiquidComponent {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.allaymc.api.block.interfaces.liquid;

import org.allaymc.api.block.BlockBehavior;
import org.allaymc.api.block.component.common.BlockLiquidComponent;

/**
* @author daoge_cmd <br>
* Allay Project <br>
*/
public interface BlockFlowingWaterBehavior extends BlockBehavior {
public interface BlockFlowingWaterBehavior extends BlockBehavior, BlockLiquidComponent {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.allaymc.api.block.interfaces.liquid;

import org.allaymc.api.block.BlockBehavior;
import org.allaymc.api.block.component.common.BlockLiquidComponent;

/**
* @author daoge_cmd <br>
* Allay Project <br>
*/
public interface BlockLavaBehavior extends BlockBehavior {
public interface BlockLavaBehavior extends BlockBehavior, BlockLiquidComponent {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.allaymc.api.block.interfaces.liquid;

import org.allaymc.api.block.BlockBehavior;
import org.allaymc.api.block.component.common.BlockLiquidComponent;

/**
* @author daoge_cmd <br>
* Allay Project <br>
*/
public interface BlockWaterBehavior extends BlockBehavior {
public interface BlockWaterBehavior extends BlockBehavior, BlockLiquidComponent {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.base.Preconditions;
import org.allaymc.api.block.BlockBehavior;
import org.allaymc.api.block.component.annotation.RequireBlockProperty;
import org.allaymc.api.block.component.common.BlockLiquidComponent;
import org.allaymc.api.block.data.BlockFace;
import org.allaymc.api.block.function.Place;
import org.allaymc.api.block.property.enums.TorchFacingDirection;
Expand Down Expand Up @@ -42,8 +43,7 @@ public boolean place(EntityPlayer player, Dimension dimension, BlockState blockS
var oldBlock = dimension.getBlockState(placeBlockPos);
var torchFace = computeTorchFacingDirection(blockFace);

// TODO: Rewrite the comment code
if ((oldBlock.getBlockType() != BlockTypes.AIR_TYPE/* && !oldBlock.getBlockAttributes().isLiquid()*/) ||
if ((oldBlock.getBlockType() != BlockTypes.AIR_TYPE && !(oldBlock.getBehavior() instanceof BlockLiquidComponent)) ||
torchFace == TorchFacingDirection.UNKNOWN) return false;

var targetBlock = dimension.getBlockState(targetBlockPos);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.allaymc.server.world.service;

import org.allaymc.api.block.component.common.BlockLiquidComponent;
import org.allaymc.api.block.data.BlockFace;
import org.allaymc.api.block.data.BlockStateWithPos;
import org.allaymc.api.block.type.BlockState;
Expand Down Expand Up @@ -41,7 +42,7 @@ public void tick(long tick) {
BlockState layer1 = dimension.getBlockState(p, 1);
BlockStateWithPos b0 = new BlockStateWithPos(layer0, new Position3i(p, dimension), 0);
layer0.getBehavior().onScheduledUpdate(b0);
if (layer1.getBlockAttributes().isLiquid()) {
if (layer1.getBehavior() instanceof BlockLiquidComponent) {
BlockStateWithPos b1 = new BlockStateWithPos(layer1, new Position3i(p, dimension), 1);
layer1.getBehavior().onScheduledUpdate(b1);
}
Expand All @@ -55,7 +56,7 @@ public void tick(long tick) {
BlockState layer0 = dimension.getBlockState(pos);
BlockState layer1 = dimension.getBlockState(pos, 1);
layer0.getBehavior().onNeighborUpdate(pos, neighborPos, blockFace, dimension);
if (layer1.getBlockAttributes().isLiquid()) {
if (layer1.getBehavior() instanceof BlockLiquidComponent) {
layer1.getBehavior().onNeighborUpdate(pos, neighborPos, blockFace, dimension);
}
c++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ void testDeserialization() {
assertEquals(15, blockAttributes.explosionResistance());
assertEquals(Float.toHexString(0.6f), Float.toHexString(blockAttributes.friction()));
assertEquals(3, blockAttributes.hardness());
assertFalse(blockAttributes.hasBlockEntity());
assertFalse(blockAttributes.hasComparatorSignal());
// assertFalse(blockAttributes.hasBlockEntity());
// assertFalse(blockAttributes.hasComparatorSignal());
assertTrue(blockAttributes.isAlwaysDestroyable());
assertFalse(blockAttributes.isContainerBlock());
assertFalse(blockAttributes.isLiquid());
// assertFalse(blockAttributes.isContainerBlock());
// assertFalse(blockAttributes.isLiquid());
assertFalse(blockAttributes.isMotionBlockingBlock());
assertFalse(blockAttributes.isPowerSource());
assertFalse(blockAttributes.isSolid());
Expand All @@ -110,17 +110,17 @@ void testDeserialization() {
assertFalse(blockAttributes.superHot());
assertEquals(0, blockAttributes.thickness());
assertEquals(0, blockAttributes.translucency());
assertTrue(blockAttributes.isAir());
assertTrue(blockAttributes.isBounceBlock());
assertTrue(blockAttributes.isButtonBlock());
assertTrue(blockAttributes.isCropBlock());
assertTrue(blockAttributes.isDoorBlock());
assertTrue(blockAttributes.isFallingBlock());
assertTrue(blockAttributes.isFenceBlock());
assertTrue(blockAttributes.isFenceGateBlock());
assertTrue(blockAttributes.isSlabBlock());
assertTrue(blockAttributes.isStemBlock());
assertTrue(blockAttributes.isThinFenceBlock());
// assertTrue(blockAttributes.isAir());
// assertTrue(blockAttributes.isBounceBlock());
// assertTrue(blockAttributes.isButtonBlock());
// assertTrue(blockAttributes.isCropBlock());
// assertTrue(blockAttributes.isDoorBlock());
// assertTrue(blockAttributes.isFallingBlock());
// assertTrue(blockAttributes.isFenceBlock());
// assertTrue(blockAttributes.isFenceGateBlock());
// assertTrue(blockAttributes.isSlabBlock());
// assertTrue(blockAttributes.isStemBlock());
// assertTrue(blockAttributes.isThinFenceBlock());
}

@Test
Expand Down

0 comments on commit 9275844

Please sign in to comment.