@@ -1,2 +1,3 @@
|
||||
.DS_Store
|
||||
.vscode/
|
||||
/build
|
||||
/.regolith
|
||||
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -70,7 +70,7 @@ Need help, want to discuss technical Minecraft, or follow future updates? [**Joi
|
||||
- [x] Correct block placement checking
|
||||
- [x] Automatic material gathering from inventories
|
||||
- [x] Material list
|
||||
- [ ] Structure Merging into SuperStructures
|
||||
- [ ] Block texture display
|
||||
|
||||
## Issues & Suggestions
|
||||
|
||||
|
||||
@@ -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 |
@@ -32,11 +32,13 @@ class BlockInfo {
|
||||
static getBlockMessage(block) {
|
||||
if (!block)
|
||||
return '§7Unknown';
|
||||
let output = `§a${block.type.id}`;
|
||||
const states = block.getAllStates();
|
||||
if (Object.keys(states).length === 0)
|
||||
return `§a${block.type.id}`;
|
||||
else
|
||||
return `§a${block.type.id}\n§7${this.getFormattedStates(states)}`;
|
||||
if (Object.keys(states).length > 0)
|
||||
output += `\n§7${this.getFormattedStates(states)}`;
|
||||
if (block.isWaterlogged)
|
||||
output += `\n§7isWaterlogged: §3true`;
|
||||
return output;
|
||||
}
|
||||
|
||||
static getFormattedStates(states) {
|
||||
@@ -31,6 +31,7 @@ export class Structure {
|
||||
if (!blockPermutation)
|
||||
return void 0;
|
||||
blockPermutation.location = structureLocation;
|
||||
blockPermutation.isWaterlogged = this.#structure.getIsWaterlogged(blockPermutation.location);
|
||||
return blockPermutation;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,10 @@ class StructureCollection {
|
||||
return structure;
|
||||
}
|
||||
|
||||
has(instanceName) {
|
||||
return Boolean(this.structures[instanceName]);
|
||||
}
|
||||
|
||||
delete(instanceName) {
|
||||
const struct = this.get(instanceName);
|
||||
struct.delete();
|
||||
@@ -36,7 +36,8 @@ export class BlockVerifier {
|
||||
return worldPermuation.type.id === structurePermuation.type.id;
|
||||
}
|
||||
|
||||
isExactMatch(worldPermuation, structurePermuation) {
|
||||
return worldPermuation.matches(structurePermuation.type.id, structurePermuation.getAllStates());
|
||||
isExactMatch(worldPermutation, structurePermutation) {
|
||||
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',
|
||||
'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',
|
||||
'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 = {
|
||||
@@ -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.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.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) {
|
||||
if (Vector.isVec3(object)) return object;
|
||||
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 container = player.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||
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);
|
||||
if (remainingItemStack)
|
||||
player.dimension.spawnItem(remainingItemStack, player.location);
|
||||
@@ -1,12 +1,14 @@
|
||||
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,
|
||||
blockIdToItemStackMap } from '../data';
|
||||
import { placeBlock } from '../utils';
|
||||
import { placeBlock, fetchMatchingItemSlot } from '../utils';
|
||||
import { Raycaster } from '../classes/Raycaster';
|
||||
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({
|
||||
identifier: 'fastEasyPlace',
|
||||
@@ -21,7 +23,8 @@ function giveActionItem(playerId) {
|
||||
const player = world.getEntity(playerId);
|
||||
const container = player.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||
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);
|
||||
if (remainingItemStack)
|
||||
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);
|
||||
|
||||
function onTick() {
|
||||
@@ -68,6 +71,12 @@ function processEasyPlace(player) {
|
||||
if (!structureBlock)
|
||||
return;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -86,7 +95,7 @@ function isHoldingActionItem(player) {
|
||||
}
|
||||
|
||||
function tryPlaceBlock(player, worldBlock, structureBlock) {
|
||||
if (isBannedBlock(player, structureBlock) || !locationIsPlaceable(worldBlock)) return;
|
||||
if (isBannedBlock(player, structureBlock) || !locationIsPlaceable(player, worldBlock)) return;
|
||||
structureBlock = tryConvertBannedToValidBlock(structureBlock);
|
||||
if (player.getGameMode() === GameMode.Creative) {
|
||||
placeBlock(player, worldBlock, structureBlock);
|
||||
@@ -96,8 +105,8 @@ function tryPlaceBlock(player, worldBlock, structureBlock) {
|
||||
}
|
||||
}
|
||||
|
||||
function locationIsPlaceable(worldBlock) {
|
||||
return worldBlock.isAir;
|
||||
function locationIsPlaceable(player, worldBlock) {
|
||||
return (worldBlock.isAir || worldBlock.isLiquid) && !isBlockInsidePlayer(player, worldBlock);
|
||||
}
|
||||
|
||||
function isBannedBlock(player, structureBlock) {
|
||||
@@ -149,15 +158,12 @@ function getPlaceableItemStack(structureBlock) {
|
||||
return newItemId ? new ItemStack(newItemId) : structureBlock.getItemStack();
|
||||
}
|
||||
|
||||
function fetchMatchingItemSlot(player, itemToMatchId) {
|
||||
if (!itemToMatchId)
|
||||
return void 0;
|
||||
const inventory = player.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||
if (!inventory)
|
||||
return void 0;
|
||||
for (let index = 0; index < inventory.size; index++) {
|
||||
const itemSlot = inventory.getSlot(index);
|
||||
if (itemSlot.hasItem() && itemSlot?.typeId === itemToMatchId)
|
||||
return itemSlot;
|
||||
}
|
||||
function isBlockInsidePlayer(player, worldBlock) {
|
||||
const playerLocation = Vector.from(player.location);
|
||||
const blockLocation = Vector.from(worldBlock.location);
|
||||
const playerMin = playerLocation.subtract({ x: PLAYER_COLLISION_BOX.width / 2, y: -0.1, z: PLAYER_COLLISION_BOX.width / 2 });
|
||||
const playerMax = playerLocation.add({ x: PLAYER_COLLISION_BOX.width / 2, y: PLAYER_COLLISION_BOX.height, z: PLAYER_COLLISION_BOX.width / 2 });
|
||||
const blockMin = blockLocation;
|
||||
const blockMax = blockLocation.add({ x: 1, y: 1, z: 1 });
|
||||
return Vector.intersect(playerMax, playerMin, blockMax, blockMin);
|
||||
}
|
||||
@@ -55,11 +55,10 @@ function onPlayerInteract(event) {
|
||||
const player = event.player;
|
||||
const target = event.block || event.target;
|
||||
const focusedInstanceName = Builders.get(player.id).materialInstanceName;
|
||||
if (!focusedInstanceName) {
|
||||
if (!focusedInstanceName || !structureCollection.has(focusedInstanceName))
|
||||
openInstanceSelectionForm(player, event);
|
||||
} else {
|
||||
else
|
||||
tryGrabMaterials(player, target, focusedInstanceName, event);
|
||||
}
|
||||
}
|
||||
|
||||
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 { specialItemPlacementConversions } from './data';
|
||||
import { blocks } from './blocks';
|
||||
import { blocks, block_sounds } from './blocks';
|
||||
|
||||
export async function forceShow(player, form, timeout = Infinity) {
|
||||
const startTick = system.currentTick;
|
||||
@@ -21,11 +21,15 @@ export function fetchMatchingItemSlot(entity, itemToMatchId) {
|
||||
const inventory = entity.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||
if (!inventory)
|
||||
return void 0;
|
||||
let smallestItemSlot;
|
||||
for (let index = 0; index < inventory.size; index++) {
|
||||
const itemSlot = inventory.getSlot(index);
|
||||
if (itemSlot.hasItem() && itemSlot?.typeId === itemToMatchId)
|
||||
return itemSlot;
|
||||
if (itemSlot.hasItem() && itemSlot?.typeId === itemToMatchId) {
|
||||
if (!smallestItemSlot || itemSlot.amount < smallestItemSlot.amount)
|
||||
smallestItemSlot = itemSlot;
|
||||
}
|
||||
}
|
||||
return smallestItemSlot;
|
||||
}
|
||||
|
||||
export function placeBlock(player, placedBlock, blockToPlace, itemSlotToConsume = void 0) {
|
||||
@@ -33,6 +37,7 @@ export function placeBlock(player, placedBlock, blockToPlace, itemSlotToConsume
|
||||
if (itemSlotToConsume)
|
||||
consumeItem(itemSlotToConsume);
|
||||
placedBlock.setPermutation(blockToPlace);
|
||||
handleWaterlogging(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) {
|
||||
const blockId = structureBlock.type.id.replace('minecraft:', '');
|
||||
const blockData = blocks[blockId];
|
||||
let blockSound = blockData['sound'] || 'stone';
|
||||
if (['glass', 'terracotta'].includes(blockSound))
|
||||
blockSound = 'stone';
|
||||
let blockSoundId = 'dig.' + blockSound;
|
||||
if (['iron', 'calcite'].includes(blockSound))
|
||||
blockSoundId = 'place.' + blockSound;
|
||||
let blockSoundId = block_sounds[blockSound].events.place?.sound
|
||||
|| block_sounds[block_sounds[blockSound].base].events.place?.sound;
|
||||
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 |