diff --git a/dependencies.gradle b/dependencies.gradle index e9543e5220..7aa2f3f71b 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -53,9 +53,6 @@ dependencies { modImplementation(forge.ae2) { transitive = false } modCompileOnly("curse.maven:ae2wtlib-459929:5217955") - //AlmostUnified - modCompileOnly(forge.almostUnified.forge) - // KJS modImplementation forge.kubejs @@ -76,6 +73,5 @@ dependencies { modImplementation(forge.javd) { transitive = false } modRuntimeOnly("curse.maven:trenzalore-870210:4848244") - // Runtime only testing mods - //modRuntimeOnly(forge.worldStripper) -} \ No newline at end of file + modImplementation(forge.jsonThings) +} diff --git a/gradle/scripts/repositories.gradle b/gradle/scripts/repositories.gradle index f893dabab4..3e0b07f98c 100644 --- a/gradle/scripts/repositories.gradle +++ b/gradle/scripts/repositories.gradle @@ -15,14 +15,13 @@ repositories { url = "https://maven.blamejared.com/" } // JEI maven { - // location of a maven mirror for JEI files, as a fallback name = "ModMaven" url = "https://modmaven.dev" } // JEI mirror, AE2 maven { url = "https://maven.parchmentmc.org" } // Parchment mappings maven { url = "https://maven.quiltmc.org/repository/release" } // Quilt Mappings maven { url = "https://maven.firstdarkdev.xyz/snapshots" } // LDLib - maven { // Flywheel + maven { url = "https://maven.tterrag.com/" content { // need to be specific here due to version overlaps @@ -30,18 +29,18 @@ repositories { includeGroup("com.tterrag.registrate") includeGroup("com.simibubi.create") } - } + } // Flywheel maven { url = "https://maven.theillusivec4.top/" } // Curios - maven { // TOP + maven { url "https://maven.k-4u.nl" - } + } // TOP maven { - // saps.dev Maven (KubeJS and Rhino) url = "https://maven.saps.dev/minecraft" content { includeGroup "dev.latvian.mods" } - } + } // saps.dev Maven (KubeJS and Rhino) maven { url = "https://maven.jamieswhiteshirt.com/libs-release" } // Reach Entity Attributes - maven { url 'https://jitpack.io' } // Mixin Extras, Fabric ASM + maven { url = 'https://jitpack.io' } // Mixin Extras, Fabric ASM + maven { url = 'https://www.dogforce-games.com/maven/' } } \ No newline at end of file diff --git a/gradle/scripts/resources.gradle b/gradle/scripts/resources.gradle index 06440b50dc..5f56a61af1 100644 --- a/gradle/scripts/resources.gradle +++ b/gradle/scripts/resources.gradle @@ -23,6 +23,7 @@ processResources { "emi_version": forge.versions.emi.get(), "top_version": forge.versions.theoneprobe.get(), "jade_version": forge.versions.jade.get(), + "jsonthings_version": forge.versions.jsonThings.get(), "mod_license": mod_license, "mod_name": mod_name, "mod_description": mod_description, diff --git a/settings.gradle b/settings.gradle index 4c22ad5ab0..06b705a323 100644 --- a/settings.gradle +++ b/settings.gradle @@ -23,7 +23,6 @@ dependencyResolutionManagement { def emiVersion = "1.1.11" def ae2Version = "15.0.18" def kjsVersion = "2001.6.4-build.120" - def auVersion = "1.20.1-0.6.0" // Forge def forgeVersion = "47.1.3" @@ -32,7 +31,7 @@ dependencyResolutionManagement { def flywheelForgeVersion = "0.6.10-10" def topForgeVersion = "1.20.1-10.0.1-3" def jadeForgeVersion = "11.6.3" - def worldStripperForgeFile = "4578579" + def jsonThingsVersion = "0.9.1" def javdVersion = "4803995" // Libs @@ -96,16 +95,13 @@ dependencyResolutionManagement { library("mixinextras-forge", "io.github.llamalad7", "mixinextras-forge").versionRef(mixinextras) def configuration = version("configuration", configurationVersion) - library("configuration", "dev.toma.configuration", "configuration-forge-1.20.1").versionRef(configuration) - - def worldStripper = version("worldStripper", worldStripperForgeFile) - library("worldStripper", "curse.maven", "worldStripper-250603").versionRef(worldStripper) + library("configuration", "dev.toma.configuration", "configuration-forge-${minecraftVersion}").versionRef(configuration) def ae2 = version("ae2", ae2Version) library("ae2", "appeng", "appliedenergistics2-forge").versionRef(ae2) - def au = version("au", auVersion) - library("almostUnified-forge", "com.almostreliable.mods", "almostunified-forge").versionRef(au) + def jsonThings = version("jsonThings", jsonThingsVersion) + library("jsonThings", "dev.gigaherz.jsonthings", "JsonThings-${minecraftVersion}").versionRef(jsonThings) def javd = version("javd", javdVersion) library("javd", "curse.maven", "javd-370890").versionRef(javd) diff --git a/src/main/java/com/gregtechceu/gtceu/api/GTValues.java b/src/main/java/com/gregtechceu/gtceu/api/GTValues.java index a578c17d0d..f03ef2c3ce 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/GTValues.java +++ b/src/main/java/com/gregtechceu/gtceu/api/GTValues.java @@ -110,7 +110,7 @@ public static int[] tiersBetween(int minInclusive, int maxInclusive) { MODID_RUBIDIUM = "rubidium", MODID_EMBEDDIUM = "embeddium", MODID_CREATE = "create", - MODID_REBORN_ENERGY = "team_reborn_energy", + MODID_JSONTHINGS = "jsonthings", MODID_ALMOSTUNIFIED = "almostunified", MODID_CURIOS = "curios", MODID_AE2WTLIB = "ae2wtlib", diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/Material.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/Material.java index 297763b219..1c7bebd37f 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/Material.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/Material.java @@ -32,6 +32,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import com.mojang.serialization.Codec; import dev.latvian.mods.rhino.util.HideFromJS; import dev.latvian.mods.rhino.util.RemapPrefixForJS; import it.unimi.dsi.fastutil.ints.IntArrayList; @@ -48,6 +49,10 @@ public class Material implements Comparable { + public static final Codec CODEC = ResourceLocation.CODEC.xmap( + rl -> GTCEuAPI.materialManager.getRegistry(rl.getNamespace()).get(rl.getPath()), + Material::getResourceLocation); + /** * Basic Info of this Material. * @@ -527,8 +532,11 @@ public void verifyMaterial() { @RemapPrefixForJS("kjs$") public static class Builder extends BuilderBase { + @Getter private final MaterialInfo materialInfo; + @Getter private final MaterialProperties properties; + @Getter private final MaterialFlags flags; /* @@ -1245,7 +1253,7 @@ public Material register() { * Holds the basic info for a Material, like the name, color, id, etc.. */ @Accessors(chain = true) - private static class MaterialInfo { + public static class MaterialInfo { /** * The modid and unlocalized name of this Material. diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/AlloyBlastProperty.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/AlloyBlastProperty.java index d52d9b7259..52b8f5fd5e 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/AlloyBlastProperty.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/AlloyBlastProperty.java @@ -2,21 +2,35 @@ import com.gregtechceu.gtceu.data.recipe.misc.alloyblast.AlloyBlastRecipeProducer; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.util.ExtraCodecs; import net.minecraft.world.level.material.Fluid; import com.google.common.base.Preconditions; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import org.jetbrains.annotations.NotNull; import java.util.function.Supplier; +@NoArgsConstructor public class AlloyBlastProperty implements IMaterialProperty { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + BuiltInRegistries.FLUID.byNameCodec().optionalFieldOf("fluid", null) + .xmap(fluid1 -> (Supplier) () -> fluid1, Supplier::get) + .forGetter(val -> (Supplier) val.fluidSupplier), + ExtraCodecs.POSITIVE_INT.optionalFieldOf("temperature", -1).forGetter(val -> val.temperature)) + .apply(instance, AlloyBlastProperty::new)); + /** * Internal material fluid field */ private Supplier fluidSupplier; + @Getter private int temperature; @Getter @@ -28,6 +42,11 @@ public AlloyBlastProperty(int temperature) { this.temperature = temperature; } + public AlloyBlastProperty(Supplier fluidSupplier, int temperature) { + this.fluidSupplier = fluidSupplier; + this.temperature = temperature; + } + @Override public void verifyProperty(MaterialProperties materialProperties) { materialProperties.ensureSet(PropertyKey.BLAST); @@ -51,8 +70,4 @@ public void setTemperature(int fluidTemperature) { Preconditions.checkArgument(fluidTemperature > 0, "Invalid temperature"); this.temperature = fluidTemperature; } - - public int getTemperature() { - return temperature; - } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/BlastProperty.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/BlastProperty.java index 0bfefaa5f0..2d4d08c845 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/BlastProperty.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/BlastProperty.java @@ -1,9 +1,27 @@ package com.gregtechceu.gtceu.api.data.chemical.material.properties; -import org.jetbrains.annotations.NotNull; +import net.minecraft.util.ExtraCodecs; +import net.minecraft.util.StringRepresentable; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +import java.util.Locale; + +@AllArgsConstructor public class BlastProperty implements IMaterialProperty { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + ExtraCodecs.POSITIVE_INT.fieldOf("blast_temperature").forGetter(val -> val.blastTemperature), + GasTier.CODEC.fieldOf("gas_tier").forGetter(val -> val.gasTier), + ExtraCodecs.NON_NEGATIVE_INT.optionalFieldOf("duration_override", -1) + .forGetter(val -> val.durationOverride), + ExtraCodecs.NON_NEGATIVE_INT.optionalFieldOf("eut_override", -1).forGetter(val -> val.EUtOverride)) + .apply(instance, BlastProperty::new)); + /** * Blast Furnace Temperature of this Material. * If below 1000K, Primitive Blast Furnace recipes will be also added. @@ -12,6 +30,7 @@ public class BlastProperty implements IMaterialProperty { * If a Material with this Property has a Fluid, its temperature * will be set to this if it is the default Fluid temperature. */ + @Getter private int blastTemperature; /** @@ -19,6 +38,8 @@ public class BlastProperty implements IMaterialProperty { *

* Default: null, meaning no Gas EBF recipes. */ + @Getter + @Setter private GasTier gasTier = null; /** @@ -26,6 +47,8 @@ public class BlastProperty implements IMaterialProperty { *

* Default: -1, meaning the duration will be: material.getAverageMass() * blastTemperature / 50 */ + @Getter + @Setter private int durationOverride = -1; /** @@ -33,19 +56,14 @@ public class BlastProperty implements IMaterialProperty { *

* Default: -1, meaning the EU/t will be 120. */ - private int eutOverride = -1; + @Getter + @Setter + private int EUtOverride = -1; public BlastProperty(int blastTemperature) { this.blastTemperature = blastTemperature; } - public BlastProperty(int blastTemperature, GasTier gasTier, int eutOverride, int durationOverride) { - this.blastTemperature = blastTemperature; - this.gasTier = gasTier; - this.eutOverride = eutOverride; - this.durationOverride = durationOverride; - } - /** * Default property constructor. */ @@ -53,59 +71,17 @@ public BlastProperty() { this(0); } - public int getBlastTemperature() { - return blastTemperature; - } - public void setBlastTemperature(int blastTemp) { if (blastTemp <= 0) throw new IllegalArgumentException("Blast Temperature must be greater than zero!"); this.blastTemperature = blastTemp; } - public GasTier getGasTier() { - return gasTier; - } - - public void setGasTier(@NotNull GasTier tier) { - this.gasTier = tier; - } - - public int getDurationOverride() { - return durationOverride; - } - - public void setDurationOverride(int duration) { - this.durationOverride = duration; - } - - public int getEUtOverride() { - return eutOverride; - } - - public void setEutOverride(int eut) { - this.eutOverride = eut; - } - @Override public void verifyProperty(MaterialProperties properties) { properties.ensureSet(PropertyKey.INGOT, true); } - public static GasTier validateGasTier(String gasTierName) { - if (gasTierName == null) return null; - else if ("LOW".equalsIgnoreCase(gasTierName)) return GasTier.LOW; - else if ("MID".equalsIgnoreCase(gasTierName)) return GasTier.MID; - else if ("HIGH".equalsIgnoreCase(gasTierName)) return GasTier.HIGH; - else if ("HIGHER".equalsIgnoreCase(gasTierName)) return GasTier.HIGHER; - else if ("HIGHEST".equalsIgnoreCase(gasTierName)) return GasTier.HIGHEST; - else { - String message = "Gas Tier must be either \"LOW\", \"MID\", \"HIGH\", \"HIGHER\", or \"HIGHEST\""; - throw new IllegalArgumentException( - "Could not find valid gas tier for name: " + gasTierName + ". " + message); - } - } - - public enum GasTier { + public enum GasTier implements StringRepresentable { // Tiers used by GTCEu LOW, @@ -117,5 +93,11 @@ public enum GasTier { HIGHEST; public static final GasTier[] VALUES = values(); + public static final Codec CODEC = StringRepresentable.fromEnum(GasTier::values); + + @Override + public String getSerializedName() { + return name().toUpperCase(Locale.ROOT); + } } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/DustProperty.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/DustProperty.java index e216d13d3a..fae7e2ea9b 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/DustProperty.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/DustProperty.java @@ -1,9 +1,18 @@ package com.gregtechceu.gtceu.api.data.chemical.material.properties; +import net.minecraft.util.ExtraCodecs; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import lombok.Getter; public class DustProperty implements IMaterialProperty { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + ExtraCodecs.POSITIVE_INT.optionalFieldOf("harvest_level", 2).forGetter(val -> val.harvestLevel), + ExtraCodecs.NON_NEGATIVE_INT.optionalFieldOf("burn_time", 0).forGetter(val -> val.burnTime)) + .apply(instance, DustProperty::new)); + /** * Tool level needed to harvest block of this Material. *

diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidPipeProperties.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidPipeProperties.java index f7c5c6c5b1..cd28f99661 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidPipeProperties.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidPipeProperties.java @@ -7,22 +7,38 @@ import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import it.unimi.dsi.fastutil.objects.Object2BooleanMap; import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.UnmodifiableView; import java.util.Collection; +import java.util.Map; import java.util.Objects; +@NoArgsConstructor public class FluidPipeProperties implements IMaterialProperty, IPropertyFluidFilter { /** * The maximum number of channels any fluid pipe can have */ public static final int MAX_PIPE_CHANNELS = 9; + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.INT.fieldOf("max_temperature").forGetter(val -> val.maxFluidTemperature), + Codec.LONG.fieldOf("throughput").forGetter(val -> val.throughput), + Codec.BOOL.optionalFieldOf("gas_proof", true).forGetter(val -> val.gasProof), + Codec.BOOL.optionalFieldOf("cryo_proof", false).forGetter(val -> val.cryoProof), + Codec.BOOL.optionalFieldOf("plasma_proof", false).forGetter(val -> val.plasmaProof), + Codec.simpleMap(FluidAttribute.CODEC, Codec.BOOL, FluidAttribute.CODEC_KEYS) + .codec() + .optionalFieldOf("can_contain", Map.of()) + .forGetter(val -> val.containmentPredicate)) + .apply(instance, FluidPipeProperties::new)); @Getter @Setter @@ -45,6 +61,17 @@ public class FluidPipeProperties implements IMaterialProperty containmentPredicate = new Object2BooleanOpenHashMap<>(); + public FluidPipeProperties(int maxFluidTemperature, long throughput, boolean gasProof, boolean cryoProof, + boolean plasmaProof, Map canContain) { + this.maxFluidTemperature = maxFluidTemperature; + this.throughput = throughput; + this.gasProof = gasProof; + this.cryoProof = cryoProof; + this.plasmaProof = plasmaProof; + this.channels = 1; + this.containmentPredicate.putAll(canContain); + } + public FluidPipeProperties(int maxFluidTemperature, long throughput, boolean gasProof, boolean acidProof, boolean cryoProof, boolean plasmaProof, int channels) { this.maxFluidTemperature = maxFluidTemperature; diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidProperty.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidProperty.java index cd06185ceb..6ef23be208 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidProperty.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/FluidProperty.java @@ -9,8 +9,9 @@ import net.minecraft.world.level.material.Fluid; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import lombok.Getter; -import lombok.NoArgsConstructor; import lombok.Setter; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -18,15 +19,29 @@ import java.util.function.Supplier; -@NoArgsConstructor public class FluidProperty implements IMaterialProperty, FluidStorage { - private final FluidStorageImpl storage = new FluidStorageImpl(); + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + FluidStorageImpl.CODEC.fieldOf("storage").forGetter(val -> val.storage), + FluidStorageKey.CODEC.optionalFieldOf("primary_key", null).forGetter(val -> val.primaryKey)) + .apply(instance, FluidProperty::new)); + + private final FluidStorageImpl storage; @Getter @Setter private FluidStorageKey primaryKey = null; + private FluidProperty(@NotNull FluidStorageImpl storage, @Nullable FluidStorageKey primaryKey) { + this.storage = storage; + this.primaryKey = primaryKey; + } + + public FluidProperty() { + this.storage = new FluidStorageImpl(); + } + public FluidProperty(@NotNull FluidStorageKey key, @NotNull FluidBuilder builder) { + this(); enqueueRegistration(key, builder); } diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/HazardProperty.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/HazardProperty.java index 110becd3e9..81553eb0d2 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/HazardProperty.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/HazardProperty.java @@ -8,15 +8,19 @@ import com.gregtechceu.gtceu.api.item.GTBucketItem; import com.gregtechceu.gtceu.api.item.TagPrefixItem; import com.gregtechceu.gtceu.api.item.armor.ArmorComponentItem; +import com.gregtechceu.gtceu.common.data.GTMedicalConditions; import com.gregtechceu.gtceu.config.ConfigHolder; import com.gregtechceu.gtceu.data.recipe.CustomTags; +import net.minecraft.util.ExtraCodecs; import net.minecraft.util.StringRepresentable; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.BucketItem; import net.minecraft.world.item.ItemStack; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import lombok.Getter; import org.jetbrains.annotations.Nullable; @@ -29,10 +33,18 @@ */ public class HazardProperty implements IMaterialProperty { - public final MedicalCondition condition; - public final HazardTrigger hazardTrigger; - public final boolean applyToDerivatives; - public final float progressionMultiplier; + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + HazardTrigger.CODEC.fieldOf("trigger").forGetter(val -> val.hazardTrigger), + MedicalCondition.CODEC.fieldOf("condition").forGetter(val -> val.condition), + ExtraCodecs.POSITIVE_FLOAT.fieldOf("progression_multiplier") + .forGetter(val -> val.progressionMultiplier), + Codec.BOOL.fieldOf("apply_to_derivatives").forGetter(val -> val.applyToDerivatives)) + .apply(instance, HazardProperty::new)); + + public MedicalCondition condition; + public HazardTrigger hazardTrigger; + public boolean applyToDerivatives; + public float progressionMultiplier; public HazardProperty(HazardTrigger hazardTrigger, MedicalCondition condition, float progressionMultiplier, boolean applyToDerivatives) { @@ -42,6 +54,10 @@ public HazardProperty(HazardTrigger hazardTrigger, MedicalCondition condition, f this.progressionMultiplier = progressionMultiplier; } + public HazardProperty() { + this(HazardTrigger.NONE, GTMedicalConditions.NONE, 0.0f, false); + } + @Override public void verifyProperty(MaterialProperties properties) {} @@ -49,6 +65,7 @@ public record HazardTrigger(String name, ProtectionType protectionType, Set ALL_TRIGGERS = new HashMap<>(); + public static final Codec CODEC = Codec.STRING.xmap(ALL_TRIGGERS::get, HazardTrigger::name); public static final HazardTrigger INHALATION = new HazardTrigger("inhalation", ProtectionType.MASK, TagPrefix.dust, TagPrefix.dustSmall, TagPrefix.dustTiny, TagPrefix.dustPure, TagPrefix.dustImpure); diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/IngotProperty.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/IngotProperty.java index d7d1be9b70..09bd8b01a0 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/IngotProperty.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/IngotProperty.java @@ -2,12 +2,22 @@ import com.gregtechceu.gtceu.api.data.chemical.material.Material; -import lombok.Getter; -import lombok.Setter; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import lombok.*; import org.jetbrains.annotations.Nullable; +@NoArgsConstructor +@AllArgsConstructor public class IngotProperty implements IMaterialProperty { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Material.CODEC.optionalFieldOf("smelt_into", null).forGetter(val -> val.smeltingInto), + Material.CODEC.optionalFieldOf("arc_smelt_into", null).forGetter(val -> val.arcSmeltingInto), + Material.CODEC.optionalFieldOf("macerate_into", null).forGetter(val -> val.macerateInto), + Material.CODEC.optionalFieldOf("magnetic_material", null).forGetter(val -> val.magneticMaterial)) + .apply(instance, IngotProperty::new)); + /** * Specifies a material into which this material parts turn when heated */ diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/ItemPipeProperties.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/ItemPipeProperties.java index 283e7660da..a1525d88d1 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/ItemPipeProperties.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/ItemPipeProperties.java @@ -1,9 +1,19 @@ package com.gregtechceu.gtceu.api.data.chemical.material.properties; +import net.minecraft.util.ExtraCodecs; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + import java.util.Objects; public class ItemPipeProperties implements IMaterialProperty { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + ExtraCodecs.POSITIVE_INT.fieldOf("priority").forGetter(val -> val.priority), + ExtraCodecs.POSITIVE_FLOAT.fieldOf("transfer_rate").forGetter(val -> val.transferRate)) + .apply(instance, ItemPipeProperties::new)); + /** * Items will try to take the path with the lowest priority */ diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/MaterialProperties.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/MaterialProperties.java index 759fe54781..e2eb1cd3b3 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/MaterialProperties.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/MaterialProperties.java @@ -5,6 +5,8 @@ import com.lowdragmc.lowdraglib.Platform; +import org.jetbrains.annotations.ApiStatus; + import java.util.*; public class MaterialProperties { @@ -45,6 +47,16 @@ public > void setProperty(PropertyKey key, IMa propertyMap.remove(PropertyKey.EMPTY); } + // Skips generic checks. don't use. + @ApiStatus.Internal + public void setPropertyNoGeneric(PropertyKey key, IMaterialProperty value) { + if (value == null) throw new IllegalArgumentException("Material Property must not be null!"); + if (hasProperty(key)) + throw new IllegalArgumentException("Material Property " + key.toString() + " already registered!"); + propertyMap.put(key, value); + propertyMap.remove(PropertyKey.EMPTY); + } + public > void removeProperty(PropertyKey property) { if (!hasProperty(property)) throw new IllegalArgumentException("Material Property " + property.toString() + " not present!"); diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/OreProperty.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/OreProperty.java index 1f6c014511..43311e4064 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/OreProperty.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/OreProperty.java @@ -2,9 +2,13 @@ import com.gregtechceu.gtceu.api.data.chemical.material.Material; +import net.minecraft.util.ExtraCodecs; import net.minecraft.util.Mth; import com.mojang.datafixers.util.Pair; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; import org.jetbrains.annotations.NotNull; @@ -14,15 +18,28 @@ import java.util.Arrays; import java.util.List; +@AllArgsConstructor public class OreProperty implements IMaterialProperty { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Material.CODEC.listOf().optionalFieldOf("byproducts", List.of()).forGetter(val -> val.oreByProducts), + ExtraCodecs.POSITIVE_INT.optionalFieldOf("ore_multiplier", 1).forGetter(val -> val.oreMultiplier), + ExtraCodecs.POSITIVE_INT.optionalFieldOf("byproduct_multiplier", 1) + .forGetter(val -> val.byProductMultiplier), + Codec.BOOL.optionalFieldOf("emissive", false).forGetter(val -> val.emissive), + Material.CODEC.optionalFieldOf("direct_smelt_result", null).forGetter(val -> val.directSmeltResult), + Material.CODEC.optionalFieldOf("washed_in", null).forGetter(val -> val.washedIn), + ExtraCodecs.POSITIVE_INT.optionalFieldOf("washed_amount", 100).forGetter(val -> val.washedAmount), + Material.CODEC.listOf().optionalFieldOf("separated_into", List.of()).forGetter(val -> val.separatedInto)) + .apply(instance, OreProperty::new)); + /** * List of Ore byproducts. *

* Default: none, meaning only this property's Material. */ @Getter - private final List oreByProducts = new ArrayList<>(); + private List oreByProducts; /** * Crushed Ore output amount multiplier during Maceration. @@ -89,18 +106,18 @@ public class OreProperty implements IMaterialProperty { * Default: none. */ @Getter - private final List separatedInto = new ArrayList<>(); + private List separatedInto; public OreProperty(int oreMultiplier, int byProductMultiplier) { - this.oreMultiplier = oreMultiplier; - this.byProductMultiplier = byProductMultiplier; - this.emissive = false; + this(oreMultiplier, byProductMultiplier, false); } public OreProperty(int oreMultiplier, int byProductMultiplier, boolean emissive) { + this.oreByProducts = new ArrayList<>(); this.oreMultiplier = oreMultiplier; this.byProductMultiplier = byProductMultiplier; this.emissive = emissive; + this.separatedInto = new ArrayList<>(); } /** diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/PropertyKey.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/PropertyKey.java index 90fb77da86..08c53ee08a 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/PropertyKey.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/PropertyKey.java @@ -1,48 +1,69 @@ package com.gregtechceu.gtceu.api.data.chemical.material.properties; +import com.mojang.serialization.Codec; +import lombok.Getter; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Supplier; + public class PropertyKey> { - public static final PropertyKey BLAST = new PropertyKey<>("blast", BlastProperty.class); + private static final Map> KEYS = new HashMap<>(); + + public static final PropertyKey BLAST = new PropertyKey<>("blast", BlastProperty.class, + BlastProperty::new, BlastProperty.CODEC); public static final PropertyKey ALLOY_BLAST = new PropertyKey<>("blast_alloy", - AlloyBlastProperty.class); - public static final PropertyKey DUST = new PropertyKey<>("dust", DustProperty.class); + AlloyBlastProperty.class, AlloyBlastProperty::new, AlloyBlastProperty.CODEC); + public static final PropertyKey DUST = new PropertyKey<>("dust", DustProperty.class, + DustProperty::new, DustProperty.CODEC); public static final PropertyKey FLUID_PIPE = new PropertyKey<>("fluid_pipe", - FluidPipeProperties.class); - public static final PropertyKey FLUID = new PropertyKey<>("fluid", FluidProperty.class); - public static final PropertyKey GEM = new PropertyKey<>("gem", GemProperty.class); - public static final PropertyKey INGOT = new PropertyKey<>("ingot", IngotProperty.class); - public static final PropertyKey POLYMER = new PropertyKey<>("polymer", PolymerProperty.class); + FluidPipeProperties.class, FluidPipeProperties::new, FluidPipeProperties.CODEC); + public static final PropertyKey FLUID = new PropertyKey<>("fluid", FluidProperty.class, + FluidProperty::new, FluidProperty.CODEC); + public static final PropertyKey GEM = new PropertyKey<>("gem", GemProperty.class, GemProperty::new, + Codec.unit(GemProperty::new)); + public static final PropertyKey INGOT = new PropertyKey<>("ingot", IngotProperty.class, + IngotProperty::new, IngotProperty.CODEC); + public static final PropertyKey POLYMER = new PropertyKey<>("polymer", PolymerProperty.class, + PolymerProperty::new, Codec.unit(PolymerProperty::new)); public static final PropertyKey ITEM_PIPE = new PropertyKey<>("item_pipe", - ItemPipeProperties.class); - public static final PropertyKey ORE = new PropertyKey<>("ore", OreProperty.class); - public static final PropertyKey TOOL = new PropertyKey<>("tool", ToolProperty.class); - public static final PropertyKey ROTOR = new PropertyKey<>("rotor", RotorProperty.class); - public static final PropertyKey WIRE = new PropertyKey<>("wire", WireProperties.class); - public static final PropertyKey WOOD = new PropertyKey<>("wood", WoodProperty.class); + ItemPipeProperties.class, ItemPipeProperties::new, ItemPipeProperties.CODEC); + public static final PropertyKey ORE = new PropertyKey<>("ore", OreProperty.class, OreProperty::new, + OreProperty.CODEC); + public static final PropertyKey TOOL = new PropertyKey<>("tool", ToolProperty.class, + ToolProperty::new, ToolProperty.CODEC); + public static final PropertyKey ROTOR = new PropertyKey<>("rotor", RotorProperty.class, + RotorProperty::new, RotorProperty.CODEC); + public static final PropertyKey WIRE = new PropertyKey<>("wire", WireProperties.class, + WireProperties::new, WireProperties.CODEC); + public static final PropertyKey WOOD = new PropertyKey<>("wood", WoodProperty.class, + WoodProperty::new, Codec.unit(WoodProperty::new)); - public static final PropertyKey HAZARD = new PropertyKey<>("hazard", HazardProperty.class); + public static final PropertyKey HAZARD = new PropertyKey<>("hazard", HazardProperty.class, + HazardProperty::new, HazardProperty.CODEC); // Empty property used to allow property-less Materials without removing base type enforcement - public static final PropertyKey EMPTY = new PropertyKey<>("empty", EmptyProperty.class); + public static final PropertyKey EMPTY = new PropertyKey<>("empty", EmptyProperty.class, + EmptyProperty::new, Codec.unit(EmptyProperty::new)); + @Getter private final String key; private final Class type; + private final Supplier defaultSupplier; + @Getter + private final Codec codec; - public PropertyKey(String key, Class type) { + public PropertyKey(String key, Class type, Supplier defaultSupplier, Codec codec) { this.key = key; this.type = type; - } - - protected String getKey() { - return key; + this.defaultSupplier = defaultSupplier; + this.codec = codec; + KEYS.put(key, this); } protected T constructDefault() { - try { - return type.newInstance(); - } catch (Exception e) { - return null; - } + return defaultSupplier.get(); } public T cast(IMaterialProperty property) { @@ -67,6 +88,10 @@ public String toString() { return key; } + public static PropertyKey getByName(String name) { + return KEYS.get(name); + } + private static class EmptyProperty implements IMaterialProperty { @Override diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/RotorProperty.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/RotorProperty.java index ae3b17ff72..dce4e2f668 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/RotorProperty.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/RotorProperty.java @@ -1,10 +1,23 @@ package com.gregtechceu.gtceu.api.data.chemical.material.properties; +import net.minecraft.util.ExtraCodecs; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import lombok.Getter; +import lombok.NoArgsConstructor; import org.jetbrains.annotations.NotNull; +@NoArgsConstructor public class RotorProperty implements IMaterialProperty { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + ExtraCodecs.POSITIVE_INT.fieldOf("power").forGetter(val -> val.power), + ExtraCodecs.POSITIVE_INT.fieldOf("durability").forGetter(val -> val.durability), + ExtraCodecs.POSITIVE_FLOAT.fieldOf("damage").forGetter(val -> val.damage), + ExtraCodecs.POSITIVE_INT.fieldOf("efficiency").forGetter(val -> val.efficiency)) + .apply(instance, RotorProperty::new)); + /** * Power of rotors made from this Material. *

diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/ToolProperty.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/ToolProperty.java index 8a1ef2ec06..185b64e526 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/ToolProperty.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/ToolProperty.java @@ -5,8 +5,11 @@ import com.gregtechceu.gtceu.api.item.tool.MaterialToolTier; import com.gregtechceu.gtceu.config.ConfigHolder; +import net.minecraft.util.ExtraCodecs; import net.minecraft.world.item.enchantment.Enchantment; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; import it.unimi.dsi.fastutil.objects.Object2IntMap; import lombok.Getter; @@ -14,11 +17,28 @@ import org.apache.commons.lang3.ArrayUtils; import java.util.Arrays; +import java.util.List; import static com.gregtechceu.gtceu.api.item.tool.GTToolType.*; public class ToolProperty implements IMaterialProperty { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + ExtraCodecs.POSITIVE_FLOAT.fieldOf("harvest_speed").forGetter(val -> val.harvestSpeed), + ExtraCodecs.POSITIVE_FLOAT.fieldOf("attack_damage").forGetter(val -> val.attackDamage), + ExtraCodecs.POSITIVE_FLOAT.fieldOf("attack_speed").forGetter(val -> val.attackSpeed), + ExtraCodecs.POSITIVE_INT.fieldOf("durability").forGetter(val -> val.durability), + ExtraCodecs.POSITIVE_INT.fieldOf("harvest_level").forGetter(val -> val.harvestLevel), + ExtraCodecs.POSITIVE_INT.optionalFieldOf("enchantability", 10).forGetter(val -> val.harvestLevel), + Codec.BOOL.optionalFieldOf("ignore_crafting_tools", false).forGetter(val -> val.ignoreCraftingTools), + Codec.BOOL.optionalFieldOf("unbreakable", false).forGetter(val -> val.isUnbreakable), + Codec.BOOL.optionalFieldOf("magnetic", false).forGetter(val -> val.isMagnetic), + ExtraCodecs.POSITIVE_INT.optionalFieldOf("durability_multiplier", 1) + .forGetter(val -> val.durabilityMultiplier), + Codec.STRING.xmap(string -> GTToolType.getTypes().get(string), type -> type.name).listOf() + .fieldOf("tool_types").forGetter(val -> List.of(val.types))) + .apply(instance, ToolProperty::new)); + /** * Harvest speed of tools made from this Material. *

@@ -125,6 +145,22 @@ public ToolProperty(float harvestSpeed, float attackDamage, int durability, int this.types = types; } + public ToolProperty(float harvestSpeed, float attackSpeed, float attackDamage, int durability, int harvestLevel, + int enchantability, boolean ignoreCraftingTools, boolean unbreakable, boolean magnetic, + int durabilityMultiplier, List types) { + this.harvestSpeed = harvestSpeed; + this.attackSpeed = attackSpeed; + this.attackDamage = attackDamage; + this.durability = durability; + this.harvestLevel = harvestLevel; + this.enchantability = enchantability; + this.ignoreCraftingTools = ignoreCraftingTools; + this.isUnbreakable = unbreakable; + this.isMagnetic = magnetic; + this.durabilityMultiplier = durabilityMultiplier; + this.types = types.toArray(GTToolType[]::new); + } + public ToolProperty() { this(1.0F, 1.0F, 100, 2, GTToolType.getTypes().values().toArray(GTToolType[]::new)); } diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/WireProperties.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/WireProperties.java index 81acb549bf..0a56a30c34 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/WireProperties.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/properties/WireProperties.java @@ -3,12 +3,26 @@ import com.gregtechceu.gtceu.api.GTValues; import com.gregtechceu.gtceu.api.data.chemical.material.Material; +import net.minecraft.util.ExtraCodecs; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + import java.util.Objects; import static com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialFlags.GENERATE_FOIL; public class WireProperties implements IMaterialProperty { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + ExtraCodecs.POSITIVE_INT.fieldOf("voltage").forGetter(val -> val.voltage), + ExtraCodecs.POSITIVE_INT.fieldOf("amperage").forGetter(val -> val.amperage), + ExtraCodecs.NON_NEGATIVE_INT.fieldOf("loss_per_block").forGetter(val -> val.lossPerBlock), + Codec.BOOL.optionalFieldOf("is_superconductor", false).forGetter(val -> val.isSuperconductor), + ExtraCodecs.NON_NEGATIVE_INT.optionalFieldOf("superconductor_critical_temperature", 0) + .forGetter(val -> val.superconductorCriticalTemperature)) + .apply(instance, WireProperties::new)); + private int voltage; private int amperage; private int lossPerBlock; diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/medicalcondition/MedicalCondition.java b/src/main/java/com/gregtechceu/gtceu/api/data/medicalcondition/MedicalCondition.java index e4e2d34289..91d29f964c 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/medicalcondition/MedicalCondition.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/medicalcondition/MedicalCondition.java @@ -10,6 +10,7 @@ import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.level.Level; +import com.mojang.serialization.Codec; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; @@ -22,6 +23,7 @@ public class MedicalCondition { public static final Map CONDITIONS = new HashMap<>(); + public static final Codec CODEC = Codec.STRING.xmap(CONDITIONS::get, condition -> condition.name); public final String name; public final int color; diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/tag/TagPrefix.java b/src/main/java/com/gregtechceu/gtceu/api/data/tag/TagPrefix.java index 2fc8c96f74..422a78be47 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/tag/TagPrefix.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/tag/TagPrefix.java @@ -17,6 +17,7 @@ import com.gregtechceu.gtceu.common.data.GTItems; import com.gregtechceu.gtceu.common.data.GTMaterials; import com.gregtechceu.gtceu.config.ConfigHolder; +import com.gregtechceu.gtceu.data.recipe.CustomTags; import com.gregtechceu.gtceu.integration.GTOreByProduct; import com.gregtechceu.gtceu.integration.kjs.GTRegistryInfo; import com.gregtechceu.gtceu.utils.FormattingUtil; @@ -721,7 +722,7 @@ public static TagPrefix get(String name) { .langValue("%s Frame") .materialAmount(GTValues.M * 2) .materialIconType(MaterialIconType.frameGt) - .miningToolTag(GTToolType.WRENCH.harvestTags.get(0)) + .miningToolTag(CustomTags.MINEABLE_WITH_WRENCH) .unificationEnabled(true) .generateBlock(true) .blockProperties(() -> RenderType::translucent, p -> p.noOcclusion()) @@ -731,98 +732,98 @@ public static TagPrefix get(String name) { // Pipes public static final TagPrefix pipeTinyFluid = new TagPrefix("pipeTinyFluid") .itemTable(() -> GTBlocks.FLUID_PIPE_BLOCKS).langValue("Tiny %s Fluid Pipe") - .miningToolTag(GTToolType.WRENCH.harvestTags.get(0)).materialAmount(GTValues.M / 2) + .miningToolTag(CustomTags.MINEABLE_WITH_WRENCH).materialAmount(GTValues.M / 2) .unificationEnabled(true); public static final TagPrefix pipeSmallFluid = new TagPrefix("pipeSmallFluid") .itemTable(() -> GTBlocks.FLUID_PIPE_BLOCKS).langValue("Small %s Fluid Pipe") - .miningToolTag(GTToolType.WRENCH.harvestTags.get(0)).materialAmount(GTValues.M).unificationEnabled(true); + .miningToolTag(CustomTags.MINEABLE_WITH_WRENCH).materialAmount(GTValues.M).unificationEnabled(true); public static final TagPrefix pipeNormalFluid = new TagPrefix("pipeNormalFluid") .itemTable(() -> GTBlocks.FLUID_PIPE_BLOCKS).langValue("Normal %s Fluid Pipe") - .miningToolTag(GTToolType.WRENCH.harvestTags.get(0)).materialAmount(GTValues.M * 3) + .miningToolTag(CustomTags.MINEABLE_WITH_WRENCH).materialAmount(GTValues.M * 3) .unificationEnabled(true); public static final TagPrefix pipeLargeFluid = new TagPrefix("pipeLargeFluid") .itemTable(() -> GTBlocks.FLUID_PIPE_BLOCKS).langValue("Large %s Fluid Pipe") - .miningToolTag(GTToolType.WRENCH.harvestTags.get(0)).materialAmount(GTValues.M * 6) + .miningToolTag(CustomTags.MINEABLE_WITH_WRENCH).materialAmount(GTValues.M * 6) .unificationEnabled(true); public static final TagPrefix pipeHugeFluid = new TagPrefix("pipeHugeFluid") .itemTable(() -> GTBlocks.FLUID_PIPE_BLOCKS).langValue("Huge %s Fluid Pipe") - .miningToolTag(GTToolType.WRENCH.harvestTags.get(0)).materialAmount(GTValues.M * 12) + .miningToolTag(CustomTags.MINEABLE_WITH_WRENCH).materialAmount(GTValues.M * 12) .unificationEnabled(true); public static final TagPrefix pipeQuadrupleFluid = new TagPrefix("pipeQuadrupleFluid") .itemTable(() -> GTBlocks.FLUID_PIPE_BLOCKS).langValue("Quadruple %s Fluid Pipe") - .miningToolTag(GTToolType.WRENCH.harvestTags.get(0)).materialAmount(GTValues.M * 4) + .miningToolTag(CustomTags.MINEABLE_WITH_WRENCH).materialAmount(GTValues.M * 4) .unificationEnabled(true); public static final TagPrefix pipeNonupleFluid = new TagPrefix("pipeNonupleFluid") .itemTable(() -> GTBlocks.FLUID_PIPE_BLOCKS).langValue("Nonuple %s Fluid Pipe") - .miningToolTag(GTToolType.WRENCH.harvestTags.get(0)).materialAmount(GTValues.M * 9) + .miningToolTag(CustomTags.MINEABLE_WITH_WRENCH).materialAmount(GTValues.M * 9) .unificationEnabled(true); public static final TagPrefix pipeSmallItem = new TagPrefix("pipeSmallItem") .itemTable(() -> GTBlocks.ITEM_PIPE_BLOCKS).langValue("Small %s Item Pipe") - .miningToolTag(GTToolType.WRENCH.harvestTags.get(0)).materialAmount(GTValues.M).unificationEnabled(true); + .miningToolTag(CustomTags.MINEABLE_WITH_WRENCH).materialAmount(GTValues.M).unificationEnabled(true); public static final TagPrefix pipeNormalItem = new TagPrefix("pipeNormalItem") .itemTable(() -> GTBlocks.ITEM_PIPE_BLOCKS).langValue("Normal %s Item Pipe") - .miningToolTag(GTToolType.WRENCH.harvestTags.get(0)).materialAmount(GTValues.M * 3) + .miningToolTag(CustomTags.MINEABLE_WITH_WRENCH).materialAmount(GTValues.M * 3) .unificationEnabled(true); public static final TagPrefix pipeLargeItem = new TagPrefix("pipeLargeItem") .itemTable(() -> GTBlocks.ITEM_PIPE_BLOCKS).langValue("Large %s Item Pipe") - .miningToolTag(GTToolType.WRENCH.harvestTags.get(0)).materialAmount(GTValues.M * 6) + .miningToolTag(CustomTags.MINEABLE_WITH_WRENCH).materialAmount(GTValues.M * 6) .unificationEnabled(true); public static final TagPrefix pipeHugeItem = new TagPrefix("pipeHugeItem") .itemTable(() -> GTBlocks.ITEM_PIPE_BLOCKS).langValue("Huge %s Item Pipe") - .miningToolTag(GTToolType.WRENCH.harvestTags.get(0)).materialAmount(GTValues.M * 12) + .miningToolTag(CustomTags.MINEABLE_WITH_WRENCH).materialAmount(GTValues.M * 12) .unificationEnabled(true); public static final TagPrefix pipeSmallRestrictive = new TagPrefix("pipeSmallRestrictive") .itemTable(() -> GTBlocks.ITEM_PIPE_BLOCKS).langValue("Small Restrictive %s Item Pipe") - .miningToolTag(GTToolType.WRENCH.harvestTags.get(0)).materialAmount(GTValues.M).unificationEnabled(true); + .miningToolTag(CustomTags.MINEABLE_WITH_WRENCH).materialAmount(GTValues.M).unificationEnabled(true); public static final TagPrefix pipeNormalRestrictive = new TagPrefix("pipeNormalRestrictive") .itemTable(() -> GTBlocks.ITEM_PIPE_BLOCKS).langValue("Normal Restrictive %s Item Pipe") - .miningToolTag(GTToolType.WRENCH.harvestTags.get(0)).materialAmount(GTValues.M * 3) + .miningToolTag(CustomTags.MINEABLE_WITH_WRENCH).materialAmount(GTValues.M * 3) .unificationEnabled(true); public static final TagPrefix pipeLargeRestrictive = new TagPrefix("pipeLargeRestrictive") .itemTable(() -> GTBlocks.ITEM_PIPE_BLOCKS).langValue("Large Restrictive %s Item Pipe") - .miningToolTag(GTToolType.WRENCH.harvestTags.get(0)).materialAmount(GTValues.M * 6) + .miningToolTag(CustomTags.MINEABLE_WITH_WRENCH).materialAmount(GTValues.M * 6) .unificationEnabled(true); public static final TagPrefix pipeHugeRestrictive = new TagPrefix("pipeHugeRestrictive") .itemTable(() -> GTBlocks.ITEM_PIPE_BLOCKS).langValue("Huge Restrictive %s Item Pipe") - .miningToolTag(GTToolType.WRENCH.harvestTags.get(0)).materialAmount(GTValues.M * 12) + .miningToolTag(CustomTags.MINEABLE_WITH_WRENCH).materialAmount(GTValues.M * 12) .unificationEnabled(true); // Wires and cables public static final TagPrefix wireGtHex = new TagPrefix("wireGtHex").itemTable(() -> GTBlocks.CABLE_BLOCKS) - .langValue("16x %s Wire").miningToolTag(GTToolType.WIRE_CUTTER.harvestTags.get(0)) + .langValue("16x %s Wire").miningToolTag(CustomTags.MINEABLE_WITH_WIRE_CUTTER) .materialAmount(GTValues.M * 8).materialIconType(MaterialIconType.wire).unificationEnabled(true); public static final TagPrefix wireGtOctal = new TagPrefix("wireGtOctal").itemTable(() -> GTBlocks.CABLE_BLOCKS) - .langValue("8x %s Wire").miningToolTag(GTToolType.WIRE_CUTTER.harvestTags.get(0)) + .langValue("8x %s Wire").miningToolTag(CustomTags.MINEABLE_WITH_WIRE_CUTTER) .materialAmount(GTValues.M * 4).materialIconType(MaterialIconType.wire).unificationEnabled(true); public static final TagPrefix wireGtQuadruple = new TagPrefix("wireGtQuadruple") .itemTable(() -> GTBlocks.CABLE_BLOCKS).langValue("4x %s Wire") - .miningToolTag(GTToolType.WIRE_CUTTER.harvestTags.get(0)).materialAmount(GTValues.M * 2) + .miningToolTag(CustomTags.MINEABLE_WITH_WIRE_CUTTER).materialAmount(GTValues.M * 2) .materialIconType(MaterialIconType.wire).unificationEnabled(true); public static final TagPrefix wireGtDouble = new TagPrefix("wireGtDouble").itemTable(() -> GTBlocks.CABLE_BLOCKS) - .langValue("2x %s Wire").miningToolTag(GTToolType.WIRE_CUTTER.harvestTags.get(0)).materialAmount(GTValues.M) + .langValue("2x %s Wire").miningToolTag(CustomTags.MINEABLE_WITH_WIRE_CUTTER).materialAmount(GTValues.M) .materialIconType(MaterialIconType.wire).unificationEnabled(true); public static final TagPrefix wireGtSingle = new TagPrefix("wireGtSingle").itemTable(() -> GTBlocks.CABLE_BLOCKS) - .langValue("1x %s Wire").miningToolTag(GTToolType.WIRE_CUTTER.harvestTags.get(0)) + .langValue("1x %s Wire").miningToolTag(CustomTags.MINEABLE_WITH_WIRE_CUTTER) .materialAmount(GTValues.M / 2).materialIconType(MaterialIconType.wire).unificationEnabled(true); public static final TagPrefix cableGtHex = new TagPrefix("cableGtHex").itemTable(() -> GTBlocks.CABLE_BLOCKS) - .langValue("16x %s Cable").miningToolTag(GTToolType.WIRE_CUTTER.harvestTags.get(0)) + .langValue("16x %s Cable").miningToolTag(CustomTags.MINEABLE_WITH_WIRE_CUTTER) .materialAmount(GTValues.M * 8).unificationEnabled(true); public static final TagPrefix cableGtOctal = new TagPrefix("cableGtOctal").itemTable(() -> GTBlocks.CABLE_BLOCKS) - .langValue("8x %s Cable").miningToolTag(GTToolType.WIRE_CUTTER.harvestTags.get(0)) + .langValue("8x %s Cable").miningToolTag(CustomTags.MINEABLE_WITH_WIRE_CUTTER) .materialAmount(GTValues.M * 4).unificationEnabled(true); public static final TagPrefix cableGtQuadruple = new TagPrefix("cableGtQuadruple") .itemTable(() -> GTBlocks.CABLE_BLOCKS).langValue("4x %s Cable") - .miningToolTag(GTToolType.WIRE_CUTTER.harvestTags.get(0)).materialAmount(GTValues.M * 2) + .miningToolTag(CustomTags.MINEABLE_WITH_WIRE_CUTTER).materialAmount(GTValues.M * 2) .unificationEnabled(true); public static final TagPrefix cableGtDouble = new TagPrefix("cableGtDouble").itemTable(() -> GTBlocks.CABLE_BLOCKS) - .langValue("2x %s Cable").miningToolTag(GTToolType.WIRE_CUTTER.harvestTags.get(0)) + .langValue("2x %s Cable").miningToolTag(CustomTags.MINEABLE_WITH_WIRE_CUTTER) .materialAmount(GTValues.M).unificationEnabled(true); public static final TagPrefix cableGtSingle = new TagPrefix("cableGtSingle").itemTable(() -> GTBlocks.CABLE_BLOCKS) - .langValue("1x %s Cable").miningToolTag(GTToolType.WIRE_CUTTER.harvestTags.get(0)) + .langValue("1x %s Cable").miningToolTag(CustomTags.MINEABLE_WITH_WIRE_CUTTER) .materialAmount(GTValues.M / 2).unificationEnabled(true); public static class Conditions { diff --git a/src/main/java/com/gregtechceu/gtceu/api/fluids/FluidBuilder.java b/src/main/java/com/gregtechceu/gtceu/api/fluids/FluidBuilder.java index eeb3fcb0c0..bcec793648 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/fluids/FluidBuilder.java +++ b/src/main/java/com/gregtechceu/gtceu/api/fluids/FluidBuilder.java @@ -14,9 +14,14 @@ import com.lowdragmc.lowdraglib.Platform; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.StringRepresentable; import net.minecraft.world.level.material.Fluid; import com.google.common.base.Preconditions; +import com.mojang.datafixers.util.Pair; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; @@ -26,15 +31,43 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; +import java.util.List; import java.util.function.Supplier; import static com.gregtechceu.gtceu.api.fluids.FluidConstants.*; +@AllArgsConstructor @Accessors(fluent = true, chain = true) public class FluidBuilder { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.STRING.fieldOf("name").forGetter(val -> val.name), + Codec.STRING.fieldOf("translation_key").forGetter(val -> val.translation), + FluidAttribute.CODEC.listOf().fieldOf("attributes").forGetter(val -> val.attributes), + StringRepresentable.fromEnum(FluidState::values).fieldOf("state").forGetter(val -> val.state), + Codec.INT.optionalFieldOf("temperature", FluidBuilder.INFER_TEMPERATURE).forGetter(val -> val.temperature), + Codec.INT.optionalFieldOf("color", FluidBuilder.INFER_COLOR).forGetter(val -> val.color), + Codec.BOOL.optionalFieldOf("is_color_enabled", true).forGetter(val -> val.isColorEnabled), + Codec.INT.optionalFieldOf("density", FluidBuilder.INFER_DENSITY).forGetter(val -> val.density), + Codec.INT.optionalFieldOf("luminosity", FluidBuilder.INFER_LUMINOSITY).forGetter(val -> val.luminosity), + Codec.INT.optionalFieldOf("viscosity", FluidBuilder.INFER_VISCOSITY).forGetter(val -> val.viscosity), + Codec.INT.optionalFieldOf("burn_time", -1).forGetter(val -> val.burnTime), + ResourceLocation.CODEC.optionalFieldOf("still_texture", null).forGetter(val -> val.still), + ResourceLocation.CODEC.optionalFieldOf("flowing_texture", null).forGetter(val -> val.flowing), + Codec.BOOL.optionalFieldOf("has_custom_still", false).forGetter(val -> val.hasCustomStill), + Codec.BOOL.optionalFieldOf("has_custom_flowing", false).forGetter(val -> val.hasCustomFlowing), + instance.group( + Codec.BOOL.optionalFieldOf("has_fluid_block", false).forGetter(val -> val.hasFluidBlock), + Codec.BOOL.optionalFieldOf("has_bucket", true).forGetter(val -> val.hasBucket)) + .apply(instance, Pair::of)) + .apply(instance, + (name, translation, attributes, state, temp, color, colorEnabled, density, luminosity, viscosity, + burnTime, stillTexture, flowingTexture, hasCustomStill, hasCustomFlowing, + pair) -> new FluidBuilder(name, translation, attributes, state, temp, color, colorEnabled, density, + luminosity, viscosity, burnTime, stillTexture, flowingTexture, hasCustomStill, + hasCustomFlowing, pair.getFirst(), pair.getSecond()))); + private static final int INFER_TEMPERATURE = -1; private static final int INFER_COLOR = 0xFFFFFFFF; private static final int INFER_DENSITY = -1; @@ -46,7 +79,7 @@ public class FluidBuilder { @Setter private String translation = null; - private final Collection attributes = new ArrayList<>(); + private final List attributes; @Setter private FluidState state = FluidState.LIQUID; @@ -61,10 +94,12 @@ public class FluidBuilder { private int burnTime = -1; @Getter - @Setter(onMethod_ = @ApiStatus.Internal) + @Setter + @ApiStatus.Internal private ResourceLocation still = null; @Getter - @Setter(onMethod_ = @ApiStatus.Internal) + @Setter + @ApiStatus.Internal private ResourceLocation flowing = null; private boolean hasCustomStill = false; private boolean hasCustomFlowing = false; @@ -72,7 +107,9 @@ public class FluidBuilder { private boolean hasFluidBlock = false; private boolean hasBucket = true; - public FluidBuilder() {} + public FluidBuilder() { + this.attributes = new ArrayList<>(); + } /** * @param temperature the temperature of the fluid in Kelvin diff --git a/src/main/java/com/gregtechceu/gtceu/api/fluids/FluidState.java b/src/main/java/com/gregtechceu/gtceu/api/fluids/FluidState.java index cde8d46441..346edf2005 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/fluids/FluidState.java +++ b/src/main/java/com/gregtechceu/gtceu/api/fluids/FluidState.java @@ -1,9 +1,13 @@ package com.gregtechceu.gtceu.api.fluids; +import net.minecraft.util.StringRepresentable; + import lombok.Getter; import org.jetbrains.annotations.NotNull; -public enum FluidState { +import java.util.Locale; + +public enum FluidState implements StringRepresentable { LIQUID("gtceu.fluid.state_liquid"), GAS("gtceu.fluid.state_gas"), @@ -16,4 +20,9 @@ public enum FluidState { FluidState(@NotNull String translationKey) { this.translationKey = translationKey; } + + @Override + public String getSerializedName() { + return name().toLowerCase(Locale.ROOT); + } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/fluids/attribute/FluidAttribute.java b/src/main/java/com/gregtechceu/gtceu/api/fluids/attribute/FluidAttribute.java index 80eae877ec..771cda24bd 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/fluids/attribute/FluidAttribute.java +++ b/src/main/java/com/gregtechceu/gtceu/api/fluids/attribute/FluidAttribute.java @@ -3,12 +3,31 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DynamicOps; +import com.mojang.serialization.Keyable; +import lombok.Getter; import org.jetbrains.annotations.NotNull; +import java.util.HashMap; +import java.util.Map; import java.util.function.Consumer; +import java.util.stream.Stream; public final class FluidAttribute { + private static final Map VALUES = new HashMap<>(); + public static final Codec CODEC = ResourceLocation.CODEC.xmap(FluidAttribute.VALUES::get, + FluidAttribute::getResourceLocation); + public static final Keyable CODEC_KEYS = new Keyable() { + + @Override + public Stream keys(DynamicOps ops) { + return VALUES.keySet().stream().map(key -> ops.createString(key.toString())); + } + }; + + @Getter private final ResourceLocation resourceLocation; private final Consumer> fluidTooltip; private final Consumer> containerTooltip; @@ -21,10 +40,7 @@ public FluidAttribute(@NotNull ResourceLocation resourceLocation, this.fluidTooltip = fluidTooltip; this.containerTooltip = containerTooltip; this.hashCode = resourceLocation.hashCode(); - } - - public @NotNull ResourceLocation getResourceLocation() { - return resourceLocation; + VALUES.put(resourceLocation, this); } public void appendFluidTooltips(@NotNull Consumer<@NotNull Component> tooltip) { diff --git a/src/main/java/com/gregtechceu/gtceu/api/fluids/store/FluidStorage.java b/src/main/java/com/gregtechceu/gtceu/api/fluids/store/FluidStorage.java index f3021425d1..965c329b26 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/fluids/store/FluidStorage.java +++ b/src/main/java/com/gregtechceu/gtceu/api/fluids/store/FluidStorage.java @@ -2,11 +2,12 @@ import com.gregtechceu.gtceu.api.fluids.FluidBuilder; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.level.material.Fluid; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import lombok.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -17,6 +18,14 @@ public interface FluidStorage { @AllArgsConstructor public static class FluidEntry { + @SuppressWarnings({ "unchecked", "deprecation" }) + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + BuiltInRegistries.FLUID.byNameCodec().fieldOf("fluid") + .xmap(fluid1 -> (Supplier) () -> fluid1, Supplier::get) + .forGetter(val -> (Supplier) val.fluid), + FluidBuilder.CODEC.optionalFieldOf("builder", null).forGetter(val -> val.builder)) + .apply(instance, FluidEntry::new)); + @Getter private Supplier fluid; @Nullable diff --git a/src/main/java/com/gregtechceu/gtceu/api/fluids/store/FluidStorageImpl.java b/src/main/java/com/gregtechceu/gtceu/api/fluids/store/FluidStorageImpl.java index a2a4165a84..97b9f6c02f 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/fluids/store/FluidStorageImpl.java +++ b/src/main/java/com/gregtechceu/gtceu/api/fluids/store/FluidStorageImpl.java @@ -7,6 +7,7 @@ import net.minecraft.world.level.material.Fluid; +import com.mojang.serialization.Codec; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -18,12 +19,21 @@ public class FluidStorageImpl implements FluidStorage { - private final Map map = new Object2ObjectOpenHashMap<>(); + public static final Codec CODEC = Codec.unboundedMap(FluidStorageKey.CODEC, FluidEntry.CODEC) + .xmap(FluidStorageImpl::new, (FluidStorageImpl fluidStorage) -> fluidStorage.map); + + private final Map map; private Map toRegister = new Object2ObjectOpenHashMap<>(); private boolean registered = false; - public FluidStorageImpl() {} + public FluidStorageImpl() { + this.map = new Object2ObjectOpenHashMap<>(); + } + + private FluidStorageImpl(Map map) { + this.map = map; + } /** * Enqueue a fluid for registration diff --git a/src/main/java/com/gregtechceu/gtceu/api/fluids/store/FluidStorageKey.java b/src/main/java/com/gregtechceu/gtceu/api/fluids/store/FluidStorageKey.java index 7d3a7fc47d..d045fe9015 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/fluids/store/FluidStorageKey.java +++ b/src/main/java/com/gregtechceu/gtceu/api/fluids/store/FluidStorageKey.java @@ -6,6 +6,7 @@ import net.minecraft.resources.ResourceLocation; +import com.mojang.serialization.Codec; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import lombok.Getter; import org.jetbrains.annotations.NotNull; @@ -18,6 +19,8 @@ public final class FluidStorageKey { private static final Map keys = new Object2ObjectOpenHashMap<>(); + public static final Codec CODEC = ResourceLocation.CODEC.xmap(FluidStorageKey.keys::get, + FluidStorageKey::getResourceLocation); @Getter private final ResourceLocation resourceLocation; diff --git a/src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java b/src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java index 98a3727a2f..f576053788 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java +++ b/src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java @@ -40,6 +40,7 @@ import com.gregtechceu.gtceu.data.pack.GTDynamicResourcePack; import com.gregtechceu.gtceu.data.pack.GTPackSource; import com.gregtechceu.gtceu.forge.AlloyBlastPropertyAddition; +import com.gregtechceu.gtceu.integration.jsonthings.parsers.MaterialParser; import com.gregtechceu.gtceu.integration.kjs.GTCEuStartupEvents; import com.gregtechceu.gtceu.integration.kjs.GTRegistryInfo; import com.gregtechceu.gtceu.integration.kjs.events.MaterialModificationEventJS; @@ -56,6 +57,7 @@ import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent; import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.event.AddPackFindersEvent; +import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.ModList; @@ -65,6 +67,7 @@ import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.javafmlmod.FMLModContainer; +import net.minecraftforge.registries.NewRegistryEvent; import net.minecraftforge.registries.RegisterEvent; import com.google.common.collect.Multimaps; @@ -72,6 +75,7 @@ import com.tterrag.registrate.providers.RegistrateLangProvider; import com.tterrag.registrate.providers.RegistrateProvider; import com.tterrag.registrate.util.nullness.NonNullConsumer; +import dev.gigaherz.jsonthings.things.parsers.ThingResourceManager; import java.util.List; @@ -82,6 +86,15 @@ public CommonProxy() { IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus(); eventBus.register(this); eventBus.addListener(AlloyBlastPropertyAddition::addAlloyBlastProperties); + + if (LDLib.isModLoaded(GTValues.MODID_JSONTHINGS)) { + IEventBus jsonThingsBus = ((FMLModContainer) ModList.get() + .getModContainerById(GTValues.MODID_JSONTHINGS) + .get()) + .getEventBus(); + ThingResourceManager manager = ThingResourceManager.instance(); + manager.registerParser(new MaterialParser(jsonThingsBus)); + } // must be set here because of KubeJS compat // trying to read this before the pre-init stage GTCEuAPI.materialManager = MaterialRegistryManager.getInstance(); @@ -211,6 +224,11 @@ private static void initMaterials() { /* End Material Registration */ } + @SubscribeEvent(priority = EventPriority.LOW) + public void newRegistry(NewRegistryEvent event) { + CommonProxy.init(); + } + @SubscribeEvent public void register(RegisterEvent event) { if (event.getRegistryKey().equals(BuiltInRegistries.LOOT_FUNCTION_TYPE.key())) @@ -220,7 +238,6 @@ public void register(RegisterEvent event) { @SubscribeEvent public void modConstruct(FMLConstructModEvent event) { // this is done to delay initialization of content to be after KJS has set up. - event.enqueueWork(CommonProxy::init); } @SubscribeEvent diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTBlocks.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTBlocks.java index 8514b5b4da..3c3ae25772 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTBlocks.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTBlocks.java @@ -14,7 +14,6 @@ import com.gregtechceu.gtceu.api.data.tag.TagPrefix; import com.gregtechceu.gtceu.api.data.tag.TagUtil; import com.gregtechceu.gtceu.api.item.*; -import com.gregtechceu.gtceu.api.item.tool.GTToolType; import com.gregtechceu.gtceu.api.machine.multiblock.IBatteryData; import com.gregtechceu.gtceu.api.pipenet.longdistance.LongDistancePipeBlock; import com.gregtechceu.gtceu.api.registry.registrate.CompassNode; @@ -421,7 +420,7 @@ private static void registerLaserPipeBlock(int index) { .properties(p -> p.dynamicShape().noOcclusion().forceSolidOn()) .blockstate(NonNullBiConsumer.noop()) .defaultLoot() - .tag(GTToolType.WIRE_CUTTER.harvestTags.get(0)) + .tag(CustomTags.MINEABLE_WITH_WIRE_CUTTER) .addLayer(() -> RenderType::cutoutMipped) .color(() -> LaserPipeBlock::tintedColor) .item(LaserPipeBlockItem::new) @@ -450,7 +449,7 @@ private static void registerOpticalPipeBlock(int index) { .properties(p -> p.dynamicShape().noOcclusion().forceSolidOn()) .blockstate(NonNullBiConsumer.noop()) .defaultLoot() - .tag(GTToolType.WIRE_CUTTER.harvestTags.get(0)) + .tag(CustomTags.MINEABLE_WITH_WIRE_CUTTER) .addLayer(() -> RenderType::cutoutMipped) .color(() -> OpticalPipeBlock::tintedColor) .item(OpticalPipeBlockItem::new) @@ -477,7 +476,7 @@ private static void registerDuctPipeBlock(int index) { .properties(p -> p.dynamicShape().noOcclusion().forceSolidOn()) .blockstate(NonNullBiConsumer.noop()) .defaultLoot() - .tag(GTToolType.WRENCH.harvestTags.get(0)) + .tag(CustomTags.MINEABLE_WITH_WRENCH) .addLayer(() -> RenderType::cutoutMipped) .item(DuctPipeBlockItem::new) .model(NonNullBiConsumer.noop()) @@ -497,7 +496,7 @@ private static void registerDuctPipeBlock(int index) { properties -> new LongDistancePipeBlock(properties, LDItemPipeType.INSTANCE)) .initialProperties(() -> Blocks.IRON_BLOCK) .blockstate(GTModels::longDistanceItemPipeModel) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.NEEDS_STONE_TOOL) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.NEEDS_STONE_TOOL) .simpleItem() .register(); @@ -506,7 +505,7 @@ private static void registerDuctPipeBlock(int index) { properties -> new LongDistancePipeBlock(properties, LDFluidPipeType.INSTANCE)) .initialProperties(() -> Blocks.IRON_BLOCK) .blockstate(GTModels::longDistanceFluidPipeModel) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.NEEDS_STONE_TOOL) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.NEEDS_STONE_TOOL) .simpleItem() .register(); @@ -644,7 +643,7 @@ private static void registerDuctPipeBlock(int index) { .properties(p -> p.sound(SoundType.WOOD).mapColor(MapColor.WOOD)) .addLayer(() -> RenderType::cutoutMipped) .blockstate(NonNullBiConsumer.noop()) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_AXE) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_AXE) .item(RendererBlockItem::new) .model(NonNullBiConsumer.noop()) .build() @@ -760,7 +759,7 @@ private static void registerDuctPipeBlock(int index) { .initialProperties(() -> Blocks.IRON_BLOCK) .properties(p -> p.isValidSpawn((state, level, pos, ent) -> false)) .blockstate(NonNullBiConsumer.noop()) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_PICKAXE) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_PICKAXE) .item(RendererBlockItem::new) .model(NonNullBiConsumer.noop()) .build() @@ -771,7 +770,7 @@ private static void registerDuctPipeBlock(int index) { .initialProperties(() -> Blocks.IRON_BLOCK) .properties(p -> p.isValidSpawn((state, level, pos, ent) -> false)) .blockstate(NonNullBiConsumer.noop()) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_PICKAXE) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_PICKAXE) .item(RendererBlockItem::new) .model(NonNullBiConsumer.noop()) .build() @@ -786,7 +785,7 @@ private static void registerDuctPipeBlock(int index) { .properties(p -> p.isValidSpawn((state, level, pos, ent) -> false)) .addLayer(() -> RenderType::cutoutMipped) .blockstate(NonNullBiConsumer.noop()) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_PICKAXE) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_PICKAXE) .item(RendererBlockItem::new) .model(NonNullBiConsumer.noop()) .build() @@ -809,7 +808,7 @@ private static BlockEntry createPipeCasingBlock(String name, ResourceLoca .properties(p -> p.isValidSpawn((state, level, pos, ent) -> false)) .addLayer(() -> RenderType::cutoutMipped) .blockstate(NonNullBiConsumer.noop()) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_PICKAXE) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_PICKAXE) .item(RendererBlockItem::new) .model(NonNullBiConsumer.noop()) .build() @@ -858,7 +857,7 @@ public static BlockEntry createCasingBlock(String name, .properties(p -> p.isValidSpawn((state, level, pos, ent) -> false)) .addLayer(type) .blockstate(NonNullBiConsumer.noop()) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_PICKAXE) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_PICKAXE) .item(RendererBlockItem::new) .model(NonNullBiConsumer.noop()) .build() @@ -879,7 +878,7 @@ private static BlockEntry createMachineCasingBlock(int tier) { .properties(p -> p.isValidSpawn((state, level, pos, ent) -> false)) .addLayer(() -> RenderType::cutoutMipped) .blockstate(NonNullBiConsumer.noop()) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_PICKAXE) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_PICKAXE) .item(RendererBlockItem::new) .model(NonNullBiConsumer.noop()) .build() @@ -906,7 +905,7 @@ private static BlockEntry createHermeticCasing(int tier) { .properties(p -> p.isValidSpawn((state, level, pos, ent) -> false)) .addLayer(() -> RenderType::cutoutMipped) .blockstate(NonNullBiConsumer.noop()) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_PICKAXE) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_PICKAXE) .item(RendererBlockItem::new) .model(NonNullBiConsumer.noop()) .build() @@ -927,7 +926,7 @@ private static BlockEntry createSteamCasing(String name, String material) .initialProperties(() -> Blocks.IRON_BLOCK) .addLayer(() -> RenderType::cutoutMipped) .blockstate(NonNullBiConsumer.noop()) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_PICKAXE) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_PICKAXE) .item(RendererBlockItem::new) .model(NonNullBiConsumer.noop()) .build() @@ -941,7 +940,7 @@ private static BlockEntry createCoilBlock(ICoilType coilType) { .properties(p -> p.isValidSpawn((state, level, pos, ent) -> false)) .addLayer(() -> RenderType::cutoutMipped) .blockstate(NonNullBiConsumer.noop()) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_PICKAXE) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_PICKAXE) .item(RendererBlockItem::new) .model(NonNullBiConsumer.noop()) .onRegister(compassNodeExist(GTCompassSections.BLOCKS, "coil_block")) @@ -966,7 +965,7 @@ private static BlockEntry createBatteryBlock(IBatteryData batteryD .properties(p -> p.isValidSpawn((state, level, pos, entityType) -> false)) .addLayer(() -> RenderType::cutoutMipped) .blockstate(NonNullBiConsumer.noop()) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_PICKAXE) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_PICKAXE) .item(RendererBlockItem::new) .model(NonNullBiConsumer.noop()) .onRegister(compassNodeExist(GTCompassSections.BLOCKS, "pss_battery")) @@ -983,7 +982,7 @@ private static BlockEntry createFusionCasing(IFusionCasingTyp .properties(properties -> properties.strength(5.0f, 10.0f).sound(SoundType.METAL)) .addLayer(() -> RenderType::cutoutMipped) .blockstate(NonNullBiConsumer.noop()) - .tag(GTToolType.WRENCH.harvestTags.get(0), CustomTags.TOOL_TIERS[casingType.getHarvestLevel()]) + .tag(CustomTags.MINEABLE_WITH_WRENCH, CustomTags.TOOL_TIERS[casingType.getHarvestLevel()]) .item(RendererBlockItem::new) .model(NonNullBiConsumer.noop()) .build() @@ -1001,7 +1000,7 @@ private static BlockEntry createCleanroomFilter(IFilterType filterType) { .isValidSpawn((blockState, blockGetter, blockPos, entityType) -> false)) .addLayer(() -> RenderType::cutoutMipped) .blockstate(NonNullBiConsumer.noop()) - .tag(GTToolType.WRENCH.harvestTags.get(0), CustomTags.TOOL_TIERS[1]) + .tag(CustomTags.MINEABLE_WITH_WRENCH, CustomTags.TOOL_TIERS[1]) .item(RendererBlockItem::new) .model(NonNullBiConsumer.noop()) .build() @@ -1018,7 +1017,7 @@ protected static BlockEntry createActiveCasing(String name, String .initialProperties(() -> Blocks.IRON_BLOCK) .addLayer(() -> RenderType::cutoutMipped) .blockstate(NonNullBiConsumer.noop()) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_PICKAXE) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_PICKAXE) .item(RendererBlockItem::new) .model(NonNullBiConsumer.noop()) .build() @@ -1042,7 +1041,7 @@ private static BlockEntry createFireboxCasing(BoilerFireboxType typ .properties(p -> p.isValidSpawn((state, level, pos, ent) -> false)) .addLayer(() -> RenderType::cutoutMipped) .blockstate(NonNullBiConsumer.noop()) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_PICKAXE) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_PICKAXE) .item(RendererBlockItem::new) .model(NonNullBiConsumer.noop()) .build() @@ -1717,7 +1716,7 @@ public static void generateStoneBlocks() { metalsheetBuilder.put(dyeColor, REGISTRATE.block("%s_metal_sheet".formatted(dyeColor.getName()), Block::new) .initialProperties(() -> Blocks.IRON_BLOCK) .properties(p -> p.strength(2.0F, 5.0F).mapColor(dyeColor)) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_PICKAXE) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_PICKAXE) .blockstate((ctx, prov) -> prov.simpleBlock(ctx.get(), prov.models().cubeAll(ctx.getName(), GTCEu.id("block/decoration/metalsheet_%s".formatted(dyeColor.getName()))))) @@ -1732,7 +1731,7 @@ public static void generateStoneBlocks() { REGISTRATE.block("%s_large_metal_sheet".formatted(dyeColor.getName()), Block::new) .initialProperties(() -> Blocks.IRON_BLOCK) .properties(p -> p.strength(2.0F, 5.0F).mapColor(dyeColor)) - .tag(GTToolType.WRENCH.harvestTags.get(0), BlockTags.MINEABLE_WITH_PICKAXE) + .tag(CustomTags.MINEABLE_WITH_WRENCH, BlockTags.MINEABLE_WITH_PICKAXE) .blockstate((ctx, prov) -> prov.simpleBlock(ctx.get(), prov.models().cubeAll(ctx.getName(), GTCEu.id("block/decoration/large_metalsheet_%s".formatted(dyeColor.getName()))))) .simpleItem() diff --git a/src/main/java/com/gregtechceu/gtceu/core/MixinHelpers.java b/src/main/java/com/gregtechceu/gtceu/core/MixinHelpers.java index ebe707b229..2ae1f37d7c 100644 --- a/src/main/java/com/gregtechceu/gtceu/core/MixinHelpers.java +++ b/src/main/java/com/gregtechceu/gtceu/core/MixinHelpers.java @@ -11,7 +11,6 @@ import com.gregtechceu.gtceu.api.data.tag.TagUtil; import com.gregtechceu.gtceu.api.fluids.store.FluidStorage; import com.gregtechceu.gtceu.api.fluids.store.FluidStorageKey; -import com.gregtechceu.gtceu.api.item.tool.GTToolType; import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.api.registry.registrate.forge.GTClientFluidTypeExtensions; import com.gregtechceu.gtceu.common.data.GTBlocks; @@ -101,7 +100,7 @@ public static void generateGTDynamicTags(Map { ResourceLocation id = machine.getId(); - tagMap.computeIfAbsent(GTToolType.WRENCH.harvestTags.get(0).location(), path -> new ArrayList<>()) + tagMap.computeIfAbsent(CustomTags.MINEABLE_WITH_WRENCH.location(), path -> new ArrayList<>()) .add(new TagLoader.EntryWithSource(TagEntry.element(id), GTValues.CUSTOM_TAG_SOURCE)); if (!ConfigHolder.INSTANCE.machines.requireGTToolsForBlocks) { tagMap.computeIfAbsent(BlockTags.MINEABLE_WITH_PICKAXE.location(), path -> new ArrayList<>()) @@ -267,7 +266,7 @@ public static void addMaterialBlockLootTables(Map l } public static void addFluidTexture(Material material, FluidStorage.FluidEntry value) { - if (value != null) { + if (value != null && value.getFluid().get() != null) { IClientFluidTypeExtensions extensions = IClientFluidTypeExtensions.of(value.getFluid().get()); if (extensions instanceof GTClientFluidTypeExtensions gtExtensions && value.getBuilder() != null) { gtExtensions.setFlowingTexture(value.getBuilder().flowing()); diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/CustomTags.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/CustomTags.java index 78723b1f45..ea57a5641d 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/CustomTags.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/CustomTags.java @@ -111,6 +111,9 @@ public class CustomTags { NEEDS_NEUTRONIUM_TOOL, }; + public static final TagKey MINEABLE_WITH_WRENCH = TagUtil.createBlockTag("mineable/wrench", false); + public static final TagKey MINEABLE_WITH_WIRE_CUTTER = TagUtil.createBlockTag("mineable/wire_cutter", false); + public static final TagKey ENDSTONE_ORE_REPLACEABLES = TagUtil.createBlockTag("end_stone_ore_replaceables"); public static final TagKey CONCRETE_BLOCK = TagUtil.createBlockTag("concrete"); public static final TagKey CONCRETE_POWDER_BLOCK = TagUtil.createBlockTag("concrete_powder"); diff --git a/src/main/java/com/gregtechceu/gtceu/integration/jsonthings/builders/MaterialBuilder.java b/src/main/java/com/gregtechceu/gtceu/integration/jsonthings/builders/MaterialBuilder.java new file mode 100644 index 0000000000..78260a21de --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/integration/jsonthings/builders/MaterialBuilder.java @@ -0,0 +1,34 @@ +package com.gregtechceu.gtceu.integration.jsonthings.builders; + +import com.gregtechceu.gtceu.api.data.chemical.material.Material; + +import net.minecraft.resources.ResourceLocation; + +import dev.gigaherz.jsonthings.things.builders.BaseBuilder; +import dev.gigaherz.jsonthings.things.parsers.ThingParser; +import lombok.Getter; + +public class MaterialBuilder extends BaseBuilder { + + @Getter + private final Material.Builder internal; + + protected MaterialBuilder(ThingParser ownerParser, ResourceLocation registryName) { + super(ownerParser, registryName); + this.internal = new Material.Builder(registryName); + } + + public static MaterialBuilder begin(ThingParser ownerParser, ResourceLocation registryName) { + return new MaterialBuilder(ownerParser, registryName); + } + + @Override + protected String getThingTypeDisplayName() { + return "Material"; + } + + @Override + protected Material buildInternal() { + return internal.buildAndRegister(); + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/integration/jsonthings/parsers/MaterialParser.java b/src/main/java/com/gregtechceu/gtceu/integration/jsonthings/parsers/MaterialParser.java new file mode 100644 index 0000000000..40d01fb9fa --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/integration/jsonthings/parsers/MaterialParser.java @@ -0,0 +1,100 @@ +package com.gregtechceu.gtceu.integration.jsonthings.parsers; + +import com.gregtechceu.gtceu.GTCEu; +import com.gregtechceu.gtceu.api.GTCEuAPI; +import com.gregtechceu.gtceu.api.data.chemical.material.event.MaterialEvent; +import com.gregtechceu.gtceu.api.data.chemical.material.event.MaterialRegistryEvent; +import com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialFlag; +import com.gregtechceu.gtceu.api.data.chemical.material.info.MaterialIconSet; +import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey; +import com.gregtechceu.gtceu.common.data.GTElements; +import com.gregtechceu.gtceu.integration.jsonthings.builders.MaterialBuilder; +import com.gregtechceu.gtceu.integration.kjs.helpers.MaterialStackWrapper; + +import net.minecraft.resources.ResourceLocation; +import net.minecraftforge.eventbus.api.IEventBus; + +import com.google.gson.JsonObject; +import com.mojang.serialization.JsonOps; +import dev.gigaherz.jsonthings.things.builders.BaseBuilder; +import dev.gigaherz.jsonthings.things.parsers.ThingParser; +import dev.gigaherz.jsonthings.util.parse.JParse; +import dev.gigaherz.jsonthings.util.parse.value.IntValue; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; + +import java.util.function.Consumer; + +public class MaterialParser extends ThingParser { + + public MaterialParser(IEventBus bus) { + super(GSON, "material"); + bus.addListener(this::registerMaterialRegistries); + bus.addListener(this::registerMaterials); + } + + public void registerMaterialRegistries(MaterialRegistryEvent event) { + LOGGER.info( + "Started registering Material registries, errors about unexpected registry domains are harmless..."); + processAndConsumeErrors(this.getThingType(), this.getBuilders(), (thing) -> { + String namespace = thing.getRegistryName().getNamespace(); + if (!namespace.equals(GTCEu.MOD_ID) && GTCEuAPI.materialManager.getRegistry(namespace) == + GTCEuAPI.materialManager.getRegistry(GTCEu.MOD_ID)) { + GTCEuAPI.materialManager.createRegistry(namespace); + } + }, BaseBuilder::getRegistryName); + LOGGER.info("Done processing thingpack Material Registries."); + } + + public void registerMaterials(MaterialEvent event) { + LOGGER.info("Started registering Material things, errors about unexpected registry domains are harmless..."); + processAndConsumeErrors(this.getThingType(), this.getBuilders(), (thing) -> { + ResourceLocation location = thing.getRegistryName(); + LOGGER.info("loading material {}", location); + thing.build(); + }, BaseBuilder::getRegistryName); + LOGGER.info("Done processing thingpack Materials."); + } + + @Override + protected MaterialBuilder processThing(ResourceLocation key, JsonObject data, + Consumer builderModification) { + MaterialBuilder builder = MaterialBuilder.begin(this, key); + JParse.begin(data) + .ifKey("material_info", (materialInfo) -> { + materialInfo.obj().ifKey("colors", colors -> { + builder.getInternal().getMaterialInfo() + .setColors(colors.array().ints() + .flatMap(values -> values.map(IntValue::getAsInt).mapToInt(Integer::intValue) + .collect(IntArrayList::new, IntList::add, IntList::addAll))); + }).ifKey("has_fluid_color", hasFluidColor -> { + builder.getInternal().getMaterialInfo().setHasFluidColor(hasFluidColor.bool().getAsBoolean()); + }).ifKey("icon_set", iconSet -> { + builder.getInternal().iconSet(MaterialIconSet.getByName(iconSet.string().getAsString())); + }).ifKey("components", components -> { + builder.getInternal() + .kjs$components((MaterialStackWrapper[]) components.array().map(MaterialStackParser::of) + .flatMap(values -> values.toArray(MaterialStackWrapper[]::new))); + }).ifKey("element", element -> { + builder.getInternal().element(GTElements.get(element.string().getAsString())); + }); + }).ifKey("properties", properties -> { + properties.array().forEach((index, any) -> { + var objValue = any.obj(); + objValue.ifKey("type", type -> { + PropertyKey propertyKey = PropertyKey.getByName(type.string().getAsString()); + var property = propertyKey.getCodec().parse(JsonOps.INSTANCE, objValue.getAsJsonObject()) + .getOrThrow(false, GTCEu.LOGGER::error); + builder.getInternal().getProperties().setPropertyNoGeneric(propertyKey, property); + }); + }); + }).ifKey("flags", flags -> { + flags.array().forEach((index, any) -> { + String name = any.string().getAsString(); + builder.getInternal().flags(MaterialFlag.getByName(name)); + }); + }); + builderModification.accept(builder); + return builder; + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/integration/jsonthings/parsers/MaterialStackParser.java b/src/main/java/com/gregtechceu/gtceu/integration/jsonthings/parsers/MaterialStackParser.java new file mode 100644 index 0000000000..0ac5e930fa --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/integration/jsonthings/parsers/MaterialStackParser.java @@ -0,0 +1,24 @@ +package com.gregtechceu.gtceu.integration.jsonthings.parsers; + +import com.gregtechceu.gtceu.common.data.GTMaterials; +import com.gregtechceu.gtceu.integration.kjs.helpers.MaterialStackWrapper; + +import dev.gigaherz.jsonthings.util.parse.value.Any; +import org.apache.commons.lang3.mutable.MutableObject; + +public class MaterialStackParser { + + public static MaterialStackWrapper of(Any any) { + var ref = new MutableObject(); + any.ifString(stringValue -> { + ref.setValue(MaterialStackWrapper.fromString(stringValue.getAsString())); + }).ifObj(objValue -> { + objValue.key("material", matId -> { + String id = matId.string().getAsString(); + long amount = objValue.hasKey("amount") ? objValue.getAsJsonObject().get("amount").getAsLong() : 1; + ref.setValue(new MaterialStackWrapper(() -> GTMaterials.get(id), amount)); + }); + }); + return ref.getValue(); + } +} diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 9eddef9509..bd53a1af87 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -75,3 +75,10 @@ mandatory = false versionRange = "[${jade_version},)" ordering = "NONE" side = "BOTH" + +[[dependencies.${mod_id}]] +modId = "jsonthings" +mandatory = false +versionRange = "[${jsonthings_version},)" +ordering = "AFTER" +side = "BOTH"