Skip to content

Commit

Permalink
clean up recipe property storage (#2607)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechLord22 authored Sep 19, 2024
1 parent 4479f8f commit efd8617
Show file tree
Hide file tree
Showing 57 changed files with 734 additions and 750 deletions.
2 changes: 2 additions & 0 deletions src/main/java/gregtech/api/GregTechAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
26 changes: 14 additions & 12 deletions src/main/java/gregtech/api/capability/impl/AbstractRecipeLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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());
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Integer, Double> maintenanceValues = getMaintenanceValues();

Expand All @@ -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<Integer, Double> maintenanceValues = getMaintenanceValues();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
Expand Down
61 changes: 23 additions & 38 deletions src/main/java/gregtech/api/recipes/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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;

Expand All @@ -113,10 +113,9 @@ public Recipe(@NotNull List<GTRecipeInput> 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();
Expand Down Expand Up @@ -742,40 +741,26 @@ public GTRecipeCategory getRecipeCategory() {
///////////////////////////////////////////////////////////
// Property Helper Methods //
///////////////////////////////////////////////////////////
public <T> T getProperty(RecipeProperty<T> property, T defaultValue) {
return recipePropertyStorage.getRecipePropertyValue(property, defaultValue);
}

public Object getPropertyRaw(String key) {
return recipePropertyStorage.getRawRecipePropertyValue(key);
}

public Set<Map.Entry<RecipeProperty<?>, Object>> getPropertyValues() {
return recipePropertyStorage.getRecipeProperties();
}

public Set<String> getPropertyKeys() {
return recipePropertyStorage.getRecipePropertyKeys();
}

public Set<RecipeProperty<?>> 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 <T> @Nullable T getProperty(@NotNull RecipeProperty<T> 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;
}
}
Loading

0 comments on commit efd8617

Please sign in to comment.