Use flag system instead of a billion booleans
This commit is contained in:
@@ -257,11 +257,19 @@ public class GuiGrid extends GuiBase {
|
|||||||
if (isHoveringOverSlot() && container.getPlayer().inventory.getItemStack() != null && (clickedButton == 0 || clickedButton == 1)) {
|
if (isHoveringOverSlot() && container.getPlayer().inventory.getItemStack() != null && (clickedButton == 0 || clickedButton == 1)) {
|
||||||
RefinedStorage.NETWORK.sendToServer(new MessageStoragePush(controller.getPos().getX(), controller.getPos().getY(), controller.getPos().getZ(), -1, clickedButton == 1));
|
RefinedStorage.NETWORK.sendToServer(new MessageStoragePush(controller.getPos().getX(), controller.getPos().getY(), controller.getPos().getZ(), -1, clickedButton == 1));
|
||||||
} else if (isHoveringOverItemInSlot() && container.getPlayer().inventory.getItemStack() == null) {
|
} else if (isHoveringOverItemInSlot() && container.getPlayer().inventory.getItemStack() == null) {
|
||||||
boolean half = clickedButton == 1;
|
int flags = 0;
|
||||||
boolean shift = GuiScreen.isShiftKeyDown();
|
|
||||||
boolean one = clickedButton == 2;
|
|
||||||
|
|
||||||
RefinedStorage.NETWORK.sendToServer(new MessageStoragePull(controller.getPos().getX(), controller.getPos().getY(), controller.getPos().getZ(), hoveringItemId, half, one, shift));
|
if (clickedButton == 1) {
|
||||||
|
flags |= MessageStoragePull.PULL_HALF;
|
||||||
|
}
|
||||||
|
if (GuiScreen.isShiftKeyDown()) {
|
||||||
|
flags |= MessageStoragePull.PULL_SHIFT;
|
||||||
|
}
|
||||||
|
if (clickedButton == 2) {
|
||||||
|
flags |= MessageStoragePull.PULL_ONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefinedStorage.NETWORK.sendToServer(new MessageStoragePull(controller.getPos().getX(), controller.getPos().getY(), controller.getPos().getZ(), hoveringItemId, flags));
|
||||||
} else if (clickedClear) {
|
} else if (clickedClear) {
|
||||||
RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingClear(grid));
|
RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingClear(grid));
|
||||||
} else {
|
} else {
|
||||||
|
@@ -10,25 +10,25 @@ import refinedstorage.storage.StorageItem;
|
|||||||
import refinedstorage.tile.TileController;
|
import refinedstorage.tile.TileController;
|
||||||
|
|
||||||
public class MessageStoragePull extends MessageHandlerPlayerToServer<MessageStoragePull> implements IMessage {
|
public class MessageStoragePull extends MessageHandlerPlayerToServer<MessageStoragePull> implements IMessage {
|
||||||
|
public static final int PULL_HALF = 1;
|
||||||
|
public static final int PULL_ONE = 2;
|
||||||
|
public static final int PULL_SHIFT = 4;
|
||||||
|
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
private int z;
|
private int z;
|
||||||
private int id;
|
private int id;
|
||||||
private boolean half;
|
private int flags;
|
||||||
private boolean one;
|
|
||||||
private boolean shift;
|
|
||||||
|
|
||||||
public MessageStoragePull() {
|
public MessageStoragePull() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageStoragePull(int x, int y, int z, int id, boolean half, boolean one, boolean shift) {
|
public MessageStoragePull(int x, int y, int z, int id, int flags) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.half = half;
|
this.flags = flags;
|
||||||
this.one = one;
|
|
||||||
this.shift = shift;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -37,9 +37,7 @@ public class MessageStoragePull extends MessageHandlerPlayerToServer<MessageStor
|
|||||||
y = buf.readInt();
|
y = buf.readInt();
|
||||||
z = buf.readInt();
|
z = buf.readInt();
|
||||||
id = buf.readInt();
|
id = buf.readInt();
|
||||||
half = buf.readBoolean();
|
flags = buf.readInt();
|
||||||
one = buf.readBoolean();
|
|
||||||
shift = buf.readBoolean();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -48,9 +46,19 @@ public class MessageStoragePull extends MessageHandlerPlayerToServer<MessageStor
|
|||||||
buf.writeInt(y);
|
buf.writeInt(y);
|
||||||
buf.writeInt(z);
|
buf.writeInt(z);
|
||||||
buf.writeInt(id);
|
buf.writeInt(id);
|
||||||
buf.writeBoolean(half);
|
buf.writeInt(flags);
|
||||||
buf.writeBoolean(one);
|
}
|
||||||
buf.writeBoolean(shift);
|
|
||||||
|
public boolean isPullingHalf() {
|
||||||
|
return (flags & PULL_HALF) == PULL_HALF;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPullingOne() {
|
||||||
|
return (flags & PULL_ONE) == PULL_ONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPullingWithShift() {
|
||||||
|
return (flags & PULL_SHIFT) == PULL_SHIFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,14 +73,16 @@ public class MessageStoragePull extends MessageHandlerPlayerToServer<MessageStor
|
|||||||
|
|
||||||
int quantity = 64;
|
int quantity = 64;
|
||||||
|
|
||||||
if (message.half && item.getQuantity() > 1) {
|
if (message.isPullingHalf() && item.getQuantity() > 1) {
|
||||||
quantity = item.getQuantity() / 2;
|
quantity = item.getQuantity() / 2;
|
||||||
|
|
||||||
if (quantity > 32) {
|
if (quantity > 32) {
|
||||||
quantity = 32;
|
quantity = 32;
|
||||||
}
|
}
|
||||||
} else if (message.one) {
|
} else if (message.isPullingOne()) {
|
||||||
quantity = 1;
|
quantity = 1;
|
||||||
|
} else if (message.isPullingWithShift()) {
|
||||||
|
// NO OP, the default quantity (64) will be fine
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quantity > item.getType().getItemStackLimit(item.toItemStack())) {
|
if (quantity > item.getType().getItemStackLimit(item.toItemStack())) {
|
||||||
@@ -82,7 +92,7 @@ public class MessageStoragePull extends MessageHandlerPlayerToServer<MessageStor
|
|||||||
ItemStack took = controller.take(item.copy(quantity).toItemStack());
|
ItemStack took = controller.take(item.copy(quantity).toItemStack());
|
||||||
|
|
||||||
if (took != null) {
|
if (took != null) {
|
||||||
if (message.shift) {
|
if (message.isPullingWithShift()) {
|
||||||
if (!player.inventory.addItemStackToInventory(took.copy())) {
|
if (!player.inventory.addItemStackToInventory(took.copy())) {
|
||||||
controller.push(took);
|
controller.push(took);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user