Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/content/Modpacks/Changes/v8.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,5 @@ As a recipe-matching optimization, input handlers whose `getTotalContentAmount()
- Calling the battery buffer constructor with the following args gives the same behaviour as a charger machine: `(info, tier, inventorySize, BatteryBufferMachine.AMPS_PER_BATTERY_CHARGER, 0)`
- Refactored Jade provider code. Use the `MachineInfoProvider` class for jade providers for a specific machine type, and `MachineTraitProvider` for providers for a specific machine trait.
- `GTUtil.getMoltenFluid(Material)` has been moved to `Material.getHotFluid()`.
- `ICopyable::copyConfig`'s `CompoundTag` argument should now be mutated by reference instead of a new one returned (and thus, the return type has been changed to `void`).
- `ICopyable::copyConfig`'s `CompoundTag` argument should now be mutated by reference instead of a new one returned (and thus, the return type has been changed to `void`).
- Tiered Chance Boosting has been formally removed from the API (as it was deprecated in v7.0.) `ChancedInput` and `ChancedOutput` kubeJS calls will throw errors if they still had chance boost values as arguments.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public List<NotifiableEnergyContainer> getCapabilityHandlers(MetaMachine machine
*/
public static List<Content> makeEUContent(EnergyStack eu) {
return List.of(
new Content(eu, ChanceLogic.getMaxChancedValue(), ChanceLogic.getMaxChancedValue(), 0));
new Content(eu, ChanceLogic.getMaxChancedValue(), ChanceLogic.getMaxChancedValue()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ public List<Object> compressIngredients(@Unmodifiable Collection<Object> ingredi
// spotless:off
if (ingredient.getContainedCustom() instanceof IntCircuitIngredient) {
list.addFirst(ingredient);
} else if (ingredient.getContainedCustom() instanceof IntProviderIngredient intProvider &&
intProvider.getInner().getCustomIngredient() instanceof IntCircuitIngredient) {
list.addFirst(ingredient);
} else {
list.add(ingredient);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ public Builder addOutputLines(GTRecipe recipe) {
if (recipe != null) {
int recipeTier = RecipeHelper.getPreOCRecipeEuTier(recipe);
int chanceTier = recipeTier + recipe.ocLevel;
var function = recipe.getType().getChanceFunction();
double maxDurationSec = (double) recipe.duration / 20.0;
var itemOutputs = recipe.getOutputContents(ItemRecipeCapability.CAP);
var fluidOutputs = recipe.getOutputContents(FluidRecipeCapability.CAP);
Expand All @@ -456,8 +455,7 @@ public Builder addOutputLines(GTRecipe recipe) {
provider.getCountProvider().getMinValue(),
provider.getCountProvider().getMaxValue());
if (item.chance() < item.maxChance()) {
countD = countD * runs * function.getBoostedChance(item, recipeTier, chanceTier) /
item.maxChance();
countD = countD * runs * item.chance() / item.maxChance();
}
countD = countD * provider.getMidRoll();
} else {
Expand All @@ -468,8 +466,7 @@ public Builder addOutputLines(GTRecipe recipe) {
countD *= count;
if (item.chance() < item.maxChance()) {
rounded = true;
countD = countD * runs * function.getBoostedChance(item, recipeTier, chanceTier) /
item.maxChance();
countD = countD * runs * item.chance() / item.maxChance();
}
count = Math.max(1, (int) Math.round(countD));
displaycount = Component.literal(String.valueOf(count));
Expand Down Expand Up @@ -500,8 +497,7 @@ public Builder addOutputLines(GTRecipe recipe) {
provider.getCountProvider().getMinValue(),
provider.getCountProvider().getMaxValue());
if (fluid.chance() < fluid.maxChance()) {
amountD = amountD * runs * function.getBoostedChance(fluid, recipeTier, chanceTier) /
fluid.maxChance();
amountD = amountD * runs * fluid.chance() / fluid.maxChance();
}
amountD = amountD * provider.getMidRoll();
} else {
Expand All @@ -512,8 +508,7 @@ public Builder addOutputLines(GTRecipe recipe) {
amountD *= amount;
if (fluid.chance() < fluid.maxChance()) {
rounded = true;
amountD = amountD * runs * function.getBoostedChance(fluid, recipeTier, chanceTier) /
fluid.maxChance();
amountD = amountD * runs * fluid.chance() / fluid.maxChance();
}
amount = Math.max(1, (int) Math.round(amountD));
displaycount = Component.literal(String.valueOf(amount));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ public List<SizedFluidIngredient> handleRecipeInner(IO io, GTRecipe recipe,
FluidStack[] fluids;

if (ingredient.ingredient() instanceof IntProviderFluidIngredient provider) {
provider.setFluidStacks(null);
provider.setSampledCount(-1);

if (simulate) {
fluids = new FluidStack[] { provider.getMaxSizeStack() };
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ public static List<SizedIngredient> handleRecipe(IO io, GTRecipe recipe, List<Si
ItemStack[] items;
int amount;
if (ingredient.ingredient().getCustomIngredient() instanceof IntProviderIngredient provider) {
provider.setItemStacks(null);
provider.setSampledCount(-1);

ItemStack output;
if (simulate) {
output = provider.getMaxSizeStack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected List<Class<?>> validMachineClasses() {
public long getInputAmperage() {
var recipeLogic = getMachine().getTrait(RecipeLogic.TYPE);
if (recipeLogic == null) return 0;
var lastRecipe = recipeLogic.getLastRecipe();
var lastRecipe = recipeLogic.getLastDisplayedRecipe();
long amperage;
if (lastRecipe != null) {
amperage = lastRecipe.getInputEUt().amperage();
Expand All @@ -49,7 +49,7 @@ public long getInputAmperage() {
public long getOutputAmperage() {
var recipeLogic = getMachine().getTrait(RecipeLogic.TYPE);
if (recipeLogic == null) return 0;
var lastRecipe = recipeLogic.getLastRecipe();
var lastRecipe = recipeLogic.getLastDisplayedRecipe();
if (lastRecipe != null) {
return lastRecipe.getOutputEUt().amperage();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ public enum Status implements StringRepresentable {
@Nullable
@Getter
@SaveField
@SyncToClient
protected GTRecipe lastRecipe;
@Nullable
@Getter
@SaveField
@SyncToClient
protected GTRecipe lastDisplayedRecipe;
@Getter
@SaveField
@SyncToClient
Expand Down Expand Up @@ -165,6 +169,7 @@ protected void onStatusSynced() {
public void resetRecipeLogic() {
recipeDirty = false;
lastRecipe = null;
lastDisplayedRecipe = null;
lastOriginRecipe = null;
consecutiveRecipes = 0;
progress = 0;
Expand Down Expand Up @@ -354,16 +359,18 @@ public void findAndHandleRecipe() {
if (!recipeDirty && lastRecipe != null && checkRecipe(lastRecipe).isSuccess()) {
GTRecipe recipe = lastRecipe;
lastRecipe = null;
lastDisplayedRecipe = null;
lastOriginRecipe = null;
setupRecipe(recipe);
} else {
// try to find and handle a new recipe
failureReasonMap.clear();
lastRecipe = null;
lastDisplayedRecipe = null;
lastOriginRecipe = null;
handleSearchingRecipes(searchRecipe());
}
syncDataHolder.markClientSyncFieldDirty("lastRecipe");
syncDataHolder.markClientSyncFieldDirty("lastDisplayedRecipe");
recipeDirty = false;
}

Expand Down Expand Up @@ -393,6 +400,8 @@ public ActionResult handleTickRecipe(GTRecipe recipe) {
var result = RecipeHelper.matchTickRecipe(getRLMachine(), recipe);
if (!result.isSuccess()) return result;

recipe.doTickPrerolls(this.chanceCaches);

result = handleTickRecipeIO(recipe, IO.IN);
if (!result.isSuccess()) return result;

Expand All @@ -410,6 +419,12 @@ public void setupRecipe(GTRecipe recipe) {
syncDataHolder.resyncAllFields();
return;
}
if (lastRecipe != null && !recipe.equals(lastRecipe)) {
chanceCaches.clear();
}
lastDisplayedRecipe = recipe.copy();
syncDataHolder.markClientSyncFieldDirty("lastDisplayedRecipe");
recipe.doPrerolls(this.chanceCaches);
var handledIO = handleRecipeIO(recipe, IO.IN);
if (handledIO.isSuccess()) {
if (lastRecipe != null && !recipe.equals(lastRecipe)) {
Expand All @@ -423,6 +438,8 @@ public void setupRecipe(GTRecipe recipe) {
duration = recipe.duration;
isActive = true;
syncDataHolder.resyncAllFields();
} else {
lastDisplayedRecipe = null;
}
}

Expand Down Expand Up @@ -541,6 +558,7 @@ public void onRecipeFinish() {
isActive = false;
// Force a recipe recheck.
lastRecipe = null;
lastDisplayedRecipe = null;
syncDataHolder.resyncAllFields();
return;
}
Expand All @@ -551,7 +569,6 @@ public void onRecipeFinish() {
markLastRecipeDirty();
} else {
lastRecipe = modified;
syncDataHolder.markClientSyncFieldDirty("lastRecipe");
}
} else {
markLastRecipeDirty();
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.gregtechceu.gtceu.api.recipe.content.Content;
import com.gregtechceu.gtceu.api.recipe.content.ContentModifier;
import com.gregtechceu.gtceu.api.recipe.ingredient.EnergyStack;
import com.gregtechceu.gtceu.api.recipe.ingredient.IRangedIngredient;

import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -16,12 +17,14 @@
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.level.Level;

import it.unimi.dsi.fastutil.objects.Object2IntMap;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.stream.Stream;

public class GTRecipe implements Recipe<RecipeInput> {

Expand Down Expand Up @@ -246,6 +249,36 @@ public ChanceLogic getChanceLogicForCapability(RecipeCapability<?> cap, IO io, b
return new EnergyStack(v, a);
}

public void doPrerolls(IdentityHashMap<RecipeCapability<?>, Object2IntMap<?>> chanceCaches) {
var rangedContents = getFullContents();
for (Content item : rangedContents) {
if (item.content() instanceof IRangedIngredient ranged)
ranged.rollSampledCount();
}
}

public void doTickPrerolls(IdentityHashMap<RecipeCapability<?>, Object2IntMap<?>> chanceCaches) {
var rangedContents = getFullTickContents();
for (Content item : rangedContents) {
if (item.content() instanceof IRangedIngredient ranged)
ranged.rollSampledCount();
}
}

public List<Content> getFullContents() {
return Stream
.concat(inputs.values().stream(), outputs.values().stream())
.flatMap(List::stream)
.toList();
}

public List<Content> getFullTickContents() {
return Stream
.concat(tickInputs.values().stream(), tickOutputs.values().stream())
.flatMap(List::stream)
.toList();
}

public int getTotalRuns() {
return parallels * subtickParallels * batchParallels;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.capability.recipe.*;
import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory;
import com.gregtechceu.gtceu.api.recipe.chance.boost.ChanceBoostFunction;
import com.gregtechceu.gtceu.api.recipe.gui.GTRecipeTypeUILayout;
import com.gregtechceu.gtceu.api.recipe.lookup.RecipeAdditionHandler;
import com.gregtechceu.gtceu.api.recipe.lookup.RecipeDB;
Expand Down Expand Up @@ -51,9 +50,6 @@ public class GTRecipeType implements RecipeType<GTRecipe> {
@Getter
@Setter
private GTRecipeBuilder recipeBuilder;
@Getter
@Setter
private ChanceBoostFunction chanceFunction = ChanceBoostFunction.NONE;
@Setter
@Getter
private GTRecipeType smallRecipeMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,7 @@ public static int getRatioForDistillery(SizedFluidIngredient fluidInput, SizedFl
}

public static boolean isFluidStackDivisibleForDistillery(SizedFluidIngredient fluidStack, int divisor) {
int amount = (fluidStack.ingredient() instanceof IRangedIngredient ranged ? ranged.getMaxRoll() :
fluidStack.amount());
// int amount = (fluidStack.ingredient() instanceof IRangedIngredient ranged ? ranged.getMaxRoll() : fluidStack.amount());
return fluidStack.amount() % divisor == 0 && fluidStack.amount() / divisor >= 25;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.gregtechceu.gtceu.api.machine.trait.RecipeHandlerGroup;
import com.gregtechceu.gtceu.api.machine.trait.RecipeHandlerGroupColor;
import com.gregtechceu.gtceu.api.machine.trait.RecipeHandlerList;
import com.gregtechceu.gtceu.api.recipe.chance.boost.ChanceBoostFunction;
import com.gregtechceu.gtceu.api.recipe.chance.logic.ChanceLogic;
import com.gregtechceu.gtceu.api.recipe.content.Content;

Expand Down Expand Up @@ -73,9 +72,6 @@ public ActionResult handle(Map<RecipeCapability<?>, List<Content>> entries) {
* Populates the content match list to know if conditions are satisfied.
*/
private void fillContentMatchList(Map<RecipeCapability<?>, List<Content>> entries) {
ChanceBoostFunction function = recipe.getType().getChanceFunction();
int recipeTier = RecipeHelper.getPreOCRecipeEuTier(recipe);
int chanceTier = recipeTier + recipe.ocLevel;
for (var entry : entries.entrySet()) {
RecipeCapability<?> cap = entry.getKey();
if (!cap.doMatchInRecipe()) continue;
Expand All @@ -97,7 +93,7 @@ private void fillContentMatchList(Map<RecipeCapability<?>, List<Content>> entrie

if (cont.chance() >= cont.maxChance()) {
contentList.add(cont.content());
} else if (cont.chance() > 0 || cont.tierChanceBoost() > 0) {
} else if (cont.chance() > 0) {
chancedContents.add(cont);
}
// Do not add Non-Consumed ingredients; they'd just get dropped after the chance roll anyway
Expand All @@ -106,8 +102,7 @@ private void fillContentMatchList(Map<RecipeCapability<?>, List<Content>> entrie
// add chanced contents to the recipe content map
if (!chancedContents.isEmpty()) {
var cache = this.chanceCaches.get(cap);
chancedContents = logic.roll(cap, chancedContents, function, recipeTier, chanceTier, cache,
recipe.getTotalRuns());
chancedContents = logic.roll(cap, chancedContents, cache, recipe.getTotalRuns());

for (Content cont : chancedContents) {
contentList.add(cont.content());
Expand Down

This file was deleted.

Loading
Loading