Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix NPE for Ultramine server #28

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package mods.battlegear2.mixins.early;

import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement;
import net.minecraft.world.WorldServer;

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;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;

import mods.battlegear2.api.core.IInventoryPlayerBattle;

Expand All @@ -30,18 +33,29 @@ public class MixinNetHandlerPlayServer {
return IInventoryPlayerBattle.isValidSwitch(original) ? 0 : -1;
}

@WrapOperation(
method = "processPlayerBlockPlacement",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/inventory/Container;getSlotFromInventory(Lnet/minecraft/inventory/IInventory;I)Lnet/minecraft/inventory/Slot;"))
private Slot battlegear2$captureSlotVariable(Container instance, IInventory j, int i, Operation<Slot> original,
@Share("slot") LocalRef<Slot> slotRef) {
Slot slot = original.call(instance, j, i);
slotRef.set(slot);
return slot;
}

@Inject(
method = "processPlayerBlockPlacement",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/entity/player/EntityPlayerMP;isChangingQuantityOnly:Z",
shift = At.Shift.AFTER,
ordinal = 1),
locals = LocalCapture.CAPTURE_FAILSOFT,
cancellable = true)
private void battlegear2$fixNPE(C08PacketPlayerBlockPlacement packetIn, CallbackInfo ci, WorldServer worldserver,
ItemStack itemstack, boolean flag, boolean placeResult, int i, int j, int k, int l, Slot slot) {
if (slot == null) {
private void battlegear2$fixNPE(C08PacketPlayerBlockPlacement packetIn, CallbackInfo ci,
@Share("slot") LocalRef<Slot> slotRef) {
if (slotRef.get() == null) {
ci.cancel();
}
}
Expand Down