diff --git a/src/main/java/com/simibubi/create/content/equipment/sandPaper/SandPaperItem.java b/src/main/java/com/simibubi/create/content/equipment/sandPaper/SandPaperItem.java index 73b2eb02da..4a0f692aa0 100644 --- a/src/main/java/com/simibubi/create/content/equipment/sandPaper/SandPaperItem.java +++ b/src/main/java/com/simibubi/create/content/equipment/sandPaper/SandPaperItem.java @@ -142,6 +142,14 @@ public ItemStack finishUsingItem(ItemStack stack, Level worldIn, LivingEntity en .placeItemBackInInventory(polished); } } + if (!toPolish.isEmpty() && toPolish.hasCraftingRemainingItem()) { + if (player instanceof FakePlayer) { + player.drop(toPolish.getCraftingRemainingItem(), false, false); + } else { + player.getInventory() + .placeItemBackInInventory(toPolish.getCraftingRemainingItem()); + } + } tag.remove("Polishing"); stack.hurtAndBreak(1, entityLiving, p -> p.broadcastBreakEvent(p.getUsedItemHand())); } diff --git a/src/main/java/com/simibubi/create/content/kinetics/crusher/CrushingWheelControllerBlockEntity.java b/src/main/java/com/simibubi/create/content/kinetics/crusher/CrushingWheelControllerBlockEntity.java index 021acaedd7..8da66b02b3 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/crusher/CrushingWheelControllerBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/kinetics/crusher/CrushingWheelControllerBlockEntity.java @@ -126,7 +126,7 @@ public void tick() { float processingSpeed = Mth.clamp((speed) / (!inventory.appliedRecipe ? (float) Math.log(inventory.getStackInSlot(0) - .getCount())/(float) Math.log(2) : 1), .25f, 20); + .getCount()) / (float) Math.log(2) : 1), .25f, 20); inventory.remainingTime -= processingSpeed; spawnParticles(inventory.getStackInSlot(0)); @@ -296,8 +296,8 @@ private void applyRecipe() { List list = new ArrayList<>(); if (recipe.isPresent()) { - int rolls = inventory.getStackInSlot(0) - .getCount(); + ItemStack input = inventory.getStackInSlot(0); + int rolls = input.getCount(); inventory.clear(); for (int roll = 0; roll < rolls; roll++) { List rolledResults = recipe.get() @@ -305,6 +305,9 @@ private void applyRecipe() { for (ItemStack stack : rolledResults) { ItemHelper.addToList(stack, list); } + if (input.hasCraftingRemainingItem()) { + ItemHelper.addToList(input.getCraftingRemainingItem(), list); + } } for (int slot = 0; slot < list.size() && slot + 1 < inventory.getSlots(); slot++) inventory.setStackInSlot(slot + 1, list.get(slot)); diff --git a/src/main/java/com/simibubi/create/content/kinetics/deployer/BeltDeployerCallbacks.java b/src/main/java/com/simibubi/create/content/kinetics/deployer/BeltDeployerCallbacks.java index c887692201..b6932c4eef 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/deployer/BeltDeployerCallbacks.java +++ b/src/main/java/com/simibubi/create/content/kinetics/deployer/BeltDeployerCallbacks.java @@ -25,6 +25,7 @@ import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.level.Level; @@ -97,7 +98,7 @@ public static void activate(TransportedItemStack transported, TransportedItemSta DeployerBlockEntity blockEntity, Recipe recipe) { List collect = - RecipeApplier.applyRecipeOn(blockEntity.getLevel(), ItemHandlerHelper.copyStackWithSize(transported.stack, 1), recipe) + RecipeApplier.applyRecipeOn(blockEntity.getLevel(), ItemHandlerHelper.copyStackWithSize(transported.stack, 1), recipe, true) .stream() .map(stack -> { TransportedItemStack copy = transported.copy(); @@ -135,11 +136,23 @@ public static void activate(TransportedItemStack transported, TransportedItemSta recipe instanceof ItemApplicationRecipe && ((ItemApplicationRecipe) recipe).shouldKeepHeldItem(); if (!keepHeld) { - if (heldItem.isDamageableItem()) + if (heldItem.isDamageableItem()) { heldItem.hurtAndBreak(1, blockEntity.player, s -> s.broadcastBreakEvent(InteractionHand.MAIN_HAND)); - else + } else { + Player player = blockEntity.player; + ItemStack leftover = heldItem.hasCraftingRemainingItem() ? heldItem.getCraftingRemainingItem() : ItemStack.EMPTY; + heldItem.shrink(1); + + if (heldItem.isEmpty()) { + player.setItemInHand(InteractionHand.MAIN_HAND, leftover); + } else { + if (!player.getInventory().add(leftover)) { + player.drop(leftover, false); + } + } + } } if (resultItem != null && !resultItem.isEmpty()) diff --git a/src/main/java/com/simibubi/create/content/kinetics/deployer/ManualApplicationRecipe.java b/src/main/java/com/simibubi/create/content/kinetics/deployer/ManualApplicationRecipe.java index d02b0fbb19..eeeeb85b6a 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/deployer/ManualApplicationRecipe.java +++ b/src/main/java/com/simibubi/create/content/kinetics/deployer/ManualApplicationRecipe.java @@ -84,10 +84,23 @@ public static void manualApplicationRecipesApplyInWorld(PlayerInteractEvent.Righ boolean keepHeld = recipe.shouldKeepHeldItem() || creative; if (!keepHeld) { - if (heldItem.isDamageableItem()) + if (heldItem.isDamageableItem()) { heldItem.hurtAndBreak(1, event.getEntity(), s -> s.broadcastBreakEvent(InteractionHand.MAIN_HAND)); - else + } else { + Player player = event.getEntity(); + InteractionHand hand = event.getHand(); + ItemStack leftover = heldItem.hasCraftingRemainingItem() ? heldItem.getCraftingRemainingItem() : ItemStack.EMPTY; + heldItem.shrink(1); + + if (heldItem.isEmpty()) { + player.setItemInHand(hand, leftover); + } else { + if (!player.getInventory().add(leftover)) { + player.drop(leftover, false); + } + } + } } awardAdvancements(event.getEntity(), transformedBlock); diff --git a/src/main/java/com/simibubi/create/content/kinetics/fan/processing/AllFanProcessingTypes.java b/src/main/java/com/simibubi/create/content/kinetics/fan/processing/AllFanProcessingTypes.java index 0d0a1c454e..19282737ee 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/fan/processing/AllFanProcessingTypes.java +++ b/src/main/java/com/simibubi/create/content/kinetics/fan/processing/AllFanProcessingTypes.java @@ -165,7 +165,7 @@ public List process(ItemStack stack, Level level) { .getResultItem(registryAccess), smeltingRecipe.get() .getResultItem(registryAccess))) { - return RecipeApplier.applyRecipeOn(level, stack, smeltingRecipe.get()); + return RecipeApplier.applyRecipeOn(level, stack, smeltingRecipe.get(), false); } } @@ -238,7 +238,7 @@ public List process(ItemStack stack, Level level) { HAUNTING_WRAPPER.setItem(0, stack); Optional recipe = AllRecipeTypes.HAUNTING.find(HAUNTING_WRAPPER, level); if (recipe.isPresent()) - return RecipeApplier.applyRecipeOn(level, stack, recipe.get()); + return RecipeApplier.applyRecipeOn(level, stack, recipe.get(), true); return null; } @@ -364,7 +364,7 @@ public List process(ItemStack stack, Level level) { .filter(AllRecipeTypes.CAN_BE_AUTOMATED); if (smokingRecipe.isPresent()) - return RecipeApplier.applyRecipeOn(level, stack, smokingRecipe.get()); + return RecipeApplier.applyRecipeOn(level, stack, smokingRecipe.get(), false); return null; } @@ -429,7 +429,7 @@ public List process(ItemStack stack, Level level) { SPLASHING_WRAPPER.setItem(0, stack); Optional recipe = AllRecipeTypes.SPLASHING.find(SPLASHING_WRAPPER, level); if (recipe.isPresent()) - return RecipeApplier.applyRecipeOn(level, stack, recipe.get()); + return RecipeApplier.applyRecipeOn(level, stack, recipe.get(), true); return null; } diff --git a/src/main/java/com/simibubi/create/content/kinetics/millstone/MillstoneBlockEntity.java b/src/main/java/com/simibubi/create/content/kinetics/millstone/MillstoneBlockEntity.java index e56086073a..e151ddaaf0 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/millstone/MillstoneBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/kinetics/millstone/MillstoneBlockEntity.java @@ -24,6 +24,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; + import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.capabilities.Capability; @@ -140,10 +141,14 @@ private void process() { } ItemStack stackInSlot = inputInv.getStackInSlot(0); + ItemStack craftingRemainingItem = stackInSlot.getCraftingRemainingItem(); stackInSlot.shrink(1); inputInv.setStackInSlot(0, stackInSlot); lastRecipe.rollResults() .forEach(stack -> ItemHandlerHelper.insertItemStacked(outputInv, stack, false)); + if (!craftingRemainingItem.isEmpty()) { + ItemHandlerHelper.insertItemStacked(outputInv, craftingRemainingItem, false); + } award(AllAdvancements.MILLSTONE); sendData(); diff --git a/src/main/java/com/simibubi/create/content/kinetics/press/MechanicalPressBlockEntity.java b/src/main/java/com/simibubi/create/content/kinetics/press/MechanicalPressBlockEntity.java index 78bb465a5a..c48614f3fe 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/press/MechanicalPressBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/kinetics/press/MechanicalPressBlockEntity.java @@ -124,12 +124,12 @@ public boolean tryProcessInWorld(ItemEntity itemEntity, boolean simulate) { ItemStack itemCreated = ItemStack.EMPTY; pressingBehaviour.particleItems.add(item); if (canProcessInBulk() || item.getCount() == 1) { - RecipeApplier.applyRecipeOn(itemEntity, recipe.get()); + RecipeApplier.applyRecipeOn(itemEntity, recipe.get(), true); itemCreated = itemEntity.getItem() .copy(); } else { for (ItemStack result : RecipeApplier.applyRecipeOn(level, ItemHandlerHelper.copyStackWithSize(item, 1), - recipe.get())) { + recipe.get(), true)) { if (itemCreated.isEmpty()) itemCreated = result.copy(); ItemEntity created = @@ -155,7 +155,7 @@ public boolean tryProcessOnBelt(TransportedItemStack input, List outp return true; pressingBehaviour.particleItems.add(input.stack); List outputs = RecipeApplier.applyRecipeOn(level, - canProcessInBulk() ? input.stack : ItemHandlerHelper.copyStackWithSize(input.stack, 1), recipe.get()); + canProcessInBulk() ? input.stack : ItemHandlerHelper.copyStackWithSize(input.stack, 1), recipe.get(), true); for (ItemStack created : outputs) { if (!created.isEmpty()) { diff --git a/src/main/java/com/simibubi/create/content/kinetics/saw/SawBlockEntity.java b/src/main/java/com/simibubi/create/content/kinetics/saw/SawBlockEntity.java index 50cdd73d60..3b1f117712 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/saw/SawBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/kinetics/saw/SawBlockEntity.java @@ -365,6 +365,8 @@ else if (recipe instanceof StonecutterRecipe || recipe.getType() == woodcuttingR for (ItemStack stack : results) { ItemHelper.addToList(stack, list); } + if (input.hasCraftingRemainingItem()) + ItemHelper.addToList(input.getCraftingRemainingItem(), list); } for (int slot = 0; slot < list.size() && slot + 1 < inventory.getSlots(); slot++) diff --git a/src/main/java/com/simibubi/create/foundation/recipe/RecipeApplier.java b/src/main/java/com/simibubi/create/foundation/recipe/RecipeApplier.java index f575218ff6..2434a1a585 100644 --- a/src/main/java/com/simibubi/create/foundation/recipe/RecipeApplier.java +++ b/src/main/java/com/simibubi/create/foundation/recipe/RecipeApplier.java @@ -12,11 +12,12 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.level.Level; + import net.minecraftforge.items.ItemHandlerHelper; public class RecipeApplier { - public static void applyRecipeOn(ItemEntity entity, Recipe recipe) { - List stacks = applyRecipeOn(entity.level(), entity.getItem(), recipe); + public static void applyRecipeOn(ItemEntity entity, Recipe recipe, boolean returnProcessingRemainder) { + List stacks = applyRecipeOn(entity.level(), entity.getItem(), recipe, returnProcessingRemainder); if (stacks == null) return; if (stacks.isEmpty()) { @@ -31,7 +32,7 @@ public static void applyRecipeOn(ItemEntity entity, Recipe recipe) { } } - public static List applyRecipeOn(Level level, ItemStack stackIn, Recipe recipe) { + public static List applyRecipeOn(Level level, ItemStack stackIn, Recipe recipe, boolean returnProcessingRemainder) { List stacks; if (recipe instanceof ProcessingRecipe pr) { @@ -56,6 +57,10 @@ public static List applyRecipeOn(Level level, ItemStack stackIn, Reci stacks.add(stack); } + + if (returnProcessingRemainder && stackIn.hasCraftingRemainingItem()) { + ItemHelper.addToList(stackIn.getCraftingRemainingItem(), stacks); + } } } else { ItemStack out = recipe.getResultItem(level.registryAccess())