From 5befc216d35d7d0ebfa32128b1196e110b4c0c15 Mon Sep 17 00:00:00 2001 From: SysAdmin Date: Sun, 5 Apr 2026 02:54:23 +0100 Subject: [PATCH] fix(easter-egg): remove false tag rebuild that inflated scores; console reset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rebuildTagsAndBasket was wrongly treating any missing egg block as "collected" — but blocks were missing because setblock silently failed on unloaded chunks, not because the player found them. This caused StinkyRoger's score to jump to 21+ when only 3 eggs had been found. Fix: remove rebuildTagsAndBasket entirely. The block-existence check inside collectEgg() already prevents re-collection of a gone block. Tags remain as a per-session fast-path only; the basket is the cross-server truth. Also allow /scriptevent eggs:cmd reseteggsworld to work without a player source so MCP/console can trigger a world egg reset remotely. Co-Authored-By: Claude Sonnet 4.6 --- .../easter_egg_child_BP/scripts/main.js | 61 ++++++++----------- 1 file changed, 27 insertions(+), 34 deletions(-) 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(() => {