From 8a6def104b416c9b8f62b1be35a6040adcf5d415 Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Thu, 5 Jan 2023 12:14:11 +0100 Subject: [PATCH] feat: know all aspects from beginning --- src/main/java/dev/tilera/auracore/Config.java | 2 + .../auracore/mixins/MixinPlayerKnowledge.java | 43 +++++++++++++++++++ src/main/resources/auracore.mixins.json | 3 +- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/main/java/dev/tilera/auracore/mixins/MixinPlayerKnowledge.java diff --git a/src/main/java/dev/tilera/auracore/Config.java b/src/main/java/dev/tilera/auracore/Config.java index eb0e548..aeff259 100644 --- a/src/main/java/dev/tilera/auracore/Config.java +++ b/src/main/java/dev/tilera/auracore/Config.java @@ -11,12 +11,14 @@ public class Config { public static int nodeRarity = 23; public static int specialNodeRarity = 75; public static boolean replaceSilverwood = true; + public static boolean knowAllAspects = true; public static void load() { config.load(); nodeRarity = config.get("worldgen", "nodeRarity", nodeRarity).getInt(nodeRarity); specialNodeRarity = config.get("worldgen", "specialNodeRarity", specialNodeRarity).getInt(specialNodeRarity); replaceSilverwood = config.getBoolean("replaceSilverwood", "worldgen", replaceSilverwood, "Replace Silverwood trees with TC3 Silverwood"); + knowAllAspects = config.getBoolean("knowAllAspects", "research", knowAllAspects, "Know all Aspects from beginning"); config.save(); } diff --git a/src/main/java/dev/tilera/auracore/mixins/MixinPlayerKnowledge.java b/src/main/java/dev/tilera/auracore/mixins/MixinPlayerKnowledge.java new file mode 100644 index 0000000..a940c21 --- /dev/null +++ b/src/main/java/dev/tilera/auracore/mixins/MixinPlayerKnowledge.java @@ -0,0 +1,43 @@ +package dev.tilera.auracore.mixins; + +import java.util.Map; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import dev.tilera.auracore.Config; +import thaumcraft.api.aspects.Aspect; +import thaumcraft.api.aspects.AspectList; +import thaumcraft.common.lib.research.PlayerKnowledge; + +@Mixin(PlayerKnowledge.class) +public abstract class MixinPlayerKnowledge { + + @Shadow(remap = false) + public Map aspectsDiscovered; + + @Inject(method = "getAspectsDiscovered", at = @At("HEAD"), remap = false) + public void onGetPlayerKnowledge(String player, CallbackInfoReturnable ci) { + AspectList known = (AspectList)this.aspectsDiscovered.get(player); + if (Config.knowAllAspects && (known == null || known.size() < Aspect.aspects.size())) { + addAllAspects(player); + } + } + + public void addAllAspects(String player) { + AspectList known = (AspectList)this.aspectsDiscovered.get(player); + if (known == null) { + known = new AspectList(); + } + for (Aspect a : Aspect.aspects.values()) { + if (!known.aspects.containsKey(a)) { + known.add(a, 0); + } + } + aspectsDiscovered.put(player, known); + } + +} diff --git a/src/main/resources/auracore.mixins.json b/src/main/resources/auracore.mixins.json index 679d5a9..848fe9a 100644 --- a/src/main/resources/auracore.mixins.json +++ b/src/main/resources/auracore.mixins.json @@ -17,7 +17,8 @@ "MixinBlockTable", "MixinBlockCrystal", "MixinEventHandlerEntity", - "MixinThaumcraftWorldGenerator" + "MixinThaumcraftWorldGenerator", + "MixinPlayerKnowledge" ], "client": [ "MixinBlockCustomOreRenderer",