Merge pull request #2 from ForestOfLight/dev

v1.0.2
This commit is contained in:
Forest
2025-07-16 13:52:21 -07:00
committed by GitHub
Unverified
71 changed files with 3816 additions and 41 deletions
+2 -1
View File
@@ -1,2 +1,3 @@
.DS_Store .DS_Store
.vscode/ /build
/.regolith
+15
View File
@@ -0,0 +1,15 @@
{
"version": "0.3.0",
"configurations": [
{
"type": "minecraft-js",
"request": "attach",
"name": "Debug with Minecraft",
"mode": "listen",
"targetModuleUuid": "8bb9a1e4-0531-4b93-8ade-3880bfe1e2fc",
"localRoot": "${workspaceFolder}/packs/BP/scripts",
"port": 19144,
"preLaunchTask": "regolith: watch"
}
]
}
+44
View File
@@ -0,0 +1,44 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "regolith: run",
"type": "shell",
"command": "regolith run",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"close": true
}
},
{
"label": "regolith: watch",
"type": "shell",
"command": "regolith watch",
"isBackground": true,
"problemMatcher": {
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": "."
}
},
"presentation": {
"echo": true,
"close": true
}
}
]
}
+1 -1
View File
@@ -70,7 +70,7 @@ Need help, want to discuss technical Minecraft, or follow future updates? [**Joi
- [x] Correct block placement checking - [x] Correct block placement checking
- [x] Automatic material gathering from inventories - [x] Automatic material gathering from inventories
- [x] Material list - [x] Material list
- [ ] Structure Merging into SuperStructures - [ ] Block texture display
## Issues & Suggestions ## Issues & Suggestions
+26
View File
@@ -0,0 +1,26 @@
{
"$schema": "https://raw.githubusercontent.com/Bedrock-OSS/regolith-schemas/main/config/v1.4.json",
"author": "ForestOfLight",
"name": "Construct",
"packs": {
"behaviorPack": "./packs/BP",
"resourcePack": "./packs/RP"
},
"regolith": {
"dataPath": "./packs/data",
"filterDefinitions": {},
"formatVersion": "1.4.0",
"profiles": {
"default": {
"export": {
"build": "standard",
"readOnly": false,
"target": "development",
"rpName": "project.name+'[RP]'",
"bpName": "project.name+'[BP]'"
},
"filters": []
}
}
}
}

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 88 KiB

File diff suppressed because it is too large Load Diff
@@ -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;
} }
@@ -40,6 +40,10 @@ class StructureCollection {
return structure; return structure;
} }
has(instanceName) {
return Boolean(this.structures[instanceName]);
}
delete(instanceName) { delete(instanceName) {
const struct = this.get(instanceName); const struct = this.get(instanceName);
struct.delete(); struct.delete();
@@ -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;
} }
} }
@@ -3,7 +3,10 @@ export const bannedBlocks = [
'wooden_door', 'spruce_door', 'birch_door', 'jungle_door', 'acacia_door', 'dark_oak_door', 'mangrove_door', 'cherry_door', 'pale_oak_door', 'wooden_door', 'spruce_door', 'birch_door', 'jungle_door', 'acacia_door', 'dark_oak_door', 'mangrove_door', 'cherry_door', 'pale_oak_door',
'bamboo_door', 'iron_door', 'crimson_door', 'warped_door', 'copper_door', 'exposed_copper_door', 'weathered_copper_door', 'oxidized_copper_door', 'bamboo_door', 'iron_door', 'crimson_door', 'warped_door', 'copper_door', 'exposed_copper_door', 'weathered_copper_door', 'oxidized_copper_door',
'waxed_copper_door', 'waxed_exposed_copper_door', 'waxed_weathered_copper_door', 'waxed_oxidized_copper_door', 'waxed_copper_door', 'waxed_exposed_copper_door', 'waxed_weathered_copper_door', 'waxed_oxidized_copper_door',
'seagrass', 'kelp', 'dried_ghast' 'seagrass', 'kelp', 'dried_ghast', 'undyed_shulker_box', 'white_shulker_box', 'orange_shulker_box', 'magenta_shulker_box',
'light_blue_shulker_box', 'yellow_shulker_box', 'lime_shulker_box', 'pink_shulker_box', 'gray_shulker_box',
'light_gray_shulker_box', 'cyan_shulker_box', 'purple_shulker_box', 'blue_shulker_box', 'brown_shulker_box',
'green_shulker_box', 'red_shulker_box', 'black_shulker_box'
]; ];
export const bannedDimensionBlocks = { export const bannedDimensionBlocks = {
@@ -31,6 +31,11 @@ Vector.rejection = function rejection(a, b) { return Vector.subtract(a, Vector.p
Vector.reflect = function reflect(v, n) { return Vector.subtract(v, Vector.multiply(n, 2 * Vector.dot(v, n))); } Vector.reflect = function reflect(v, n) { return Vector.subtract(v, Vector.multiply(n, 2 * Vector.dot(v, n))); }
Vector.lerp = function lerp(a, b, t) { return Vector.multiply(a, 1 - t).add(Vector.multiply(b, t)); } Vector.lerp = function lerp(a, b, t) { return Vector.multiply(a, 1 - t).add(Vector.multiply(b, t)); }
Vector.distance = function distance(a, b) { return Vector.magnitude(Vector.subtract(a, b)); } Vector.distance = function distance(a, b) { return Vector.magnitude(Vector.subtract(a, b)); }
Vector.intersect = function intersect(maxA, minA, maxB, minB) {
return (maxA.x >= minB.x && minA.x <= maxB.x) &&
(maxA.y >= minB.y && minA.y <= maxB.y) &&
(maxA.z >= minB.z && minA.z <= maxB.z);
}
Vector.from = function from(object) { Vector.from = function from(object) {
if (Vector.isVec3(object)) return object; if (Vector.isVec3(object)) return object;
if (Array.isArray(object)) return new Vector(object[0], object[1], object[2]); if (Array.isArray(object)) return new Vector(object[0], object[1], object[2]);
@@ -19,7 +19,8 @@ function giveActionItem(playerId) {
const player = world.getEntity(playerId); const player = world.getEntity(playerId);
const container = player.getComponent(EntityComponentTypes.Inventory)?.container; const container = player.getComponent(EntityComponentTypes.Inventory)?.container;
const itemStack = new ItemStack('construct:easy_place'); const itemStack = new ItemStack('construct:easy_place');
if (!container.contains(itemStack)) { const offhandItemStack = player.getComponent(EntityComponentTypes.Equippable).getEquipment(EquipmentSlot.Offhand);
if (!container.contains(itemStack) && offhandItemStack?.typeId !== 'construct:easy_place') {
const remainingItemStack = container.addItem(itemStack); const remainingItemStack = container.addItem(itemStack);
if (remainingItemStack) if (remainingItemStack)
player.dimension.spawnItem(remainingItemStack, player.location); player.dimension.spawnItem(remainingItemStack, player.location);
@@ -1,12 +1,14 @@
import { BuilderOption } from '../classes/Builder/BuilderOption'; import { BuilderOption } from '../classes/Builder/BuilderOption';
import { BlockPermutation, EntityComponentTypes, EquipmentSlot, GameMode, InputMode, ItemStack, system, world } from '@minecraft/server'; import { BlockPermutation, EntityComponentTypes, EquipmentSlot, GameMode, ItemStack, system, world } from '@minecraft/server';
import { bannedBlocks, bannedToValidBlockMap, whitelistedBlockStates, resetToBlockStates, bannedDimensionBlocks, import { bannedBlocks, bannedToValidBlockMap, whitelistedBlockStates, resetToBlockStates, bannedDimensionBlocks,
blockIdToItemStackMap } from '../data'; blockIdToItemStackMap } from '../data';
import { placeBlock } from '../utils'; import { placeBlock, fetchMatchingItemSlot } from '../utils';
import { Raycaster } from '../classes/Raycaster'; import { Raycaster } from '../classes/Raycaster';
import { Builders } from '../classes/Builder/Builders'; import { Builders } from '../classes/Builder/Builders';
import { Vector } from '../lib/Vector';
const PROCESS_INTERVAL = 2; // Fast Easy Place will attempt to place twice when at an interval of 1. const locationsPlacedLastTick = new Set();
const PLAYER_COLLISION_BOX = { width: 0.6, height: 1.8 };
const builderOption = new BuilderOption({ const builderOption = new BuilderOption({
identifier: 'fastEasyPlace', identifier: 'fastEasyPlace',
@@ -21,7 +23,8 @@ function giveActionItem(playerId) {
const player = world.getEntity(playerId); const player = world.getEntity(playerId);
const container = player.getComponent(EntityComponentTypes.Inventory)?.container; const container = player.getComponent(EntityComponentTypes.Inventory)?.container;
const itemStack = new ItemStack('construct:easy_place'); const itemStack = new ItemStack('construct:easy_place');
if (!container.contains(itemStack)) { const offhandItemStack = player.getComponent(EntityComponentTypes.Equippable).getEquipment(EquipmentSlot.Offhand);
if (!container.contains(itemStack) && offhandItemStack?.typeId !== 'construct:easy_place') {
const remainingItemStack = container.addItem(itemStack); const remainingItemStack = container.addItem(itemStack);
if (remainingItemStack) if (remainingItemStack)
player.dimension.spawnItem(remainingItemStack, player.location); player.dimension.spawnItem(remainingItemStack, player.location);
@@ -46,7 +49,7 @@ function removeActionItem(playerId) {
} }
} }
system.runInterval(onTick, PROCESS_INTERVAL); system.runInterval(onTick);
world.beforeEvents.playerInteractWithBlock.subscribe(onPlayerInteractWithBlock); world.beforeEvents.playerInteractWithBlock.subscribe(onPlayerInteractWithBlock);
function onTick() { function onTick() {
@@ -68,6 +71,12 @@ function processEasyPlace(player) {
if (!structureBlock) if (!structureBlock)
return; return;
const worldBlock = player.dimension.getBlock(structureBlock.location); const worldBlock = player.dimension.getBlock(structureBlock.location);
if (locationsPlacedLastTick.has(JSON.stringify(worldBlock.location)))
return;
locationsPlacedLastTick.add(JSON.stringify(worldBlock.location));
system.runTimeout(() => {
locationsPlacedLastTick.delete(JSON.stringify(worldBlock.location));
}, 2);
tryPlaceBlock(player, worldBlock, structureBlock.permutation); tryPlaceBlock(player, worldBlock, structureBlock.permutation);
} }
@@ -86,7 +95,7 @@ function isHoldingActionItem(player) {
} }
function tryPlaceBlock(player, worldBlock, structureBlock) { function tryPlaceBlock(player, worldBlock, structureBlock) {
if (isBannedBlock(player, structureBlock) || !locationIsPlaceable(worldBlock)) return; if (isBannedBlock(player, structureBlock) || !locationIsPlaceable(player, worldBlock)) return;
structureBlock = tryConvertBannedToValidBlock(structureBlock); structureBlock = tryConvertBannedToValidBlock(structureBlock);
if (player.getGameMode() === GameMode.Creative) { if (player.getGameMode() === GameMode.Creative) {
placeBlock(player, worldBlock, structureBlock); placeBlock(player, worldBlock, structureBlock);
@@ -96,8 +105,8 @@ function tryPlaceBlock(player, worldBlock, structureBlock) {
} }
} }
function locationIsPlaceable(worldBlock) { function locationIsPlaceable(player, worldBlock) {
return worldBlock.isAir; return (worldBlock.isAir || worldBlock.isLiquid) && !isBlockInsidePlayer(player, worldBlock);
} }
function isBannedBlock(player, structureBlock) { function isBannedBlock(player, structureBlock) {
@@ -149,15 +158,12 @@ function getPlaceableItemStack(structureBlock) {
return newItemId ? new ItemStack(newItemId) : structureBlock.getItemStack(); return newItemId ? new ItemStack(newItemId) : structureBlock.getItemStack();
} }
function fetchMatchingItemSlot(player, itemToMatchId) { function isBlockInsidePlayer(player, worldBlock) {
if (!itemToMatchId) const playerLocation = Vector.from(player.location);
return void 0; const blockLocation = Vector.from(worldBlock.location);
const inventory = player.getComponent(EntityComponentTypes.Inventory)?.container; const playerMin = playerLocation.subtract({ x: PLAYER_COLLISION_BOX.width / 2, y: -0.1, z: PLAYER_COLLISION_BOX.width / 2 });
if (!inventory) const playerMax = playerLocation.add({ x: PLAYER_COLLISION_BOX.width / 2, y: PLAYER_COLLISION_BOX.height, z: PLAYER_COLLISION_BOX.width / 2 });
return void 0; const blockMin = blockLocation;
for (let index = 0; index < inventory.size; index++) { const blockMax = blockLocation.add({ x: 1, y: 1, z: 1 });
const itemSlot = inventory.getSlot(index); return Vector.intersect(playerMax, playerMin, blockMax, blockMin);
if (itemSlot.hasItem() && itemSlot?.typeId === itemToMatchId)
return itemSlot;
}
} }
@@ -55,11 +55,10 @@ function onPlayerInteract(event) {
const player = event.player; const player = event.player;
const target = event.block || event.target; const target = event.block || event.target;
const focusedInstanceName = Builders.get(player.id).materialInstanceName; const focusedInstanceName = Builders.get(player.id).materialInstanceName;
if (!focusedInstanceName) { if (!focusedInstanceName || !structureCollection.has(focusedInstanceName))
openInstanceSelectionForm(player, event); openInstanceSelectionForm(player, event);
} else { else
tryGrabMaterials(player, target, focusedInstanceName, event); tryGrabMaterials(player, target, focusedInstanceName, event);
}
} }
function isActionItem(itemStack) { function isActionItem(itemStack) {
@@ -1,7 +1,7 @@
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, block_sounds } from './blocks';
export async function forceShow(player, form, timeout = Infinity) { export async function forceShow(player, form, timeout = Infinity) {
const startTick = system.currentTick; const startTick = system.currentTick;
@@ -21,11 +21,15 @@ export function fetchMatchingItemSlot(entity, itemToMatchId) {
const inventory = entity.getComponent(EntityComponentTypes.Inventory)?.container; const inventory = entity.getComponent(EntityComponentTypes.Inventory)?.container;
if (!inventory) if (!inventory)
return void 0; return void 0;
let smallestItemSlot;
for (let index = 0; index < inventory.size; index++) { for (let index = 0; index < inventory.size; index++) {
const itemSlot = inventory.getSlot(index); const itemSlot = inventory.getSlot(index);
if (itemSlot.hasItem() && itemSlot?.typeId === itemToMatchId) if (itemSlot.hasItem() && itemSlot?.typeId === itemToMatchId) {
return itemSlot; if (!smallestItemSlot || itemSlot.amount < smallestItemSlot.amount)
smallestItemSlot = itemSlot;
} }
}
return smallestItemSlot;
} }
export function placeBlock(player, placedBlock, blockToPlace, itemSlotToConsume = void 0) { export function placeBlock(player, placedBlock, blockToPlace, itemSlotToConsume = void 0) {
@@ -33,6 +37,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,14 +53,16 @@ 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];
let blockSound = blockData['sound'] || 'stone'; let blockSound = blockData['sound'] || 'stone';
if (['glass', 'terracotta'].includes(blockSound)) let blockSoundId = block_sounds[blockSound].events.place?.sound
blockSound = 'stone'; || block_sounds[block_sounds[blockSound].base].events.place?.sound;
let blockSoundId = 'dig.' + blockSound;
if (['iron', 'calcite'].includes(blockSound))
blockSoundId = 'place.' + blockSound;
player.dimension.playSound(blockSoundId, block.location); player.dimension.playSound(blockSoundId, block.location);
} }

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 88 KiB

Before

Width:  |  Height:  |  Size: 290 B

After

Width:  |  Height:  |  Size: 290 B

Before

Width:  |  Height:  |  Size: 250 B

After

Width:  |  Height:  |  Size: 250 B

Before

Width:  |  Height:  |  Size: 242 B

After

Width:  |  Height:  |  Size: 242 B

Before

Width:  |  Height:  |  Size: 83 B

After

Width:  |  Height:  |  Size: 83 B