diff --git a/easter-egg-addon/easter_egg_child_BP/scripts/main.js b/easter-egg-addon/easter_egg_child_BP/scripts/main.js index c4d7747..0dd35ec 100644 --- a/easter-egg-addon/easter_egg_child_BP/scripts/main.js +++ b/easter-egg-addon/easter_egg_child_BP/scripts/main.js @@ -119,37 +119,15 @@ function updateBasket(player, j, l, m) { } catch (e) {} } -// ─── Tag Rebuild ───────────────────────────────────────────────── -// When a player (re)joins, rebuild their local found-egg tags based on which -// egg blocks are actually missing from the world. This handles the case where -// a player transferred away and their server-local tags were wiped. -// After rebuilding, sync the basket count to the accurate value. +// ─── Basket Initialisation ─────────────────────────────────────── +// Give a fresh basket to players who don't have one yet. +// We do NOT reconstruct tags from missing blocks on re-join because a missing +// block might mean "never placed" (chunk not loaded) rather than "collected". +// The block existence check inside collectEgg() is the sole guard against +// re-collecting an already-found egg. -function rebuildTagsAndBasket(player) { - const positions = getEggPositions(); - if (!positions || positions.length === 0) return; - const overworld = world.getDimension("overworld"); - let found = 0; - for (const egg of positions) { - const tagId = `egg_${PREFIX}_${egg.id}`; - if (player.hasTag(tagId)) { - found++; - continue; - } - try { - const block = overworld.getBlock({ x: egg.x, y: egg.y, z: egg.z }); - // Block gone (air/non-terracotta) means this egg was previously collected - if (!block || !block.typeId.includes("glazed_terracotta")) { - player.addTag(tagId); - found++; - } - } catch (e) {} - } - // Update basket with accurate count for this world - const counts = getBasketCounts(player); - if (PREFIX === "j") updateBasket(player, found, counts.l, counts.m); - else if (PREFIX === "l") updateBasket(player, counts.j, found, counts.m); - else if (PREFIX === "m") updateBasket(player, counts.j, counts.l, found); +function giveBasketIfMissing(player) { + if (!getBasket(player)) updateBasket(player, 0, 0, 0); } // ─── Cached Positions ──────────────────────────────────────────── @@ -446,9 +424,24 @@ try { system.afterEvents.scriptEventReceive.subscribe((event) => { if (event.id !== "eggs:cmd") return; + const msg = (event.message || "").trim().toLowerCase(); + + // Allow reseteggsworld from console (sourceEntity is null when run via MCP/RCON) + if (msg === "reseteggsworld") { + try { + world.setDynamicProperty("eggs_placed", "false"); + world.setDynamicProperty("eggs_data", ""); + world.setDynamicProperty("egg_center", ""); + } catch (e) {} + eggPositions = null; + eggsPlacedThisSession = false; + world.sendMessage("§6[Eggs] §fEgg data cleared — eggs will re-place on next player spawn."); + return; + } + const player = event.sourceEntity; if (!player) return; - handleEggCommand(player, `!${(event.message || "").trim().toLowerCase()}`); + handleEggCommand(player, `!${msg}`); }); // ─── Startup ───────────────────────────────────────────────────── @@ -468,10 +461,10 @@ world.afterEvents.playerSpawn.subscribe((event) => { system.runTimeout(() => placeAllEggs(playerPos), 40); } - // Rebuild lost tags and sync basket (80 ticks gives placeAllEggs time to finish) + // Give basket if player doesn't have one yet system.runTimeout(() => { - try { rebuildTagsAndBasket(player); } catch (e) {} - }, 80); + try { giveBasketIfMissing(player); } catch (e) {} + }, 40); }); system.run(() => {