waterlogging support

This commit is contained in:
ForestOfLight
2025-07-10 15:24:32 -07:00
Unverified
parent 357327e9b0
commit 9bb2b002c9
5 changed files with 18 additions and 8 deletions
+6 -4
View File
@@ -32,11 +32,13 @@ class BlockInfo {
static getBlockMessage(block) { static getBlockMessage(block) {
if (!block) if (!block)
return '§7Unknown'; return '§7Unknown';
let output = `§a${block.type.id}`;
const states = block.getAllStates(); const states = block.getAllStates();
if (Object.keys(states).length === 0) if (Object.keys(states).length > 0)
return `§a${block.type.id}`; output += `\n§7${this.getFormattedStates(states)}`;
else if (block.isWaterlogged)
return `§a${block.type.id}\n§7${this.getFormattedStates(states)}`; output += `\n§7isWaterlogged: §3true`;
return output;
} }
static getFormattedStates(states) { static getFormattedStates(states) {
@@ -31,6 +31,7 @@ export class Structure {
if (!blockPermutation) if (!blockPermutation)
return void 0; return void 0;
blockPermutation.location = structureLocation; blockPermutation.location = structureLocation;
blockPermutation.isWaterlogged = this.#structure.getIsWaterlogged(blockPermutation.location);
return blockPermutation; return blockPermutation;
} }
@@ -36,7 +36,8 @@ export class BlockVerifier {
return worldPermuation.type.id === structurePermuation.type.id; return worldPermuation.type.id === structurePermuation.type.id;
} }
isExactMatch(worldPermuation, structurePermuation) { isExactMatch(worldPermutation, structurePermutation) {
return worldPermuation.matches(structurePermuation.type.id, structurePermuation.getAllStates()); return worldPermutation.matches(structurePermutation.type.id, structurePermutation.getAllStates())
&& this.block.isWaterlogged === structurePermutation.isWaterlogged;
} }
} }
+1 -1
View File
@@ -97,7 +97,7 @@ function tryPlaceBlock(player, worldBlock, structureBlock) {
} }
function locationIsPlaceable(worldBlock) { function locationIsPlaceable(worldBlock) {
return worldBlock.isAir; return worldBlock.isAir || worldBlock.isLiquid;
} }
function isBannedBlock(player, structureBlock) { function isBannedBlock(player, structureBlock) {
+7 -1
View File
@@ -1,4 +1,4 @@
import { system, EntityComponentTypes } from '@minecraft/server'; import { system, EntityComponentTypes, LiquidType } from '@minecraft/server';
import { FormCancelationReason } from '@minecraft/server-ui'; import { FormCancelationReason } from '@minecraft/server-ui';
import { specialItemPlacementConversions } from './data'; import { specialItemPlacementConversions } from './data';
import { blocks } from './blocks'; import { blocks } from './blocks';
@@ -33,6 +33,7 @@ export function placeBlock(player, placedBlock, blockToPlace, itemSlotToConsume
if (itemSlotToConsume) if (itemSlotToConsume)
consumeItem(itemSlotToConsume); consumeItem(itemSlotToConsume);
placedBlock.setPermutation(blockToPlace); placedBlock.setPermutation(blockToPlace);
handleWaterlogging(placedBlock, blockToPlace);
playBlockPlacementSound(player, placedBlock, blockToPlace); playBlockPlacementSound(player, placedBlock, blockToPlace);
}); });
} }
@@ -48,6 +49,11 @@ function consumeItem(itemSlot) {
} }
} }
function handleWaterlogging(block, structureBlock) {
if (block.isLiquid && structureBlock.canContainLiquid(LiquidType.Water))
block.setWaterlogged(true);
}
function playBlockPlacementSound(player, block, structureBlock) { function playBlockPlacementSound(player, block, structureBlock) {
const blockId = structureBlock.type.id.replace('minecraft:', ''); const blockId = structureBlock.type.id.replace('minecraft:', '');
const blockData = blocks[blockId]; const blockData = blocks[blockId];