You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
3.0 KiB
JavaScript
53 lines
3.0 KiB
JavaScript
// core/fx.js; placement undo, break particles, display summon, brush feedback, debounce.
|
|
import { system, ItemStack, isCreative } from "./mc.js";
|
|
|
|
export function undoPlace(anchor, player, itemId, name) {
|
|
try { anchor.setType("minecraft:air"); } catch {}
|
|
try { if (!isCreative(player)) { const inv = player.getComponent("minecraft:inventory")?.container; if (inv) inv.addItem(new ItemStack(itemId, 1)); } } catch {}
|
|
try { player.onScreenDisplay.setActionBar("§cNot enough room for the " + name); } catch {}
|
|
try { player.playSound("note.didgeridoo", { volume: 0.85 }); } catch {} // DecoCraft's placement-rejected cue
|
|
}
|
|
|
|
export function breakFx(dim, x, y, z) { try { dim.spawnParticle("rzb_dcs:breakdeco", { x, y, z }); } catch {} }
|
|
export function breakAir(nb) { if (!nb) return; const d = nb.dimension, x = nb.x, y = nb.y, z = nb.z; try { nb.setType("minecraft:air"); } catch {} breakFx(d, x + 0.5, y + 0.5, z + 0.5); }
|
|
|
|
export function summonDisplay(dim, entityId, x, y, z, yaw) {
|
|
try { dim.runCommand(`summon ${entityId} ${x} ${y} ${z} ${yaw} 0`); } catch {}
|
|
}
|
|
|
|
export function debounced(store, key, ticks) {
|
|
if (store.has(key)) return true;
|
|
store.add(key); system.runTimeout(() => store.delete(key), ticks);
|
|
return false;
|
|
}
|
|
|
|
const _toggleRecent = new Set();
|
|
export function toggleDebounced(x, y, z) {
|
|
return debounced(_toggleRecent, Math.floor(x) + "," + Math.floor(y) + "," + Math.floor(z), 12);
|
|
}
|
|
|
|
const P_ALIAS = { rosegold: "pink", silver: "lightgray", gold: "yellow", berry: "magenta", clovers: "green", tulips: "lime", flowers1: "pink", flowers2: "purple", spring: "lime", plain: "white", cherry: "brown", ebony: "brown", oak: "brown", palm: "brown", spruce: "brown" };
|
|
const P_COLORS = ["lightblue", "lightgray", "black", "blue", "brown", "cyan", "gray", "green", "lime", "magenta", "orange", "pink", "purple", "red", "white", "yellow"];
|
|
|
|
export const BRUSH_ALIAS = {
|
|
"rzb_dcs:su36_horchata": "white", "rzb_dcs:su36_jamaica": "red", "rzb_dcs:su36_tamarind": "brown", "rzb_dcs:su36_lemonade": "yellow",
|
|
"rzb_dcs:su36_lemonade_pink": "pink", "rzb_dcs:su36_limeade": "lime", "rzb_dcs:su36_orangeade": "orange",
|
|
"rzb_dcs:sp35_robin": "red", "rzb_dcs:sp35_blue_j": "blue",
|
|
"rzb_dcs:su01_1": "yellow", "rzb_dcs:su01_2": "lightblue", "rzb_dcs:su01_3": "pink", "rzb_dcs:su01_4": "lime",
|
|
"rzb_dcs:su01_5": "orange", "rzb_dcs:su01_6": "blue", "rzb_dcs:su01_7": "red", "rzb_dcs:su01_rainbow": "magenta",
|
|
};
|
|
export function particleFor(blockId) {
|
|
const key = ("" + blockId).replace(/_e$/, "");
|
|
if (BRUSH_ALIAS[key]) return BRUSH_ALIAS[key];
|
|
const v = key.replace(/^rzb_dcs:sp\d+_?/, "").replace(/^p_/, "");
|
|
for (const k in P_ALIAS) if (v.includes(k)) return P_ALIAS[k];
|
|
for (const c of P_COLORS) if (v.includes(c)) return c;
|
|
return "white";
|
|
}
|
|
|
|
export function brushFx(dim, loc, pcol, player) {
|
|
try { player?.playAnimation("animation.rzb_dcs.player.interact"); } catch {}
|
|
try { dim.playSound("sign.ink_sac.use", loc, { volume: 0.8 }); } catch {}
|
|
try { dim.runCommand(`particle rzb_dcs:decobrush_${pcol} ${loc.x + 0.5} ${loc.y + 0.6} ${loc.z + 0.5}`); } catch {}
|
|
}
|