From efd861770802097cb10ecb4c731d72223f131756 Mon Sep 17 00:00:00 2001 From: TechLord22 <37029404+TechLord22@users.noreply.github.com> Date: Thu, 19 Sep 2024 13:32:53 -0400 Subject: [PATCH] clean up recipe property storage (#2607) --- src/main/java/gregtech/api/GregTechAPI.java | 2 + .../api/block/IHeatingCoilBlockStats.java | 2 +- .../capability/impl/AbstractRecipeLogic.java | 26 ++-- .../impl/ComputationRecipeLogic.java | 9 +- .../api/capability/impl/FuelRecipeLogic.java | 4 +- .../impl/HeatingCoilRecipeLogic.java | 12 +- .../impl/MultiblockFuelRecipeLogic.java | 6 +- .../impl/MultiblockRecipeLogic.java | 8 +- .../capability/impl/PrimitiveRecipeLogic.java | 4 +- .../capability/impl/RecipeLogicEnergy.java | 4 +- .../java/gregtech/api/recipes/Recipe.java | 61 +++----- .../gregtech/api/recipes/RecipeBuilder.java | 95 +++++------- .../builders/AssemblyLineRecipeBuilder.java | 18 +-- .../recipes/builders/BlastRecipeBuilder.java | 9 +- .../builders/ComputationRecipeBuilder.java | 8 +- .../recipes/builders/FusionRecipeBuilder.java | 9 +- .../builders/ImplosionRecipeBuilder.java | 62 ++++---- .../builders/PrimitiveRecipeBuilder.java | 2 +- .../machines/RecipeMapAssemblyLine.java | 28 ++-- .../RecipeProperty.java | 45 ++++-- .../properties/RecipePropertyRegistry.java | 29 ++++ .../properties/RecipePropertyStorage.java | 119 +++++++++++++++ .../properties/RecipePropertyStorageImpl.java | 111 ++++++++++++++ .../impl}/CleanroomProperty.java | 29 ++-- .../impl}/ComputationProperty.java | 24 ++- .../impl}/DimensionProperty.java | 47 ++++-- .../impl}/FusionEUToStartProperty.java | 22 ++- .../impl}/ImplosionExplosiveProperty.java | 24 ++- .../impl}/PrimitiveProperty.java | 24 ++- .../impl}/ResearchProperty.java | 28 +++- .../impl}/ResearchPropertyData.java | 22 ++- .../impl}/ScanProperty.java | 20 ++- .../impl}/TemperatureProperty.java | 19 ++- .../impl}/TotalComputationProperty.java | 24 ++- .../recipeproperties/DefaultProperty.java | 19 --- .../EmptyRecipePropertyStorage.java | 65 --------- .../IRecipePropertyStorage.java | 60 -------- .../RecipePropertyStorage.java | 134 ----------------- .../gregtech/api/recipes/ui/RecipeMapUI.java | 6 +- .../api/util/AssemblyLineManager.java | 2 +- .../java/gregtech/common/CommonProxy.java | 2 +- .../electric/MetaTileEntityAssemblyLine.java | 2 +- .../electric/MetaTileEntityCrackingUnit.java | 4 +- .../MetaTileEntityElectricBlastFurnace.java | 2 +- .../electric/MetaTileEntityFusionReactor.java | 8 +- .../electric/MetaTileEntityMultiSmelter.java | 4 +- .../MetaTileEntityProcessingArray.java | 4 +- .../electric/MetaTileEntityPyrolyseOven.java | 4 +- src/main/java/gregtech/core/CoreModule.java | 2 +- .../crafttweaker/recipe/CTRecipe.java | 11 -- .../crafttweaker/recipe/CTRecipeBuilder.java | 12 +- .../integration/groovy/GroovyExpansions.java | 2 +- .../jei/basic/MaterialTreeCategory.java | 2 +- .../jei/recipe/GTRecipeWrapper.java | 29 ++-- .../jei/recipe/RecipeMapCategory.java | 8 +- .../handlers/MaterialRecipeHandler.java | 8 +- .../RecipePropertyStorageTest.java | 138 ------------------ 57 files changed, 734 insertions(+), 750 deletions(-) rename src/main/java/gregtech/api/recipes/{recipeproperties => properties}/RecipeProperty.java (62%) create mode 100644 src/main/java/gregtech/api/recipes/properties/RecipePropertyRegistry.java create mode 100644 src/main/java/gregtech/api/recipes/properties/RecipePropertyStorage.java create mode 100644 src/main/java/gregtech/api/recipes/properties/RecipePropertyStorageImpl.java rename src/main/java/gregtech/api/recipes/{recipeproperties => properties/impl}/CleanroomProperty.java (63%) rename src/main/java/gregtech/api/recipes/{recipeproperties => properties/impl}/ComputationProperty.java (53%) rename src/main/java/gregtech/api/recipes/{recipeproperties => properties/impl}/DimensionProperty.java (63%) rename src/main/java/gregtech/api/recipes/{recipeproperties => properties/impl}/FusionEUToStartProperty.java (74%) rename src/main/java/gregtech/api/recipes/{recipeproperties => properties/impl}/ImplosionExplosiveProperty.java (55%) rename src/main/java/gregtech/api/recipes/{recipeproperties => properties/impl}/PrimitiveProperty.java (55%) rename src/main/java/gregtech/api/recipes/{recipeproperties => properties/impl}/ResearchProperty.java (50%) rename src/main/java/gregtech/api/recipes/{recipeproperties => properties/impl}/ResearchPropertyData.java (66%) rename src/main/java/gregtech/api/recipes/{recipeproperties => properties/impl}/ScanProperty.java (56%) rename src/main/java/gregtech/api/recipes/{recipeproperties => properties/impl}/TemperatureProperty.java (79%) rename src/main/java/gregtech/api/recipes/{recipeproperties => properties/impl}/TotalComputationProperty.java (56%) delete mode 100644 src/main/java/gregtech/api/recipes/recipeproperties/DefaultProperty.java delete mode 100644 src/main/java/gregtech/api/recipes/recipeproperties/EmptyRecipePropertyStorage.java delete mode 100644 src/main/java/gregtech/api/recipes/recipeproperties/IRecipePropertyStorage.java delete mode 100644 src/main/java/gregtech/api/recipes/recipeproperties/RecipePropertyStorage.java delete mode 100644 src/test/java/gregtech/api/recipes/recipeproperties/RecipePropertyStorageTest.java diff --git a/src/main/java/gregtech/api/GregTechAPI.java b/src/main/java/gregtech/api/GregTechAPI.java index 01845f8b047..4e3bc8bc69c 100644 --- a/src/main/java/gregtech/api/GregTechAPI.java +++ b/src/main/java/gregtech/api/GregTechAPI.java @@ -11,6 +11,7 @@ import gregtech.api.metatileentity.registry.MTEManager; import gregtech.api.modules.IModuleManager; import gregtech.api.network.INetworkHandler; +import gregtech.api.recipes.properties.RecipePropertyRegistry; import gregtech.api.sound.ISoundManager; import gregtech.api.unification.material.Material; import gregtech.api.unification.material.registry.IMaterialRegistryManager; @@ -56,6 +57,7 @@ public class GregTechAPI { public static MTEManager mteManager; /** GT's data migrations API */ public static final MigrationAPI MIGRATIONS = new MigrationAPI(); + public static final RecipePropertyRegistry RECIPE_PROPERTIES = new RecipePropertyRegistry(); /** Will be available at the Pre-Initialization stage */ private static boolean highTier; diff --git a/src/main/java/gregtech/api/block/IHeatingCoilBlockStats.java b/src/main/java/gregtech/api/block/IHeatingCoilBlockStats.java index 5f6e5c49c06..0e2b7427591 100644 --- a/src/main/java/gregtech/api/block/IHeatingCoilBlockStats.java +++ b/src/main/java/gregtech/api/block/IHeatingCoilBlockStats.java @@ -1,6 +1,6 @@ package gregtech.api.block; -import gregtech.api.recipes.recipeproperties.TemperatureProperty; +import gregtech.api.recipes.properties.impl.TemperatureProperty; import gregtech.api.unification.material.Material; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java index ced966ccc48..455ae3afd47 100644 --- a/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java @@ -18,9 +18,9 @@ import gregtech.api.recipes.logic.IParallelableRecipeLogic; import gregtech.api.recipes.logic.OCParams; import gregtech.api.recipes.logic.OCResult; -import gregtech.api.recipes.recipeproperties.CleanroomProperty; -import gregtech.api.recipes.recipeproperties.DimensionProperty; -import gregtech.api.recipes.recipeproperties.IRecipePropertyStorage; +import gregtech.api.recipes.properties.RecipePropertyStorage; +import gregtech.api.recipes.properties.impl.CleanroomProperty; +import gregtech.api.recipes.properties.impl.DimensionProperty; import gregtech.api.util.GTLog; import gregtech.api.util.GTTransferUtils; import gregtech.api.util.GTUtility; @@ -441,9 +441,11 @@ protected boolean checkCleanroomRequirement(@NotNull Recipe recipe) { } protected boolean checkDimensionRequirement(@NotNull Recipe recipe) { - if (!recipe.hasProperty(DimensionProperty.getInstance())) return true; - return recipe.getProperty(DimensionProperty.getInstance(), DimensionProperty.DimensionPropertyList.EMPTY_LIST) - .checkDimension(this.getMetaTileEntity().getWorld().provider.getDimension()); + DimensionProperty.DimensionPropertyList list = recipe.getProperty(DimensionProperty.getInstance(), null); + if (list == null) { + return true; + } + return list.checkDimension(this.getMetaTileEntity().getWorld().provider.getDimension()); } /** @@ -682,7 +684,7 @@ protected static boolean areItemStacksEqual(@NotNull ItemStack stackA, @NotNull @NotNull IMultipleTankHandler importFluids) { calculateOverclock(recipe); - modifyOverclockPost(ocResult, recipe.getRecipePropertyStorage()); + modifyOverclockPost(ocResult, recipe.propertyStorage()); if (ocResult.parallel() > 1) { recipe = subTickOC(ocResult, recipe, importInventory, importFluids); @@ -814,7 +816,7 @@ protected boolean hasEnoughPower(long eut, int duration) { * @param ocResult The overclock result * @param storage the RecipePropertyStorage of the recipe being processed */ - protected void modifyOverclockPost(@NotNull OCResult ocResult, @NotNull IRecipePropertyStorage storage) {} + protected void modifyOverclockPost(@NotNull OCResult ocResult, @NotNull RecipePropertyStorage storage) {} /** * Calculates the overclocked Recipe's final duration and EU/t @@ -837,13 +839,13 @@ protected final void calculateOverclock(@NotNull Recipe recipe) { * @param ocResult the result of overclocking */ protected void performOverclocking(@NotNull Recipe recipe, @NotNull OCParams ocParams, @NotNull OCResult ocResult) { - modifyOverclockPre(ocParams, recipe.getRecipePropertyStorage()); + modifyOverclockPre(ocParams, recipe.propertyStorage()); if (ocParams.ocAmount() <= 0) { // number of OCs is <= 0, so do not overclock ocResult.init(ocParams.eut(), ocParams.duration()); } else { - runOverclockingLogic(ocParams, ocResult, recipe.getRecipePropertyStorage(), getMaximumOverclockVoltage()); + runOverclockingLogic(ocParams, ocResult, recipe.propertyStorage(), getMaximumOverclockVoltage()); } } @@ -873,7 +875,7 @@ protected int getNumberOfOCs(long recipeEUt) { * @param ocParams an array of [recipeEUt, recipeDuration, numberOfOCs] * @param storage the RecipePropertyStorage of the recipe being processed */ - protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull IRecipePropertyStorage storage) {} + protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull RecipePropertyStorage storage) {} /** * Calls the desired overclocking logic to be run for the recipe. Performs the actual overclocking on the provided @@ -885,7 +887,7 @@ protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull IRecipePr * @param maxVoltage the maximum voltage the recipe is allowed to be run at */ protected void runOverclockingLogic(@NotNull OCParams ocParams, @NotNull OCResult ocResult, - @NotNull IRecipePropertyStorage propertyStorage, long maxVoltage) { + @NotNull RecipePropertyStorage propertyStorage, long maxVoltage) { standardOC(ocParams, ocResult, maxVoltage, getOverclockingDurationFactor(), getOverclockingVoltageFactor()); } diff --git a/src/main/java/gregtech/api/capability/impl/ComputationRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/ComputationRecipeLogic.java index 99284729017..67c3c03fbc9 100644 --- a/src/main/java/gregtech/api/capability/impl/ComputationRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/ComputationRecipeLogic.java @@ -4,8 +4,8 @@ import gregtech.api.capability.IOpticalComputationReceiver; import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController; import gregtech.api.recipes.Recipe; -import gregtech.api.recipes.recipeproperties.ComputationProperty; -import gregtech.api.recipes.recipeproperties.TotalComputationProperty; +import gregtech.api.recipes.properties.impl.ComputationProperty; +import gregtech.api.recipes.properties.impl.TotalComputationProperty; import net.minecraft.nbt.NBTTagCompound; @@ -49,11 +49,12 @@ public boolean checkRecipe(@NotNull Recipe recipe) { if (!super.checkRecipe(recipe)) { return false; } - if (!recipe.hasProperty(ComputationProperty.getInstance())) { + int recipeCWUt = recipe.getProperty(ComputationProperty.getInstance(), 0); + if (recipeCWUt == 0) { return true; } + IOpticalComputationProvider provider = getComputationProvider(); - int recipeCWUt = recipe.getProperty(ComputationProperty.getInstance(), 0); return provider.requestCWUt(recipeCWUt, true) >= recipeCWUt; } diff --git a/src/main/java/gregtech/api/capability/impl/FuelRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/FuelRecipeLogic.java index f70ca3fcde9..26871a55d3c 100644 --- a/src/main/java/gregtech/api/capability/impl/FuelRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/FuelRecipeLogic.java @@ -6,7 +6,7 @@ import gregtech.api.recipes.RecipeMap; import gregtech.api.recipes.logic.OCParams; import gregtech.api.recipes.logic.OCResult; -import gregtech.api.recipes.recipeproperties.IRecipePropertyStorage; +import gregtech.api.recipes.properties.RecipePropertyStorage; import org.jetbrains.annotations.NotNull; @@ -40,7 +40,7 @@ protected boolean hasEnoughPower(long eut, int duration) { @Override protected void runOverclockingLogic(@NotNull OCParams ocParams, @NotNull OCResult ocResult, - @NotNull IRecipePropertyStorage propertyStorage, long maxVoltage) { + @NotNull RecipePropertyStorage propertyStorage, long maxVoltage) { standardOC(ocParams, ocResult, maxVoltage, getOverclockingDurationFactor(), getOverclockingVoltageFactor()); } diff --git a/src/main/java/gregtech/api/capability/impl/HeatingCoilRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/HeatingCoilRecipeLogic.java index 1c97891e9bb..fc9bd216d55 100644 --- a/src/main/java/gregtech/api/capability/impl/HeatingCoilRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/HeatingCoilRecipeLogic.java @@ -5,8 +5,8 @@ import gregtech.api.recipes.logic.OCParams; import gregtech.api.recipes.logic.OCResult; import gregtech.api.recipes.logic.OverclockingLogic; -import gregtech.api.recipes.recipeproperties.IRecipePropertyStorage; -import gregtech.api.recipes.recipeproperties.TemperatureProperty; +import gregtech.api.recipes.properties.RecipePropertyStorage; +import gregtech.api.recipes.properties.impl.TemperatureProperty; import org.jetbrains.annotations.NotNull; @@ -26,18 +26,18 @@ public HeatingCoilRecipeLogic(RecipeMapMultiblockController metaTileEntity) { } @Override - protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull IRecipePropertyStorage storage) { + protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull RecipePropertyStorage storage) { super.modifyOverclockPre(ocParams, storage); // coil EU/t discount ocParams.setEut(OverclockingLogic.applyCoilEUtDiscount(ocParams.eut(), ((IHeatingCoil) metaTileEntity).getCurrentTemperature(), - storage.getRecipePropertyValue(TemperatureProperty.getInstance(), 0))); + storage.get(TemperatureProperty.getInstance(), 0))); } @Override protected void runOverclockingLogic(@NotNull OCParams ocParams, @NotNull OCResult ocResult, - @NotNull IRecipePropertyStorage propertyStorage, long maxVoltage) { + @NotNull RecipePropertyStorage propertyStorage, long maxVoltage) { heatingCoilOC(ocParams, ocResult, maxVoltage, ((IHeatingCoil) metaTileEntity).getCurrentTemperature(), - propertyStorage.getRecipePropertyValue(TemperatureProperty.getInstance(), 0)); + propertyStorage.get(TemperatureProperty.getInstance(), 0)); } } diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockFuelRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockFuelRecipeLogic.java index 746593f366a..30c5e5410e3 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockFuelRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockFuelRecipeLogic.java @@ -8,7 +8,7 @@ import gregtech.api.recipes.Recipe; import gregtech.api.recipes.logic.OCParams; import gregtech.api.recipes.logic.OCResult; -import gregtech.api.recipes.recipeproperties.IRecipePropertyStorage; +import gregtech.api.recipes.properties.RecipePropertyStorage; import gregtech.api.util.GTUtility; import gregtech.api.util.TextFormattingUtil; @@ -29,7 +29,7 @@ public MultiblockFuelRecipeLogic(RecipeMapMultiblockController tileEntity) { } @Override - protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull IRecipePropertyStorage storage) { + protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull RecipePropertyStorage storage) { // apply maintenance bonuses Tuple maintenanceValues = getMaintenanceValues(); @@ -40,7 +40,7 @@ protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull IRecipePr } @Override - protected void modifyOverclockPost(@NotNull OCResult ocResult, @NotNull IRecipePropertyStorage storage) { + protected void modifyOverclockPost(@NotNull OCResult ocResult, @NotNull RecipePropertyStorage storage) { // apply maintenance penalties Tuple maintenanceValues = getMaintenanceValues(); diff --git a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java index 200f92ca873..ff95f0fbb0c 100644 --- a/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java @@ -12,7 +12,7 @@ import gregtech.api.recipes.RecipeMap; import gregtech.api.recipes.logic.OCParams; import gregtech.api.recipes.logic.OCResult; -import gregtech.api.recipes.recipeproperties.IRecipePropertyStorage; +import gregtech.api.recipes.properties.RecipePropertyStorage; import gregtech.api.util.GTUtility; import gregtech.common.ConfigHolder; @@ -281,7 +281,7 @@ protected boolean prepareRecipeDistinct(Recipe recipe) { } @Override - protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull IRecipePropertyStorage storage) { + protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull RecipePropertyStorage storage) { super.modifyOverclockPre(ocParams, storage); // apply maintenance bonuses @@ -295,13 +295,13 @@ protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull IRecipePr @Override protected void runOverclockingLogic(@NotNull OCParams ocParams, @NotNull OCResult ocResult, - @NotNull IRecipePropertyStorage propertyStorage, long maxVoltage) { + @NotNull RecipePropertyStorage propertyStorage, long maxVoltage) { subTickParallelOC(ocParams, ocResult, maxVoltage, getOverclockingDurationFactor(), getOverclockingVoltageFactor()); } @Override - protected void modifyOverclockPost(@NotNull OCResult ocResult, @NotNull IRecipePropertyStorage storage) { + protected void modifyOverclockPost(@NotNull OCResult ocResult, @NotNull RecipePropertyStorage storage) { super.modifyOverclockPost(ocResult, storage); // apply maintenance penalties diff --git a/src/main/java/gregtech/api/capability/impl/PrimitiveRecipeLogic.java b/src/main/java/gregtech/api/capability/impl/PrimitiveRecipeLogic.java index d1893fa8f84..40e4f13ca43 100644 --- a/src/main/java/gregtech/api/capability/impl/PrimitiveRecipeLogic.java +++ b/src/main/java/gregtech/api/capability/impl/PrimitiveRecipeLogic.java @@ -5,7 +5,7 @@ import gregtech.api.recipes.RecipeMap; import gregtech.api.recipes.logic.OCParams; import gregtech.api.recipes.logic.OCResult; -import gregtech.api.recipes.recipeproperties.IRecipePropertyStorage; +import gregtech.api.recipes.properties.RecipePropertyStorage; import org.jetbrains.annotations.NotNull; @@ -50,7 +50,7 @@ public long getMaxVoltage() { @Override protected void runOverclockingLogic(@NotNull OCParams ocParams, @NotNull OCResult ocResult, - @NotNull IRecipePropertyStorage propertyStorage, long maxVoltage) { + @NotNull RecipePropertyStorage propertyStorage, long maxVoltage) { ocParams.setEut(1L); super.runOverclockingLogic(ocParams, ocResult, propertyStorage, maxVoltage); } diff --git a/src/main/java/gregtech/api/capability/impl/RecipeLogicEnergy.java b/src/main/java/gregtech/api/capability/impl/RecipeLogicEnergy.java index 4e62346dcf2..8460b2a7aa7 100644 --- a/src/main/java/gregtech/api/capability/impl/RecipeLogicEnergy.java +++ b/src/main/java/gregtech/api/capability/impl/RecipeLogicEnergy.java @@ -5,7 +5,7 @@ import gregtech.api.recipes.RecipeMap; import gregtech.api.recipes.logic.OCParams; import gregtech.api.recipes.logic.OCResult; -import gregtech.api.recipes.recipeproperties.IRecipePropertyStorage; +import gregtech.api.recipes.properties.RecipePropertyStorage; import org.jetbrains.annotations.NotNull; @@ -56,7 +56,7 @@ public long getMaxVoltage() { @Override protected void runOverclockingLogic(@NotNull OCParams ocParams, @NotNull OCResult ocResult, - @NotNull IRecipePropertyStorage propertyStorage, long maxVoltage) { + @NotNull RecipePropertyStorage propertyStorage, long maxVoltage) { subTickNonParallelOC(ocParams, ocResult, maxVoltage, getOverclockingDurationFactor(), getOverclockingVoltageFactor()); } diff --git a/src/main/java/gregtech/api/recipes/Recipe.java b/src/main/java/gregtech/api/recipes/Recipe.java index 923c463e0c4..ff495651ac5 100644 --- a/src/main/java/gregtech/api/recipes/Recipe.java +++ b/src/main/java/gregtech/api/recipes/Recipe.java @@ -8,9 +8,9 @@ import gregtech.api.recipes.chance.output.impl.ChancedFluidOutput; import gregtech.api.recipes.chance.output.impl.ChancedItemOutput; import gregtech.api.recipes.ingredients.GTRecipeInput; -import gregtech.api.recipes.recipeproperties.EmptyRecipePropertyStorage; -import gregtech.api.recipes.recipeproperties.IRecipePropertyStorage; -import gregtech.api.recipes.recipeproperties.RecipeProperty; +import gregtech.api.recipes.properties.RecipeProperty; +import gregtech.api.recipes.properties.RecipePropertyStorage; +import gregtech.api.recipes.properties.RecipePropertyStorageImpl; import gregtech.api.util.GTUtility; import gregtech.api.util.ItemStackHashStrategy; import gregtech.integration.groovy.GroovyScriptModule; @@ -26,15 +26,15 @@ import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.tuple.Pair; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.Set; /** * Class that represent machine recipe. @@ -99,7 +99,7 @@ public static int getMaxChancedValue() { // TODO YEET private final boolean isCTRecipe; private final boolean groovyRecipe; - private final IRecipePropertyStorage recipePropertyStorage; + private final RecipePropertyStorage recipePropertyStorage; private final int hashCode; @@ -113,10 +113,9 @@ public Recipe(@NotNull List inputs, long EUt, boolean hidden, boolean isCTRecipe, - IRecipePropertyStorage recipePropertyStorage, + @NotNull RecipePropertyStorage recipePropertyStorage, @NotNull GTRecipeCategory recipeCategory) { - this.recipePropertyStorage = recipePropertyStorage == null ? EmptyRecipePropertyStorage.INSTANCE : - recipePropertyStorage; + this.recipePropertyStorage = recipePropertyStorage; this.inputs = GTRecipeInputCache.deduplicateInputs(inputs); if (outputs.isEmpty()) { this.outputs = Collections.emptyList(); @@ -742,40 +741,26 @@ public GTRecipeCategory getRecipeCategory() { /////////////////////////////////////////////////////////// // Property Helper Methods // /////////////////////////////////////////////////////////// - public T getProperty(RecipeProperty property, T defaultValue) { - return recipePropertyStorage.getRecipePropertyValue(property, defaultValue); - } - - public Object getPropertyRaw(String key) { - return recipePropertyStorage.getRawRecipePropertyValue(key); - } - - public Set, Object>> getPropertyValues() { - return recipePropertyStorage.getRecipeProperties(); - } - - public Set getPropertyKeys() { - return recipePropertyStorage.getRecipePropertyKeys(); - } - - public Set> getPropertyTypes() { - return recipePropertyStorage.getPropertyTypes(); - } - public boolean hasProperty(RecipeProperty property) { - return recipePropertyStorage.hasRecipeProperty(property); - } - - public int getPropertyCount() { - return recipePropertyStorage.getSize(); + /** + * @see RecipePropertyStorageImpl#get(RecipeProperty, Object) + */ + @Contract("_, !null -> !null") + public @Nullable T getProperty(@NotNull RecipeProperty property, @Nullable T defaultValue) { + return recipePropertyStorage.get(property, defaultValue); } - public int getUnhiddenPropertyCount() { - return (int) recipePropertyStorage.getRecipeProperties().stream() - .filter((property) -> !property.getKey().isHidden()).count(); + /** + * @see RecipePropertyStorageImpl#contains(RecipeProperty) + */ + public boolean hasProperty(@NotNull RecipeProperty property) { + return recipePropertyStorage.contains(property); } - public IRecipePropertyStorage getRecipePropertyStorage() { + /** + * @return the property storage + */ + public @NotNull RecipePropertyStorage propertyStorage() { return recipePropertyStorage; } } diff --git a/src/main/java/gregtech/api/recipes/RecipeBuilder.java b/src/main/java/gregtech/api/recipes/RecipeBuilder.java index b57b8c25db4..0a6f07ee6e7 100644 --- a/src/main/java/gregtech/api/recipes/RecipeBuilder.java +++ b/src/main/java/gregtech/api/recipes/RecipeBuilder.java @@ -16,11 +16,11 @@ import gregtech.api.recipes.ingredients.IntCircuitIngredient; 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; +import gregtech.api.recipes.properties.RecipeProperty; +import gregtech.api.recipes.properties.RecipePropertyStorage; +import gregtech.api.recipes.properties.RecipePropertyStorageImpl; +import gregtech.api.recipes.properties.impl.CleanroomProperty; +import gregtech.api.recipes.properties.impl.DimensionProperty; import gregtech.api.unification.OreDictUnifier; import gregtech.api.unification.material.Material; import gregtech.api.unification.ore.OrePrefix; @@ -44,7 +44,6 @@ import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient; import crafttweaker.CraftTweakerAPI; 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.ApiStatus; import org.jetbrains.annotations.MustBeInvokedByOverriders; @@ -84,7 +83,7 @@ public class RecipeBuilder> { protected boolean isCTRecipe = false; protected int parallel = 0; protected EnumValidationResult recipeStatus = EnumValidationResult.VALID; - protected @Nullable IRecipePropertyStorage recipePropertyStorage = null; + protected RecipePropertyStorage recipePropertyStorage = RecipePropertyStorage.EMPTY; protected boolean recipePropertyStorageErrored = false; protected RecipeBuilder() { @@ -108,10 +107,7 @@ public RecipeBuilder(Recipe recipe, RecipeMap recipeMap) { this.EUt = recipe.getEUt(); this.hidden = recipe.isHidden(); this.category = recipe.getRecipeCategory(); - this.recipePropertyStorage = recipe.getRecipePropertyStorage().copy(); - if (this.recipePropertyStorage != null) { - this.recipePropertyStorage.freeze(false); - } + this.recipePropertyStorage = recipe.propertyStorage().copy(); } @SuppressWarnings("CopyConstructorMissesField") @@ -129,11 +125,7 @@ protected RecipeBuilder(RecipeBuilder recipeBuilder) { this.EUt = recipeBuilder.EUt; this.hidden = recipeBuilder.hidden; this.category = recipeBuilder.category; - this.recipePropertyStorage = recipeBuilder.recipePropertyStorage == null ? null : - recipeBuilder.recipePropertyStorage.copy(); - if (this.recipePropertyStorage != null) { - this.recipePropertyStorage = this.recipePropertyStorage.copy(); - } + this.recipePropertyStorage = recipeBuilder.recipePropertyStorage.copy(); } public R cleanroom(@Nullable CleanroomType cleanroom) { @@ -150,7 +142,7 @@ public R dimension(int dimensionID) { public R dimension(int dimensionID, boolean toBlackList) { DimensionProperty.DimensionPropertyList dimensionIDs = getCompleteDimensionIDs(); - if (dimensionIDs == DimensionProperty.DimensionPropertyList.EMPTY_LIST) { + if (dimensionIDs == null) { dimensionIDs = new DimensionProperty.DimensionPropertyList(); this.applyProperty(DimensionProperty.getInstance(), dimensionIDs); } @@ -158,29 +150,26 @@ public R dimension(int dimensionID, boolean 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 @Nullable DimensionProperty.DimensionPropertyList getCompleteDimensionIDs() { + return this.recipePropertyStorage.get(DimensionProperty.getInstance(), null); } - public IntList getDimensionIDs() { - return this.recipePropertyStorage == null ? IntLists.EMPTY_LIST : - this.recipePropertyStorage.getRecipePropertyValue(DimensionProperty.getInstance(), - DimensionProperty.DimensionPropertyList.EMPTY_LIST).whiteListDimensions; + public @NotNull IntList getDimensionIDs() { + return this.recipePropertyStorage.get(DimensionProperty.getInstance(), + 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 @NotNull IntList getBlockedDimensionIDs() { + return this.recipePropertyStorage.get(DimensionProperty.getInstance(), + DimensionProperty.DimensionPropertyList.EMPTY_LIST).blackListDimensions; } - public boolean applyProperty(@NotNull String key, @Nullable Object value) { + @MustBeInvokedByOverriders + public boolean applyPropertyCT(@NotNull String key, @NotNull Object value) { if (key.equals(DimensionProperty.KEY)) { if (value instanceof DimensionProperty.DimensionPropertyList list) { DimensionProperty.DimensionPropertyList dimensionIDs = getCompleteDimensionIDs(); - if (dimensionIDs == DimensionProperty.DimensionPropertyList.EMPTY_LIST) { + if (dimensionIDs == null) { dimensionIDs = new DimensionProperty.DimensionPropertyList(); this.applyProperty(DimensionProperty.getInstance(), dimensionIDs); } @@ -201,22 +190,16 @@ public boolean applyProperty(@NotNull String key, @Nullable Object value) { return false; } - public boolean applyProperty(@NotNull RecipeProperty property, @Nullable Object value) { - if (value == null) { - if (this.recipePropertyStorage != null) { - return this.recipePropertyStorage.remove(property); - } - } else { - if (this.recipePropertyStorage == null) { - this.recipePropertyStorage = new RecipePropertyStorage(); - } - boolean stored = this.recipePropertyStorage.store(property, value); - if (!stored) { - this.recipePropertyStorageErrored = true; - } - return stored; + public final boolean applyProperty(@NotNull RecipeProperty property, @NotNull Object value) { + if (this.recipePropertyStorage == RecipePropertyStorage.EMPTY) { + this.recipePropertyStorage = new RecipePropertyStorageImpl(); + } + + boolean stored = this.recipePropertyStorage.store(property, value); + if (!stored) { + this.recipePropertyStorageErrored = true; } - return true; + return stored; } public R input(GTRecipeInput input) { @@ -791,8 +774,8 @@ public void chancedOutputsMultiply(Recipe chancedOutputsFrom, int numberOfOperat */ public R append(Recipe recipe, int multiplier, boolean multiplyDuration) { - for (Map.Entry, Object> property : recipe.getPropertyValues()) { - this.applyProperty(property.getKey().getKey(), property.getValue()); + for (Map.Entry, Object> property : recipe.propertyStorage().entrySet()) { + this.applyPropertyCT(property.getKey().getKey(), property.getValue()); } // Create holders for the various parts of the new multiplied Recipe @@ -905,12 +888,9 @@ public R copy() { return (R) new RecipeBuilder<>(this); } - protected EnumValidationResult finalizeAndValidate() { - return recipePropertyStorageErrored ? EnumValidationResult.INVALID : validate(); - } - public ValidationResult build() { - return ValidationResult.newResult(finalizeAndValidate(), new Recipe(inputs, outputs, + EnumValidationResult result = recipePropertyStorageErrored ? EnumValidationResult.INVALID : validate(); + return ValidationResult.newResult(result, new Recipe(inputs, outputs, new ChancedOutputList<>(this.chancedOutputLogic, chancedOutputs), fluidInputs, fluidOutputs, new ChancedOutputList<>(this.chancedFluidOutputLogic, chancedFluidOutputs), @@ -956,9 +936,6 @@ protected EnumValidationResult validate() { if (recipeStatus == EnumValidationResult.INVALID) { GTLog.logger.error("Invalid recipe, read the errors above: {}", this); } - if (recipePropertyStorage != null) { - recipePropertyStorage.freeze(true); - } return recipeStatus; } @@ -1067,10 +1044,8 @@ public int getDuration() { return duration; } - @Nullable - public CleanroomType getCleanroom() { - return this.recipePropertyStorage == null ? null : - this.recipePropertyStorage.getRecipePropertyValue(CleanroomProperty.getInstance(), null); + public @Nullable CleanroomType getCleanroom() { + return this.recipePropertyStorage.get(CleanroomProperty.getInstance(), null); } @Override diff --git a/src/main/java/gregtech/api/recipes/builders/AssemblyLineRecipeBuilder.java b/src/main/java/gregtech/api/recipes/builders/AssemblyLineRecipeBuilder.java index 40a23a261ff..dc711dd0a0a 100644 --- a/src/main/java/gregtech/api/recipes/builders/AssemblyLineRecipeBuilder.java +++ b/src/main/java/gregtech/api/recipes/builders/AssemblyLineRecipeBuilder.java @@ -4,8 +4,8 @@ import gregtech.api.recipes.Recipe; import gregtech.api.recipes.RecipeBuilder; import gregtech.api.recipes.RecipeMap; -import gregtech.api.recipes.recipeproperties.ResearchProperty; -import gregtech.api.recipes.recipeproperties.ResearchPropertyData; +import gregtech.api.recipes.properties.impl.ResearchProperty; +import gregtech.api.recipes.properties.impl.ResearchPropertyData; import gregtech.api.util.AssemblyLineManager; import gregtech.api.util.EnumValidationResult; import gregtech.api.util.GTLog; @@ -14,7 +14,6 @@ import net.minecraft.item.ItemStack; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -45,14 +44,15 @@ public AssemblyLineRecipeBuilder copy() { } @Override - public boolean applyProperty(@NotNull String key, @Nullable Object value) { + public boolean applyPropertyCT(@NotNull String key, @NotNull Object value) { if (key.equals(ResearchProperty.KEY)) { if (value instanceof ItemStack itemStack) { scannerResearch(itemStack); return true; } + return false; } - return super.applyProperty(key, value); + return super.applyPropertyCT(key, value); } private boolean applyResearchProperty(ResearchPropertyData.ResearchEntry researchEntry) { @@ -70,15 +70,13 @@ private boolean applyResearchProperty(ResearchPropertyData.ResearchEntry researc return false; } - if (recipePropertyStorage != null && recipePropertyStorage.hasRecipeProperty(ResearchProperty.getInstance())) { - ResearchPropertyData property = recipePropertyStorage.getRecipePropertyValue(ResearchProperty.getInstance(), - null); - if (property == null) throw new IllegalStateException("Property storage has a null property"); + ResearchPropertyData property = recipePropertyStorage.get(ResearchProperty.getInstance(), null); + if (property != null) { property.add(researchEntry); return true; } - ResearchPropertyData property = new ResearchPropertyData(); + property = new ResearchPropertyData(); if (applyProperty(ResearchProperty.getInstance(), property)) { property.add(researchEntry); return true; diff --git a/src/main/java/gregtech/api/recipes/builders/BlastRecipeBuilder.java b/src/main/java/gregtech/api/recipes/builders/BlastRecipeBuilder.java index 8aa2bd236cc..c5bf92c5e16 100644 --- a/src/main/java/gregtech/api/recipes/builders/BlastRecipeBuilder.java +++ b/src/main/java/gregtech/api/recipes/builders/BlastRecipeBuilder.java @@ -3,7 +3,7 @@ import gregtech.api.recipes.Recipe; import gregtech.api.recipes.RecipeBuilder; import gregtech.api.recipes.RecipeMap; -import gregtech.api.recipes.recipeproperties.TemperatureProperty; +import gregtech.api.recipes.properties.impl.TemperatureProperty; import gregtech.api.util.EnumValidationResult; import gregtech.api.util.GTLog; @@ -28,12 +28,12 @@ public BlastRecipeBuilder copy() { } @Override - public boolean applyProperty(@NotNull String key, Object value) { + public boolean applyPropertyCT(@NotNull String key, @NotNull Object value) { if (key.equals(TemperatureProperty.KEY)) { this.blastFurnaceTemp(((Number) value).intValue()); return true; } - return super.applyProperty(key, value); + return super.applyPropertyCT(key, value); } public BlastRecipeBuilder blastFurnaceTemp(int blastFurnaceTemp) { @@ -47,8 +47,7 @@ public BlastRecipeBuilder blastFurnaceTemp(int blastFurnaceTemp) { } public int getBlastFurnaceTemp() { - return this.recipePropertyStorage == null ? 0 : - this.recipePropertyStorage.getRecipePropertyValue(TemperatureProperty.getInstance(), 0); + return this.recipePropertyStorage.get(TemperatureProperty.getInstance(), 0); } @Override diff --git a/src/main/java/gregtech/api/recipes/builders/ComputationRecipeBuilder.java b/src/main/java/gregtech/api/recipes/builders/ComputationRecipeBuilder.java index 2da0309972a..1d6c49a75d8 100644 --- a/src/main/java/gregtech/api/recipes/builders/ComputationRecipeBuilder.java +++ b/src/main/java/gregtech/api/recipes/builders/ComputationRecipeBuilder.java @@ -3,8 +3,8 @@ import gregtech.api.recipes.Recipe; import gregtech.api.recipes.RecipeBuilder; import gregtech.api.recipes.RecipeMap; -import gregtech.api.recipes.recipeproperties.ComputationProperty; -import gregtech.api.recipes.recipeproperties.TotalComputationProperty; +import gregtech.api.recipes.properties.impl.ComputationProperty; +import gregtech.api.recipes.properties.impl.TotalComputationProperty; import gregtech.api.util.EnumValidationResult; import gregtech.api.util.GTLog; @@ -28,7 +28,7 @@ public ComputationRecipeBuilder copy() { } @Override - public boolean applyProperty(@NotNull String key, Object value) { + public boolean applyPropertyCT(@NotNull String key, @NotNull Object value) { if (key.equals(ComputationProperty.KEY)) { this.CWUt(((Number) value).intValue()); return true; @@ -37,7 +37,7 @@ public boolean applyProperty(@NotNull String key, Object value) { this.totalCWU(((Number) value).intValue()); return true; } - return super.applyProperty(key, value); + return super.applyPropertyCT(key, value); } public ComputationRecipeBuilder CWUt(int cwut) { diff --git a/src/main/java/gregtech/api/recipes/builders/FusionRecipeBuilder.java b/src/main/java/gregtech/api/recipes/builders/FusionRecipeBuilder.java index a6f56e1420a..91622a9950c 100644 --- a/src/main/java/gregtech/api/recipes/builders/FusionRecipeBuilder.java +++ b/src/main/java/gregtech/api/recipes/builders/FusionRecipeBuilder.java @@ -3,7 +3,7 @@ import gregtech.api.recipes.Recipe; import gregtech.api.recipes.RecipeBuilder; import gregtech.api.recipes.RecipeMap; -import gregtech.api.recipes.recipeproperties.FusionEUToStartProperty; +import gregtech.api.recipes.properties.impl.FusionEUToStartProperty; import gregtech.api.util.EnumValidationResult; import gregtech.api.util.GTLog; @@ -28,12 +28,12 @@ public FusionRecipeBuilder copy() { } @Override - public boolean applyProperty(@NotNull String key, Object value) { + public boolean applyPropertyCT(@NotNull String key, @NotNull Object value) { if (key.equals(FusionEUToStartProperty.KEY)) { this.EUToStart(((Number) value).longValue()); return true; } - return super.applyProperty(key, value); + return super.applyPropertyCT(key, value); } public FusionRecipeBuilder EUToStart(long EUToStart) { @@ -46,8 +46,7 @@ public FusionRecipeBuilder EUToStart(long EUToStart) { } public long getEUToStart() { - return this.recipePropertyStorage == null ? 0L : - this.recipePropertyStorage.getRecipePropertyValue(FusionEUToStartProperty.getInstance(), 0L); + return this.recipePropertyStorage.get(FusionEUToStartProperty.getInstance(), 0L); } @Override diff --git a/src/main/java/gregtech/api/recipes/builders/ImplosionRecipeBuilder.java b/src/main/java/gregtech/api/recipes/builders/ImplosionRecipeBuilder.java index 3ada0e83415..ce078b9751b 100644 --- a/src/main/java/gregtech/api/recipes/builders/ImplosionRecipeBuilder.java +++ b/src/main/java/gregtech/api/recipes/builders/ImplosionRecipeBuilder.java @@ -4,10 +4,9 @@ import gregtech.api.recipes.RecipeBuilder; import gregtech.api.recipes.RecipeMap; import gregtech.api.recipes.ingredients.GTRecipeItemInput; -import gregtech.api.recipes.recipeproperties.ImplosionExplosiveProperty; +import gregtech.api.recipes.properties.impl.ImplosionExplosiveProperty; import gregtech.api.util.EnumValidationResult; import gregtech.api.util.GTLog; -import gregtech.api.util.ValidationResult; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; @@ -34,61 +33,52 @@ public ImplosionRecipeBuilder copy() { } @Override - public boolean applyProperty(@NotNull String key, Object value) { + public boolean applyPropertyCT(@NotNull String key, @NotNull Object value) { if (key.equals(ImplosionExplosiveProperty.KEY)) { - if (value instanceof ItemStack) { - this.applyProperty(ImplosionExplosiveProperty.getInstance(), value); - } else { - this.applyProperty(ImplosionExplosiveProperty.getInstance(), new ItemStack(Blocks.TNT, (int) value)); + if (value instanceof ItemStack stack) { + return this.applyProperty(ImplosionExplosiveProperty.getInstance(), stack); + } else if (value instanceof Number number) { + return this.applyProperty(ImplosionExplosiveProperty.getInstance(), number.intValue()); } - return true; + return false; } - return super.applyProperty(key, value); + return super.applyPropertyCT(key, value); } @ZenMethod - public ImplosionRecipeBuilder explosivesAmount(int explosivesAmount) { - if (1 > explosivesAmount || explosivesAmount > 64) { - GTLog.logger.error("Amount of explosives should be from 1 to 64 inclusive", new Throwable()); - recipeStatus = EnumValidationResult.INVALID; - } - this.applyProperty(ImplosionExplosiveProperty.getInstance(), new ItemStack(Blocks.TNT, explosivesAmount)); - return this; + public ImplosionRecipeBuilder explosives(int amount) { + return explosives(new ItemStack(Blocks.TNT, amount)); } @ZenMethod - public ImplosionRecipeBuilder explosivesType(ItemStack explosivesType) { - if (1 > explosivesType.getCount() || explosivesType.getCount() > 64) { + public ImplosionRecipeBuilder explosives(@NotNull ItemStack explosive) { + if (explosive.isEmpty()) { + GTLog.logger.error("Cannot use empty explosives", new Throwable()); + this.recipeStatus = EnumValidationResult.INVALID; + return this; + } + + int count = explosive.getCount(); + if (count < 1 || count > 64) { GTLog.logger.error("Amount of explosives should be from 1 to 64 inclusive", new Throwable()); recipeStatus = EnumValidationResult.INVALID; + return this; } - this.applyProperty(ImplosionExplosiveProperty.getInstance(), explosivesType); - return this; - } - - public ItemStack getExplosivesType() { - if (this.recipePropertyStorage == null) { - return ItemStack.EMPTY; + if (this.applyProperty(ImplosionExplosiveProperty.getInstance(), explosive)) { + this.inputs.add(new GTRecipeItemInput(explosive)); } - return this.recipePropertyStorage.getRecipePropertyValue(ImplosionExplosiveProperty.getInstance(), - ItemStack.EMPTY); + return this; } - public ValidationResult build() { - ItemStack explosivesType = getExplosivesType(); - if (!explosivesType.isEmpty()) { - this.inputs.add(new GTRecipeItemInput(explosivesType)); - } else { - this.recipePropertyStorageErrored = true; - } - return super.build(); + public @NotNull ItemStack getExplosives() { + return this.recipePropertyStorage.get(ImplosionExplosiveProperty.getInstance(), ItemStack.EMPTY); } @Override public String toString() { return new ToStringBuilder(this) .appendSuper(super.toString()) - .append(ImplosionExplosiveProperty.getInstance().getKey(), getExplosivesType()) + .append(ImplosionExplosiveProperty.getInstance().getKey(), getExplosives()) .toString(); } } diff --git a/src/main/java/gregtech/api/recipes/builders/PrimitiveRecipeBuilder.java b/src/main/java/gregtech/api/recipes/builders/PrimitiveRecipeBuilder.java index 858a94d1177..ec0e8cf2202 100644 --- a/src/main/java/gregtech/api/recipes/builders/PrimitiveRecipeBuilder.java +++ b/src/main/java/gregtech/api/recipes/builders/PrimitiveRecipeBuilder.java @@ -3,7 +3,7 @@ import gregtech.api.recipes.Recipe; import gregtech.api.recipes.RecipeBuilder; import gregtech.api.recipes.RecipeMap; -import gregtech.api.recipes.recipeproperties.PrimitiveProperty; +import gregtech.api.recipes.properties.impl.PrimitiveProperty; import gregtech.api.util.ValidationResult; public class PrimitiveRecipeBuilder extends RecipeBuilder { diff --git a/src/main/java/gregtech/api/recipes/machines/RecipeMapAssemblyLine.java b/src/main/java/gregtech/api/recipes/machines/RecipeMapAssemblyLine.java index 5c23b88f6a2..d1d8301a3c7 100644 --- a/src/main/java/gregtech/api/recipes/machines/RecipeMapAssemblyLine.java +++ b/src/main/java/gregtech/api/recipes/machines/RecipeMapAssemblyLine.java @@ -3,8 +3,8 @@ import gregtech.api.recipes.Recipe; import gregtech.api.recipes.RecipeBuilder; import gregtech.api.recipes.RecipeMap; -import gregtech.api.recipes.recipeproperties.ResearchProperty; -import gregtech.api.recipes.recipeproperties.ResearchPropertyData; +import gregtech.api.recipes.properties.impl.ResearchProperty; +import gregtech.api.recipes.properties.impl.ResearchPropertyData; import gregtech.api.recipes.ui.RecipeMapUIFunction; import gregtech.core.sound.GTSoundEvents; @@ -32,15 +32,11 @@ public RecipeMapAssemblyLine(@NotNull String unlocalizedName, @NotNull R default @Override public boolean compileRecipe(Recipe recipe) { if (!super.compileRecipe(recipe)) return false; - if (recipe.hasProperty(ResearchProperty.getInstance())) { - ResearchPropertyData data = recipe.getProperty(ResearchProperty.getInstance(), null); - if (data != null) { - for (ResearchPropertyData.ResearchEntry entry : data) { - addDataStickEntry(entry.getResearchId(), recipe); - } - return true; + ResearchPropertyData data = recipe.getProperty(ResearchProperty.getInstance(), null); + if (data != null) { + for (ResearchPropertyData.ResearchEntry entry : data) { + addDataStickEntry(entry.researchId(), recipe); } - return false; } return true; } @@ -48,15 +44,11 @@ public boolean compileRecipe(Recipe recipe) { @Override public boolean removeRecipe(@NotNull Recipe recipe) { if (!super.removeRecipe(recipe)) return false; - if (recipe.hasProperty(ResearchProperty.getInstance())) { - ResearchPropertyData data = recipe.getProperty(ResearchProperty.getInstance(), null); - if (data != null) { - for (ResearchPropertyData.ResearchEntry entry : data) { - removeDataStickEntry(entry.getResearchId(), recipe); - } - return true; + ResearchPropertyData data = recipe.getProperty(ResearchProperty.getInstance(), null); + if (data != null) { + for (ResearchPropertyData.ResearchEntry entry : data) { + removeDataStickEntry(entry.researchId(), recipe); } - return false; } return true; } diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/RecipeProperty.java b/src/main/java/gregtech/api/recipes/properties/RecipeProperty.java similarity index 62% rename from src/main/java/gregtech/api/recipes/recipeproperties/RecipeProperty.java rename to src/main/java/gregtech/api/recipes/properties/RecipeProperty.java index 9dde81bb195..bb54c07603f 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/RecipeProperty.java +++ b/src/main/java/gregtech/api/recipes/properties/RecipeProperty.java @@ -1,11 +1,13 @@ -package gregtech.api.recipes.recipeproperties; +package gregtech.api.recipes.properties; import net.minecraft.client.Minecraft; +import net.minecraft.nbt.NBTBase; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import org.jetbrains.annotations.NotNull; + import java.util.List; -import java.util.Objects; public abstract class RecipeProperty { @@ -17,6 +19,18 @@ protected RecipeProperty(String key, Class type) { this.type = type; } + /** + * @param value the value to serialize + * @return the serialized form of the value + */ + public abstract @NotNull NBTBase serialize(@NotNull Object value); + + /** + * @param nbt the nbt to deserialize + * @return the deserialized property value + */ + public abstract @NotNull Object deserialize(@NotNull NBTBase nbt); + @SideOnly(Side.CLIENT) public abstract void drawInfo(Minecraft minecraft, int x, int y, int color, Object value); @@ -28,19 +42,15 @@ public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value, @SideOnly(Side.CLIENT) public void getTooltipStrings(List tooltip, int mouseX, int mouseY, Object value) {} - public int getInfoHeight(Object value) { + public int getInfoHeight(@NotNull Object value) { return 10; // GTRecipeWrapper#LINE_HEIGHT } - public boolean isOfType(Class otherType) { - return this.type == otherType; - } - - public String getKey() { + public final @NotNull String getKey() { return key; } - public T castValue(Object value) { + protected final T castValue(@NotNull Object value) { return this.type.cast(value); } @@ -75,15 +85,20 @@ public boolean hideDuration() { } @Override - public boolean equals(Object o) { + public final boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RecipeProperty that = (RecipeProperty) o; - return Objects.equals(type, that.type) && Objects.equals(key, that.key); + if (!(o instanceof RecipePropertythat)) return false; + + return type.equals(that.type) && getKey().equals(that.getKey()); + } + + @Override + public final int hashCode() { + return 31 * type.hashCode() + getKey().hashCode(); } @Override - public int hashCode() { - return Objects.hash(type, key); + public String toString() { + return "RecipeProperty{" + "key='" + key + "'}"; } } diff --git a/src/main/java/gregtech/api/recipes/properties/RecipePropertyRegistry.java b/src/main/java/gregtech/api/recipes/properties/RecipePropertyRegistry.java new file mode 100644 index 00000000000..13defc9f723 --- /dev/null +++ b/src/main/java/gregtech/api/recipes/properties/RecipePropertyRegistry.java @@ -0,0 +1,29 @@ +package gregtech.api.recipes.properties; + +import it.unimi.dsi.fastutil.objects.Object2ReferenceOpenHashMap; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; + +public final class RecipePropertyRegistry { + + private final Map> map = new Object2ReferenceOpenHashMap<>(); + + /** + * @param key the RecipeProperty's key + * @param property the property's instance + */ + public void register(@NotNull String key, @NotNull RecipeProperty property) { + if (map.containsKey(key)) { + throw new IllegalArgumentException("RecipeProperty is already registered: " + key); + } + map.put(key, property); + } + + @ApiStatus.Internal + public @Nullable RecipeProperty get(@NotNull String key) { + return map.get(key); + } +} diff --git a/src/main/java/gregtech/api/recipes/properties/RecipePropertyStorage.java b/src/main/java/gregtech/api/recipes/properties/RecipePropertyStorage.java new file mode 100644 index 00000000000..790143293dd --- /dev/null +++ b/src/main/java/gregtech/api/recipes/properties/RecipePropertyStorage.java @@ -0,0 +1,119 @@ +package gregtech.api.recipes.properties; + +import gregtech.api.util.GTLog; + +import net.minecraft.nbt.NBTTagCompound; + +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.UnmodifiableView; + +import java.util.Collections; +import java.util.Map; +import java.util.Set; + +public interface RecipePropertyStorage { + + /** + * @param recipeProperty the property to store + * @param value the value to store + * @return if the store succeeds + */ + boolean store(@NotNull RecipeProperty recipeProperty, @NotNull Object value); + + /** + * @return a copy of this property storage + */ + @NotNull + RecipePropertyStorage copy(); + + /** + * @return number of stored properties + */ + int size(); + + /** + * @return all stored properties and values + */ + @NotNull + Set, Object>> entrySet(); + + /** + * @param recipeProperty the property to retrieve + * @param defaultValue default value if the property is not found + * @param the type of returned value + * @return value associated with the provided recipeProperty, otherwise the default + */ + @Contract("_, !null -> !null") + @Nullable T get(@NotNull RecipeProperty recipeProperty, @Nullable T defaultValue); + + /** + * @param recipeProperty the property to check + * @return if the property is in this storage + */ + boolean contains(@NotNull RecipeProperty recipeProperty); + + /** + * @return the recipe property values + */ + @UnmodifiableView + @NotNull + Set<@NotNull RecipeProperty> values(); + + @NotNull + NBTTagCompound serializeNBT(); + + void deserializeNBT(@NotNull NBTTagCompound nbt); + + RecipePropertyStorage EMPTY = new RecipePropertyStorage() { + + @Override + public boolean store(@NotNull RecipeProperty recipeProperty, @NotNull Object value) { + throw new UnsupportedOperationException("empty"); + } + + @Override + public @NotNull RecipePropertyStorage copy() { + return this; + } + + @Override + public int size() { + return 0; + } + + @Override + public @NotNull Set, Object>> entrySet() { + return Collections.emptySet(); + } + + @Override + public @Nullable T get(@NotNull RecipeProperty recipeProperty, @Nullable T defaultValue) { + return defaultValue; + } + + @Override + public boolean contains(@NotNull RecipeProperty recipeProperty) { + return false; + } + + @Override + public @UnmodifiableView @NotNull Set<@NotNull RecipeProperty> values() { + return Collections.emptySet(); + } + + @Override + public @NotNull NBTTagCompound serializeNBT() { + return new NBTTagCompound(); + } + + @Override + public void deserializeNBT(@NotNull NBTTagCompound nbt) { + if (!nbt.isEmpty()) { + GTLog.logger.warn("Tried to deserialize non-empty tag in RecipePropertyStorage.EMPTY: {}", nbt, + new Throwable()); + } + } + }; +} diff --git a/src/main/java/gregtech/api/recipes/properties/RecipePropertyStorageImpl.java b/src/main/java/gregtech/api/recipes/properties/RecipePropertyStorageImpl.java new file mode 100644 index 00000000000..ffc7ea21227 --- /dev/null +++ b/src/main/java/gregtech/api/recipes/properties/RecipePropertyStorageImpl.java @@ -0,0 +1,111 @@ +package gregtech.api.recipes.properties; + +import gregtech.api.GregTechAPI; +import gregtech.api.util.GTLog; + +import net.minecraft.nbt.NBTTagCompound; + +import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.UnmodifiableView; + +import java.util.Map; +import java.util.Set; + +public final class RecipePropertyStorageImpl implements RecipePropertyStorage { + + private final Map, Object> map; + + public RecipePropertyStorageImpl() { + this(new Object2ObjectArrayMap<>(1)); + } + + private RecipePropertyStorageImpl(@NotNull Map, Object> map) { + this.map = map; + } + + @Override + public boolean store(@NotNull RecipeProperty recipeProperty, @NotNull Object value) { + String key = recipeProperty.getKey(); + if (map.containsKey(recipeProperty)) { + GTLog.logger.warn("Duplicate recipe property added: {} -> {}", key, value, new Throwable()); + return false; + } + + try { + recipeProperty.castValue(value); + } catch (ClassCastException e) { + GTLog.logger.error("Provided incorrect value for RecipeProperty with key {}", key, e); + return false; + } + + map.put(recipeProperty, value); + return true; + } + + @Override + public @NotNull RecipePropertyStorage copy() { + return new RecipePropertyStorageImpl(new Object2ObjectArrayMap<>(this.map)); + } + + @Override + public int size() { + return map.size(); + } + + @Override + public @NotNull Set, Object>> entrySet() { + return this.map.entrySet(); + } + + @Override + @Contract("_, !null -> !null") + public @Nullable T get(@NotNull RecipeProperty recipeProperty, @Nullable T defaultValue) { + var value = map.get(recipeProperty); + if (value == null) { + return defaultValue; + } + + return recipeProperty.castValue(value); + } + + @Override + public boolean contains(@NotNull RecipeProperty recipeProperty) { + return map.containsKey(recipeProperty); + } + + @Override + @UnmodifiableView + public @NotNull Set<@NotNull RecipeProperty> values() { + return map.keySet(); + } + + @Override + public @NotNull String toString() { + return "RecipePropertyStorage{" + map + '}'; + } + + @Override + public @NotNull NBTTagCompound serializeNBT() { + NBTTagCompound tag = new NBTTagCompound(); + for (var entry : map.entrySet()) { + var property = entry.getKey(); + tag.setTag(property.getKey(), property.serialize(entry.getValue())); + } + return tag; + } + + @Override + public void deserializeNBT(@NotNull NBTTagCompound nbt) { + for (var entry : nbt.tagMap.entrySet()) { + var property = GregTechAPI.RECIPE_PROPERTIES.get(entry.getKey()); + if (property == null) { + GTLog.logger.warn("Failed to read property with key {}", entry.getKey()); + continue; + } + map.put(property, property.deserialize(entry.getValue())); + } + } +} diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/CleanroomProperty.java b/src/main/java/gregtech/api/recipes/properties/impl/CleanroomProperty.java similarity index 63% rename from src/main/java/gregtech/api/recipes/recipeproperties/CleanroomProperty.java rename to src/main/java/gregtech/api/recipes/properties/impl/CleanroomProperty.java index e048ffa5626..5329b868c04 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/CleanroomProperty.java +++ b/src/main/java/gregtech/api/recipes/properties/impl/CleanroomProperty.java @@ -1,15 +1,21 @@ -package gregtech.api.recipes.recipeproperties; +package gregtech.api.recipes.properties.impl; +import gregtech.api.GregTechAPI; import gregtech.api.metatileentity.multiblock.CleanroomType; +import gregtech.api.recipes.properties.RecipeProperty; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagString; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.jetbrains.annotations.NotNull; -public class CleanroomProperty extends RecipeProperty { +import java.util.Objects; + +public final class CleanroomProperty extends RecipeProperty { public static final String KEY = "cleanroom"; @@ -22,24 +28,27 @@ private CleanroomProperty() { public static CleanroomProperty getInstance() { if (INSTANCE == null) { INSTANCE = new CleanroomProperty(); + GregTechAPI.RECIPE_PROPERTIES.register(KEY, INSTANCE); } return INSTANCE; } @Override - @SideOnly(Side.CLIENT) - public void drawInfo(@NotNull Minecraft minecraft, int x, int y, int color, Object value) { - CleanroomType type = castValue(value); - if (type == null) return; + public @NotNull NBTBase serialize(@NotNull Object value) { + return new NBTTagString(castValue(value).getName()); + } - minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.cleanroom", getName(type)), x, y, color); + @Override + public @NotNull Object deserialize(@NotNull NBTBase nbt) { + return Objects.requireNonNull(CleanroomType.getByName(((NBTTagString) nbt).getString())); } @Override - public int getInfoHeight(Object value) { + @SideOnly(Side.CLIENT) + public void drawInfo(@NotNull Minecraft minecraft, int x, int y, int color, Object value) { CleanroomType type = castValue(value); - if (type == null) return 0; - return super.getInfoHeight(value); + + minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.cleanroom", getName(type)), x, y, color); } @NotNull diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/ComputationProperty.java b/src/main/java/gregtech/api/recipes/properties/impl/ComputationProperty.java similarity index 53% rename from src/main/java/gregtech/api/recipes/recipeproperties/ComputationProperty.java rename to src/main/java/gregtech/api/recipes/properties/impl/ComputationProperty.java index 5f2de1b653b..f57a6ed2ea7 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/ComputationProperty.java +++ b/src/main/java/gregtech/api/recipes/properties/impl/ComputationProperty.java @@ -1,27 +1,45 @@ -package gregtech.api.recipes.recipeproperties; +package gregtech.api.recipes.properties.impl; + +import gregtech.api.GregTechAPI; +import gregtech.api.recipes.properties.RecipeProperty; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagInt; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class ComputationProperty extends RecipeProperty { +import org.jetbrains.annotations.NotNull; + +public final class ComputationProperty extends RecipeProperty { public static final String KEY = "computation_per_tick"; private static ComputationProperty INSTANCE; - protected ComputationProperty() { + private ComputationProperty() { super(KEY, Integer.class); } public static ComputationProperty getInstance() { if (INSTANCE == null) { INSTANCE = new ComputationProperty(); + GregTechAPI.RECIPE_PROPERTIES.register(KEY, INSTANCE); } return INSTANCE; } + @Override + public @NotNull NBTBase serialize(@NotNull Object value) { + return new NBTTagInt(castValue(value)); + } + + @Override + public @NotNull Object deserialize(@NotNull NBTBase nbt) { + return ((NBTTagInt) nbt).getInt(); + } + @Override @SideOnly(Side.CLIENT) public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) { diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java b/src/main/java/gregtech/api/recipes/properties/impl/DimensionProperty.java similarity index 63% rename from src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java rename to src/main/java/gregtech/api/recipes/properties/impl/DimensionProperty.java index 3795db18aa1..721300af5d4 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/DimensionProperty.java +++ b/src/main/java/gregtech/api/recipes/properties/impl/DimensionProperty.java @@ -1,17 +1,22 @@ -package gregtech.api.recipes.recipeproperties; +package gregtech.api.recipes.properties.impl; +import gregtech.api.GregTechAPI; +import gregtech.api.recipes.properties.RecipeProperty; import gregtech.api.worldgen.config.WorldGenRegistry; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; +import org.jetbrains.annotations.NotNull; -public class DimensionProperty extends RecipeProperty { +public final class DimensionProperty extends RecipeProperty { public static final String KEY = "dimension"; @@ -22,11 +27,36 @@ private DimensionProperty() { } public static DimensionProperty getInstance() { - if (INSTANCE == null) + if (INSTANCE == null) { INSTANCE = new DimensionProperty(); + GregTechAPI.RECIPE_PROPERTIES.register(KEY, INSTANCE); + } return INSTANCE; } + @Override + public @NotNull NBTBase serialize(@NotNull Object value) { + DimensionPropertyList list = castValue(value); + NBTTagCompound tag = new NBTTagCompound(); + tag.setIntArray("whiteListDimensions", list.whiteListDimensions.toArray(new int[0])); + tag.setIntArray("blackListDimensions", list.blackListDimensions.toArray(new int[0])); + return tag; + } + + @Override + public @NotNull Object deserialize(@NotNull NBTBase nbt) { + NBTTagCompound tag = (NBTTagCompound) nbt; + DimensionPropertyList list = new DimensionPropertyList(); + for (int i : tag.getIntArray("whiteListDimensions")) { + list.add(i, false); + } + + for (int i : tag.getIntArray("blackListDimensions")) { + list.add(i, true); + } + return tag; + } + @Override @SideOnly(Side.CLIENT) public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) { @@ -62,8 +92,8 @@ public static class DimensionPropertyList { public static DimensionPropertyList EMPTY_LIST = new DimensionPropertyList(); - public IntList whiteListDimensions = new IntArrayList(); - public IntList blackListDimensions = new IntArrayList(); + public final IntList whiteListDimensions = new IntArrayList(); + public final IntList blackListDimensions = new IntArrayList(); public void add(int key, boolean toBlacklist) { if (toBlacklist) { @@ -75,16 +105,13 @@ public void add(int key, boolean toBlacklist) { } } - public void merge(DimensionPropertyList list) { + public void merge(@NotNull 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; + return !blackListDimensions.contains(dim) && whiteListDimensions.contains(dim); } } } diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/FusionEUToStartProperty.java b/src/main/java/gregtech/api/recipes/properties/impl/FusionEUToStartProperty.java similarity index 74% rename from src/main/java/gregtech/api/recipes/recipeproperties/FusionEUToStartProperty.java rename to src/main/java/gregtech/api/recipes/properties/impl/FusionEUToStartProperty.java index 758480a4816..13446abe8d1 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/FusionEUToStartProperty.java +++ b/src/main/java/gregtech/api/recipes/properties/impl/FusionEUToStartProperty.java @@ -1,19 +1,24 @@ -package gregtech.api.recipes.recipeproperties; +package gregtech.api.recipes.properties.impl; +import gregtech.api.GregTechAPI; +import gregtech.api.recipes.properties.RecipeProperty; import gregtech.api.util.TextFormattingUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagLong; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.tuple.Pair; +import org.jetbrains.annotations.NotNull; import java.util.Map; import java.util.TreeMap; -public class FusionEUToStartProperty extends RecipeProperty { +public final class FusionEUToStartProperty extends RecipeProperty { public static final String KEY = "eu_to_start"; @@ -21,18 +26,29 @@ public class FusionEUToStartProperty extends RecipeProperty { private static FusionEUToStartProperty INSTANCE; - protected FusionEUToStartProperty() { + private FusionEUToStartProperty() { super(KEY, Long.class); } public static FusionEUToStartProperty getInstance() { if (INSTANCE == null) { INSTANCE = new FusionEUToStartProperty(); + GregTechAPI.RECIPE_PROPERTIES.register(KEY, INSTANCE); } return INSTANCE; } + @Override + public @NotNull NBTBase serialize(@NotNull Object value) { + return new NBTTagLong(castValue(value)); + } + + @Override + public @NotNull Object deserialize(@NotNull NBTBase nbt) { + return ((NBTTagLong) nbt).getLong(); + } + @Override @SideOnly(Side.CLIENT) public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) { diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/ImplosionExplosiveProperty.java b/src/main/java/gregtech/api/recipes/properties/impl/ImplosionExplosiveProperty.java similarity index 55% rename from src/main/java/gregtech/api/recipes/recipeproperties/ImplosionExplosiveProperty.java rename to src/main/java/gregtech/api/recipes/properties/impl/ImplosionExplosiveProperty.java index fd88401041b..915fc5aa4e3 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/ImplosionExplosiveProperty.java +++ b/src/main/java/gregtech/api/recipes/properties/impl/ImplosionExplosiveProperty.java @@ -1,12 +1,19 @@ -package gregtech.api.recipes.recipeproperties; +package gregtech.api.recipes.properties.impl; + +import gregtech.api.GregTechAPI; +import gregtech.api.recipes.properties.RecipeProperty; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class ImplosionExplosiveProperty extends RecipeProperty { +import org.jetbrains.annotations.NotNull; + +public final class ImplosionExplosiveProperty extends RecipeProperty { public static final String KEY = "explosives"; @@ -19,16 +26,27 @@ private ImplosionExplosiveProperty() { public static ImplosionExplosiveProperty getInstance() { if (INSTANCE == null) { INSTANCE = new ImplosionExplosiveProperty(); + GregTechAPI.RECIPE_PROPERTIES.register(KEY, INSTANCE); } return INSTANCE; } + @Override + public @NotNull NBTBase serialize(@NotNull Object value) { + return castValue(value).serializeNBT(); + } + + @Override + public @NotNull Object deserialize(@NotNull NBTBase nbt) { + return new ItemStack((NBTTagCompound) nbt); + } + @Override @SideOnly(Side.CLIENT) public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) { minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.explosive", - ((ItemStack) value).getDisplayName()), x, y, color); + castValue(value).getDisplayName()), x, y, color); } @Override diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/PrimitiveProperty.java b/src/main/java/gregtech/api/recipes/properties/impl/PrimitiveProperty.java similarity index 55% rename from src/main/java/gregtech/api/recipes/recipeproperties/PrimitiveProperty.java rename to src/main/java/gregtech/api/recipes/properties/impl/PrimitiveProperty.java index 908127d3573..22b49f00bb8 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/PrimitiveProperty.java +++ b/src/main/java/gregtech/api/recipes/properties/impl/PrimitiveProperty.java @@ -1,13 +1,20 @@ -package gregtech.api.recipes.recipeproperties; +package gregtech.api.recipes.properties.impl; + +import gregtech.api.GregTechAPI; +import gregtech.api.recipes.properties.RecipeProperty; import net.minecraft.client.Minecraft; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagByte; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import org.jetbrains.annotations.NotNull; + /** * Simple Marker Property to tell JEI to not display Total EU and EU/t. */ -public class PrimitiveProperty extends RecipeProperty { +public final class PrimitiveProperty extends RecipeProperty { public static final String KEY = "primitive_property"; private static PrimitiveProperty INSTANCE; @@ -19,16 +26,27 @@ private PrimitiveProperty() { public static PrimitiveProperty getInstance() { if (INSTANCE == null) { INSTANCE = new PrimitiveProperty(); + GregTechAPI.RECIPE_PROPERTIES.register(KEY, INSTANCE); } return INSTANCE; } + @Override + public @NotNull NBTBase serialize(@NotNull Object value) { + return new NBTTagByte((byte) (castValue(value) ? 1 : 0)); + } + + @Override + public @NotNull Object deserialize(@NotNull NBTBase nbt) { + return ((NBTTagByte) nbt).getByte() == 1; + } + @Override @SideOnly(Side.CLIENT) public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) {} @Override - public int getInfoHeight(Object value) { + public int getInfoHeight(@NotNull Object value) { return 0; } diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/ResearchProperty.java b/src/main/java/gregtech/api/recipes/properties/impl/ResearchProperty.java similarity index 50% rename from src/main/java/gregtech/api/recipes/recipeproperties/ResearchProperty.java rename to src/main/java/gregtech/api/recipes/properties/impl/ResearchProperty.java index ec4d6ab105e..15b538fa5d6 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/ResearchProperty.java +++ b/src/main/java/gregtech/api/recipes/properties/impl/ResearchProperty.java @@ -1,7 +1,12 @@ -package gregtech.api.recipes.recipeproperties; +package gregtech.api.recipes.properties.impl; + +import gregtech.api.GregTechAPI; +import gregtech.api.recipes.properties.RecipeProperty; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagList; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -21,10 +26,31 @@ private ResearchProperty() { public static ResearchProperty getInstance() { if (INSTANCE == null) { INSTANCE = new ResearchProperty(); + GregTechAPI.RECIPE_PROPERTIES.register(KEY, INSTANCE); } return INSTANCE; } + @Override + public @NotNull NBTBase serialize(@NotNull Object value) { + NBTTagList list = new NBTTagList(); + for (var entry : castValue(value)) { + list.appendTag(entry.serializeNBT()); + } + return list; + } + + @Override + public @NotNull Object deserialize(@NotNull NBTBase nbt) { + NBTTagList list = (NBTTagList) nbt; + ResearchPropertyData data = new ResearchPropertyData(); + for (int i = 0; i < list.tagCount(); i++) { + data.add(ResearchPropertyData.ResearchEntry.deserializeFromNBT(list.getCompoundTagAt(i))); + } + + return data; + } + @Override @SideOnly(Side.CLIENT) public void drawInfo(@NotNull Minecraft minecraft, int x, int y, int color, Object value) { diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/ResearchPropertyData.java b/src/main/java/gregtech/api/recipes/properties/impl/ResearchPropertyData.java similarity index 66% rename from src/main/java/gregtech/api/recipes/recipeproperties/ResearchPropertyData.java rename to src/main/java/gregtech/api/recipes/properties/impl/ResearchPropertyData.java index 4b199221d6c..95a5159aac0 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/ResearchPropertyData.java +++ b/src/main/java/gregtech/api/recipes/properties/impl/ResearchPropertyData.java @@ -1,6 +1,7 @@ -package gregtech.api.recipes.recipeproperties; +package gregtech.api.recipes.properties.impl; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import org.jetbrains.annotations.NotNull; @@ -12,8 +13,6 @@ public final class ResearchPropertyData implements Iterable entries = new ArrayList<>(); - public ResearchPropertyData() {} - /** * @param entry the entry to add */ @@ -46,14 +45,23 @@ public ResearchEntry(@NotNull String researchId, @NotNull ItemStack dataItem) { this.dataItem = dataItem; } - @NotNull - public String getResearchId() { + public @NotNull String researchId() { return researchId; } - @NotNull - public ItemStack getDataItem() { + public @NotNull ItemStack dataItem() { return dataItem; } + + public @NotNull NBTTagCompound serializeNBT() { + NBTTagCompound tag = new NBTTagCompound(); + tag.setString("researchId", researchId); + tag.setTag("dataItem", dataItem.serializeNBT()); + return tag; + } + + public static @NotNull ResearchEntry deserializeFromNBT(@NotNull NBTTagCompound tag) { + return new ResearchEntry(tag.getString("researchId"), new ItemStack(tag.getCompoundTag("dataItem"))); + } } } diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/ScanProperty.java b/src/main/java/gregtech/api/recipes/properties/impl/ScanProperty.java similarity index 56% rename from src/main/java/gregtech/api/recipes/recipeproperties/ScanProperty.java rename to src/main/java/gregtech/api/recipes/properties/impl/ScanProperty.java index 8018561a710..4e80ca61c20 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/ScanProperty.java +++ b/src/main/java/gregtech/api/recipes/properties/impl/ScanProperty.java @@ -1,13 +1,18 @@ -package gregtech.api.recipes.recipeproperties; +package gregtech.api.recipes.properties.impl; + +import gregtech.api.GregTechAPI; +import gregtech.api.recipes.properties.RecipeProperty; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagByte; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.jetbrains.annotations.NotNull; -public class ScanProperty extends RecipeProperty { +public final class ScanProperty extends RecipeProperty { public static final String KEY = "scan"; @@ -21,10 +26,21 @@ private ScanProperty() { public static ScanProperty getInstance() { if (INSTANCE == null) { INSTANCE = new ScanProperty(); + GregTechAPI.RECIPE_PROPERTIES.register(KEY, INSTANCE); } return INSTANCE; } + @Override + public @NotNull NBTBase serialize(@NotNull Object value) { + return new NBTTagByte((byte) (castValue(value) ? 1 : 0)); + } + + @Override + public @NotNull Object deserialize(@NotNull NBTBase nbt) { + return ((NBTTagByte) nbt).getByte() == 1; + } + @Override @SideOnly(Side.CLIENT) public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) { diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/TemperatureProperty.java b/src/main/java/gregtech/api/recipes/properties/impl/TemperatureProperty.java similarity index 79% rename from src/main/java/gregtech/api/recipes/recipeproperties/TemperatureProperty.java rename to src/main/java/gregtech/api/recipes/properties/impl/TemperatureProperty.java index c9c1681d9ae..3764158baed 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/TemperatureProperty.java +++ b/src/main/java/gregtech/api/recipes/properties/impl/TemperatureProperty.java @@ -1,9 +1,13 @@ -package gregtech.api.recipes.recipeproperties; +package gregtech.api.recipes.properties.impl; +import gregtech.api.GregTechAPI; +import gregtech.api.recipes.properties.RecipeProperty; import gregtech.api.unification.material.Material; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagInt; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -13,7 +17,7 @@ import java.util.Map; import java.util.TreeMap; -public class TemperatureProperty extends RecipeProperty { +public final class TemperatureProperty extends RecipeProperty { public static final String KEY = "temperature"; @@ -28,10 +32,21 @@ private TemperatureProperty() { public static TemperatureProperty getInstance() { if (INSTANCE == null) { INSTANCE = new TemperatureProperty(); + GregTechAPI.RECIPE_PROPERTIES.register(KEY, INSTANCE); } return INSTANCE; } + @Override + public @NotNull NBTBase serialize(@NotNull Object value) { + return new NBTTagInt(castValue(value)); + } + + @Override + public @NotNull Object deserialize(@NotNull NBTBase nbt) { + return ((NBTTagInt) nbt).getInt(); + } + @Override @SideOnly(Side.CLIENT) public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) { diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/TotalComputationProperty.java b/src/main/java/gregtech/api/recipes/properties/impl/TotalComputationProperty.java similarity index 56% rename from src/main/java/gregtech/api/recipes/recipeproperties/TotalComputationProperty.java rename to src/main/java/gregtech/api/recipes/properties/impl/TotalComputationProperty.java index a6247be32c4..0704e44cb46 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/TotalComputationProperty.java +++ b/src/main/java/gregtech/api/recipes/properties/impl/TotalComputationProperty.java @@ -1,27 +1,45 @@ -package gregtech.api.recipes.recipeproperties; +package gregtech.api.recipes.properties.impl; + +import gregtech.api.GregTechAPI; +import gregtech.api.recipes.properties.RecipeProperty; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagInt; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class TotalComputationProperty extends RecipeProperty { +import org.jetbrains.annotations.NotNull; + +public final class TotalComputationProperty extends RecipeProperty { public static final String KEY = "total_computation"; private static TotalComputationProperty INSTANCE; - protected TotalComputationProperty() { + private TotalComputationProperty() { super(KEY, Integer.class); } public static TotalComputationProperty getInstance() { if (INSTANCE == null) { INSTANCE = new TotalComputationProperty(); + GregTechAPI.RECIPE_PROPERTIES.register(KEY, INSTANCE); } return INSTANCE; } + @Override + public @NotNull NBTBase serialize(@NotNull Object value) { + return new NBTTagInt(castValue(value)); + } + + @Override + public @NotNull Object deserialize(@NotNull NBTBase nbt) { + return ((NBTTagInt) nbt).getInt(); + } + @Override @SideOnly(Side.CLIENT) public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) { diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/DefaultProperty.java b/src/main/java/gregtech/api/recipes/recipeproperties/DefaultProperty.java deleted file mode 100644 index 1579297b2cd..00000000000 --- a/src/main/java/gregtech/api/recipes/recipeproperties/DefaultProperty.java +++ /dev/null @@ -1,19 +0,0 @@ -package gregtech.api.recipes.recipeproperties; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.resources.I18n; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -public class DefaultProperty extends RecipeProperty { - - public DefaultProperty(String key, Class type) { - super(key, type); - } - - @SideOnly(Side.CLIENT) - public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) { - minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe." + getKey(), - castValue(value)), x, y, color); - } -} diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/EmptyRecipePropertyStorage.java b/src/main/java/gregtech/api/recipes/recipeproperties/EmptyRecipePropertyStorage.java deleted file mode 100644 index 89f6bb201d6..00000000000 --- a/src/main/java/gregtech/api/recipes/recipeproperties/EmptyRecipePropertyStorage.java +++ /dev/null @@ -1,65 +0,0 @@ -package gregtech.api.recipes.recipeproperties; - -import java.util.Collections; -import java.util.Map; -import java.util.Set; - -public final class EmptyRecipePropertyStorage implements IRecipePropertyStorage { - - public static final EmptyRecipePropertyStorage INSTANCE = new EmptyRecipePropertyStorage(); - - private EmptyRecipePropertyStorage() {} - - @Override - public boolean store(RecipeProperty recipeProperty, Object value) { - return false; - } - - @Override - public boolean remove(RecipeProperty recipeProperty) { - return false; - } - - @Override - public void freeze(boolean frozen) {} - - @Override - public IRecipePropertyStorage copy() { - return null; // Fresh for RecipeBuilder to handle - } - - @Override - public int getSize() { - return 0; - } - - @Override - public Set, Object>> getRecipeProperties() { - return Collections.emptySet(); - } - - @Override - public T getRecipePropertyValue(RecipeProperty recipeProperty, T defaultValue) { - return defaultValue; - } - - @Override - public boolean hasRecipeProperty(RecipeProperty recipeProperty) { - return false; - } - - @Override - public Set getRecipePropertyKeys() { - return Collections.emptySet(); - } - - @Override - public Set> getPropertyTypes() { - return Collections.emptySet(); - } - - @Override - public Object getRawRecipePropertyValue(String key) { - return null; - } -} diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/IRecipePropertyStorage.java b/src/main/java/gregtech/api/recipes/recipeproperties/IRecipePropertyStorage.java deleted file mode 100644 index 9781e2484ce..00000000000 --- a/src/main/java/gregtech/api/recipes/recipeproperties/IRecipePropertyStorage.java +++ /dev/null @@ -1,60 +0,0 @@ -package gregtech.api.recipes.recipeproperties; - -import java.util.Map; -import java.util.Set; - -public interface IRecipePropertyStorage { - - /** - * Stores new {@link RecipeProperty} with value - * - * @param recipeProperty {@link RecipeProperty} - * @param value value - * @return {@code true} if store succeeds; otherwise {@code false} - */ - boolean store(RecipeProperty recipeProperty, Object value); - - boolean remove(RecipeProperty recipeProperty); - - void freeze(boolean frozen); - - IRecipePropertyStorage copy(); - - /** - * Provides information how many {@link RecipeProperty} are stored - * - * @return number of stored {@link RecipeProperty} - */ - int getSize(); - - /** - * Provides all stored {@link RecipeProperty} - * - * @return all stored {@link RecipeProperty} and values - */ - Set, Object>> getRecipeProperties(); - - /** - * Provides casted value for one specific {@link RecipeProperty} if is stored or defaultValue - * - * @param recipeProperty {@link RecipeProperty} - * @param defaultValue Default value if recipeProperty is not found - * @param Type of returned value - * @return value tied with provided recipeProperty on success; otherwise defaultValue - */ - T getRecipePropertyValue(RecipeProperty recipeProperty, T defaultValue); - - boolean hasRecipeProperty(RecipeProperty recipeProperty); - - Set getRecipePropertyKeys(); - - Set> getPropertyTypes(); - - /** - * Provides un-casted value for one specific {@link RecipeProperty} searched by key - * - * @param key Key of stored {@link RecipeProperty} - * @return {@link Object} value on success; otherwise {@code null} - */ - Object getRawRecipePropertyValue(String key); -} diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/RecipePropertyStorage.java b/src/main/java/gregtech/api/recipes/recipeproperties/RecipePropertyStorage.java deleted file mode 100644 index cf38c40ef3e..00000000000 --- a/src/main/java/gregtech/api/recipes/recipeproperties/RecipePropertyStorage.java +++ /dev/null @@ -1,134 +0,0 @@ -package gregtech.api.recipes.recipeproperties; - -import gregtech.api.util.GTLog; - -import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -public class RecipePropertyStorage implements IRecipePropertyStorage { - - private final Map, Object> recipeProperties; - - private boolean frozen = false; - - public RecipePropertyStorage() { - recipeProperties = new Object2ObjectArrayMap<>(1); - } - - private RecipePropertyStorage(Map, Object> recipeProperties) { - this(); - this.recipeProperties.putAll(recipeProperties); - } - - @Override - public boolean store(RecipeProperty recipeProperty, Object value) { - boolean success = true; - String key = recipeProperty.getKey(); - if (frozen) { - GTLog.logger.warn("Unable to add RecipeProperty with key {} as the storage is frozen", key); - success = false; - } - for (RecipeProperty existingRecipeProperty : recipeProperties.keySet()) { - if (existingRecipeProperty.getKey().equals(key)) { - GTLog.logger.warn("Unable to add RecipeProperty with key {} as it already exists", key); - success = false; - } - } - - if (value == null) { - GTLog.logger.warn("Provided value is null for RecipeProperty with key {}", key); - success = false; - } - - try { - recipeProperty.castValue(value); - } catch (ClassCastException e) { - GTLog.logger.warn("Provided incorrect value for RecipeProperty with key {}", key, e); - success = false; - } - - if (success) { - recipeProperties.put(recipeProperty, value); - } else { - GTLog.logger.warn("RecipePropertyStorage error found", new Throwable()); - } - - return success; - } - - @Override - public boolean remove(RecipeProperty recipeProperty) { - return this.recipeProperties.remove(recipeProperty) != null; - } - - @Override - public void freeze(boolean frozen) { - this.frozen = frozen; - } - - @Override - public IRecipePropertyStorage copy() { - return new RecipePropertyStorage(this.recipeProperties); - } - - @Override - public int getSize() { - return recipeProperties.size(); - } - - @Override - public Set, Object>> getRecipeProperties() { - return this.recipeProperties.entrySet(); - } - - @Override - public T getRecipePropertyValue(RecipeProperty recipeProperty, T defaultValue) { - Object value = recipeProperties.get(recipeProperty); - - if (value == null) { - return defaultValue; - } - - return recipeProperty.castValue(value); - } - - public boolean hasRecipeProperty(RecipeProperty recipeProperty) { - return recipeProperties.containsKey(recipeProperty); - } - - @Override - public Set getRecipePropertyKeys() { - HashSet keys = new HashSet<>(); - - recipeProperties.keySet().forEach(recipeProperty -> keys.add(recipeProperty.getKey())); - - return keys; - } - - @Override - public Set> getPropertyTypes() { - return recipeProperties.keySet(); - } - - @Override - public Object getRawRecipePropertyValue(String key) { - RecipeProperty recipeProperty = getRecipePropertyValue(key); - if (recipeProperty != null) { - return recipeProperties.get(recipeProperty); - } - - return null; - } - - private RecipeProperty getRecipePropertyValue(String key) { - for (RecipeProperty recipeProperty : recipeProperties.keySet()) { - if (recipeProperty.getKey().equals(key)) - return recipeProperty; - } - - return null; - } -} diff --git a/src/main/java/gregtech/api/recipes/ui/RecipeMapUI.java b/src/main/java/gregtech/api/recipes/ui/RecipeMapUI.java index a85fd546cae..a6d66d3e62e 100644 --- a/src/main/java/gregtech/api/recipes/ui/RecipeMapUI.java +++ b/src/main/java/gregtech/api/recipes/ui/RecipeMapUI.java @@ -283,8 +283,10 @@ public int getPropertyHeightShift() { int maxPropertyCount = 0; if (shouldShiftWidgets()) { for (Recipe recipe : recipeMap.getRecipeList()) { - if (recipe.getPropertyCount() > maxPropertyCount) - maxPropertyCount = recipe.getPropertyCount(); + int count = recipe.propertyStorage().size(); + if (count > maxPropertyCount) { + maxPropertyCount = count; + } } } return maxPropertyCount * 10; // GTRecipeWrapper#LINE_HEIGHT diff --git a/src/main/java/gregtech/api/util/AssemblyLineManager.java b/src/main/java/gregtech/api/util/AssemblyLineManager.java index a2652acfa84..7601c0e73cd 100644 --- a/src/main/java/gregtech/api/util/AssemblyLineManager.java +++ b/src/main/java/gregtech/api/util/AssemblyLineManager.java @@ -11,7 +11,7 @@ import gregtech.api.recipes.ingredients.nbtmatch.NBTMatcher; import gregtech.api.recipes.machines.IScannerRecipeMap; import gregtech.api.recipes.machines.RecipeMapScanner; -import gregtech.api.recipes.recipeproperties.ScanProperty; +import gregtech.api.recipes.properties.impl.ScanProperty; import gregtech.common.ConfigHolder; import gregtech.common.items.MetaItems; diff --git a/src/main/java/gregtech/common/CommonProxy.java b/src/main/java/gregtech/common/CommonProxy.java index 6817aaa7ce5..1a43a28aa62 100644 --- a/src/main/java/gregtech/common/CommonProxy.java +++ b/src/main/java/gregtech/common/CommonProxy.java @@ -10,7 +10,7 @@ import gregtech.api.recipes.GTRecipeInputCache; import gregtech.api.recipes.ModHandler; import gregtech.api.recipes.ingredients.GTRecipeOreInput; -import gregtech.api.recipes.recipeproperties.FusionEUToStartProperty; +import gregtech.api.recipes.properties.impl.FusionEUToStartProperty; import gregtech.api.terminal.TerminalRegistry; import gregtech.api.unification.material.Material; import gregtech.api.unification.material.info.MaterialFlags; diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityAssemblyLine.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityAssemblyLine.java index fb2de88df33..69b648b41cb 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityAssemblyLine.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityAssemblyLine.java @@ -14,7 +14,7 @@ import gregtech.api.recipes.Recipe; import gregtech.api.recipes.RecipeMaps; import gregtech.api.recipes.ingredients.GTRecipeInput; -import gregtech.api.recipes.recipeproperties.ResearchProperty; +import gregtech.api.recipes.properties.impl.ResearchProperty; import gregtech.api.util.GTUtility; import gregtech.api.util.RelativeDirection; import gregtech.client.particle.GTLaserBeamParticle; diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityCrackingUnit.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityCrackingUnit.java index d71dca8cd0d..b1bd30b8574 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityCrackingUnit.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityCrackingUnit.java @@ -12,7 +12,7 @@ import gregtech.api.pattern.PatternMatchContext; import gregtech.api.recipes.RecipeMaps; import gregtech.api.recipes.logic.OCResult; -import gregtech.api.recipes.recipeproperties.IRecipePropertyStorage; +import gregtech.api.recipes.properties.RecipePropertyStorage; import gregtech.api.util.GTUtility; import gregtech.api.util.TextComponentUtil; import gregtech.client.renderer.ICubeRenderer; @@ -150,7 +150,7 @@ public CrackingUnitWorkableHandler(RecipeMapMultiblockController tileEntity) { } @Override - protected void modifyOverclockPost(@NotNull OCResult ocResult, @NotNull IRecipePropertyStorage storage) { + protected void modifyOverclockPost(@NotNull OCResult ocResult, @NotNull RecipePropertyStorage storage) { super.modifyOverclockPost(ocResult, storage); int coilTier = ((MetaTileEntityCrackingUnit) metaTileEntity).getCoilTier(); diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityElectricBlastFurnace.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityElectricBlastFurnace.java index 78d9449eaf2..89c277d7c8d 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityElectricBlastFurnace.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityElectricBlastFurnace.java @@ -17,7 +17,7 @@ import gregtech.api.pattern.PatternMatchContext; import gregtech.api.recipes.Recipe; import gregtech.api.recipes.RecipeMaps; -import gregtech.api.recipes.recipeproperties.TemperatureProperty; +import gregtech.api.recipes.properties.impl.TemperatureProperty; import gregtech.api.util.GTUtility; import gregtech.api.util.TextComponentUtil; import gregtech.api.util.TextFormattingUtil; diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityFusionReactor.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityFusionReactor.java index 4b6b9db00d5..b9a918639f3 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityFusionReactor.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityFusionReactor.java @@ -30,8 +30,8 @@ import gregtech.api.recipes.Recipe; import gregtech.api.recipes.RecipeMaps; import gregtech.api.recipes.logic.OCParams; -import gregtech.api.recipes.recipeproperties.FusionEUToStartProperty; -import gregtech.api.recipes.recipeproperties.IRecipePropertyStorage; +import gregtech.api.recipes.properties.RecipePropertyStorage; +import gregtech.api.recipes.properties.impl.FusionEUToStartProperty; import gregtech.api.util.RelativeDirection; import gregtech.api.util.TextComponentUtil; import gregtech.api.util.TextFormattingUtil; @@ -637,13 +637,13 @@ public boolean checkRecipe(@NotNull Recipe recipe) { } @Override - protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull IRecipePropertyStorage storage) { + protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull RecipePropertyStorage storage) { super.modifyOverclockPre(ocParams, storage); // Limit the number of OCs to the difference in fusion reactor MK. // I.e., a MK2 reactor can overclock a MK1 recipe once, and a // MK3 reactor can overclock a MK2 recipe once, or a MK1 recipe twice. - long euToStart = storage.getRecipePropertyValue(FusionEUToStartProperty.getInstance(), 0L); + long euToStart = storage.get(FusionEUToStartProperty.getInstance(), 0L); int fusionTier = FusionEUToStartProperty.getFusionTier(euToStart); if (fusionTier != 0) fusionTier = MetaTileEntityFusionReactor.this.tier - fusionTier; ocParams.setOcAmount(Math.min(fusionTier, ocParams.ocAmount())); diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityMultiSmelter.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityMultiSmelter.java index d25c923630d..71fca7ba8d4 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityMultiSmelter.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityMultiSmelter.java @@ -17,7 +17,7 @@ import gregtech.api.recipes.logic.OCParams; import gregtech.api.recipes.logic.OCResult; import gregtech.api.recipes.machines.RecipeMapFurnace; -import gregtech.api.recipes.recipeproperties.IRecipePropertyStorage; +import gregtech.api.recipes.properties.RecipePropertyStorage; import gregtech.api.util.GTUtility; import gregtech.api.util.TextComponentUtil; import gregtech.api.util.TextFormattingUtil; @@ -208,7 +208,7 @@ public ParallelLogicType getParallelLogicType() { @Override protected void runOverclockingLogic(@NotNull OCParams ocParams, @NotNull OCResult ocResult, - @NotNull IRecipePropertyStorage propertyStorage, long maxVoltage) { + @NotNull RecipePropertyStorage propertyStorage, long maxVoltage) { standardOC(ocParams, ocResult, maxVoltage, getOverclockingDurationFactor(), getOverclockingVoltageFactor()); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityProcessingArray.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityProcessingArray.java index 7a8fd7a9162..4759bb1dec7 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityProcessingArray.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityProcessingArray.java @@ -24,7 +24,7 @@ import gregtech.api.recipes.RecipeMap; import gregtech.api.recipes.logic.OCParams; import gregtech.api.recipes.logic.OCResult; -import gregtech.api.recipes.recipeproperties.IRecipePropertyStorage; +import gregtech.api.recipes.properties.RecipePropertyStorage; import gregtech.api.util.GTUtility; import gregtech.api.util.TextComponentUtil; import gregtech.api.util.TextFormattingUtil; @@ -417,7 +417,7 @@ protected int getNumberOfOCs(long recipeEUt) { @Override protected void runOverclockingLogic(@NotNull OCParams ocParams, @NotNull OCResult ocResult, - @NotNull IRecipePropertyStorage propertyStorage, long maxVoltage) { + @NotNull RecipePropertyStorage propertyStorage, long maxVoltage) { subTickNonParallelOC(ocParams, ocResult, maxVoltage, getOverclockingDurationFactor(), getOverclockingVoltageFactor()); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityPyrolyseOven.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityPyrolyseOven.java index efda75b7dc6..b4715563582 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityPyrolyseOven.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityPyrolyseOven.java @@ -12,7 +12,7 @@ import gregtech.api.pattern.PatternMatchContext; import gregtech.api.recipes.RecipeMaps; import gregtech.api.recipes.logic.OCResult; -import gregtech.api.recipes.recipeproperties.IRecipePropertyStorage; +import gregtech.api.recipes.properties.RecipePropertyStorage; import gregtech.api.util.GTUtility; import gregtech.api.util.TextComponentUtil; import gregtech.client.renderer.ICubeRenderer; @@ -173,7 +173,7 @@ public PyrolyseOvenWorkableHandler(RecipeMapMultiblockController tileEntity) { } @Override - protected void modifyOverclockPost(@NotNull OCResult ocResult, @NotNull IRecipePropertyStorage storage) { + protected void modifyOverclockPost(@NotNull OCResult ocResult, @NotNull RecipePropertyStorage storage) { super.modifyOverclockPost(ocResult, storage); int coilTier = ((MetaTileEntityPyrolyseOven) metaTileEntity).getCoilTier(); diff --git a/src/main/java/gregtech/core/CoreModule.java b/src/main/java/gregtech/core/CoreModule.java index 149c19344ec..aecbe907d48 100644 --- a/src/main/java/gregtech/core/CoreModule.java +++ b/src/main/java/gregtech/core/CoreModule.java @@ -20,7 +20,7 @@ import gregtech.api.mui.GTGuis; import gregtech.api.recipes.ModHandler; import gregtech.api.recipes.RecipeMap; -import gregtech.api.recipes.recipeproperties.TemperatureProperty; +import gregtech.api.recipes.properties.impl.TemperatureProperty; import gregtech.api.unification.OreDictUnifier; import gregtech.api.unification.material.Materials; import gregtech.api.unification.material.event.MaterialEvent; diff --git a/src/main/java/gregtech/integration/crafttweaker/recipe/CTRecipe.java b/src/main/java/gregtech/integration/crafttweaker/recipe/CTRecipe.java index 728c190a0d3..ac71e2f0fbb 100644 --- a/src/main/java/gregtech/integration/crafttweaker/recipe/CTRecipe.java +++ b/src/main/java/gregtech/integration/crafttweaker/recipe/CTRecipe.java @@ -15,7 +15,6 @@ import stanhebben.zenscript.annotations.ZenGetter; import stanhebben.zenscript.annotations.ZenMethod; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -90,16 +89,6 @@ public boolean isHidden() { return this.backingRecipe.isHidden(); } - @ZenGetter("propertyKeys") - public List getPropertyKeys() { - return new ArrayList<>(this.backingRecipe.getPropertyKeys()); - } - - @ZenMethod - public Object getProperty(String key) { - return this.backingRecipe.getPropertyRaw(key); - } - @ZenMethod public boolean remove() { return this.recipeMap.removeRecipe(this.backingRecipe); diff --git a/src/main/java/gregtech/integration/crafttweaker/recipe/CTRecipeBuilder.java b/src/main/java/gregtech/integration/crafttweaker/recipe/CTRecipeBuilder.java index be74a57456c..b419cc4960b 100644 --- a/src/main/java/gregtech/integration/crafttweaker/recipe/CTRecipeBuilder.java +++ b/src/main/java/gregtech/integration/crafttweaker/recipe/CTRecipeBuilder.java @@ -220,7 +220,7 @@ public CTRecipeBuilder fluidOutputs(ILiquidStack... ingredients) { @ZenMethod public CTRecipeBuilder property(String key, int value) { - boolean applied = this.backingBuilder.applyProperty(key, value); + boolean applied = this.backingBuilder.applyPropertyCT(key, value); if (!applied) { throw new IllegalArgumentException("Property " + key + " cannot be applied to recipe type " + @@ -231,7 +231,7 @@ public CTRecipeBuilder property(String key, int value) { @ZenMethod public CTRecipeBuilder property(String key, String value) { - boolean applied = this.backingBuilder.applyProperty(key, value); + boolean applied = this.backingBuilder.applyPropertyCT(key, value); if (!applied) { throw new IllegalArgumentException("Property " + key + " cannot be applied to recipe type " + @@ -242,7 +242,7 @@ public CTRecipeBuilder property(String key, String value) { @ZenMethod public CTRecipeBuilder property(String key, boolean value) { - boolean applied = this.backingBuilder.applyProperty(key, value); + boolean applied = this.backingBuilder.applyPropertyCT(key, value); if (!applied) { throw new IllegalArgumentException("Property " + key + " cannot be applied to recipe type " + @@ -253,7 +253,7 @@ public CTRecipeBuilder property(String key, boolean value) { @ZenMethod public CTRecipeBuilder property(String key, long value) { - boolean applied = this.backingBuilder.applyProperty(key, value); + boolean applied = this.backingBuilder.applyPropertyCT(key, value); if (!applied) { throw new IllegalArgumentException("Property " + key + " cannot be applied to recipe type " + @@ -264,7 +264,7 @@ public CTRecipeBuilder property(String key, long value) { @ZenMethod public CTRecipeBuilder property(String key, float value) { - boolean applied = this.backingBuilder.applyProperty(key, value); + boolean applied = this.backingBuilder.applyPropertyCT(key, value); if (!applied) { throw new IllegalArgumentException("Property " + key + " cannot be applied to recipe type " + @@ -275,7 +275,7 @@ public CTRecipeBuilder property(String key, float value) { @ZenMethod public CTRecipeBuilder property(String key, IItemStack item) { - boolean applied = this.backingBuilder.applyProperty(key, CraftTweakerMC.getItemStack(item)); + boolean applied = this.backingBuilder.applyPropertyCT(key, CraftTweakerMC.getItemStack(item)); if (!applied) { throw new IllegalArgumentException("Property " + key + " cannot be applied to recipe type " + diff --git a/src/main/java/gregtech/integration/groovy/GroovyExpansions.java b/src/main/java/gregtech/integration/groovy/GroovyExpansions.java index ff00a9d1b5b..00a7906fb0e 100644 --- a/src/main/java/gregtech/integration/groovy/GroovyExpansions.java +++ b/src/main/java/gregtech/integration/groovy/GroovyExpansions.java @@ -18,7 +18,7 @@ public class GroovyExpansions { public static > RecipeBuilder property(RecipeBuilder builder, String key, Object value) { - if (!builder.applyProperty(key, value)) { + if (!builder.applyPropertyCT(key, value)) { GroovyLog.get().error("Failed to add property '{}' with '{}' to recipe", key, value); } return builder; diff --git a/src/main/java/gregtech/integration/jei/basic/MaterialTreeCategory.java b/src/main/java/gregtech/integration/jei/basic/MaterialTreeCategory.java index 16a26032f73..b3c8b6e10b2 100644 --- a/src/main/java/gregtech/integration/jei/basic/MaterialTreeCategory.java +++ b/src/main/java/gregtech/integration/jei/basic/MaterialTreeCategory.java @@ -2,7 +2,7 @@ import gregtech.api.GTValues; import gregtech.api.gui.GuiTextures; -import gregtech.api.recipes.recipeproperties.TemperatureProperty; +import gregtech.api.recipes.properties.impl.TemperatureProperty; import gregtech.api.unification.OreDictUnifier; import gregtech.api.unification.material.Materials; import gregtech.api.unification.ore.OrePrefix; diff --git a/src/main/java/gregtech/integration/jei/recipe/GTRecipeWrapper.java b/src/main/java/gregtech/integration/jei/recipe/GTRecipeWrapper.java index f0fb97c1f1c..7dae031a66a 100644 --- a/src/main/java/gregtech/integration/jei/recipe/GTRecipeWrapper.java +++ b/src/main/java/gregtech/integration/jei/recipe/GTRecipeWrapper.java @@ -16,10 +16,10 @@ import gregtech.api.recipes.ingredients.GTRecipeInput; import gregtech.api.recipes.machines.IResearchRecipeMap; import gregtech.api.recipes.machines.IScannerRecipeMap; -import gregtech.api.recipes.recipeproperties.ComputationProperty; -import gregtech.api.recipes.recipeproperties.RecipeProperty; -import gregtech.api.recipes.recipeproperties.ScanProperty; -import gregtech.api.recipes.recipeproperties.TotalComputationProperty; +import gregtech.api.recipes.properties.RecipeProperty; +import gregtech.api.recipes.properties.impl.ComputationProperty; +import gregtech.api.recipes.properties.impl.ScanProperty; +import gregtech.api.recipes.properties.impl.TotalComputationProperty; import gregtech.api.util.AssemblyLineManager; import gregtech.api.util.ClipboardUtil; import gregtech.api.util.GTUtility; @@ -44,7 +44,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.function.BooleanSupplier; import java.util.stream.Collectors; @@ -239,7 +238,8 @@ public void addIngredientTooltips(@NotNull Collection tooltip, boolean n @Override public void drawInfo(@NotNull Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) { super.drawInfo(minecraft, recipeWidth, recipeHeight, mouseX, mouseY); - var properties = recipe.getPropertyTypes(); + var storage = recipe.propertyStorage(); + var properties = storage.values(); boolean drawTotalEU = properties.isEmpty() || properties.stream().noneMatch(RecipeProperty::hideTotalEU); boolean drawEUt = properties.isEmpty() || properties.stream().noneMatch(RecipeProperty::hideEUt); boolean drawDuration = properties.isEmpty() || properties.stream().noneMatch(RecipeProperty::hideDuration); @@ -249,15 +249,18 @@ public void drawInfo(@NotNull Minecraft minecraft, int recipeWidth, int recipeHe if (drawEUt) defaultLines++; if (drawDuration) defaultLines++; - int yPosition = recipeHeight - ((recipe.getUnhiddenPropertyCount() + defaultLines) * 10 - 3); + int unhiddenCount = (int) storage.entrySet().stream() + .filter((property) -> !property.getKey().isHidden()) + .count(); + int yPosition = recipeHeight - ((unhiddenCount + defaultLines) * 10 - 3); // Default entries if (drawTotalEU) { long eu = recipe.getEUt() * recipe.getDuration(); // sadly we still need a custom override here, since computation uses duration and EU/t very differently - if (recipe.hasProperty(TotalComputationProperty.getInstance()) && - recipe.hasProperty(ComputationProperty.getInstance())) { - int minimumCWUt = recipe.getProperty(ComputationProperty.getInstance(), 1); + if (storage.contains(TotalComputationProperty.getInstance()) && + storage.contains(ComputationProperty.getInstance())) { + int minimumCWUt = storage.get(ComputationProperty.getInstance(), 1); minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.max_eu", eu / minimumCWUt), 0, yPosition, 0x111111); } else { @@ -280,10 +283,10 @@ public void drawInfo(@NotNull Minecraft minecraft, int recipeWidth, int recipeHe } // Property custom entries - for (Map.Entry, Object> propertyEntry : recipe.getPropertyValues()) { + for (var propertyEntry : storage.entrySet()) { if (!propertyEntry.getKey().isHidden()) { RecipeProperty property = propertyEntry.getKey(); - Object value = propertyEntry.getValue(); + var value = propertyEntry.getValue(); property.drawInfo(minecraft, 0, yPosition += property.getInfoHeight(value), 0x111111, value, mouseX, mouseY); } @@ -294,7 +297,7 @@ public void drawInfo(@NotNull Minecraft minecraft, int recipeWidth, int recipeHe @Override public List getTooltipStrings(int mouseX, int mouseY) { List tooltips = new ArrayList<>(); - for (var entry : recipe.getPropertyValues()) { + for (var entry : recipe.propertyStorage().entrySet()) { if (!entry.getKey().isHidden()) { RecipeProperty property = entry.getKey(); Object value = entry.getValue(); diff --git a/src/main/java/gregtech/integration/jei/recipe/RecipeMapCategory.java b/src/main/java/gregtech/integration/jei/recipe/RecipeMapCategory.java index 52039a21b07..31dde8f7874 100644 --- a/src/main/java/gregtech/integration/jei/recipe/RecipeMapCategory.java +++ b/src/main/java/gregtech/integration/jei/recipe/RecipeMapCategory.java @@ -12,8 +12,8 @@ import gregtech.api.recipes.RecipeMap; import gregtech.api.recipes.RecipeMaps; import gregtech.api.recipes.category.GTRecipeCategory; -import gregtech.api.recipes.recipeproperties.ResearchProperty; -import gregtech.api.recipes.recipeproperties.ResearchPropertyData; +import gregtech.api.recipes.properties.impl.ResearchProperty; +import gregtech.api.recipes.properties.impl.ResearchPropertyData; import gregtech.api.util.AssemblyLineManager; import gregtech.api.util.GTUtility; import gregtech.api.util.LocalizationUtils; @@ -213,9 +213,9 @@ public void setRecipe(IRecipeLayout recipeLayout, @NotNull GTRecipeWrapper recip if (data != null) { List dataItems = new ArrayList<>(); for (ResearchPropertyData.ResearchEntry entry : data) { - ItemStack dataStick = entry.getDataItem().copy(); + ItemStack dataStick = entry.dataItem().copy(); AssemblyLineManager.writeResearchToNBT(GTUtility.getOrCreateNbtCompound(dataStick), - entry.getResearchId()); + entry.researchId()); dataItems.add(dataStick); } itemStackGroup.set(16, dataItems); diff --git a/src/main/java/gregtech/loaders/recipe/handlers/MaterialRecipeHandler.java b/src/main/java/gregtech/loaders/recipe/handlers/MaterialRecipeHandler.java index cbdf94add16..3b048b093c6 100644 --- a/src/main/java/gregtech/loaders/recipe/handlers/MaterialRecipeHandler.java +++ b/src/main/java/gregtech/loaders/recipe/handlers/MaterialRecipeHandler.java @@ -91,28 +91,28 @@ public static void processDust(OrePrefix dustPrefix, Material mat, DustProperty .inputs(GTUtility.copy(4, dustStack)) .outputs(GTUtility.copy(3, gemStack)) .chancedOutput(dust, Materials.DarkAsh, 2500, 0) - .explosivesType(new ItemStack(MetaBlocks.POWDERBARREL, 8)) + .explosives(new ItemStack(MetaBlocks.POWDERBARREL, 8)) .buildAndRegister(); RecipeMaps.IMPLOSION_RECIPES.recipeBuilder() .inputs(GTUtility.copy(4, dustStack)) .outputs(GTUtility.copy(3, gemStack)) .chancedOutput(dust, Materials.DarkAsh, 2500, 0) - .explosivesAmount(4) + .explosives(4) .buildAndRegister(); RecipeMaps.IMPLOSION_RECIPES.recipeBuilder() .inputs(GTUtility.copy(4, dustStack)) .outputs(GTUtility.copy(3, gemStack)) .chancedOutput(dust, Materials.DarkAsh, 2500, 0) - .explosivesType(MetaItems.DYNAMITE.getStackForm(2)) + .explosives(MetaItems.DYNAMITE.getStackForm(2)) .buildAndRegister(); RecipeMaps.IMPLOSION_RECIPES.recipeBuilder() .inputs(GTUtility.copy(4, dustStack)) .outputs(GTUtility.copy(3, gemStack)) .chancedOutput(dust, Materials.DarkAsh, 2500, 0) - .explosivesType(new ItemStack(MetaBlocks.ITNT)) + .explosives(new ItemStack(MetaBlocks.ITNT)) .buildAndRegister(); } diff --git a/src/test/java/gregtech/api/recipes/recipeproperties/RecipePropertyStorageTest.java b/src/test/java/gregtech/api/recipes/recipeproperties/RecipePropertyStorageTest.java deleted file mode 100644 index e3daea5e015..00000000000 --- a/src/test/java/gregtech/api/recipes/recipeproperties/RecipePropertyStorageTest.java +++ /dev/null @@ -1,138 +0,0 @@ -package gregtech.api.recipes.recipeproperties; - -import org.hamcrest.MatcherAssert; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import static org.hamcrest.CoreMatchers.is; - -public class RecipePropertyStorageTest { - - private static final String propInt1Key = "propInt1"; - - private static final DefaultProperty propInt1 = new DefaultProperty<>(propInt1Key, Integer.class); - private static final DefaultProperty propInt2 = new DefaultProperty<>("propInt2", Integer.class); - private static final DefaultProperty propInt1_2 = new DefaultProperty<>("propInt1", Integer.class); - private static final DefaultProperty wrongCast = new DefaultProperty<>("wrongCast", Integer.class); - - private RecipePropertyStorage storage; - - @BeforeEach - public void initTestStub() { - this.storage = new RecipePropertyStorage(); - } - - @Test - public void storing_unique_recipe_properties_succeeds() { - MatcherAssert.assertThat(storage.store(propInt1, 1), is(true)); - MatcherAssert.assertThat(storage.store(propInt2, 1), is(true)); - } - - @Test - public void storing_same_property_twice_fails() { - MatcherAssert.assertThat(storage.store(propInt1, 1), is(true)); - MatcherAssert.assertThat(storage.store(propInt1, 1), is(false)); - } - - @Test - public void storing_unique_properties_with_same_key_fails() { - MatcherAssert.assertThat(storage.store(propInt1, 1), is(true)); - MatcherAssert.assertThat(storage.store(propInt1_2, 1), is(false)); - } - - @Test - public void storing_property_with_wrong_cast_fails() { - MatcherAssert.assertThat(storage.store(wrongCast, "This is not int"), is(false)); - } - - @Test - public void storing_property_without_value_fails() { - MatcherAssert.assertThat(storage.store(propInt1, null), is(false)); - } - - @Test - public void get_size_returns_correct_value() { - storage.store(propInt1, 1); // succeeds - - MatcherAssert.assertThat(storage.getSize(), is(1)); - - storage.store(propInt2, 2); // succeeds - - MatcherAssert.assertThat(storage.getSize(), is(2)); - - storage.store(propInt1, 1); // fails - - MatcherAssert.assertThat(storage.getSize(), is(2)); - } - - @Test - public void get_recipe_properties_returns_correct_value() { - storage.store(propInt1, 1); // succeeds - storage.store(propInt2, 2); // succeeds - - Map, Object> map = new HashMap<>(); - map.put(propInt1, 1); - map.put(propInt2, 2); - Set, Object>> expectedProperties = map.entrySet(); - - Set, Object>> actualProperties = storage.getRecipeProperties(); - - MatcherAssert.assertThat(actualProperties.size(), is(2)); - MatcherAssert.assertThat( - actualProperties.containsAll(expectedProperties) && expectedProperties.containsAll(actualProperties), - is(true)); - } - - @Test - public void get_recipe_property_value_returns_correct_value_if_exists() { - final int expectedValue = 1; - storage.store(propInt1, expectedValue); // succeeds - - int actual = storage.getRecipePropertyValue(propInt1, 0); - - MatcherAssert.assertThat(actual, is(expectedValue)); - } - - @Test - public void get_recipe_property_value_returns_default_value_if_does_not_exists() { - final int expectedValue = 0; - storage.store(propInt1, 1); // succeeds - - int actual = storage.getRecipePropertyValue(propInt2, expectedValue); - - MatcherAssert.assertThat(actual, is(expectedValue)); - } - - @Test - // CT way - public void get_recipe_property_keys() { - storage.store(propInt1, 1); // succeeds - storage.store(propInt2, 2); // succeeds - - Set expectedKeys = new HashSet<>(); - expectedKeys.add(propInt1.getKey()); - expectedKeys.add(propInt2.getKey()); - - Set actualKeys = storage.getRecipePropertyKeys(); - - MatcherAssert.assertThat(expectedKeys.containsAll(actualKeys) && actualKeys.containsAll(expectedKeys), - is(true)); - } - - @Test - // CT way - public void get_raw_recipe_property_value_via_string_key() { - final int expectedValue = 1; - - storage.store(propInt1, expectedValue); // succeeds - - Object actualValue = storage.getRawRecipePropertyValue(propInt1.getKey()); - - MatcherAssert.assertThat(actualValue, is(expectedValue)); - } -}