Skip to content

Commit

Permalink
fix: revert old MixCraftingMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
Senior-S committed Oct 19, 2024
1 parent 98abc2d commit d38cb04
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,19 @@ repositories {
dependencies {
minecraft 'net.minecraftforge:forge:' + minecraft_version + '-' + forge_version

// Mixin Extras
implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:0.4.0"))
implementation(jarJar("io.github.llamalad7:mixinextras-forge:0.4.0")) {
jarJar.ranged(it, "[0.4.0,)")
}

annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'

// KubeJS
implementation fg.deobf("dev.latvian.mods:kubejs-forge:${kubejs_version}")
implementation fg.deobf("dev.latvian.mods:rhino-forge:${rhino_version}")
implementation fg.deobf("dev.architectury:architectury-forge:${architectury_version}")

// Mixin Extras
implementation(annotationProcessor("io.github.llamalad7:mixinextras-common:0.4.0"))
implementation(jarJar("io.github.llamalad7:mixinextras-forge:0.4.0")) {
jarJar.ranged(it, "[0.4.0,)")
}

// L2
compileOnly fg.deobf("dev.xkmc.l2library:l2library:2.4.28")
compileOnly fg.deobf("dev.xkmc.l2tabs:l2tabs:0.3.1")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
package com.seniors.justlevelingfork.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import com.seniors.justlevelingfork.common.capability.AptitudeCapability;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.inventory.CraftingMenu;
import net.minecraft.world.inventory.ResultContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
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.CallbackInfo;

@Mixin(CraftingMenu.class)
public abstract class MixCraftingMenu {
@WrapOperation(method = "slotChangedCraftingGrid", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/ResultContainer;setItem(ILnet/minecraft/world/item/ItemStack;)V"))
private static void slotChangedCraftingGrid(ResultContainer container, int slotIndex, ItemStack stack, Operation<Void> original, @Local(argsOnly = true, index = 2) Player player, @Local(argsOnly = true, index = 3) CraftingContainer craftingInventory) {
@Inject(at = @At("TAIL"), method = "slotChangedCraftingGrid")
private static void slotChangedCraftingGrid(AbstractContainerMenu pMenu, Level level, Player player, CraftingContainer container, ResultContainer resultContainer, CallbackInfo ci){
if (player instanceof ServerPlayer serverPlayer){
ItemStack itemStack = resultContainer.getItem(0);

if (!serverPlayer.isCreative()) {
AptitudeCapability provider = AptitudeCapability.get(player);

if (provider != null && !provider.canUseItem(serverPlayer, stack)){
stack = ItemStack.EMPTY;

original.call(container, slotIndex, stack);
if (provider != null && !provider.canUseItem(serverPlayer, itemStack)){
resultContainer.setItem(0, ItemStack.EMPTY);
}
}
}
Expand Down

0 comments on commit d38cb04

Please sign in to comment.