Skip to content

Commit 3309159

Browse files
authored
335,544.32% recipe logic improvement (GregTechCEu#3645)
1 parent d6f7ef9 commit 3309159

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

src/main/java/com/gregtechceu/gtceu/api/recipe/RecipeRunner.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,12 @@ private ActionResult handleContents() {
125125
for (RecipeHandlerList handler : handlerGroups.getOrDefault(BUS_DISTINCT, Collections.emptyList())) {
126126
// Handle the contents of this handler and also all the bypassed handlers
127127
var res = handler.handleRecipe(io, recipe, searchRecipeContents, true);
128-
for (RecipeHandlerList bypassHandler : handlerGroups.getOrDefault(BYPASS_DISTINCT,
129-
Collections.emptyList())) {
130-
res = bypassHandler.handleRecipe(io, recipe, res, true);
128+
if (!res.isEmpty()) {
129+
for (RecipeHandlerList bypassHandler : handlerGroups.getOrDefault(BYPASS_DISTINCT,
130+
Collections.emptyList())) {
131+
res = bypassHandler.handleRecipe(io, recipe, res, true);
132+
if (res.isEmpty()) break;
133+
}
131134
}
132135
if (res.isEmpty()) {
133136
if (!simulated) {

src/main/java/com/gregtechceu/gtceu/integration/ae2/machine/MEPatternBufferPartMachine.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,10 @@ public List<ItemStack> getItems() {
494494

495495
public List<FluidStack> getFluids() {
496496
if (fluidStacks == null) {
497-
fluidStacks = fluidInventory.object2LongEntrySet().stream()
498-
.map(e -> new FluidStack(e.getKey(), GTMath.saturatedCast(e.getLongValue())))
499-
.toList();
497+
fluidStacks = new ArrayList<>();
498+
fluidInventory.object2LongEntrySet().stream()
499+
.map(e -> GTMath.splitFluidStacks(e.getKey(), e.getLongValue()))
500+
.forEach(fluidStacks::addAll);
500501
}
501502
return fluidStacks;
502503
}

src/main/java/com/gregtechceu/gtceu/utils/GTMath.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.minecraft.MethodsReturnNonnullByDefault;
44
import net.minecraft.world.item.ItemStack;
5+
import net.minecraftforge.fluids.FluidStack;
56

67
import it.unimi.dsi.fastutil.ints.IntArrayList;
78
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
@@ -24,15 +25,31 @@ public static long clamp(long value, long min, long max) {
2425
}
2526

2627
public static List<ItemStack> splitStacks(ItemStack stack, long amount) {
27-
int count = saturatedCast(amount);
28-
int fullStacks = count / 64;
29-
int rem = count % 64;
28+
int fullStacks = (int) (amount / Integer.MAX_VALUE);
29+
int rem = (int) (amount % Integer.MAX_VALUE);
3030
List<ItemStack> stacks = new ObjectArrayList<>(fullStacks + 1);
31-
if (fullStacks > 0) stacks.addAll(Collections.nCopies(fullStacks, stack.copyWithCount(64)));
31+
if (fullStacks > 0) stacks.addAll(Collections.nCopies(fullStacks, stack.copyWithCount(Integer.MAX_VALUE)));
3232
if (rem > 0) stacks.add(stack.copyWithCount(rem));
3333
return stacks;
3434
}
3535

36+
public static List<FluidStack> splitFluidStacks(FluidStack stack, long amount) {
37+
int fullStacks = (int) (amount / Integer.MAX_VALUE);
38+
int rem = (int) (amount % Integer.MAX_VALUE);
39+
List<FluidStack> stacks = new ObjectArrayList<>(fullStacks + 1);
40+
if (fullStacks > 0) {
41+
var copy = stack.copy();
42+
copy.setAmount(Integer.MAX_VALUE);
43+
stacks.addAll(Collections.nCopies(fullStacks, copy));
44+
}
45+
if (rem > 0) {
46+
var copy = stack.copy();
47+
copy.setAmount(rem);
48+
stacks.add(copy);
49+
}
50+
return stacks;
51+
}
52+
3653
public static int[] split(long value) {
3754
IntArrayList result = new IntArrayList();
3855
while (value > 0) {

0 commit comments

Comments
 (0)