package dev.cobblesurvival.selftest import dev.cobblesurvival.ore.BaseLoot import dev.cobblesurvival.zone.InZoneCondition import dev.cobblesurvival.zone.Zones import net.minecraft.core.BlockPos import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.gametest.framework.GameTestAssertException import net.minecraft.world.level.storage.loot.LootContext import net.minecraft.world.level.storage.loot.LootParams import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets import net.minecraft.world.level.storage.loot.parameters.LootContextParams import net.minecraft.world.phys.Vec3 import java.util.Optional /** * Cobblebase's base jobs only dig up the pasture zone's ores (Adrian, 2026-10-31): Cobblebase's built-in copies of the * mining and finder tables are gone, `cobblesurvival:in_zone` holds only inside its zones, and Mining's common table * gives Button Isle coal but no iron and Westmarch iron but no coal (world/zones.json: coal is Button Isle's only ore, * raw iron comes from Westmarch). */ object BaseLootTests { private const val ROLLS = 200 fun all() = listOf(SelfTestCase("base_jobs_dig_their_zones_ores", 40, ::baseJobsDigTheirZonesOres)) /** A spot in [zone], high above the ground so no cave zone lies there. */ private fun spotIn(s: Scenario, zone: String): BlockPos { val sample = Zones.samples[zone] ?: throw GameTestAssertException("no sample point for $zone") val pos = BlockPos(sample.x, 250, sample.z) s.check(Zones.at(s.level, pos)?.id == zone) { "the sample point of $zone lies in ${Zones.at(s.level, pos)?.id}" } return pos } private fun baseJobsDigTheirZonesOres(s: Scenario) { val level = s.level s.check(BaseLoot.builtInLeft().isEmpty()) { "Cobblebase still rolls its own copies of ${BaseLoot.builtInLeft()}" } val isle = spotIn(s, "button_isle") val westmarch = spotIn(s, "westmarch") val params = LootParams.Builder(level).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(isle)).create(LootContextParamSets.CHEST) val context = LootContext.Builder(params).create(Optional.empty()) s.check(InZoneCondition(listOf("button_isle")).test(context)) { "in_zone [button_isle] is false on Button Isle" } s.check(!InZoneCondition(listOf("westmarch")).test(context)) { "in_zone [westmarch] is true on Button Isle" } fun dug(pos: BlockPos, table: String) = (1..ROLLS).flatMap { BaseLoot.roll(table, level, pos) } .map { BuiltInRegistries.ITEM.getKey(it.item).path }.toSet() val onIsle = dug(isle, "cobblebase:mining_common") s.check("coal" in onIsle && "raw_iron" !in onIsle && "raw_copper" !in onIsle) { "Mining on Button Isle dug up $onIsle" } val inWestmarch = dug(westmarch, "cobblebase:mining_common") s.check("raw_iron" in inWestmarch && "coal" !in inWestmarch) { "Mining in Westmarch dug up $inWestmarch" } val gems = (dug(isle, "cobblebase:mining_uncommon") + dug(isle, "cobblebase:mining_ultra_rare")).filter { it.endsWith("_gem") } s.check(gems.isEmpty()) { "Mining still digs up type gems: $gems" } val stones = dug(isle, "cobblebase:finder_evo_common") s.check(stones.isEmpty()) { "the Evolution-item Finder found $stones on Button Isle, which has no evolution stones" } s.helper.succeed() } }