Skip to content

Commit

Permalink
documentation, annotations, use overclockPolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
TechLord22 committed Nov 23, 2021
1 parent 8d077ca commit e5b8db7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraftforge.fluids.IFluidTank;
import net.minecraftforge.items.IItemHandlerModifiable;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -63,6 +64,10 @@ public abstract class AbstractRecipeLogic extends MTETrait implements IWorkable,

protected boolean hasPerfectOC = false;

/**
* DO NOT use the parallelLimit field directly, EVER
* use {@link AbstractRecipeLogic#setParallelLimit(int)} instead
*/
private int parallelLimit = 1;

public AbstractRecipeLogic(MetaTileEntity tileEntity, RecipeMap<?> recipeMap) {
Expand All @@ -82,7 +87,9 @@ public AbstractRecipeLogic(MetaTileEntity tileEntity, RecipeMap<?> recipeMap, bo

protected abstract boolean drawEnergy(int recipeEUt);

protected abstract long getMaxVoltage();
protected long getMaxVoltage() {
return this.overclockPolicy.getAsLong();
}

protected IItemHandlerModifiable getInputInventory() {
return metaTileEntity.getImportItems();
Expand Down Expand Up @@ -293,6 +300,11 @@ protected boolean prepareRecipe(Recipe recipe) {
return false;
}


/**
* DO NOT use the parallelLimit field directly, EVER
* @return the current parallel limit of the logic
*/
public int getParallelLimit() {
return parallelLimit;
}
Expand All @@ -305,7 +317,7 @@ public Enum<ParallelLogicType> getParallelLogicType() {
return ParallelLogicType.MULTIPLY;
}

protected int getMinTankCapacity(IMultipleTankHandler tanks) {
protected int getMinTankCapacity(@Nonnull IMultipleTankHandler tanks) {
if (tanks.getTanks() == 0) {
return 0;
}
Expand Down Expand Up @@ -385,7 +397,7 @@ protected boolean setupAndConsumeRecipeInputs(Recipe recipe, IItemHandlerModifia
* @param recipe the recipe to run
* @return an int array of {OverclockedEUt, OverclockedDuration}
*/
protected int[] calculateOverclock(Recipe recipe) {
protected int[] calculateOverclock(@Nonnull Recipe recipe) {
int recipeEUt = recipe.getEUt();
int recipeDuration = recipe.getDuration();
// Cannot overclock, keep recipe the same
Expand Down Expand Up @@ -437,7 +449,7 @@ protected int[] performOverclocking(Recipe recipe, boolean negativeEU) {
* @param maxOverclocks the maximum amount of overclocks to perform
* @return an int array of {OverclockedEUt, OverclockedDuration}
*/
protected int[] runOverclockingLogic(Recipe recipe, boolean negativeEU, int maxOverclocks) {
protected int[] runOverclockingLogic(@Nonnull Recipe recipe, boolean negativeEU, int maxOverclocks) {
return runOverclockingLogic(recipe.getEUt() * (negativeEU ? -1 : 1), recipe.getDuration(), maxOverclocks);
}

Expand Down Expand Up @@ -469,7 +481,7 @@ protected double getOverclockingVoltageMultiplier() {
}

/**
* applies standard logic for overclocking
* applies standard logic for overclocking, where each overclock modifies energy and duration
*
* @param recipeEUt the EU/t of the recipe to overclock
* @param maximumVoltage the maximum voltage the recipe is allowed to be run at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import gregtech.api.recipes.RecipeMap;
import net.minecraftforge.items.IItemHandlerModifiable;

import javax.annotation.Nonnull;

public interface IParallelableRecipeLogic {

/**
Expand All @@ -16,7 +18,7 @@ public interface IParallelableRecipeLogic {
*
* @param builder the recipe builder
*/
default void applyParallelBonus(RecipeBuilder<?> builder) {
default void applyParallelBonus(@Nonnull RecipeBuilder<?> builder) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import gregtech.api.render.Textures;
import net.minecraft.util.ResourceLocation;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
Expand All @@ -38,7 +39,7 @@ protected RecipeLogicEnergy createWorkable(RecipeMap<?> recipeMap) {
return result;
}

protected boolean checkRecipe(Recipe recipe) {
protected boolean checkRecipe(@Nonnull Recipe recipe) {
List<Integer> recipeDimensions = recipe.getProperty(GasCollectorDimensionProperty.getInstance(), new ArrayList<>());
for (Integer dimension : recipeDimensions) {
if (dimension == this.getWorld().provider.getDimension()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void invalidateStructure() {
}

@Override
public boolean checkRecipe(Recipe recipe, boolean consumeIfSuccess) {
public boolean checkRecipe(@Nonnull Recipe recipe, boolean consumeIfSuccess) {
return this.blastFurnaceTemperature >= recipe.getProperty(BlastTemperatureProperty.getInstance(), 0);
}

Expand Down Expand Up @@ -193,6 +193,7 @@ public static int[] blastFurnaceOverclockingLogic(int recipeEUt, long maximumVol

// perfect overclock for every 1800k over recipe temperature
if (amountPerfectOC > 0) {
// use the normal overclock logic to do perfect OCs up to as many times as calculated
int[] overclock = standardOverclockingLogic(recipeEUt, maximumVoltage, recipeDuration, PERFECT_OVERCLOCK_DURATION_DIVISOR, STANDARD_OVERCLOCK_VOLTAGE_MULTIPLIER, amountPerfectOC);

// overclock normally as much as possible after perfects are exhausted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public void updateWorkable() {

@Override
protected boolean checkRecipe(Recipe recipe) {
// if the reactor is not able to hold enough energy for it, do not run the recipe
if (recipe.getProperty(FusionEUToStartProperty.getInstance(), 0L) > energyContainer.getEnergyCapacity())
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public ParallelLogicType getParallelLogicType() {
}

@Override
public void applyParallelBonus(RecipeBuilder<?> builder) {
public void applyParallelBonus(@Nonnull RecipeBuilder<?> builder) {
builder.EUt(Math.max(1, 16 / heatingCoilDiscount))
.duration((int) Math.max(1.0, 256 * builder.getParallel() / (getParallelLimit() * 1.0)));
}
Expand Down

0 comments on commit e5b8db7

Please sign in to comment.