Skip to content

Commit

Permalink
fix: TWEAK_HAND_RESTOCK support totem of undying (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
zly2006 authored Jul 4, 2024
1 parent b54456f commit 17bacc9
Showing 1 changed file with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package fi.dy.masa.tweakeroo.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.client.network.ClientCommonNetworkHandler;
import net.minecraft.client.network.ClientConnectionState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.network.ClientConnection;
import net.minecraft.util.Hand;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -14,10 +23,19 @@
import fi.dy.masa.tweakeroo.data.ServerDataSyncer;
import fi.dy.masa.tweakeroo.tweaks.PlacementTweaks;
import fi.dy.masa.tweakeroo.util.MiscUtils;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ClientPlayNetworkHandler.class)
public abstract class MixinClientPlayNetworkHandler
public abstract class MixinClientPlayNetworkHandler extends ClientCommonNetworkHandler
{
protected MixinClientPlayNetworkHandler(MinecraftClient client, ClientConnection connection, ClientConnectionState connectionState)
{
super(client, connection, connectionState);
}

@Unique
private static Hand totemOfUndyingRestockHand;

@Inject(method = "onScreenHandlerSlotUpdate", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/screen/ScreenHandler;setStackInSlot(IILnet/minecraft/item/ItemStack;)V"),
Expand All @@ -30,6 +48,23 @@ private void onHandleSetSlot(ScreenHandlerSlotUpdateS2CPacket packet, CallbackIn
}
}

@Inject(method = "onScreenHandlerSlotUpdate", at = @At("RETURN"))
private void afterHandleSetSlot(ScreenHandlerSlotUpdateS2CPacket packet, CallbackInfo ci)
{
if (FeatureToggle.TWEAK_HAND_RESTOCK.getBooleanValue() && totemOfUndyingRestockHand != null)
{
if (this.client.player == null)
{
totemOfUndyingRestockHand = null;
}
else if (this.client.player.getStackInHand(totemOfUndyingRestockHand).isEmpty())
{
PlacementTweaks.tryRestockHand(this.client.player, totemOfUndyingRestockHand, Items.TOTEM_OF_UNDYING.getDefaultStack());
totemOfUndyingRestockHand = null;
}
}
}

@Inject(method = "onDeathMessage", at = @At(value = "INVOKE", // onCombatEvent
target = "Lnet/minecraft/client/MinecraftClient;setScreen(Lnet/minecraft/client/gui/screen/Screen;)V"))
private void onPlayerDeath(DeathMessageS2CPacket packetIn, CallbackInfo ci)
Expand Down Expand Up @@ -67,4 +102,17 @@ else if (payload.getId().id().equals(DataManager.SERVUX_ENTITY_DATA))
DataManager.getInstance().setHasServuxServer(true);
}
}

@Inject(
method = "getActiveTotemOfUndying",
at = @At(value = "RETURN", ordinal = 0)
)
private static void onPlayerUseTotemOfUndying(PlayerEntity player, CallbackInfoReturnable<ItemStack> cir, @Local Hand hand)
{
if (FeatureToggle.TWEAK_HAND_RESTOCK.getBooleanValue())
{
totemOfUndyingRestockHand = hand;
PlacementTweaks.cacheStackInHand(hand);
}
}
}

0 comments on commit 17bacc9

Please sign in to comment.