Add missing SpreadItemParam values, add checks and corrections to ClientWindowActionPacket.

This commit is contained in:
Steveice10 2018-09-06 18:45:11 -07:00
parent 04372d0571
commit 3e43b954c1
3 changed files with 15 additions and 16 deletions

View file

@ -219,6 +219,9 @@ public class MagicValues {
register(SpreadItemParam.RIGHT_MOUSE_BEGIN_DRAG, 4);
register(SpreadItemParam.RIGHT_MOUSE_ADD_SLOT, 5);
register(SpreadItemParam.RIGHT_MOUSE_END_DRAG, 6);
register(SpreadItemParam.MIDDLE_MOUSE_BEGIN_DRAG, 8);
register(SpreadItemParam.MIDDLE_MOUSE_ADD_SLOT, 9);
register(SpreadItemParam.MIDDLE_MOUSE_END_DRAG, 10);
register(FillStackParam.FILL, 0);

View file

@ -6,5 +6,8 @@ public enum SpreadItemParam implements WindowActionParam {
LEFT_MOUSE_END_DRAG,
RIGHT_MOUSE_BEGIN_DRAG,
RIGHT_MOUSE_ADD_SLOT,
RIGHT_MOUSE_END_DRAG;
RIGHT_MOUSE_END_DRAG,
MIDDLE_MOUSE_BEGIN_DRAG,
MIDDLE_MOUSE_ADD_SLOT,
MIDDLE_MOUSE_END_DRAG;
}

View file

@ -31,6 +31,10 @@ public class ClientWindowActionPacket extends MinecraftPacket {
}
public ClientWindowActionPacket(int windowId, int actionId, int slot, ItemStack clicked, WindowAction action, WindowActionParam param) {
if((param == DropItemParam.LEFT_CLICK_OUTSIDE_NOT_HOLDING || param == DropItemParam.RIGHT_CLICK_OUTSIDE_NOT_HOLDING) && slot != -999) {
throw new IllegalArgumentException("Slot must be -999 with param LEFT_CLICK_OUTSIDE_NOT_HOLDING or RIGHT_CLICK_OUTSIDE_NOT_HOLDING");
}
this.windowId = windowId;
this.actionId = actionId;
this.slot = slot;
@ -92,21 +96,10 @@ public class ClientWindowActionPacket extends MinecraftPacket {
public void write(NetOutput out) throws IOException {
out.writeByte(this.windowId);
out.writeShort(this.slot);
int param = 0;
if(this.action == WindowAction.CLICK_ITEM) {
param = MagicValues.value(Integer.class, (Enum<?>) this.param);
} else if(this.action == WindowAction.SHIFT_CLICK_ITEM) {
param = MagicValues.value(Integer.class, (Enum<?>) this.param);
} else if(this.action == WindowAction.MOVE_TO_HOTBAR_SLOT) {
param = MagicValues.value(Integer.class, (Enum<?>) this.param);
} else if(this.action == WindowAction.CREATIVE_GRAB_MAX_STACK) {
param = MagicValues.value(Integer.class, (Enum<?>) this.param);
} else if(this.action == WindowAction.DROP_ITEM) {
param = MagicValues.value(Integer.class, (Enum<?>) this.param) + (this.slot != -999 ? 2 : 0);
} else if(this.action == WindowAction.SPREAD_ITEM) {
param = MagicValues.value(Integer.class, (Enum<?>) this.param);
} else if(this.action == WindowAction.FILL_STACK) {
param = MagicValues.value(Integer.class, (Enum<?>) this.param);
int param = MagicValues.value(Integer.class, this.param);
if(this.action == WindowAction.DROP_ITEM) {
param %= 2;
}
out.writeByte(param);