-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split InventoryPlayer into client/server mixin
- Loading branch information
Showing
3 changed files
with
49 additions
and
34 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
.../com/github/matt159/dws/mixin/mixins/client/minecraft/inventory/InventoryPlayerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
42 changes: 9 additions & 33 deletions
42
.../com/github/matt159/dws/mixin/mixins/common/minecraft/inventory/InventoryPlayerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters