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)) {
|
||||
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) {
|
||||
boolean half = clickedButton == 1;
|
||||
boolean shift = GuiScreen.isShiftKeyDown();
|
||||
boolean one = clickedButton == 2;
|
||||
int flags = 0;
|
||||
|
||||
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) {
|
||||
RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingClear(grid));
|
||||
} else {
|
||||
|
@@ -10,25 +10,25 @@ import refinedstorage.storage.StorageItem;
|
||||
import refinedstorage.tile.TileController;
|
||||
|
||||
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 y;
|
||||
private int z;
|
||||
private int id;
|
||||
private boolean half;
|
||||
private boolean one;
|
||||
private boolean shift;
|
||||
private int flags;
|
||||
|
||||
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.y = y;
|
||||
this.z = z;
|
||||
this.id = id;
|
||||
this.half = half;
|
||||
this.one = one;
|
||||
this.shift = shift;
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,9 +37,7 @@ public class MessageStoragePull extends MessageHandlerPlayerToServer<MessageStor
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
id = buf.readInt();
|
||||
half = buf.readBoolean();
|
||||
one = buf.readBoolean();
|
||||
shift = buf.readBoolean();
|
||||
flags = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,9 +46,19 @@ public class MessageStoragePull extends MessageHandlerPlayerToServer<MessageStor
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeInt(id);
|
||||
buf.writeBoolean(half);
|
||||
buf.writeBoolean(one);
|
||||
buf.writeBoolean(shift);
|
||||
buf.writeInt(flags);
|
||||
}
|
||||
|
||||
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
|
||||
@@ -65,14 +73,16 @@ public class MessageStoragePull extends MessageHandlerPlayerToServer<MessageStor
|
||||
|
||||
int quantity = 64;
|
||||
|
||||
if (message.half && item.getQuantity() > 1) {
|
||||
if (message.isPullingHalf() && item.getQuantity() > 1) {
|
||||
quantity = item.getQuantity() / 2;
|
||||
|
||||
if (quantity > 32) {
|
||||
quantity = 32;
|
||||
}
|
||||
} else if (message.one) {
|
||||
} else if (message.isPullingOne()) {
|
||||
quantity = 1;
|
||||
} else if (message.isPullingWithShift()) {
|
||||
// NO OP, the default quantity (64) will be fine
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
if (took != null) {
|
||||
if (message.shift) {
|
||||
if (message.isPullingWithShift()) {
|
||||
if (!player.inventory.addItemStackToInventory(took.copy())) {
|
||||
controller.push(took);
|
||||
}
|
||||
|
Reference in New Issue
Block a user