Skip to content

Commit

Permalink
Use stack-aware recipe remainders
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuxel committed Aug 7, 2024
1 parent 71bc6be commit 0ec852a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import juuxel.adorn.fluid.FluidReference;
import juuxel.adorn.item.AdornItems;
import juuxel.adorn.menu.BrewerMenu;
import juuxel.adorn.platform.ItemBridge;
import juuxel.adorn.recipe.AdornRecipes;
import juuxel.adorn.recipe.BrewerInput;
import juuxel.adorn.recipe.FluidBrewingRecipe;
Expand Down Expand Up @@ -142,15 +143,14 @@ private boolean isActive() {

private static void decrementIngredient(BrewerBlockEntity brewer, int slot) {
var stack = brewer.getStack(slot);
// TODO: Use stack-aware version on Fabric (and Neo if available)
var remainder = stack.getItem().getRecipeRemainder();
var remainder = ItemBridge.get().getRecipeRemainder(stack);
stack.decrement(1);

if (remainder != null) {
if (!remainder.isEmpty()) {
if (stack.isEmpty()) {
brewer.setStack(slot, new ItemStack(remainder));
brewer.setStack(slot, remainder);
} else {
ItemScatterer.spawn(brewer.world, brewer.pos.getX() + 0.5, brewer.pos.getY() + 0.5, brewer.pos.getZ() + 0.5, new ItemStack(remainder));
ItemScatterer.spawn(brewer.world, brewer.pos.getX() + 0.5, brewer.pos.getY() + 0.5, brewer.pos.getZ() + 0.5, remainder);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions common/src/main/java/juuxel/adorn/compat/emi/EmiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import juuxel.adorn.fluid.FluidIngredient;
import juuxel.adorn.fluid.FluidUnit;
import juuxel.adorn.platform.FluidBridge;
import juuxel.adorn.platform.ItemBridge;
import net.minecraft.item.Item;

public final class EmiUtil {
Expand All @@ -23,9 +24,9 @@ public static EmiIngredient withRemainders(EmiIngredient ingredient) {
for (var stack : ingredient.getEmiStacks()) {
var item = stack.getKeyOfType(Item.class);
if (item == null) continue;
if (item.hasRecipeRemainder()) {
// TODO: Use stack-aware recipe remainders
stack.setRemainder(EmiStack.of(item.getRecipeRemainder()));
var remainder = ItemBridge.get().getRecipeRemainder(stack.getItemStack());
if (!remainder.isEmpty()) {
stack.setRemainder(EmiStack.of(remainder));
}
}

Expand Down
15 changes: 15 additions & 0 deletions common/src/main/java/juuxel/adorn/platform/ItemBridge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package juuxel.adorn.platform;

import juuxel.adorn.util.InlineServices;
import juuxel.adorn.util.Services;
import net.minecraft.item.ItemStack;

@InlineServices
public interface ItemBridge {
ItemStack getRecipeRemainder(ItemStack stack);

@InlineServices.Getter
static ItemBridge get() {
return Services.load(ItemBridge.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package juuxel.adorn.platform.fabric;

import juuxel.adorn.platform.ItemBridge;
import net.minecraft.item.ItemStack;

public final class ItemBridgeFabric implements ItemBridge {
@Override
public ItemStack getRecipeRemainder(ItemStack stack) {
return stack.getRecipeRemainder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
juuxel.adorn.platform.fabric.ItemBridgeFabric
11 changes: 11 additions & 0 deletions forge/src/main/java/juuxel/adorn/platform/neo/ItemBridgeNeo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package juuxel.adorn.platform.neo;

import juuxel.adorn.platform.ItemBridge;
import net.minecraft.item.ItemStack;

public final class ItemBridgeNeo implements ItemBridge {
@Override
public ItemStack getRecipeRemainder(ItemStack stack) {
return stack.hasCraftingRemainingItem() ? stack.getCraftingRemainingItem() : ItemStack.EMPTY;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
juuxel.adorn.platform.neo.ItemBridgeNeo

0 comments on commit 0ec852a

Please sign in to comment.