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
|
|
// features/display.js animated display pieces (place a block -> spawn an entity).
|
|
import { DISPLAY_DIR_YAW } from "../core/grid.js";
|
|
import { summonDisplay, breakFx, particleFor } from "../core/fx.js";
|
|
import { onPlace, onBreak } from "../core/events.js";
|
|
import { BlockPermutation } from "../core/mc.js";
|
|
|
|
|
|
const DISPLAY_BLOCKS = {
|
|
"rzb_dcs:su36_horchata": { entity: "rzb_dcs:su36_horchata_e", y: 0 },
|
|
"rzb_dcs:su36_jamaica": { entity: "rzb_dcs:su36_jamaica_e", y: 0 },
|
|
"rzb_dcs:su36_tamarind": { entity: "rzb_dcs:su36_tamarind_e", y: 0 },
|
|
"rzb_dcs:su36_lemonade": { entity: "rzb_dcs:su36_lemonade_e", y: 0 },
|
|
"rzb_dcs:su36_lemonade_pink": { entity: "rzb_dcs:su36_lemonade_pink_e", y: 0 },
|
|
"rzb_dcs:su36_limeade": { entity: "rzb_dcs:su36_limeade_e", y: 0 },
|
|
"rzb_dcs:su36_orangeade": { entity: "rzb_dcs:su36_orangeade_e", y: 0 },
|
|
"rzb_dcs:wi37": { entity: "rzb_dcs:pinata", y: 0 },
|
|
"rzb_dcs:wi43": { entity: "rzb_dcs:globe_igloo", y: 0 },
|
|
"rzb_dcs:wi44": { entity: "rzb_dcs:globe_tree", y: 0 }
|
|
};
|
|
|
|
onPlace((ev) => {
|
|
const b = ev.block, cfg = DISPLAY_BLOCKS[b.typeId]; if (!cfg) return;
|
|
let yaw = 0; try { yaw = DISPLAY_DIR_YAW[b.permutation.getState("minecraft:cardinal_direction")] ?? 0; } catch {}
|
|
summonDisplay(b.dimension, cfg.entity, b.x + 0.5, b.y + (cfg.y ?? 0), b.z + 0.5, yaw);
|
|
});
|
|
|
|
|
|
onBreak((ev) => {
|
|
const id = ev.brokenBlockPermutation?.type?.id, cfg = id && DISPLAY_BLOCKS[id]; if (!cfg) return;
|
|
const b = ev.block, at = { x: b.x + 0.5, y: b.y + (cfg.y ?? 0), z: b.z + 0.5 };
|
|
for (const ent of b.dimension.getEntities({ type: cfg.entity, location: at, maxDistance: 0.55 })) ent.remove();
|
|
breakFx(b.dimension, at.x, b.y + 0.5, at.z);
|
|
});
|
|
|
|
const DISPLAY_BRUSH = {};
|
|
const regDisplayBrush = (ids) => { for (const id of ids) DISPLAY_BRUSH[id] = ids; };
|
|
regDisplayBrush(["rzb_dcs:su36_jamaica", "rzb_dcs:su36_orangeade", "rzb_dcs:su36_lemonade", "rzb_dcs:su36_limeade", "rzb_dcs:su36_lemonade_pink", "rzb_dcs:su36_horchata", "rzb_dcs:su36_tamarind"]);
|
|
|
|
export const displayAnchorBrushable = (id) => !!DISPLAY_BRUSH[id];
|
|
export function displayAnchorRecolor(block) { // returns the new variant's brush-particle colour (via BRUSH_ALIAS), or false
|
|
const cur = block?.typeId, seq = DISPLAY_BRUSH[cur]; if (!seq) return false;
|
|
const nextId = seq[(seq.indexOf(cur) + 1) % seq.length];
|
|
const cfg = DISPLAY_BLOCKS[cur], nextCfg = DISPLAY_BLOCKS[nextId]; if (!cfg || !nextCfg) return false;
|
|
const dim = block.dimension, ax = block.x, ay = block.y, az = block.z;
|
|
let dir = "south"; try { dir = block.permutation.getState("minecraft:cardinal_direction") ?? "south"; } catch {}
|
|
try { block.setPermutation(BlockPermutation.resolve(nextId, { "minecraft:cardinal_direction": dir })); } catch {}
|
|
const at = { x: ax + 0.5, y: ay + (cfg.y ?? 0), z: az + 0.5 };
|
|
for (const e of dim.getEntities({ type: cfg.entity, location: at, maxDistance: 0.6 })) { try { e.remove(); } catch {} }
|
|
summonDisplay(dim, nextCfg.entity, ax + 0.5, ay + (nextCfg.y ?? 0), az + 0.5, DISPLAY_DIR_YAW[dir] ?? 0);
|
|
return particleFor(nextId);
|
|
}
|