Stackable Block Template
(Custom Components v2)
Una plantilla de bloque stackeable utilizando Custom Components v2 para Minecraft Bedrock Edition.
Plantilla de Bloque Stackeable
Una plantilla para crear bloques stackeables personalizados en Minecraft Bedrock Edition utilizando Custom Components v2. Aprende cómo implementar comportamientos, estados y componentes de bloques...
Código
BP/blocks/stackable.json:
1{ 2 "format_version": "1.21.110", 3 "minecraft:block": { 4 "description": { 5 "identifier": "sl:stackable", 6 "menu_category": { 7 "category": "items" 8 }, 9 "states": { 10 "sl:stackable_state": [0, 1, 2, 3] 11 } 12 }, 13 "components": { 14 "minecraft:collision_box": { 15 "origin": [-6.5, 0, -6], 16 "size": [7, 8, 7] 17 }, 18 "minecraft:selection_box": { 19 "origin": [-6.5, 0, -6], 20 "size": [7, 8, 7] 21 }, 22 "minecraft:material_instances": { 23 "*": { 24 "render_method": "alpha_test", 25 "texture": "sl:stackable" 26 } 27 }, 28 "minecraft:geometry": { 29 "identifier": "geometry.stackable", 30 "bone_visibility": { 31 "first_cube": false, 32 "second_cube": false, 33 "third_cube": false, 34 "fourth_cube": false 35 } 36 }, 37 38 // El componente personalizado. 39 // NO CAMBIES EL NOMBRE SI HARAS TU ADDON PUBLICO. 40 // DEBES DAR CREDITOS POR EL CODIGO. 41 // LEER LA LICENCIA 42 "sl:stackable": { 43 "state": "sl:stackable_state", // Debe ser igual que en tu "states": {}. 44 45 "maxStack": 3, // La cantidad maxima de tu estado. 46 47 // La lista de bloques que serviran para que 48 // el estado de tu bloque aumente en +1. 49 50 // Debe de incluir el id de tu bloque 51 // si quieres que el mismo aumente el estado 52 // (uso recomendado) 53 "stackBlocks": [ 54 "sl:stackable", 55 "minecraft:dirt", 56 "minecraft:stone", 57 "minecraft:oak_planks" 58 ], 59 60 // El sonido que hará tu bloque al colocarse 61 // y aumentar el estado. 62 "sound": "beacon.activate" 63 } 64 }, 65 "permutations": [ 66 { 67 "condition": "q.block_state('sl:stackable_state') == 0", 68 "components": { 69 "minecraft:geometry": { 70 "identifier": "geometry.stackable", 71 "bone_visibility": { 72 "first_cube": true, 73 "second_cube": false, 74 "third_cube": false, 75 "fourth_cube": false 76 } 77 } 78 } 79 }, 80 { 81 "condition": "q.block_state('sl:stackable_state') == 1", 82 "components": { 83 "minecraft:geometry": { 84 "identifier": "geometry.stackable", 85 "bone_visibility": { 86 "first_cube": true, 87 "second_cube": true, 88 "third_cube": false, 89 "fourth_cube": false 90 } 91 } 92 } 93 }, 94 { 95 "condition": "q.block_state('sl:stackable_state') == 2", 96 "components": { 97 "minecraft:geometry": { 98 "identifier": "geometry.stackable", 99 "bone_visibility": { 100 "first_cube": true, 101 "second_cube": true, 102 "third_cube": true, 103 "fourth_cube": false 104 } 105 } 106 } 107 }, 108 { 109 "condition": "q.block_state('sl:stackable_state') == 3", 110 "components": { 111 "minecraft:geometry": { 112 "identifier": "geometry.stackable", 113 "bone_visibility": { 114 "first_cube": true, 115 "second_cube": true, 116 "third_cube": true, 117 "fourth_cube": true 118 } 119 } 120 } 121 } 122 ] 123 } 124}
Script
BP/scripts/stackableComp.js
1import { system, EquipmentSlot, GameMode } from "@minecraft/server"; 2 3/** @type {import('@minecraft/server').BlockCustomComponent} */ 4const stackableComp = { 5 onPlace: ({ block }, { params }) => { 6 const { state, sound } = params; 7 if (!state) return; 8 const perm = block.permutation; 9 block.setPermutation(perm.withState(state, 0)); 10 11 if (sound) block.dimension.playSound(sound, block.location); 12 }, 13 14 onPlayerInteract: ({ block, player, dimension }, { params }) => { 15 const { state, maxStack, stackBlocks, sound } = params; 16 const perm = block.permutation; 17 const currentStackState = perm.getState(state); 18 19 if (currentStackState >= maxStack) return console.warn("Max state reached"); 20 21 const eqComp = player.getComponent("equippable"); 22 if (!eqComp) return; 23 24 const item = eqComp.getEquipment(EquipmentSlot.Mainhand); 25 if (!item) return; 26 const itemName = item.typeId; 27 28 if (!Array.isArray(stackBlocks)) return; 29 if (!stackBlocks.includes(itemName)) return; 30 31 block.setPermutation(perm.withState(state, currentStackState + 1)); 32 33 if (sound) dimension.playSound(sound, block.location); 34 35 if (player.getGameMode().match(GameMode.Creative)) return; 36 37 const newItem = item.clone(); 38 newItem.amount -= 1; 39 eqComp.setEquipment(EquipmentSlot.Mainhand, newItem); 40 }, 41}; 42 43system.beforeEvents.startup.subscribe(({ blockComponentRegistry }) => { 44 // NO CAMBIAR EL NOMBRE "sl:stackable" 45 // DEL COMPONENTE SI PIENSAS PUBLICAR TU ADDON, LEE LA LICENCIA. 46 blockComponentRegistry.registerCustomComponent("sl:stackable", stackableComp); 47 console.warn("[STComp] Stackable comp registered"); 48});
License (STAL) :
-
Stackable Template Addon License (STAL) — 2025
-
Copyright (c) 2025 ScriptLabsMC / a.j.r._.uribe
Definitions
- "Template" means the code, assets, and documentation provided with this file.
- "Public distribution" means any making-available to the public, including publishing to public repositories or marketplaces.
- "Custom component" means the JavaScript custom element identified as "sl:stackable".
Grant of Rights
Permission is granted to use, copy, modify, and distribute the Template, subject to the conditions below when the Template or any derivative is publicly distributed.
Conditions for public distribution
- Preservation of component identifier
- When publicly distributing source form of the Template or a derivative, you must retain the custom component identifier "sl:stackable" for the component that provides the original Template's core behavior.
- Binary, bundled, or minified forms that do not expose component identifiers in source may include a clear notice in accompanying documentation stating that the original component name is preserved in source form.
- This requirement is intended as a branding/attribution condition and not to prevent reasonable modifications. If renaming is necessary for compatibility, contact the author.
- Preservation of parameters and structure
- Public derivatives that expose the component API must preserve the parameter names and fundamental structural contract for compatibility with existing content that relies on this Template.
- Non-public/internal builds are exempt.
- Attribution and license file
- Any public distribution must include this license file in the project root and include credit to "ScriptLabsMC" or "a.j.r._.uribe" (choose one) in the project's README, credits, or about section.
Compliance and termination
- Failure to comply with these conditions terminates the granted rights. If you become aware of non-compliance, contact the author to resolve.
Disclaimer and liability
- THE TEMPLATE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY ARISING FROM USE OF THE TEMPLATE.
Other
- This license does not grant any patent rights. Consult legal counsel for patent considerations.
- This license is not a substitute for legal advice. If you require legally binding terms or have questions, consult a qualified attorney.
- Questions: join discord server
- By using or distributing this Template you agree to comply with these terms.
📁 Archivos incluidos
BP/blocks/stackable_block.jsonLógica del bloque stackeable utilizando Custom Components v2.
BP/scripts/stackableComp.jsEl custom component que otorga la logica del template