Skip to content

Commit

Permalink
tweaked things
Browse files Browse the repository at this point in the history
  • Loading branch information
Globox1997 committed Jun 1, 2024
1 parent 2ba6c1f commit c3da86c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/main/java/net/backslot/BackSlotMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ public void onInitialize() {
BackSlotServerPacket.init();
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Iterable<ItemStack>> info) {
@Inject(method = "getEquippedItems", at = @At("RETURN"), cancellable = true)
private void getEquippedItemsMixin(CallbackInfoReturnable<Iterable<ItemStack>> info) {
if ((Entity) (Object) this instanceof PlayerEntity playerEntity) {
ItemStack backSlotStack = playerEntity.getInventory().getStack(41);
ItemStack beltSlotStack = playerEntity.getInventory().getStack(42);
Expand Down
18 changes: 7 additions & 11 deletions src/main/java/net/backslot/mixin/PlayerInventoryMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,7 +52,7 @@ public PlayerInventoryMixin(PlayerEntity player) {
}

@Inject(method = "<init>*", 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);
Expand All @@ -62,7 +62,7 @@ private void onConstructed(PlayerEntity playerEntity, CallbackInfo info) {
}

@Inject(method = "writeNbt", at = @At("TAIL"))
public void serializeMixin(NbtList tag, CallbackInfoReturnable<NbtList> info) {
public void writeNbtMixin(NbtList tag, CallbackInfoReturnable<NbtList> info) {
if (!this.backSlot.get(0).isEmpty()) {
NbtCompound compoundTag = new NbtCompound();
compoundTag.putByte("Slot", (byte) (110));
Expand All @@ -77,7 +77,7 @@ public void serializeMixin(NbtList tag, CallbackInfoReturnable<NbtList> 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) {
Expand All @@ -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<Integer> info) {
int size = 0;
for (DefaultedList<ItemStack> 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<Boolean> info) {
if (!this.backSlot.isEmpty() || !this.beltSlot.isEmpty()) {
info.setReturnValue(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CraftingInventory> {
private static boolean changeArrangement = BackSlotMain.CONFIG.changeSlotArrangement;

Expand All @@ -33,13 +33,14 @@ public PlayerScreenHandlerMixin(ScreenHandlerType<PlayerScreenHandler> screenHan
}

// Tried different injection points to fix a mod compatibility bug but it didnt work
@Inject(method = "<init>*", at = @At("TAIL"))
@Inject(method = "<init>*", 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/backslot.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"PlayerInventoryMixin",
"PlayerScreenHandlerMixin",
"ServerPlayerEntityMixin",
"EntityMixin",
"LivingEntityMixin",
"EntityTrackerEntryMixin",
"ExperienceOrbEntityMixin",
"compat.OnDeathItemDropCompatibility"
Expand Down

0 comments on commit c3da86c

Please sign in to comment.