Initial commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.kasetoatz.bettertridentreturn.mixin;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.client.network.ClientPlayerInteractionManager;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.slot.SlotActionType;
|
||||
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 static com.kasetoatz.bettertridentreturn.util.Util.*;
|
||||
|
||||
@Mixin(PlayerInventory.class)
|
||||
public class PlayerInventoryMixin
|
||||
{
|
||||
@Inject(method="setStack", at=@At("HEAD"))
|
||||
public void setStack(int slot, ItemStack stack, CallbackInfo ci)
|
||||
{
|
||||
if (stack.getItem() != Items.TRIDENT || returnSlot == -1 || returnSlot == slot)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
||||
ClientPlayerInteractionManager manager = MinecraftClient.getInstance().interactionManager;
|
||||
if (player == null || manager == null || !player.getInventory().getStack(returnSlot).isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
manager.clickSlot(player.playerScreenHandler.syncId, getSlotID(slot), 0, SlotActionType.PICKUP, player);
|
||||
manager.clickSlot(player.playerScreenHandler.syncId, getSlotID(returnSlot), 0, SlotActionType.PICKUP, player);
|
||||
returnSlot = -1;
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package com.kasetoatz.bettertridentreturn.mixin;
|
||||
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.TridentItem;
|
||||
import net.minecraft.world.World;
|
||||
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 static com.kasetoatz.bettertridentreturn.util.Util.returnSlot;
|
||||
|
||||
@Mixin(TridentItem.class)
|
||||
public class TridentItemMixin
|
||||
{
|
||||
@Inject(method="onStoppedUsing", at=@At(value="INVOKE", target="Lnet/minecraft/entity/player/PlayerEntity;incrementStat(Lnet/minecraft/stat/Stat;)V"))
|
||||
public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks, CallbackInfoReturnable<Boolean> cir)
|
||||
{
|
||||
if (user instanceof PlayerEntity player)
|
||||
{
|
||||
returnSlot = (player.getOffHandStack() == stack) ? PlayerInventory.OFF_HAND_SLOT : player.getInventory().getSelectedSlot();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package com.kasetoatz.bettertridentreturn.util;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
|
||||
public class Util
|
||||
{
|
||||
public static int returnSlot = -1;
|
||||
|
||||
public static int getSlotID(int index)
|
||||
{
|
||||
return (index == PlayerInventory.OFF_HAND_SLOT) ? 45 : (index < PlayerInventory.getHotbarSize()) ? index + PlayerInventory.MAIN_SIZE : index;
|
||||
}
|
||||
}
|
16
src/main/resources/bettertridentreturn.mixins.json
Normal file
16
src/main/resources/bettertridentreturn.mixins.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.kasetoatz.bettertridentreturn.mixin",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"client": [
|
||||
"PlayerInventoryMixin",
|
||||
"TridentItemMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"overwrites": {
|
||||
"requireAnnotations": true
|
||||
}
|
||||
}
|
19
src/main/resources/fabric.mod.json
Normal file
19
src/main/resources/fabric.mod.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "bettertridentreturn",
|
||||
"version": "${version}",
|
||||
"name": "BetterTridentReturn",
|
||||
"description": "",
|
||||
"authors": [],
|
||||
"contact": {},
|
||||
"license": "MIT",
|
||||
"environment": "client",
|
||||
"mixins": [
|
||||
"bettertridentreturn.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=${loader_version}",
|
||||
"fabric": "*",
|
||||
"minecraft": "${minecraft_version}"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user