-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: modify craft result when assembling, supports quick crafting
- Loading branch information
Showing
4 changed files
with
61 additions
and
12 deletions.
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
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
30 changes: 30 additions & 0 deletions
30
src/main/java/com/lovetropics/minigames/mixin/CraftingMenuMixin.java
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,30 @@ | ||
package com.lovetropics.minigames.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import com.lovetropics.minigames.common.core.game.IGameManager; | ||
import com.lovetropics.minigames.common.core.game.IGamePhase; | ||
import com.lovetropics.minigames.common.core.game.behavior.event.GamePlayerEvents; | ||
import net.minecraft.core.HolderLookup; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.inventory.CraftingMenu; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.crafting.CraftingInput; | ||
import net.minecraft.world.item.crafting.CraftingRecipe; | ||
import net.minecraft.world.item.crafting.RecipeInput; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(CraftingMenu.class) | ||
public class CraftingMenuMixin { | ||
@WrapOperation(method = "slotChangedCraftingGrid", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/crafting/CraftingRecipe;assemble(Lnet/minecraft/world/item/crafting/RecipeInput;Lnet/minecraft/core/HolderLookup$Provider;)Lnet/minecraft/world/item/ItemStack;")) | ||
private static ItemStack modifyResult(CraftingRecipe recipe, RecipeInput input, HolderLookup.Provider provider, Operation<ItemStack> original, @Local ServerPlayer player) { | ||
ItemStack originalResult = original.call(recipe, input, provider); | ||
IGamePhase game = IGameManager.get().getGamePhaseFor(player); | ||
if (game != null) { | ||
return game.invoker(GamePlayerEvents.CRAFT_RESULT).modifyResult(player, originalResult, (CraftingInput) input, recipe); | ||
} | ||
return originalResult; | ||
} | ||
} |
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