From db59e0d5a4e3561481bef55f12bbc6ac4b003d18 Mon Sep 17 00:00:00 2001 From: Rundas <38040866+Rundas01@users.noreply.github.com> Date: Mon, 30 Sep 2024 23:30:26 +0200 Subject: [PATCH 1/4] Add methods to change a material's composition --- .../gregtech/api/unification/material/Material.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/gregtech/api/unification/material/Material.java b/src/main/java/gregtech/api/unification/material/Material.java index 18770e5325c..20f094f52b2 100644 --- a/src/main/java/gregtech/api/unification/material/Material.java +++ b/src/main/java/gregtech/api/unification/material/Material.java @@ -110,6 +110,13 @@ public Material setFormula(String formula, boolean withFormatting) { return this; } + @ZenMethod + public Material setComponents(MaterialStack... components) { + this.materialInfo.setComponents(components); + this.chemicalFormula = this.calculateChemicalFormula(); + return this; + } + public ImmutableList getMaterialComponents() { return materialInfo.componentList; } @@ -1172,5 +1179,10 @@ private void verifyInfo(MaterialProperties p, boolean averageRGB) { } } } + + public MaterialInfo setComponents(MaterialStack... components) { + this.componentList = ImmutableList.copyOf(Arrays.stream(components).toList()); + return this; + } } } From e77fd4a5542e8ec29912bd325da8125c5fb7599b Mon Sep 17 00:00:00 2001 From: Rundas <38040866+Rundas01@users.noreply.github.com> Date: Tue, 1 Oct 2024 11:05:59 +0200 Subject: [PATCH 2/4] java 17 moment --- src/main/java/gregtech/api/unification/material/Material.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/unification/material/Material.java b/src/main/java/gregtech/api/unification/material/Material.java index 20f094f52b2..4058008e793 100644 --- a/src/main/java/gregtech/api/unification/material/Material.java +++ b/src/main/java/gregtech/api/unification/material/Material.java @@ -38,6 +38,7 @@ import java.util.*; import java.util.function.Consumer; import java.util.function.UnaryOperator; +import java.util.stream.Collectors; @ZenClass("mods.gregtech.material.Material") @ZenRegister @@ -1181,7 +1182,7 @@ private void verifyInfo(MaterialProperties p, boolean averageRGB) { } public MaterialInfo setComponents(MaterialStack... components) { - this.componentList = ImmutableList.copyOf(Arrays.stream(components).toList()); + this.componentList = ImmutableList.copyOf(Arrays.stream(components).collect(Collectors.toList())); return this; } } From 7f53a3f4d208960f1a6295360285113bce65114a Mon Sep 17 00:00:00 2001 From: Rundas <38040866+Rundas01@users.noreply.github.com> Date: Tue, 1 Oct 2024 12:08:46 +0200 Subject: [PATCH 3/4] final fix the formula needed to be nulled at first. otherwise, the old formula would be used for the new components --- .../api/unification/material/Material.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/gregtech/api/unification/material/Material.java b/src/main/java/gregtech/api/unification/material/Material.java index 4058008e793..86ffd80c28c 100644 --- a/src/main/java/gregtech/api/unification/material/Material.java +++ b/src/main/java/gregtech/api/unification/material/Material.java @@ -10,7 +10,22 @@ import gregtech.api.unification.material.info.MaterialFlag; import gregtech.api.unification.material.info.MaterialFlags; import gregtech.api.unification.material.info.MaterialIconSet; -import gregtech.api.unification.material.properties.*; +import gregtech.api.unification.material.properties.BlastProperty; +import gregtech.api.unification.material.properties.DustProperty; +import gregtech.api.unification.material.properties.FluidPipeProperties; +import gregtech.api.unification.material.properties.FluidProperty; +import gregtech.api.unification.material.properties.GemProperty; +import gregtech.api.unification.material.properties.IMaterialProperty; +import gregtech.api.unification.material.properties.IngotProperty; +import gregtech.api.unification.material.properties.ItemPipeProperties; +import gregtech.api.unification.material.properties.MaterialProperties; +import gregtech.api.unification.material.properties.OreProperty; +import gregtech.api.unification.material.properties.PolymerProperty; +import gregtech.api.unification.material.properties.PropertyKey; +import gregtech.api.unification.material.properties.RotorProperty; +import gregtech.api.unification.material.properties.ToolProperty; +import gregtech.api.unification.material.properties.WireProperties; +import gregtech.api.unification.material.properties.WoodProperty; import gregtech.api.unification.material.registry.MaterialRegistry; import gregtech.api.unification.stack.MaterialStack; import gregtech.api.util.FluidTooltipUtil; @@ -35,7 +50,11 @@ import stanhebben.zenscript.annotations.ZenMethod; import stanhebben.zenscript.annotations.ZenOperator; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Objects; import java.util.function.Consumer; import java.util.function.UnaryOperator; import java.util.stream.Collectors; @@ -114,7 +133,8 @@ public Material setFormula(String formula, boolean withFormatting) { @ZenMethod public Material setComponents(MaterialStack... components) { this.materialInfo.setComponents(components); - this.chemicalFormula = this.calculateChemicalFormula(); + this.chemicalFormula = null; + this.chemicalFormula = calculateChemicalFormula(); return this; } From c25f49a4f057388abb18726b725bb509719dbc24 Mon Sep 17 00:00:00 2001 From: Rundas <38040866+Rundas01@users.noreply.github.com> Date: Tue, 8 Oct 2024 11:18:36 +0200 Subject: [PATCH 4/4] Implemented brachy's requested changes --- src/main/java/gregtech/api/unification/material/Material.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/unification/material/Material.java b/src/main/java/gregtech/api/unification/material/Material.java index 86ffd80c28c..29c4c9fd9e4 100644 --- a/src/main/java/gregtech/api/unification/material/Material.java +++ b/src/main/java/gregtech/api/unification/material/Material.java @@ -57,7 +57,6 @@ import java.util.Objects; import java.util.function.Consumer; import java.util.function.UnaryOperator; -import java.util.stream.Collectors; @ZenClass("mods.gregtech.material.Material") @ZenRegister @@ -1202,7 +1201,7 @@ private void verifyInfo(MaterialProperties p, boolean averageRGB) { } public MaterialInfo setComponents(MaterialStack... components) { - this.componentList = ImmutableList.copyOf(Arrays.stream(components).collect(Collectors.toList())); + this.componentList = ImmutableList.copyOf(Arrays.asList(components)); return this; } }