add custom items for tool picker, easy place, & material grabber

This commit is contained in:
ForestOfLight
2025-06-07 18:52:42 -07:00
Unverified
parent f077982544
commit 137100114a
10 changed files with 92 additions and 19 deletions
+22
View File
@@ -0,0 +1,22 @@
{
"format_version": "1.20.30",
"minecraft:item": {
"description": {
"identifier": "construct:easy_place",
"category": "Items"
},
"components": {
"minecraft:max_stack_size": 1,
"minecraft:icon": {
"texture": "construct:easy_place"
},
"minecraft:display_name": {
"value": "Easy Place"
},
"minecraft:wearable": {
"dispensable": true,
"slot": "slot.weapon.offhand"
}
}
}
}
+22
View File
@@ -0,0 +1,22 @@
{
"format_version": "1.20.30",
"minecraft:item": {
"description": {
"identifier": "construct:material_grabber",
"category": "Items"
},
"components": {
"minecraft:max_stack_size": 1,
"minecraft:icon": {
"texture": "construct:material_grabber"
},
"minecraft:display_name": {
"value": "Material Grabber"
},
"minecraft:wearable": {
"dispensable": true,
"slot": "slot.weapon.offhand"
}
}
}
}
+22
View File
@@ -0,0 +1,22 @@
{
"format_version": "1.20.30",
"minecraft:item": {
"description": {
"identifier": "construct:tool_picker",
"category": "Items"
},
"components": {
"minecraft:max_stack_size": 1,
"minecraft:icon": {
"texture": "construct:tool_picker"
},
"minecraft:display_name": {
"value": "Construct Tool Picker"
},
"minecraft:wearable": {
"dispensable": true,
"slot": "slot.weapon.offhand"
}
}
}
}
+7 -11
View File
@@ -1,5 +1,5 @@
import { BuilderOption } from '../classes/Builder/BuilderOption'; import { BuilderOption } from '../classes/Builder/BuilderOption';
import { BlockPermutation, EntityComponentTypes, GameMode, ItemStack, system, world } from '@minecraft/server'; import { BlockPermutation, EntityComponentTypes, EquipmentSlot, GameMode, ItemStack, system, world } from '@minecraft/server';
import { structureCollection } from '../classes/Structure/StructureCollection'; import { structureCollection } from '../classes/Structure/StructureCollection';
import { bannedBlocks, bannedToValidBlockMap, whitelistedBlockStates, resetToBlockStates, bannedDimensionBlocks, specialItemPlacementConversions, import { bannedBlocks, bannedToValidBlockMap, whitelistedBlockStates, resetToBlockStates, bannedDimensionBlocks, specialItemPlacementConversions,
blockIdToItemStackMap } from '../data'; blockIdToItemStackMap } from '../data';
@@ -11,29 +11,25 @@ const builderOption = new BuilderOption({
identifier: 'easyPlace', identifier: 'easyPlace',
displayName: 'Easy Place', displayName: 'Easy Place',
description: 'Always place the correct structure block.', description: 'Always place the correct structure block.',
howToUse: "Name a paper 'Easy Place', then put it in the inventory slot above your first hotbar slot to always place the correct blocks in a structure." howToUse: "Hold the Easy Place item in your offhand to always place the correct blocks in a structure."
}); });
world.beforeEvents.playerPlaceBlock.subscribe(onPlayerPlaceBlock); world.beforeEvents.playerPlaceBlock.subscribe(onPlayerPlaceBlock);
function onPlayerPlaceBlock(event) { function onPlayerPlaceBlock(event) {
const { player, block } = event; const { player, block } = event;
if (!player || !block || !builderOption.isEnabled(player.id) || !hasActionItemInCorrectSlot(player)) return; if (!player || !block || !builderOption.isEnabled(player.id) || !isHoldingActionItem(player)) return;
const structureBlock = structureCollection.fetchStructureBlock(block.dimension.id, block.location); const structureBlock = structureCollection.fetchStructureBlock(block.dimension.id, block.location);
if (!structureBlock) if (!structureBlock)
return; return;
tryPlaceBlock(event, player, block, structureBlock); tryPlaceBlock(event, player, block, structureBlock);
} }
function hasActionItemInCorrectSlot(player) { function isHoldingActionItem(player) {
const inventory = player.getComponent(EntityComponentTypes.Inventory)?.container; const offhandItemStack = player.getComponent(EntityComponentTypes.Equippable).getEquipment(EquipmentSlot.Offhand);
if (!inventory) if (!offhandItemStack)
return false; return false;
const actionSlot = inventory.getSlot(ACTION_SLOT); return offhandItemStack.typeId === 'construct:easy_place';
return actionSlot.hasItem()
&& actionSlot.typeId === 'minecraft:paper'
&& actionSlot.nameTag?.toLowerCase().includes('easy')
&& actionSlot.nameTag?.toLowerCase().includes('place');
} }
function tryPlaceBlock(event, player, block, structureBlock) { function tryPlaceBlock(event, player, block, structureBlock) {
@@ -11,7 +11,7 @@ const builderOption = new BuilderOption({
identifier: 'fastEasyPlace', identifier: 'fastEasyPlace',
displayName: 'Fast Easy Place', displayName: 'Fast Easy Place',
description: 'Place correct structure blocks just by looking at them.', description: 'Place correct structure blocks just by looking at them.',
howToUse: "Hold a paper named 'Easy Place' in your hand and look at blocks in a structure to place them." howToUse: "Hold the Easy Place item in your main hand and look at blocks in a structure to place them."
}); });
system.runInterval(onTick, PROCESS_INTERVAL); system.runInterval(onTick, PROCESS_INTERVAL);
@@ -37,9 +37,7 @@ function isHoldingActionItem(player) {
const mainhandItemStack = player.getComponent(EntityComponentTypes.Equippable).getEquipment(EquipmentSlot.Mainhand); const mainhandItemStack = player.getComponent(EntityComponentTypes.Equippable).getEquipment(EquipmentSlot.Mainhand);
if (!mainhandItemStack) if (!mainhandItemStack)
return false; return false;
return mainhandItemStack.typeId === 'minecraft:paper' return mainhandItemStack.typeId === 'construct:easy_place';
&& mainhandItemStack.nameTag?.toLowerCase().includes('easy')
&& mainhandItemStack.nameTag?.toLowerCase().includes('place');
} }
function tryPlaceBlock(player, worldBlock, structureBlock) { function tryPlaceBlock(player, worldBlock, structureBlock) {
@@ -16,14 +16,14 @@ world.beforeEvents.playerInteractWithBlock.subscribe(onPlayerInteract);
world.beforeEvents.playerInteractWithEntity.subscribe(onPlayerInteract); world.beforeEvents.playerInteractWithEntity.subscribe(onPlayerInteract);
function onItemUse(event) { function onItemUse(event) {
if (!isActionItem(event.itemStack) || !builderOption.isEnabled(event.source.id)) if (!isActionItem(event.itemStack) || !builderOption.isEnabled(event.source?.id))
return; return;
event.cancel = true; event.cancel = true;
system.run(() => new MaterialGrabberForm(event.source)); system.run(() => new MaterialGrabberForm(event.source));
} }
function onPlayerInteract(event) { function onPlayerInteract(event) {
if (!isActionItem(event.itemStack) || !builderOption.isEnabled(event.player.id)) if (!isActionItem(event.itemStack) || !builderOption.isEnabled(event.player?.id))
return; return;
const player = event.player; const player = event.player;
const target = event.block || event.target; const target = event.block || event.target;
@@ -40,8 +40,7 @@ function onPlayerInteract(event) {
} }
function isActionItem(itemStack) { function isActionItem(itemStack) {
return itemStack?.nameTag?.toLowerCase().includes('material') return itemStack.typeId === 'construct:material_grabber';
&& itemStack?.nameTag?.toLowerCase().includes('grabber');
} }
function getActiveMaterials(player) { function getActiveMaterials(player) {
+14
View File
@@ -0,0 +1,14 @@
{
"resource_pack_name": "Construct Resource Pack",
"texture_data": {
"construct:tool_picker": {
"textures": "textures/items/tool_picker"
},
"construct:easy_place": {
"textures": "textures/items/easy_place"
},
"construct:material_grabber": {
"textures": "textures/items/material_grabber"
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B