fix(easter-egg): remove false tag rebuild that inflated scores; console reset
All checks were successful
Deploy Addons / deploy (push) Successful in 14s
All checks were successful
Deploy Addons / deploy (push) Successful in 14s
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 <noreply@anthropic.com>
This commit is contained in:
@@ -119,37 +119,15 @@ function updateBasket(player, j, l, m) {
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Tag Rebuild ─────────────────────────────────────────────────
|
// ─── Basket Initialisation ───────────────────────────────────────
|
||||||
// When a player (re)joins, rebuild their local found-egg tags based on which
|
// Give a fresh basket to players who don't have one yet.
|
||||||
// egg blocks are actually missing from the world. This handles the case where
|
// We do NOT reconstruct tags from missing blocks on re-join because a missing
|
||||||
// a player transferred away and their server-local tags were wiped.
|
// block might mean "never placed" (chunk not loaded) rather than "collected".
|
||||||
// After rebuilding, sync the basket count to the accurate value.
|
// The block existence check inside collectEgg() is the sole guard against
|
||||||
|
// re-collecting an already-found egg.
|
||||||
|
|
||||||
function rebuildTagsAndBasket(player) {
|
function giveBasketIfMissing(player) {
|
||||||
const positions = getEggPositions();
|
if (!getBasket(player)) updateBasket(player, 0, 0, 0);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Cached Positions ────────────────────────────────────────────
|
// ─── Cached Positions ────────────────────────────────────────────
|
||||||
@@ -446,9 +424,24 @@ try {
|
|||||||
|
|
||||||
system.afterEvents.scriptEventReceive.subscribe((event) => {
|
system.afterEvents.scriptEventReceive.subscribe((event) => {
|
||||||
if (event.id !== "eggs:cmd") return;
|
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;
|
const player = event.sourceEntity;
|
||||||
if (!player) return;
|
if (!player) return;
|
||||||
handleEggCommand(player, `!${(event.message || "").trim().toLowerCase()}`);
|
handleEggCommand(player, `!${msg}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// ─── Startup ─────────────────────────────────────────────────────
|
// ─── Startup ─────────────────────────────────────────────────────
|
||||||
@@ -468,10 +461,10 @@ world.afterEvents.playerSpawn.subscribe((event) => {
|
|||||||
system.runTimeout(() => placeAllEggs(playerPos), 40);
|
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(() => {
|
system.runTimeout(() => {
|
||||||
try { rebuildTagsAndBasket(player); } catch (e) {}
|
try { giveBasketIfMissing(player); } catch (e) {}
|
||||||
}, 80);
|
}, 40);
|
||||||
});
|
});
|
||||||
|
|
||||||
system.run(() => {
|
system.run(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user