Skip to content

Commit

Permalink
split InventoryPlayer into client/server mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-159 committed May 5, 2024
1 parent d92adfa commit a635744
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.github.matt159.dws.mixin.mixins.client.minecraft.inventory;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;

@Mixin(InventoryPlayer.class)
public abstract class InventoryPlayerMixin implements IInventory {
@Shadow
public int currentItem;

@Inject(method = "changeCurrentItem",
at = @At("HEAD"),
cancellable = true,
require = 1)
private void injectChangeCurrentItem(int delta, CallbackInfo ci) {
delta = Math.min(1, delta);
delta = Math.max(-1, delta);

// -= because scrolling down should decrement the selected slot
this.currentItem -= delta;

if (this.currentItem < 0) {
this.currentItem = 17;
}

if (this.currentItem > 17) {
this.currentItem = 0;
}
//cancelling it here because the vanilla implementation is really dumb
ci.cancel();
}
}
Original file line number Diff line number Diff line change
@@ -1,56 +1,32 @@
package com.github.matt159.dws.mixin.mixins.common.minecraft.inventory;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.InventoryPlayer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.entity.player.InventoryPlayer;

@Mixin(InventoryPlayer.class)
public abstract class InventoryPlayerMixin {
@Shadow public int currentItem;

@ModifyConstant(method = { "<init>",
"readFromNBT" },
constant = @Constant(intValue = 36),
require = 1)
require = 2)
private int modifyInventoryArraySize(int constant) {
return 72;
}

@ModifyConstant(method = { "getHotbarSize",
"getCurrentItem" },
@ModifyConstant(method = { "getHotbarSize"},
constant = @Constant(intValue = 9),
require = 1)
private static int modifyHotbarSize(int constant) {
return 18;
}

@SideOnly(Side.CLIENT)
@Inject(method = "changeCurrentItem",
at = @At("HEAD"),
cancellable = true,
require = 1)
private void injectChangeCurrentItem(int delta, CallbackInfo ci) {
delta = Math.min(1, delta);
delta = Math.max(-1, delta);

// -= because scrolling down should decrement the selected slot
this.currentItem -= delta;

if (this.currentItem < 0) {
this.currentItem = 17;
}

if (this.currentItem > 17) {
this.currentItem = 0;
}
//cancelling it here because the vanilla implementation is really dumb
ci.cancel();
@ModifyConstant(method = { "getCurrentItem"},
constant = @Constant(intValue = 9),
require = 1)
private int modifyGetCurrentItem(int constant) {
return 18;
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/github/matt159/dws/mixin/plugin/Mixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public enum Mixin implements IMixin {
ForgeHooksMixin (COMMON, always(), "minecraft.ForgeHooksMixin"),
GameSettingsMixin (CLIENT, always(), "minecraft.GameSettingsMixin"),
GuiUtilsMixin (CLIENT, always(), "minecraft.GuiUtilsMixin"),
InventoryPlayerMixin (COMMON, always(), "minecraft.inventory.InventoryPlayerMixin"),
InventoryPlayerMixin_CLIENT (CLIENT, always(), "minecraft.inventory.InventoryPlayerMixin"),
InventoryPlayerMixin_COMMON (COMMON, always(), "minecraft.inventory.InventoryPlayerMixin"),
MinecraftMixin (CLIENT, always(), "minecraft.MinecraftMixin"),
NetHandlerPlayClientMixin (CLIENT, always(), "minecraft.NetHandlerPlayClientMixin"),
NetHandlerPlayServerMixin (COMMON, always(), "minecraft.NetHandlerPlayServerMixin"),
Expand Down

0 comments on commit a635744

Please sign in to comment.