i forget what this code is doing

This commit is contained in:
petrak@ 2023-06-05 21:54:24 -05:00
parent 3c73a7da98
commit 8b2995d2c4
2 changed files with 22 additions and 10 deletions

View file

@ -8,10 +8,10 @@ entityReachVersion=2.3.0
emiVersion=0.4.0+1.19
gravityApiVersion=0.7.12+fabric
clothConfigVersion=8.2.88
trinketsVersion=3.4.0
modmenuVersion=4.1.1
clothConfigVersion=8.2.88
modmenuVersion=4.1.2
# Optimizations
sodiumVersion=mc1.19.2-0.4.4

View file

@ -4,6 +4,7 @@ import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.api.mod.HexConfig;
import at.petrak.hexcasting.common.loot.HexLootHandler;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import com.google.gson.GsonBuilder;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import me.shedaniel.autoconfig.AutoConfig;
@ -38,7 +39,12 @@ public class FabricHexConfig extends PartitioningSerializer.GlobalData {
public final Server server = new Server();
public static FabricHexConfig setup() {
AutoConfig.register(FabricHexConfig.class, PartitioningSerializer.wrap(GsonConfigSerializer::new));
var gson = new GsonBuilder()
.setPrettyPrinting()
.registerTypeAdapter(ResourceLocation.class, new ResourceLocation.Serializer())
.create();
AutoConfig.register(FabricHexConfig.class, PartitioningSerializer.wrap((cfg, clazz) ->
new GsonConfigSerializer<>(cfg, clazz, gson)));
var instance = AutoConfig.getConfigHolder(FabricHexConfig.class).getConfig();
HexConfig.setCommon(instance.common);
@ -172,10 +178,11 @@ public class FabricHexConfig extends PartitioningSerializer.GlobalData {
@ConfigEntry.Gui.Tooltip
private List<String> tpDimDenylist = DEFAULT_DIM_TP_DENYLIST;
// ModMenu bad and doesn't like java objects in here so we do stupid string parsing
@ConfigEntry.Gui.Tooltip
private List<ScrollInjectionMirror> scrollInjectionsRaw = HexLootHandler.DEFAULT_SCROLL_INJECTS
private List<String> scrollInjectionsRaw = HexLootHandler.DEFAULT_SCROLL_INJECTS
.stream()
.map(si -> new ScrollInjectionMirror(si.injectee(), si.countRange()))
.map(si -> si.injectee() + " " + si.countRange())
.toList();
@ConfigEntry.Gui.Excluded
private transient Object2IntMap<ResourceLocation> scrollInjections;
@ -193,8 +200,16 @@ public class FabricHexConfig extends PartitioningSerializer.GlobalData {
this.maxSpellCircleLength = Math.max(this.maxSpellCircleLength, 4);
this.scrollInjections = new Object2IntOpenHashMap<>();
for (var mirror : this.scrollInjectionsRaw) {
this.scrollInjections.put(mirror.injectee(), mirror.countRange());
try {
for (var auugh : this.scrollInjectionsRaw) {
String[] split = auugh.split(" ");
ResourceLocation loc = new ResourceLocation(split[0]);
int count = Integer.parseInt(split[1]);
this.scrollInjections.put(loc, count);
}
} catch (Exception e) {
throw new ValidationException("Bad parsing of scroll injects", e);
}
this.loreChance = Mth.clamp(this.loreChance, 0.0, 1.0);
@ -249,8 +264,5 @@ public class FabricHexConfig extends PartitioningSerializer.GlobalData {
public double getLoreChance() {
return loreChance;
}
record ScrollInjectionMirror(ResourceLocation injectee, int countRange) {
}
}
}