Requesting packet stuff
This commit is contained in:
		| @@ -1,20 +1,29 @@ | ||||
| package refinedstorage.gui; | ||||
|  | ||||
| import com.google.common.primitives.Ints; | ||||
| import net.minecraft.client.gui.GuiButton; | ||||
| import net.minecraft.client.gui.GuiTextField; | ||||
| import net.minecraftforge.fml.client.FMLClientHandler; | ||||
| import refinedstorage.container.ContainerDummy; | ||||
|  | ||||
| import java.io.IOException; | ||||
|  | ||||
| public class GuiCraftingSettings extends GuiBase { | ||||
|     private GuiTextField amountField; | ||||
|     private GuiGrid gridGui; | ||||
|     private int id; | ||||
|     private GuiButton startButton; | ||||
|  | ||||
|     public GuiCraftingSettings() { | ||||
|     public GuiCraftingSettings(GuiGrid gridGui, int id) { | ||||
|         super(new ContainerDummy(), 143, 61); | ||||
|  | ||||
|         this.gridGui = gridGui; | ||||
|         this.id = id; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void init(int x, int y) { | ||||
|         addButton(x + 48, y + 35, 50, 20, t("misc.refinedstorage:start")); | ||||
|         startButton = addButton(x + 48, y + 35, 50, 20, t("misc.refinedstorage:start")); | ||||
|  | ||||
|         amountField = new GuiTextField(0, fontRendererObj, x + 39 + 1, y + 21 + 1, 69 - 6, fontRendererObj.FONT_HEIGHT); | ||||
|         amountField.setEnableBackgroundDrawing(false); | ||||
| @@ -51,4 +60,19 @@ public class GuiCraftingSettings extends GuiBase { | ||||
|             super.keyTyped(character, keyCode); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     protected void actionPerformed(GuiButton button) throws IOException { | ||||
|         super.actionPerformed(button); | ||||
|  | ||||
|         if (button.id == startButton.id) { | ||||
|             Integer quantity = Ints.tryParse(amountField.getText()); | ||||
|  | ||||
|             if (quantity != null && quantity > 0) { | ||||
|                 gridGui.getGrid().onCraftingRequested(id, quantity); | ||||
|  | ||||
|                 FMLClientHandler.instance().showGuiScreen(gridGui); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -69,6 +69,10 @@ public class GuiGrid extends GuiBase { | ||||
|         searchField.setFocused(true); | ||||
|     } | ||||
|  | ||||
|     public IGrid getGrid() { | ||||
|         return grid; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void update(int x, int y) { | ||||
|         items.clear(); | ||||
| @@ -268,7 +272,7 @@ public class GuiGrid extends GuiBase { | ||||
|                 grid.onItemPush(-1, clickedButton == 1); | ||||
|             } else if (isHoveringOverItemInSlot() && container.getPlayer().inventory.getItemStack() == null) { | ||||
|                 if (items.get(hoveringSlot).getQuantity() == 0) { | ||||
|                     FMLCommonHandler.instance().showGuiScreen(new GuiCraftingSettings()); | ||||
|                     FMLCommonHandler.instance().showGuiScreen(new GuiCraftingSettings(this, hoveringItemId)); | ||||
|                 } else { | ||||
|                     int flags = 0; | ||||
|  | ||||
|   | ||||
							
								
								
									
										54
									
								
								src/main/java/refinedstorage/network/MessageGridCraftingStart.java
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										54
									
								
								src/main/java/refinedstorage/network/MessageGridCraftingStart.java
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,54 @@ | ||||
| package refinedstorage.network; | ||||
|  | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import net.minecraft.entity.player.EntityPlayerMP; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraftforge.fml.common.network.simpleimpl.IMessage; | ||||
| import refinedstorage.tile.grid.TileGrid; | ||||
|  | ||||
| public class MessageGridCraftingStart extends MessageHandlerPlayerToServer<MessageGridCraftingStart> implements IMessage { | ||||
|     private int gridX; | ||||
|     private int gridY; | ||||
|     private int gridZ; | ||||
|     private int id; | ||||
|     private int quantity; | ||||
|  | ||||
|     public MessageGridCraftingStart() { | ||||
|     } | ||||
|  | ||||
|     public MessageGridCraftingStart(int gridX, int gridY, int gridZ, int id, int quantity) { | ||||
|         this.gridX = gridX; | ||||
|         this.gridY = gridY; | ||||
|         this.gridZ = gridZ; | ||||
|         this.id = id; | ||||
|         this.quantity = quantity; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         gridX = buf.readInt(); | ||||
|         gridY = buf.readInt(); | ||||
|         gridZ = buf.readInt(); | ||||
|         id = buf.readInt(); | ||||
|         quantity = buf.readInt(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         buf.writeInt(gridX); | ||||
|         buf.writeInt(gridY); | ||||
|         buf.writeInt(gridZ); | ||||
|         buf.writeInt(id); | ||||
|         buf.writeInt(quantity); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void handle(MessageGridCraftingStart message, EntityPlayerMP player) { | ||||
|         TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.gridX, message.gridY, message.gridZ)); | ||||
|  | ||||
|         if (tile instanceof TileGrid && ((TileGrid) tile).isConnected() && message.quantity > 0 && message.id >= 0) { | ||||
|             ((TileGrid) tile).getController().onCraftingRequested(message.id, message.quantity); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -51,7 +51,7 @@ public class MessageGridStoragePull extends MessageHandlerPlayerToServer<Message | ||||
|         if (tile instanceof TileGrid && ((TileGrid) tile).isConnected()) { | ||||
|             TileController controller = ((TileGrid) tile).getController(); | ||||
|  | ||||
|             if (message.id < controller.getItemGroups().size()) { | ||||
|             if (message.id >= 0 && message.id < controller.getItemGroups().size()) { | ||||
|                 controller.handleStoragePull(message.id, message.flags, player); | ||||
|             } | ||||
|         } | ||||
|   | ||||
							
								
								
									
										54
									
								
								src/main/java/refinedstorage/network/MessageWirelessGridCraftingStart.java
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										54
									
								
								src/main/java/refinedstorage/network/MessageWirelessGridCraftingStart.java
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,54 @@ | ||||
| package refinedstorage.network; | ||||
|  | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import net.minecraft.entity.player.EntityPlayerMP; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.util.math.BlockPos; | ||||
| import net.minecraftforge.fml.common.network.simpleimpl.IMessage; | ||||
| import refinedstorage.tile.TileController; | ||||
|  | ||||
| public class MessageWirelessGridCraftingStart extends MessageHandlerPlayerToServer<MessageWirelessGridCraftingStart> implements IMessage { | ||||
|     private int controllerX; | ||||
|     private int controllerY; | ||||
|     private int controllerZ; | ||||
|     private int id; | ||||
|     private int quantity; | ||||
|  | ||||
|     public MessageWirelessGridCraftingStart() { | ||||
|     } | ||||
|  | ||||
|     public MessageWirelessGridCraftingStart(int controllerX, int controllerY, int controllerZ, int id, int quantity) { | ||||
|         this.controllerX = controllerX; | ||||
|         this.controllerY = controllerY; | ||||
|         this.controllerZ = controllerZ; | ||||
|         this.id = id; | ||||
|         this.quantity = quantity; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         controllerX = buf.readInt(); | ||||
|         controllerY = buf.readInt(); | ||||
|         controllerZ = buf.readInt(); | ||||
|         id = buf.readInt(); | ||||
|         quantity = buf.readInt(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         buf.writeInt(controllerX); | ||||
|         buf.writeInt(controllerY); | ||||
|         buf.writeInt(controllerZ); | ||||
|         buf.writeInt(id); | ||||
|         buf.writeInt(quantity); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void handle(MessageWirelessGridCraftingStart message, EntityPlayerMP player) { | ||||
|         TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.controllerX, message.controllerY, message.controllerZ)); | ||||
|  | ||||
|         if (tile instanceof TileController && ((TileController) tile).isActive() && message.quantity > 0 && message.id >= 0) { | ||||
|             ((TileController) tile).onCraftingRequested(message.id, message.quantity); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -50,7 +50,7 @@ public class MessageWirelessGridStoragePull extends MessageHandlerPlayerToServer | ||||
|         if (tile instanceof TileController && ((TileController) tile).isActive()) { | ||||
|             TileController controller = (TileController) tile; | ||||
|  | ||||
|             if (message.id < controller.getItemGroups().size()) { | ||||
|             if (message.id >= 0 && message.id < controller.getItemGroups().size()) { | ||||
|                 controller.handleStoragePull(message.id, message.flags, player); | ||||
|             } | ||||
|         } | ||||
|   | ||||
| @@ -50,6 +50,8 @@ public class CommonProxy { | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageWirelessGridStoragePush.class, MessageWirelessGridStoragePush.class, 17, Side.SERVER); | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageWirelessGridStoragePull.class, MessageWirelessGridStoragePull.class, 18, Side.SERVER); | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageGridCraftingShift.class, MessageGridCraftingShift.class, 19, Side.SERVER); | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageGridCraftingStart.class, MessageGridCraftingStart.class, 20, Side.SERVER); | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageWirelessGridCraftingStart.class, MessageWirelessGridCraftingStart.class, 21, Side.SERVER); | ||||
|  | ||||
|         NetworkRegistry.INSTANCE.registerGuiHandler(RefinedStorage.INSTANCE, new GuiHandler()); | ||||
|  | ||||
| @@ -86,13 +88,13 @@ public class CommonProxy { | ||||
|         registerBlock(RefinedStorageBlocks.CRAFTING_MONITOR); | ||||
|  | ||||
|         registerItem(RefinedStorageItems.STORAGE_DISK); | ||||
|         registerItem(RefinedStorageItems.PATTERN); | ||||
|         registerItem(RefinedStorageItems.WIRELESS_GRID); | ||||
|         registerItem(RefinedStorageItems.QUARTZ_ENRICHED_IRON); | ||||
|         registerItem(RefinedStorageItems.CORE); | ||||
|         registerItem(RefinedStorageItems.SILICON); | ||||
|         registerItem(RefinedStorageItems.PROCESSOR); | ||||
|         registerItem(RefinedStorageItems.STORAGE_PART); | ||||
|         registerItem(RefinedStorageItems.PATTERN); | ||||
|  | ||||
|         // Processors | ||||
|         SoldererRegistry.addRecipe(new SoldererRecipePrintedProcessor(ItemProcessor.TYPE_PRINTED_BASIC)); | ||||
|   | ||||
| @@ -606,4 +606,8 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor | ||||
|             group.toBytes(buf, getItemGroups().indexOf(group)); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void onCraftingRequested(int id, int quantity) { | ||||
|         System.out.println("Requested crafting for item " + id + " with quantity of " + quantity); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -27,6 +27,8 @@ public interface IGrid { | ||||
|  | ||||
|     void onSearchBoxModeChanged(int searchBoxMode); | ||||
|  | ||||
|     void onCraftingRequested(int id, int quantity); | ||||
|  | ||||
|     IRedstoneModeConfig getRedstoneModeSetting(); | ||||
|  | ||||
|     boolean isConnected(); | ||||
|   | ||||
| @@ -16,6 +16,7 @@ import refinedstorage.block.EnumGridType; | ||||
| import refinedstorage.container.ContainerGrid; | ||||
| import refinedstorage.inventory.InventorySimple; | ||||
| import refinedstorage.item.ItemPattern; | ||||
| import refinedstorage.network.MessageGridCraftingStart; | ||||
| import refinedstorage.network.MessageGridSettingsUpdate; | ||||
| import refinedstorage.network.MessageGridStoragePull; | ||||
| import refinedstorage.network.MessageGridStoragePush; | ||||
| @@ -251,6 +252,11 @@ public class TileGrid extends TileMachine implements IGrid { | ||||
|         RefinedStorage.NETWORK.sendToServer(new MessageGridSettingsUpdate(this, sortingDirection, sortingType, searchBoxMode)); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onCraftingRequested(int id, int quantity) { | ||||
|         RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingStart(getPos().getX(), getPos().getY(), getPos().getZ(), id, quantity)); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public IRedstoneModeConfig getRedstoneModeSetting() { | ||||
|         return this; | ||||
|   | ||||
| @@ -8,6 +8,7 @@ import net.minecraft.util.math.BlockPos; | ||||
| import refinedstorage.RefinedStorage; | ||||
| import refinedstorage.block.EnumGridType; | ||||
| import refinedstorage.item.ItemWirelessGrid; | ||||
| import refinedstorage.network.MessageWirelessGridCraftingStart; | ||||
| import refinedstorage.network.MessageWirelessGridSettingsUpdate; | ||||
| import refinedstorage.network.MessageWirelessGridStoragePull; | ||||
| import refinedstorage.network.MessageWirelessGridStoragePush; | ||||
| @@ -101,6 +102,11 @@ public class WirelessGrid implements IGrid { | ||||
|         this.searchBoxMode = searchBoxMode; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onCraftingRequested(int id, int quantity) { | ||||
|         RefinedStorage.NETWORK.sendToServer(new MessageWirelessGridCraftingStart(ItemWirelessGrid.getX(stack), ItemWirelessGrid.getY(stack), ItemWirelessGrid.getZ(stack), id, quantity)); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public IRedstoneModeConfig getRedstoneModeSetting() { | ||||
|         return null; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Raoul Van den Berge
					Raoul Van den Berge