-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
114 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
server/src/main/java/org/allaymc/server/block/component/BlockWaterBaseComponentImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.allaymc.server.block.component; | ||
|
||
import org.allaymc.api.block.BlockBehavior; | ||
import org.allaymc.api.block.dto.BlockStateWithPos; | ||
import org.allaymc.api.block.dto.PlayerInteractInfo; | ||
import org.allaymc.api.block.type.BlockState; | ||
import org.allaymc.api.block.type.BlockType; | ||
import org.allaymc.api.block.type.BlockTypes; | ||
|
||
import static org.allaymc.api.block.type.BlockTypes.AIR; | ||
|
||
/** | ||
* @author daoge_cmd | ||
*/ | ||
public class BlockWaterBaseComponentImpl extends BlockLiquidBaseComponentImpl { | ||
public BlockWaterBaseComponentImpl(BlockType<? extends BlockBehavior> blockType) { | ||
super(blockType); | ||
} | ||
|
||
@Override | ||
public void onReplace(BlockStateWithPos currentBlockState, BlockState newBlockState, PlayerInteractInfo placementInfo) { | ||
super.onReplace(currentBlockState, newBlockState, placementInfo); | ||
|
||
if (currentBlockState.layer() != 0) { | ||
return; | ||
} | ||
|
||
var dim = currentBlockState.pos().dimension(); | ||
if (newBlockState.getBlockType() != AIR && newBlockState.getBlockStateData().canContainLiquid()) { | ||
// If the old block is water and the new block can contain liquid, | ||
// we need to move water to layer 1 | ||
dim.setBlockState(currentBlockState.pos(), BlockTypes.WATER.getDefaultState(), 1); | ||
} | ||
} | ||
|
||
@Override | ||
public void afterNeighborLayerReplace(BlockStateWithPos currentBlockState, BlockState newBlockState, PlayerInteractInfo placementInfo) { | ||
super.afterNeighborLayerReplace(currentBlockState, newBlockState, placementInfo); | ||
|
||
if (currentBlockState.layer() != 0 || newBlockState.getBlockType() == BlockTypes.WATER) { | ||
return; | ||
} | ||
|
||
var dim = currentBlockState.pos().dimension(); | ||
if (newBlockState.getBlockType() == AIR) { | ||
// Move layer 1 water back to layer 0 | ||
dim.setBlockState(currentBlockState.pos(), BlockTypes.WATER.getDefaultState(), 0); | ||
dim.setBlockState(currentBlockState.pos(), BlockTypes.AIR.getDefaultState(), 1); | ||
return; | ||
} | ||
|
||
if (!newBlockState.getBlockStateData().canContainLiquid()) { | ||
// New layer 0 block cannot contain liquid, remove layer 1 water | ||
dim.setBlockState(currentBlockState.pos(), BlockTypes.AIR.getDefaultState(), 1); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...n/java/org/allaymc/server/block/component/event/CBlockAfterNeighborLayerReplaceEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.allaymc.server.block.component.event; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.allaymc.api.block.dto.BlockStateWithPos; | ||
import org.allaymc.api.block.dto.PlayerInteractInfo; | ||
import org.allaymc.api.block.type.BlockState; | ||
import org.allaymc.api.eventbus.event.Event; | ||
|
||
/** | ||
* @author daoge_cmd | ||
*/ | ||
@Getter | ||
@AllArgsConstructor | ||
public class CBlockAfterNeighborLayerReplaceEvent extends Event { | ||
protected BlockStateWithPos currentBlockState; | ||
protected BlockState newBlockState; | ||
protected PlayerInteractInfo placementInfo; // Can be null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters