diff --git a/src/main/java/net/backslot/BackSlotMain.java b/src/main/java/net/backslot/BackSlotMain.java index f861d53..bf0d407 100644 --- a/src/main/java/net/backslot/BackSlotMain.java +++ b/src/main/java/net/backslot/BackSlotMain.java @@ -30,4 +30,6 @@ public void onInitialize() { BackSlotServerPacket.init(); } + + } \ No newline at end of file diff --git a/src/main/java/net/backslot/mixin/EntityMixin.java b/src/main/java/net/backslot/mixin/LivingEntityMixin.java similarity index 81% rename from src/main/java/net/backslot/mixin/EntityMixin.java rename to src/main/java/net/backslot/mixin/LivingEntityMixin.java index 210c3bf..e2af61b 100644 --- a/src/main/java/net/backslot/mixin/EntityMixin.java +++ b/src/main/java/net/backslot/mixin/LivingEntityMixin.java @@ -10,14 +10,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -@Mixin(Entity.class) -public class EntityMixin { +@Mixin(LivingEntity.class) +public class LivingEntityMixin { - @Inject(method = "getItemsEquipped", at = @At("RETURN"), cancellable = true) - private void getItemsEquippedMixin(CallbackInfoReturnable> info) { + @Inject(method = "getEquippedItems", at = @At("RETURN"), cancellable = true) + private void getEquippedItemsMixin(CallbackInfoReturnable> info) { if ((Entity) (Object) this instanceof PlayerEntity playerEntity) { ItemStack backSlotStack = playerEntity.getInventory().getStack(41); ItemStack beltSlotStack = playerEntity.getInventory().getStack(42); diff --git a/src/main/java/net/backslot/mixin/PlayerInventoryMixin.java b/src/main/java/net/backslot/mixin/PlayerInventoryMixin.java index 0eafe8e..c35da20 100644 --- a/src/main/java/net/backslot/mixin/PlayerInventoryMixin.java +++ b/src/main/java/net/backslot/mixin/PlayerInventoryMixin.java @@ -22,7 +22,7 @@ import net.minecraft.nbt.NbtList; import net.minecraft.util.collection.DefaultedList; -@Mixin(PlayerInventory.class) +@Mixin(value = PlayerInventory.class, priority = 999) public abstract class PlayerInventoryMixin implements Inventory { @Shadow @Final @@ -52,7 +52,7 @@ public PlayerInventoryMixin(PlayerEntity player) { } @Inject(method = "*", at = @At("RETURN")) - private void onConstructed(PlayerEntity playerEntity, CallbackInfo info) { + private void initMixin(PlayerEntity playerEntity, CallbackInfo info) { this.backSlot = DefaultedList.ofSize(1, ItemStack.EMPTY); this.beltSlot = DefaultedList.ofSize(1, ItemStack.EMPTY); this.combinedInventory = new ArrayList<>(combinedInventory); @@ -62,7 +62,7 @@ private void onConstructed(PlayerEntity playerEntity, CallbackInfo info) { } @Inject(method = "writeNbt", at = @At("TAIL")) - public void serializeMixin(NbtList tag, CallbackInfoReturnable info) { + public void writeNbtMixin(NbtList tag, CallbackInfoReturnable info) { if (!this.backSlot.get(0).isEmpty()) { NbtCompound compoundTag = new NbtCompound(); compoundTag.putByte("Slot", (byte) (110)); @@ -77,7 +77,7 @@ public void serializeMixin(NbtList tag, CallbackInfoReturnable info) { } @Inject(method = "readNbt", at = @At("TAIL")) - public void deserializeMixin(NbtList tag, CallbackInfo info) { + public void readNbtMixin(NbtList tag, CallbackInfo info) { this.backSlot.clear(); this.beltSlot.clear(); for (int i = 0; i < tag.size(); ++i) { @@ -94,16 +94,12 @@ public void deserializeMixin(NbtList tag, CallbackInfo info) { } } - @Inject(method = "size", at = @At("HEAD"), cancellable = true) + @Inject(method = "size", at = @At("RETURN"), cancellable = true) public void sizeMixin(CallbackInfoReturnable info) { - int size = 0; - for (DefaultedList list : combinedInventory) { - size += list.size(); - } - info.setReturnValue(size); + info.setReturnValue(info.getReturnValue() + 2); } - @Inject(method = "isEmpty", at = @At("HEAD"), cancellable = true) + @Inject(method = "isEmpty", at = @At("TAIL"), cancellable = true) public void isEmptyMixin(CallbackInfoReturnable info) { if (!this.backSlot.isEmpty() || !this.beltSlot.isEmpty()) { info.setReturnValue(false); diff --git a/src/main/java/net/backslot/mixin/PlayerScreenHandlerMixin.java b/src/main/java/net/backslot/mixin/PlayerScreenHandlerMixin.java index 872ce8c..dee9ac9 100644 --- a/src/main/java/net/backslot/mixin/PlayerScreenHandlerMixin.java +++ b/src/main/java/net/backslot/mixin/PlayerScreenHandlerMixin.java @@ -24,7 +24,7 @@ import net.fabricmc.api.EnvType; import net.minecraft.enchantment.EnchantmentHelper; -@Mixin(PlayerScreenHandler.class) +@Mixin(value = PlayerScreenHandler.class, priority = 999) public abstract class PlayerScreenHandlerMixin extends AbstractRecipeScreenHandler { private static boolean changeArrangement = BackSlotMain.CONFIG.changeSlotArrangement; @@ -33,13 +33,14 @@ public PlayerScreenHandlerMixin(ScreenHandlerType screenHan } // Tried different injection points to fix a mod compatibility bug but it didnt work - @Inject(method = "*", at = @At("TAIL")) + @Inject(method = "*", at = @At("RETURN")) private void onConstructed(PlayerInventory inventory, boolean onServer, PlayerEntity owner, CallbackInfo info) { int backSlotX = BackSlotMain.CONFIG.backSlotX; int backSlotY = BackSlotMain.CONFIG.backSlotY; int beltSlotX = BackSlotMain.CONFIG.beltSlotX; int beltSlotY = BackSlotMain.CONFIG.beltSlotY; + if (changeArrangement) { backSlotX += 75; backSlotY += 22; diff --git a/src/main/java/net/backslot/mixin/client/CreativeInventoryScreenMixin.java b/src/main/java/net/backslot/mixin/client/CreativeInventoryScreenMixin.java index 82651f2..bf2546b 100644 --- a/src/main/java/net/backslot/mixin/client/CreativeInventoryScreenMixin.java +++ b/src/main/java/net/backslot/mixin/client/CreativeInventoryScreenMixin.java @@ -19,7 +19,6 @@ public abstract class CreativeInventoryScreenMixin extends AbstractInventoryScre public CreativeInventoryScreenMixin(PlayerEntity player) { super(new CreativeInventoryScreen.CreativeScreenHandler(player), player.getInventory(), ScreenTexts.EMPTY); - player.currentScreenHandler = this.handler; } @Inject(method = "setSelectedTab", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/screen/ingame/CreativeInventoryScreen;deleteItemSlot:Lnet/minecraft/screen/slot/Slot;", shift = At.Shift.BEFORE)) diff --git a/src/main/resources/backslot.mixins.json b/src/main/resources/backslot.mixins.json index 3bcd0f4..02015ec 100644 --- a/src/main/resources/backslot.mixins.json +++ b/src/main/resources/backslot.mixins.json @@ -8,7 +8,7 @@ "PlayerInventoryMixin", "PlayerScreenHandlerMixin", "ServerPlayerEntityMixin", - "EntityMixin", + "LivingEntityMixin", "EntityTrackerEntryMixin", "ExperienceOrbEntityMixin", "compat.OnDeathItemDropCompatibility"