From b7cce33d82a956f2afea46a02fe30721fc0f51cf Mon Sep 17 00:00:00 2001 From: M-W-K Date: Wed, 13 Mar 2024 08:55:02 -0600 Subject: [PATCH 1/7] Generify DimensionProperty --- .../gregtech/api/recipes/RecipeBuilder.java | 42 +++++++++- .../java/gregtech/api/recipes/RecipeMaps.java | 5 +- .../builders/GasCollectorRecipeBuilder.java | 82 ------------------- ...onProperty.java => DimensionProperty.java} | 10 +-- .../electric/MetaTileEntityGasCollector.java | 4 +- 5 files changed, 50 insertions(+), 93 deletions(-) delete mode 100644 src/main/java/gregtech/api/recipes/builders/GasCollectorRecipeBuilder.java rename src/main/java/gregtech/api/recipes/recipeproperties/{GasCollectorDimensionProperty.java => DimensionProperty.java} (80%) diff --git a/src/main/java/gregtech/api/recipes/RecipeBuilder.java b/src/main/java/gregtech/api/recipes/RecipeBuilder.java index 87175224c5d..d32d18172d8 100644 --- a/src/main/java/gregtech/api/recipes/RecipeBuilder.java +++ b/src/main/java/gregtech/api/recipes/RecipeBuilder.java @@ -13,6 +13,7 @@ import gregtech.api.recipes.ingredients.nbtmatch.NBTCondition; import gregtech.api.recipes.ingredients.nbtmatch.NBTMatcher; import gregtech.api.recipes.recipeproperties.CleanroomProperty; +import gregtech.api.recipes.recipeproperties.DimensionProperty; import gregtech.api.recipes.recipeproperties.IRecipePropertyStorage; import gregtech.api.recipes.recipeproperties.RecipeProperty; import gregtech.api.recipes.recipeproperties.RecipePropertyStorage; @@ -39,6 +40,9 @@ import com.cleanroommc.groovyscript.api.IIngredient; import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient; import crafttweaker.CraftTweakerAPI; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; +import it.unimi.dsi.fastutil.ints.IntLists; import org.apache.commons.lang3.builder.ToStringBuilder; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -137,8 +141,43 @@ public R cleanroom(@Nullable CleanroomType cleanroom) { return (R) this; } + public R dimension(int dimensionID) { + IntList dimensionIDs = getDimensionIDs(); + if (dimensionIDs == IntLists.EMPTY_LIST) { + dimensionIDs = new IntArrayList(); + this.applyProperty(DimensionProperty.getInstance(), dimensionIDs); + } + dimensionIDs.add(dimensionID); + return (R) this; + } + + public IntList getDimensionIDs() { + return this.recipePropertyStorage == null ? IntLists.EMPTY_LIST : + this.recipePropertyStorage.getRecipePropertyValue(DimensionProperty.getInstance(), + IntLists.EMPTY_LIST); + } + public boolean applyProperty(@NotNull String key, @Nullable Object value) { - if (key.equals(CleanroomProperty.KEY)) { + if (key.equals(DimensionProperty.KEY)) { + if (value instanceof Integer) { + this.dimension((Integer) value); + } else if (value instanceof List && !((List) value).isEmpty() && + ((List) value).get(0) instanceof Integer) { + IntList dimensionIDs = getDimensionIDs(); + if (dimensionIDs == IntLists.EMPTY_LIST) { + dimensionIDs = new IntArrayList(); + this.applyProperty(DimensionProperty.getInstance(), dimensionIDs); + } + dimensionIDs.addAll((List) value); + } else { + if (isCTRecipe) { + CraftTweakerAPI.logError("Dimension for Dimension Property needs to be an Integer"); + return false; + } + throw new IllegalArgumentException("Invalid Dimension Property Type!"); + } + return true; + } else if (key.equals(CleanroomProperty.KEY)) { if (value instanceof CleanroomType) { this.cleanroom((CleanroomType) value); } else if (value instanceof String) { @@ -976,6 +1015,7 @@ public String toString() { .append("EUt", EUt) .append("hidden", hidden) .append("cleanroom", getCleanroom()) + .append(DimensionProperty.getInstance().getKey(), getDimensionIDs().toString()) .append("recipeStatus", recipeStatus) .toString(); } diff --git a/src/main/java/gregtech/api/recipes/RecipeMaps.java b/src/main/java/gregtech/api/recipes/RecipeMaps.java index e61261ddd09..9cd9547457f 100644 --- a/src/main/java/gregtech/api/recipes/RecipeMaps.java +++ b/src/main/java/gregtech/api/recipes/RecipeMaps.java @@ -11,7 +11,6 @@ import gregtech.api.recipes.builders.ComputationRecipeBuilder; import gregtech.api.recipes.builders.FuelRecipeBuilder; import gregtech.api.recipes.builders.FusionRecipeBuilder; -import gregtech.api.recipes.builders.GasCollectorRecipeBuilder; import gregtech.api.recipes.builders.ImplosionRecipeBuilder; import gregtech.api.recipes.builders.PrimitiveRecipeBuilder; import gregtech.api.recipes.builders.SimpleRecipeBuilder; @@ -982,8 +981,8 @@ public final class RecipeMaps { .build(); @ZenProperty - public static final RecipeMap GAS_COLLECTOR_RECIPES = new RecipeMapBuilder<>( - "gas_collector", new GasCollectorRecipeBuilder()) + public static final RecipeMap GAS_COLLECTOR_RECIPES = new RecipeMapBuilder<>( + "gas_collector", new SimpleRecipeBuilder()) .itemInputs(1) .fluidOutputs(1) .itemSlotOverlay(GuiTextures.INT_CIRCUIT_OVERLAY, false, true) diff --git a/src/main/java/gregtech/api/recipes/builders/GasCollectorRecipeBuilder.java b/src/main/java/gregtech/api/recipes/builders/GasCollectorRecipeBuilder.java deleted file mode 100644 index fe3bb345305..00000000000 --- a/src/main/java/gregtech/api/recipes/builders/GasCollectorRecipeBuilder.java +++ /dev/null @@ -1,82 +0,0 @@ -package gregtech.api.recipes.builders; - -import gregtech.api.recipes.Recipe; -import gregtech.api.recipes.RecipeBuilder; -import gregtech.api.recipes.RecipeMap; -import gregtech.api.recipes.recipeproperties.GasCollectorDimensionProperty; - -import crafttweaker.CraftTweakerAPI; -import it.unimi.dsi.fastutil.ints.IntArrayList; -import it.unimi.dsi.fastutil.ints.IntList; -import it.unimi.dsi.fastutil.ints.IntLists; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class GasCollectorRecipeBuilder extends RecipeBuilder { - - public GasCollectorRecipeBuilder() {} - - public GasCollectorRecipeBuilder(Recipe recipe, RecipeMap recipeMap) { - super(recipe, recipeMap); - } - - public GasCollectorRecipeBuilder(RecipeBuilder recipeBuilder) { - super(recipeBuilder); - } - - @Override - public GasCollectorRecipeBuilder copy() { - return new GasCollectorRecipeBuilder(this); - } - - @Override - public boolean applyProperty(@NotNull String key, Object value) { - if (key.equals(GasCollectorDimensionProperty.KEY)) { - if (value instanceof Integer) { - this.dimension((Integer) value); - } else if (value instanceof List && !((List) value).isEmpty() && - ((List) value).get(0) instanceof Integer) { - IntList dimensionIDs = getDimensionIDs(); - if (dimensionIDs == IntLists.EMPTY_LIST) { - dimensionIDs = new IntArrayList(); - this.applyProperty(GasCollectorDimensionProperty.getInstance(), dimensionIDs); - } - dimensionIDs.addAll((List) value); - } else { - if (isCTRecipe) { - CraftTweakerAPI.logError("Dimension for Gas Collector needs to be a Integer"); - return false; - } - throw new IllegalArgumentException("Invalid Dimension Property Type!"); - } - return true; - } - return super.applyProperty(key, value); - } - - public GasCollectorRecipeBuilder dimension(int dimensionID) { - IntList dimensionIDs = getDimensionIDs(); - if (dimensionIDs == IntLists.EMPTY_LIST) { - dimensionIDs = new IntArrayList(); - this.applyProperty(GasCollectorDimensionProperty.getInstance(), dimensionIDs); - } - dimensionIDs.add(dimensionID); - return this; - } - - public IntList getDimensionIDs() { - return this.recipePropertyStorage == null ? IntLists.EMPTY_LIST : - this.recipePropertyStorage.getRecipePropertyValue(GasCollectorDimensionProperty.getInstance(), - IntLists.EMPTY_LIST); - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .appendSuper(super.toString()) - .append(GasCollectorDimensionProperty.getInstance().getKey(), getDimensionIDs().toString()) - .toString(); - } -} diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/GasCollectorDimensionProperty.java b/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java similarity index 80% rename from src/main/java/gregtech/api/recipes/recipeproperties/GasCollectorDimensionProperty.java rename to src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java index 94bb810e3b1..1eb84ea4bed 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/GasCollectorDimensionProperty.java +++ b/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java @@ -8,19 +8,19 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.IntList; -public class GasCollectorDimensionProperty extends RecipeProperty { +public class DimensionProperty extends RecipeProperty { public static final String KEY = "dimension"; - private static GasCollectorDimensionProperty INSTANCE; + private static DimensionProperty INSTANCE; - private GasCollectorDimensionProperty() { + private DimensionProperty() { super(KEY, IntList.class); } - public static GasCollectorDimensionProperty getInstance() { + public static DimensionProperty getInstance() { if (INSTANCE == null) - INSTANCE = new GasCollectorDimensionProperty(); + INSTANCE = new DimensionProperty(); return INSTANCE; } diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityGasCollector.java b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityGasCollector.java index 77bdd3b0485..272ca8bac2e 100644 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityGasCollector.java +++ b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityGasCollector.java @@ -8,7 +8,7 @@ import gregtech.api.recipes.Recipe; import gregtech.api.recipes.RecipeMap; import gregtech.api.recipes.RecipeMaps; -import gregtech.api.recipes.recipeproperties.GasCollectorDimensionProperty; +import gregtech.api.recipes.recipeproperties.DimensionProperty; import gregtech.client.renderer.ICubeRenderer; import gregtech.client.renderer.texture.Textures; @@ -40,7 +40,7 @@ protected RecipeLogicEnergy createWorkable(RecipeMap recipeMap) { } protected boolean checkRecipe(@NotNull Recipe recipe) { - for (int dimension : recipe.getProperty(GasCollectorDimensionProperty.getInstance(), IntLists.EMPTY_LIST)) { + for (int dimension : recipe.getProperty(DimensionProperty.getInstance(), IntLists.EMPTY_LIST)) { if (dimension == this.getWorld().provider.getDimension()) { return true; } From e1e0d92e322762d0bb9a3e119ff6051045e3aa9b Mon Sep 17 00:00:00 2001 From: M-W-K Date: Wed, 13 Mar 2024 11:28:25 -0600 Subject: [PATCH 2/7] Oh yea, I need to move the check too --- .../capability/impl/AbstractRecipeLogic.java | 10 +++++- .../electric/MetaTileEntityGasCollector.java | 31 +------------------ 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index ce4eab33ac9..687f89248ef 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -16,6 +16,7 @@ import gregtech.api.recipes.RecipeMap; import gregtech.api.recipes.logic.IParallelableRecipeLogic; import gregtech.api.recipes.recipeproperties.CleanroomProperty; +import gregtech.api.recipes.recipeproperties.DimensionProperty; import gregtech.api.recipes.recipeproperties.IRecipePropertyStorage; import gregtech.api.util.GTTransferUtils; import gregtech.api.util.GTUtility; @@ -33,6 +34,7 @@ import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.items.IItemHandlerModifiable; +import it.unimi.dsi.fastutil.ints.IntLists; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -407,7 +409,7 @@ protected boolean checkPreviousRecipe() { * @return true if the recipe is allowed to be used, else false */ public boolean checkRecipe(@NotNull Recipe recipe) { - return checkCleanroomRequirement(recipe); + return checkCleanroomRequirement(recipe) && checkDimensionRequirement(recipe); } /** @@ -431,6 +433,12 @@ protected boolean checkCleanroomRequirement(@NotNull Recipe recipe) { return false; } + protected boolean checkDimensionRequirement(@NotNull Recipe recipe) { + if (!recipe.hasProperty(DimensionProperty.getInstance())) return true; + int currentDimension = this.getMetaTileEntity().getWorld().provider.getDimension(); + return recipe.getProperty(DimensionProperty.getInstance(), IntLists.EMPTY_LIST).contains(currentDimension); + } + /** * Prepares the recipe to be run. *
    diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityGasCollector.java b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityGasCollector.java index 272ca8bac2e..8300d2b5fc9 100644 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityGasCollector.java +++ b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityGasCollector.java @@ -1,24 +1,17 @@ package gregtech.common.metatileentities.electric; -import gregtech.api.capability.IEnergyContainer; import gregtech.api.capability.impl.RecipeLogicEnergy; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.SimpleMachineMetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; -import gregtech.api.recipes.Recipe; import gregtech.api.recipes.RecipeMap; import gregtech.api.recipes.RecipeMaps; -import gregtech.api.recipes.recipeproperties.DimensionProperty; import gregtech.client.renderer.ICubeRenderer; import gregtech.client.renderer.texture.Textures; import net.minecraft.util.ResourceLocation; -import it.unimi.dsi.fastutil.ints.IntLists; -import org.jetbrains.annotations.NotNull; - import java.util.function.Function; -import java.util.function.Supplier; public class MetaTileEntityGasCollector extends SimpleMachineMetaTileEntity { @@ -36,28 +29,6 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { @Override protected RecipeLogicEnergy createWorkable(RecipeMap recipeMap) { - return new GasCollectorRecipeLogic(this, recipeMap, () -> energyContainer); - } - - protected boolean checkRecipe(@NotNull Recipe recipe) { - for (int dimension : recipe.getProperty(DimensionProperty.getInstance(), IntLists.EMPTY_LIST)) { - if (dimension == this.getWorld().provider.getDimension()) { - return true; - } - } - return false; - } - - private static class GasCollectorRecipeLogic extends RecipeLogicEnergy { - - public GasCollectorRecipeLogic(MetaTileEntity metaTileEntity, RecipeMap recipeMap, - Supplier energyContainer) { - super(metaTileEntity, recipeMap, energyContainer); - } - - @Override - public boolean checkRecipe(@NotNull Recipe recipe) { - return ((MetaTileEntityGasCollector) metaTileEntity).checkRecipe(recipe) && super.checkRecipe(recipe); - } + return new RecipeLogicEnergy(this, recipeMap, () -> energyContainer); } } From 4403597daa8935b2fef071065d7f1d2a561b5a65 Mon Sep 17 00:00:00 2001 From: M-W-K Date: Wed, 13 Mar 2024 23:20:23 -0600 Subject: [PATCH 3/7] Blacklist support --- .../capability/impl/AbstractRecipeLogic.java | 4 +- .../gregtech/api/recipes/RecipeBuilder.java | 58 +++++++++++-------- .../recipeproperties/DimensionProperty.java | 44 ++++++++++++-- .../resources/assets/gregtech/lang/en_us.lang | 1 + 4 files changed, 76 insertions(+), 31 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index 687f89248ef..36dbc09e12d 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -435,8 +435,8 @@ protected boolean checkCleanroomRequirement(@NotNull Recipe recipe) { protected boolean checkDimensionRequirement(@NotNull Recipe recipe) { if (!recipe.hasProperty(DimensionProperty.getInstance())) return true; - int currentDimension = this.getMetaTileEntity().getWorld().provider.getDimension(); - return recipe.getProperty(DimensionProperty.getInstance(), IntLists.EMPTY_LIST).contains(currentDimension); + return recipe.getProperty(DimensionProperty.getInstance(), DimensionProperty.DimensionPropertyList.EMPTY_LIST) + .checkDimension(this.getMetaTileEntity().getWorld().provider.getDimension()); } /** diff --git a/src/main/java/gregtech/api/recipes/RecipeBuilder.java b/src/main/java/gregtech/api/recipes/RecipeBuilder.java index d32d18172d8..bf4c67c074f 100644 --- a/src/main/java/gregtech/api/recipes/RecipeBuilder.java +++ b/src/main/java/gregtech/api/recipes/RecipeBuilder.java @@ -40,7 +40,6 @@ import com.cleanroommc.groovyscript.api.IIngredient; import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient; import crafttweaker.CraftTweakerAPI; -import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.ints.IntLists; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -142,41 +141,49 @@ public R cleanroom(@Nullable CleanroomType cleanroom) { } public R dimension(int dimensionID) { - IntList dimensionIDs = getDimensionIDs(); - if (dimensionIDs == IntLists.EMPTY_LIST) { - dimensionIDs = new IntArrayList(); + return dimension(dimensionID, false); + } + + public R dimension(int dimensionID, boolean toBlackList) { + DimensionProperty.DimensionPropertyList dimensionIDs = getCompleteDimensionIDs(); + if (dimensionIDs == DimensionProperty.DimensionPropertyList.EMPTY_LIST) { + dimensionIDs = new DimensionProperty.DimensionPropertyList(); this.applyProperty(DimensionProperty.getInstance(), dimensionIDs); } - dimensionIDs.add(dimensionID); + dimensionIDs.add(dimensionID, toBlackList); return (R) this; } + public DimensionProperty.DimensionPropertyList getCompleteDimensionIDs() { + return this.recipePropertyStorage == null ? DimensionProperty.DimensionPropertyList.EMPTY_LIST : + this.recipePropertyStorage.getRecipePropertyValue(DimensionProperty.getInstance(), + DimensionProperty.DimensionPropertyList.EMPTY_LIST); + } + public IntList getDimensionIDs() { return this.recipePropertyStorage == null ? IntLists.EMPTY_LIST : this.recipePropertyStorage.getRecipePropertyValue(DimensionProperty.getInstance(), - IntLists.EMPTY_LIST); + DimensionProperty.DimensionPropertyList.EMPTY_LIST).whiteListDimensions; + } + + public IntList getBlockedDimensionIDs() { + return this.recipePropertyStorage == null ? IntLists.EMPTY_LIST : + this.recipePropertyStorage.getRecipePropertyValue(DimensionProperty.getInstance(), + DimensionProperty.DimensionPropertyList.EMPTY_LIST).whiteListDimensions; } public boolean applyProperty(@NotNull String key, @Nullable Object value) { if (key.equals(DimensionProperty.KEY)) { - if (value instanceof Integer) { - this.dimension((Integer) value); - } else if (value instanceof List && !((List) value).isEmpty() && - ((List) value).get(0) instanceof Integer) { - IntList dimensionIDs = getDimensionIDs(); - if (dimensionIDs == IntLists.EMPTY_LIST) { - dimensionIDs = new IntArrayList(); - this.applyProperty(DimensionProperty.getInstance(), dimensionIDs); - } - dimensionIDs.addAll((List) value); - } else { - if (isCTRecipe) { - CraftTweakerAPI.logError("Dimension for Dimension Property needs to be an Integer"); - return false; - } - throw new IllegalArgumentException("Invalid Dimension Property Type!"); - } - return true; + if (value instanceof DimensionProperty.DimensionPropertyList list) { + DimensionProperty.DimensionPropertyList dimensionIDs = getCompleteDimensionIDs(); + if (dimensionIDs == DimensionProperty.DimensionPropertyList.EMPTY_LIST) { + dimensionIDs = new DimensionProperty.DimensionPropertyList(); + this.applyProperty(DimensionProperty.getInstance(), dimensionIDs); + } + dimensionIDs.merge(list); + return true; + } + return false; } else if (key.equals(CleanroomProperty.KEY)) { if (value instanceof CleanroomType) { this.cleanroom((CleanroomType) value); @@ -1015,7 +1022,8 @@ public String toString() { .append("EUt", EUt) .append("hidden", hidden) .append("cleanroom", getCleanroom()) - .append(DimensionProperty.getInstance().getKey(), getDimensionIDs().toString()) + .append("dimensions", getDimensionIDs().toString()) + .append("dimensions_b", getBlockedDimensionIDs().toString()) .append("recipeStatus", recipeStatus) .toString(); } diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java b/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java index 1eb84ea4bed..be0dafdcff8 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java +++ b/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java @@ -2,20 +2,23 @@ import gregtech.api.worldgen.config.WorldGenRegistry; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntLists; + import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.IntList; -public class DimensionProperty extends RecipeProperty { +public class DimensionProperty extends RecipeProperty { public static final String KEY = "dimension"; private static DimensionProperty INSTANCE; private DimensionProperty() { - super(KEY, IntList.class); + super(KEY, DimensionPropertyList.class); } public static DimensionProperty getInstance() { @@ -26,8 +29,14 @@ public static DimensionProperty getInstance() { @Override public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) { - minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.dimensions", - getDimensionsForRecipe(castValue(value))), x, y, color); + DimensionPropertyList list = castValue(value); + + if (list.whiteListDimensions.size() > 0) + minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.dimensions", + getDimensionsForRecipe(castValue(value).whiteListDimensions)), x, y, color); + if (list.blackListDimensions.size() > 0) + minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.dimensions_b", + getDimensionsForRecipe(castValue(value).blackListDimensions)), x, y, color); } private static String getDimensionsForRecipe(IntList value) { @@ -45,4 +54,31 @@ private static String getDimensionsForRecipe(IntList value) { } return str; } + + // It would've been better to have one list and swap between blacklist and whitelist, but that would've been + // a bit awkward to apply to the property in practice. + public static class DimensionPropertyList { + + public static DimensionPropertyList EMPTY_LIST = new DimensionPropertyList(); + + public IntList whiteListDimensions = new IntArrayList(); + public IntList blackListDimensions = new IntArrayList(); + + public void add(int key, boolean toBlacklist) { + if (toBlacklist) blackListDimensions.add(key); + else whiteListDimensions.add(key); + } + + public void merge(DimensionPropertyList list) { + this.whiteListDimensions.addAll(list.whiteListDimensions); + this.blackListDimensions.addAll(list.blackListDimensions); + } + + public boolean checkDimension(int dim) { + boolean valid = true; + if (this.blackListDimensions.size() > 0) valid = !this.blackListDimensions.contains(dim); + if (this.whiteListDimensions.size() > 0) valid = this.whiteListDimensions.contains(dim); + return valid; + } + } } diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index 6fc2ebe2f39..0ce196ba4d3 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -5337,6 +5337,7 @@ gregtech.recipe.temperature=Temperature: %,dK (%s) gregtech.recipe.explosive=Explosive: %s gregtech.recipe.eu_to_start=Energy To Start: %sEU gregtech.recipe.dimensions=Dimensions: %s +gregtech.recipe.dimensions_b=Blocked Dimensions: %s gregtech.recipe.cleanroom=Requires %s gregtech.recipe.cleanroom.display_name=Cleanroom gregtech.recipe.cleanroom_sterile.display_name=Sterile Cleanroom From 4248ac81643d4c4499bdef5ab45484713fa901aa Mon Sep 17 00:00:00 2001 From: M-W-K Date: Wed, 13 Mar 2024 23:20:50 -0600 Subject: [PATCH 4/7] blackless --- .../gregtech/api/capability/impl/AbstractRecipeLogic.java | 1 - .../api/recipes/recipeproperties/DimensionProperty.java | 8 +++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index 36dbc09e12d..6d8877ff1dc 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -34,7 +34,6 @@ import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.items.IItemHandlerModifiable; -import it.unimi.dsi.fastutil.ints.IntLists; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java b/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java index be0dafdcff8..428f736aec6 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java +++ b/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java @@ -2,13 +2,11 @@ import gregtech.api.worldgen.config.WorldGenRegistry; -import it.unimi.dsi.fastutil.ints.IntArrayList; -import it.unimi.dsi.fastutil.ints.IntLists; - import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; public class DimensionProperty extends RecipeProperty { @@ -33,10 +31,10 @@ public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) if (list.whiteListDimensions.size() > 0) minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.dimensions", - getDimensionsForRecipe(castValue(value).whiteListDimensions)), x, y, color); + getDimensionsForRecipe(castValue(value).whiteListDimensions)), x, y, color); if (list.blackListDimensions.size() > 0) minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.dimensions_b", - getDimensionsForRecipe(castValue(value).blackListDimensions)), x, y, color); + getDimensionsForRecipe(castValue(value).blackListDimensions)), x, y, color); } private static String getDimensionsForRecipe(IntList value) { From b0a0eec1168c821d639f63ff661e75478c8ec61a Mon Sep 17 00:00:00 2001 From: M-W-K Date: Sat, 23 Mar 2024 12:30:07 -0600 Subject: [PATCH 5/7] Descriptify --- src/main/java/gregtech/api/recipes/RecipeBuilder.java | 2 +- .../api/recipes/recipeproperties/DimensionProperty.java | 2 +- src/main/resources/assets/gregtech/lang/en_us.lang | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/gregtech/api/recipes/RecipeBuilder.java b/src/main/java/gregtech/api/recipes/RecipeBuilder.java index bf4c67c074f..1b59129381a 100644 --- a/src/main/java/gregtech/api/recipes/RecipeBuilder.java +++ b/src/main/java/gregtech/api/recipes/RecipeBuilder.java @@ -1023,7 +1023,7 @@ public String toString() { .append("hidden", hidden) .append("cleanroom", getCleanroom()) .append("dimensions", getDimensionIDs().toString()) - .append("dimensions_b", getBlockedDimensionIDs().toString()) + .append("dimensions_blocked", getBlockedDimensionIDs().toString()) .append("recipeStatus", recipeStatus) .toString(); } diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java b/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java index 428f736aec6..7d8f3ce2149 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java +++ b/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java @@ -33,7 +33,7 @@ public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.dimensions", getDimensionsForRecipe(castValue(value).whiteListDimensions)), x, y, color); if (list.blackListDimensions.size() > 0) - minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.dimensions_b", + minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.dimensions_blocked", getDimensionsForRecipe(castValue(value).blackListDimensions)), x, y, color); } diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index 0ce196ba4d3..42c4c0ac26c 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -5337,7 +5337,7 @@ gregtech.recipe.temperature=Temperature: %,dK (%s) gregtech.recipe.explosive=Explosive: %s gregtech.recipe.eu_to_start=Energy To Start: %sEU gregtech.recipe.dimensions=Dimensions: %s -gregtech.recipe.dimensions_b=Blocked Dimensions: %s +gregtech.recipe.dimensions_blocked=Blocked Dimensions: %s gregtech.recipe.cleanroom=Requires %s gregtech.recipe.cleanroom.display_name=Cleanroom gregtech.recipe.cleanroom_sterile.display_name=Sterile Cleanroom From 568c57cfc66788f20fa699278b5616c8fdfc08df Mon Sep 17 00:00:00 2001 From: M-W-K Date: Wed, 27 Mar 2024 01:52:08 -0600 Subject: [PATCH 6/7] Prevent a dimension from inhabiting both lists --- .../recipes/recipeproperties/DimensionProperty.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java b/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java index 7d8f3ce2149..6a1c3cd06e1 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java +++ b/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java @@ -63,8 +63,14 @@ public static class DimensionPropertyList { public IntList blackListDimensions = new IntArrayList(); public void add(int key, boolean toBlacklist) { - if (toBlacklist) blackListDimensions.add(key); - else whiteListDimensions.add(key); + if (toBlacklist) { + blackListDimensions.add(key); + whiteListDimensions.rem(key); + } + else { + whiteListDimensions.add(key); + blackListDimensions.rem(key); + } } public void merge(DimensionPropertyList list) { From 6bed027351853189aea0bb106b97d3e2681c2024 Mon Sep 17 00:00:00 2001 From: M-W-K Date: Wed, 27 Mar 2024 01:58:29 -0600 Subject: [PATCH 7/7] (I am) listless --- .../api/recipes/recipeproperties/DimensionProperty.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java b/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java index 6a1c3cd06e1..f233e7cd7f3 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java +++ b/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java @@ -66,8 +66,7 @@ public void add(int key, boolean toBlacklist) { if (toBlacklist) { blackListDimensions.add(key); whiteListDimensions.rem(key); - } - else { + } else { whiteListDimensions.add(key); blackListDimensions.rem(key); }