Shift clicking from grid crafting
This commit is contained in:
@@ -6,9 +6,14 @@ import refinedstorage.block.EnumGridType;
|
|||||||
import refinedstorage.container.slot.SlotGridCraftingResult;
|
import refinedstorage.container.slot.SlotGridCraftingResult;
|
||||||
import refinedstorage.tile.TileGrid;
|
import refinedstorage.tile.TileGrid;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ContainerGrid extends ContainerBase {
|
public class ContainerGrid extends ContainerBase {
|
||||||
private TileGrid grid;
|
private TileGrid grid;
|
||||||
|
|
||||||
|
private List<Slot> craftingSlots = new ArrayList<Slot>();
|
||||||
|
|
||||||
public ContainerGrid(EntityPlayer player, TileGrid grid) {
|
public ContainerGrid(EntityPlayer player, TileGrid grid) {
|
||||||
super(player);
|
super(player);
|
||||||
|
|
||||||
@@ -21,7 +26,11 @@ public class ContainerGrid extends ContainerBase {
|
|||||||
int y = 106;
|
int y = 106;
|
||||||
|
|
||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i) {
|
||||||
addSlotToContainer(new Slot(grid.getCraftingInventory(), i, x, y));
|
Slot slot = new Slot(grid.getCraftingInventory(), i, x, y);
|
||||||
|
|
||||||
|
craftingSlots.add(slot);
|
||||||
|
|
||||||
|
addSlotToContainer(slot);
|
||||||
|
|
||||||
x += 18;
|
x += 18;
|
||||||
|
|
||||||
@@ -34,4 +43,8 @@ public class ContainerGrid extends ContainerBase {
|
|||||||
addSlotToContainer(new SlotGridCraftingResult(player, grid.getCraftingInventory(), grid.getCraftingResultInventory(), grid, 0, 133 + 4, 120 + 4));
|
addSlotToContainer(new SlotGridCraftingResult(player, grid.getCraftingInventory(), grid.getCraftingResultInventory(), grid, 0, 133 + 4, 120 + 4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Slot> getCraftingSlots() {
|
||||||
|
return craftingSlots;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,7 @@ import refinedstorage.gui.sidebutton.SideButtonGridSortingDirection;
|
|||||||
import refinedstorage.gui.sidebutton.SideButtonGridSortingType;
|
import refinedstorage.gui.sidebutton.SideButtonGridSortingType;
|
||||||
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
||||||
import refinedstorage.network.MessageGridCraftingClear;
|
import refinedstorage.network.MessageGridCraftingClear;
|
||||||
|
import refinedstorage.network.MessageGridCraftingPush;
|
||||||
import refinedstorage.network.MessageStoragePull;
|
import refinedstorage.network.MessageStoragePull;
|
||||||
import refinedstorage.network.MessageStoragePush;
|
import refinedstorage.network.MessageStoragePush;
|
||||||
import refinedstorage.storage.StorageItem;
|
import refinedstorage.storage.StorageItem;
|
||||||
@@ -279,6 +280,15 @@ public class GuiGrid extends GuiBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (grid.getType() == EnumGridType.CRAFTING) {
|
||||||
|
for (Slot slot : container.getCraftingSlots()) {
|
||||||
|
if (inBounds(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX - guiLeft, mouseY - guiTop)) {
|
||||||
|
if (GuiScreen.isShiftKeyDown()) {
|
||||||
|
RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingPush(grid, slot.getSlotIndex()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
62
src/main/java/refinedstorage/network/MessageGridCraftingPush.java
Executable file
62
src/main/java/refinedstorage/network/MessageGridCraftingPush.java
Executable file
@@ -0,0 +1,62 @@
|
|||||||
|
package refinedstorage.network;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
|
import refinedstorage.block.EnumGridType;
|
||||||
|
import refinedstorage.tile.TileGrid;
|
||||||
|
|
||||||
|
public class MessageGridCraftingPush extends MessageHandlerPlayerToServer<MessageGridCraftingPush> implements IMessage {
|
||||||
|
private int x;
|
||||||
|
private int y;
|
||||||
|
private int z;
|
||||||
|
private int craftingSlot;
|
||||||
|
|
||||||
|
public MessageGridCraftingPush() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageGridCraftingPush(TileGrid grid, int craftingSlot) {
|
||||||
|
this.x = grid.getPos().getX();
|
||||||
|
this.y = grid.getPos().getY();
|
||||||
|
this.z = grid.getPos().getZ();
|
||||||
|
this.craftingSlot = craftingSlot;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
x = buf.readInt();
|
||||||
|
y = buf.readInt();
|
||||||
|
z = buf.readInt();
|
||||||
|
craftingSlot = buf.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
buf.writeInt(x);
|
||||||
|
buf.writeInt(y);
|
||||||
|
buf.writeInt(z);
|
||||||
|
buf.writeInt(craftingSlot);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(MessageGridCraftingPush message, EntityPlayerMP player) {
|
||||||
|
TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.x, message.y, message.z));
|
||||||
|
|
||||||
|
if (tile instanceof TileGrid) {
|
||||||
|
TileGrid grid = (TileGrid) tile;
|
||||||
|
|
||||||
|
if (grid.isConnected() && grid.getType() == EnumGridType.CRAFTING && message.craftingSlot < grid.getCraftingInventory().getSizeInventory()) {
|
||||||
|
ItemStack stack = grid.getCraftingInventory().getStackInSlot(message.craftingSlot);
|
||||||
|
|
||||||
|
if (stack != null) {
|
||||||
|
if (grid.getController().push(stack)) {
|
||||||
|
grid.getCraftingInventory().setInventorySlotContents(message.craftingSlot, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -38,6 +38,7 @@ public class CommonProxy {
|
|||||||
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingClear.class, MessageGridCraftingClear.class, 9, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingClear.class, MessageGridCraftingClear.class, 9, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessagePriorityUpdate.class, MessagePriorityUpdate.class, 10, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessagePriorityUpdate.class, MessagePriorityUpdate.class, 10, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageGridSortingUpdate.class, MessageGridSortingUpdate.class, 11, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageGridSortingUpdate.class, MessageGridSortingUpdate.class, 11, Side.SERVER);
|
||||||
|
RefinedStorage.NETWORK.registerMessage(MessageGridCraftingPush.class, MessageGridCraftingPush.class, 12, Side.SERVER);
|
||||||
|
|
||||||
NetworkRegistry.INSTANCE.registerGuiHandler(RefinedStorage.INSTANCE, new GuiHandler());
|
NetworkRegistry.INSTANCE.registerGuiHandler(RefinedStorage.INSTANCE, new GuiHandler());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user