diff --git a/src/main/java/net/rotgruengelb/landscape/command/debuglet/zone/RuleSetsDebuglet.java b/src/main/java/net/rotgruengelb/landscape/command/debuglet/zone/RuleSetsDebuglet.java index f52b417..805bb5c 100644 --- a/src/main/java/net/rotgruengelb/landscape/command/debuglet/zone/RuleSetsDebuglet.java +++ b/src/main/java/net/rotgruengelb/landscape/command/debuglet/zone/RuleSetsDebuglet.java @@ -5,18 +5,17 @@ import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; import net.minecraft.util.Identifier; -import net.rotgruengelb.landscape.feature.zones.rule.RuleSetDataManager; import net.rotgruengelb.landscape.feature.zones.rule.RuleSet; +import net.rotgruengelb.landscape.feature.zones.rule.RuleSetDataManager; import java.util.Map; -import java.util.Set; public class RuleSetsDebuglet { public static int showAvailableRuleSets(CommandContext ctx) { - Set rulesets = RuleSetDataManager.getRuleSets(); - for (Identifier ruleSet : rulesets) { + Map ruleSets = RuleSetDataManager.getRuleSets(); + for (Identifier identifier : ruleSets.keySet()) { ctx.getSource() - .sendMessage(Text.literal("ruleset: " + ruleSet + " -> " + RuleSetDataManager.getRuleSet(ruleSet) + .sendMessage(Text.literal("ruleset: " + identifier + " -> " + ruleSets.get(identifier) .name())); } return 1; @@ -24,7 +23,8 @@ public static int showAvailableRuleSets(CommandContext ctx) public static int showRuleSetRules(CommandContext ctx) { String ruleSetName = StringArgumentType.getString(ctx, "ruleset_name"); - RuleSet ruleSet = RuleSetDataManager.getRuleSet(Identifier.tryParse(ruleSetName)); + RuleSet ruleSet = RuleSetDataManager.getRuleSet(Identifier.tryParse(ruleSetName), ctx.getSource() + .getWorld()); if (ruleSet == null) { ctx.getSource() .sendError(Text.literal("No RuleSet with name " + ruleSetName + " found")); diff --git a/src/main/java/net/rotgruengelb/landscape/feature/zones/LandscapeAPI.java b/src/main/java/net/rotgruengelb/landscape/feature/zones/LandscapeAPI.java index 0d6d491..599d863 100644 --- a/src/main/java/net/rotgruengelb/landscape/feature/zones/LandscapeAPI.java +++ b/src/main/java/net/rotgruengelb/landscape/feature/zones/LandscapeAPI.java @@ -30,7 +30,7 @@ public static Optional allowsAction(BlockPos pos, String rule, World wo zoneManagerContexts.stream() .filter(zoneManagerContext -> zoneManagerContext.isBlockPosInZone(pos, false)) .forEach(zoneManagerContext -> { - RuleSet ruleSet = RuleSet.of(zoneManagerContext.ruleSet()); + RuleSet ruleSet = RuleSet.of(zoneManagerContext.ruleSet(), world); if (ruleSet.containsRule(rule)) { values.put(zoneManagerContext.priority(), ruleSet.getRuleValue(rule)); } diff --git a/src/main/java/net/rotgruengelb/landscape/feature/zones/rule/RuleSet.java b/src/main/java/net/rotgruengelb/landscape/feature/zones/rule/RuleSet.java index 8fcb2e9..82a699b 100644 --- a/src/main/java/net/rotgruengelb/landscape/feature/zones/rule/RuleSet.java +++ b/src/main/java/net/rotgruengelb/landscape/feature/zones/rule/RuleSet.java @@ -3,6 +3,7 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.util.Identifier; +import net.minecraft.world.World; import java.util.HashMap; import java.util.Map; @@ -17,8 +18,8 @@ public record RuleSet(String name, .forGetter(RuleSet::name), Codec.unboundedMap(Codec.STRING, Codec.BOOL) .fieldOf("rules").forGetter(RuleSet::rules)).apply(instance, RuleSet::new)); - public static RuleSet of(Identifier name) { - return RuleSetDataManager.getRuleSet(name); + public static RuleSet of(Identifier name, World world) { + return RuleSetDataManager.getRuleSet(name, world); } public boolean containsRule(String rule) { diff --git a/src/main/java/net/rotgruengelb/landscape/feature/zones/rule/RuleSetDataManager.java b/src/main/java/net/rotgruengelb/landscape/feature/zones/rule/RuleSetDataManager.java index 3069c23..c43f44b 100644 --- a/src/main/java/net/rotgruengelb/landscape/feature/zones/rule/RuleSetDataManager.java +++ b/src/main/java/net/rotgruengelb/landscape/feature/zones/rule/RuleSetDataManager.java @@ -12,17 +12,18 @@ import net.minecraft.resource.ResourceType; import net.minecraft.util.Identifier; import net.minecraft.util.profiler.Profiler; +import net.minecraft.world.World; import net.rotgruengelb.landscape.Landscape; import net.rotgruengelb.landscape.registry.LandscapeRegistries; import org.slf4j.Logger; import java.util.HashMap; import java.util.Map; -import java.util.Set; public class RuleSetDataManager extends JsonDataLoader implements IdentifiableResourceReloadListener { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping() .create(); + private static final Map ruleSets = new HashMap<>(); public static RuleSetDataManager INSTANCE; private final DynamicRegistryManager registryManager; private final Logger LOGGER = Landscape.getClassLogger(); @@ -37,13 +38,12 @@ public static void register(DynamicRegistryManager registryManager) { ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(INSTANCE); } - public static RuleSet getRuleSet(Identifier identifier) { - return INSTANCE.registryManager.get(LandscapeRegistries.RULESETS).getOrEmpty(identifier) - .orElse(RuleSet.EMPTY_RULESET); + public static RuleSet getRuleSet(Identifier identifier, World world) { + return world.getRegistryManager().get(LandscapeRegistries.RULESETS).get(identifier); } - public static Set getRuleSets() { - return INSTANCE.registryManager.get(LandscapeRegistries.RULESETS).getIds(); + public static Map getRuleSets() { + return ruleSets; } @Override @@ -54,6 +54,8 @@ public Identifier getFabricId() { @Override protected void apply(Map prepared, ResourceManager manager, Profiler profiler) { + ruleSets.clear(); + LOGGER.info("Loading Data RuleSets for Landscape! ( Path: data/{namespace}/landscapes/rulesets/{name}.json -> RuleSet: {namespace}:{name} )"); for (Identifier identifier : prepared.keySet()) { @@ -70,7 +72,7 @@ protected void apply(Map prepared, ResourceManager mana rules.put(entry.getKey(), entry.getValue().getAsBoolean()); } - RuleSet ruleSet = new RuleSet(json.get("name").getAsString(), rules); + ruleSets.put(identifier, new RuleSet(json.get("name").getAsString(), rules)); LOGGER.debug("Loaded RuleSet: " + identifier); } diff --git a/src/main/resources/data/landscape/landscape/rulesets/player_walks_on_fluid.json b/src/main/resources/data/landscape/landscape/rulesets/player_walks_on_fluid.json deleted file mode 100644 index b0d518b..0000000 --- a/src/main/resources/data/landscape/landscape/rulesets/player_walks_on_fluid.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "built-in player_walks_on_fluid", - "rules": { - "core.player.walks_on_fluid": true - } -} \ No newline at end of file