-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package mod.leronus.mores.mixin; | ||
|
||
import mod.leronus.mores.item.ModItems; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.inventory.SimpleInventory; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.recipe.RecipeType; | ||
import net.minecraft.recipe.SmeltingRecipe; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.math.BlockPos; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Mixin(Block.class) | ||
public class BlockMixin { | ||
|
||
@Inject( | ||
method = "getDroppedStacks(Lnet/minecraft/block/BlockState;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/entity/BlockEntity;Lnet/minecraft/entity/Entity;Lnet/minecraft/item/ItemStack;)Ljava/util/List;", | ||
at = @At("RETURN"), | ||
cancellable = true) | ||
private static void getDroppedStacks(BlockState state, ServerWorld world, BlockPos pos, BlockEntity blockEntity, Entity entity, ItemStack stack, CallbackInfoReturnable<List<ItemStack>> cir) { | ||
List<ItemStack> items = new ArrayList<>(); | ||
List<ItemStack> returnValue = cir.getReturnValue(); | ||
if (stack.getItem() != ModItems.RUBY_AXE && stack.getItem() != ModItems.RUBY_PICKAXE && stack.getItem() != ModItems.RUBY_SHOVEL && stack.getItem() != ModItems.RUBY_HOE) { | ||
cir.setReturnValue(returnValue); | ||
return; | ||
} | ||
for (ItemStack itemStack : returnValue) { | ||
// Optional<SmeltingRecipe> recipe = world.getRecipeManager().listAllOfType(RecipeType.SMELTING).stream().filter((smeltingRecipe -> smeltingRecipe.getPreviewInputs().get(0).test(itemStack))).findFirst(); | ||
Optional<SmeltingRecipe> recipe = world.getRecipeManager().getFirstMatch(RecipeType.SMELTING, new SimpleInventory(itemStack), world); | ||
|
||
if (recipe.isPresent()) { | ||
ItemStack smelted = recipe.get().getOutput(world.getRegistryManager()).copy(); | ||
smelted.setCount(itemStack.getCount()); | ||
items.add(smelted); | ||
} else { | ||
items.add(itemStack); | ||
} | ||
} | ||
cir.setReturnValue(items); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters