Send a packet on shift clicking
This commit is contained in:
		| @@ -7,7 +7,6 @@ import net.minecraft.inventory.Container; | ||||
| import net.minecraft.inventory.Slot; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import refinedstorage.container.slot.SlotDisabled; | ||||
| import refinedstorage.container.slot.SlotGridCraftingResult; | ||||
| import refinedstorage.container.slot.SlotSpecimen; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| @@ -99,10 +98,6 @@ public abstract class ContainerBase extends Container { | ||||
|             } | ||||
|  | ||||
|             return player.inventory.getItemStack(); | ||||
|         } else if (slot instanceof SlotGridCraftingResult && slot.getHasStack() && GuiScreen.isShiftKeyDown()) { | ||||
|             ((SlotGridCraftingResult) slot).onShiftClick(player); | ||||
|  | ||||
|             return null; | ||||
|         } else if (slot instanceof SlotDisabled) { | ||||
|             return null; | ||||
|         } | ||||
|   | ||||
| @@ -1,11 +1,15 @@ | ||||
| package refinedstorage.container; | ||||
|  | ||||
| import net.minecraft.client.gui.GuiScreen; | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| import net.minecraft.inventory.ClickType; | ||||
| import net.minecraft.inventory.ICrafting; | ||||
| import net.minecraft.inventory.Slot; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import refinedstorage.RefinedStorage; | ||||
| import refinedstorage.block.EnumGridType; | ||||
| import refinedstorage.container.slot.SlotGridCraftingResult; | ||||
| import refinedstorage.network.MessageGridCraftingShift; | ||||
| import refinedstorage.tile.grid.IGrid; | ||||
| import refinedstorage.tile.grid.TileGrid; | ||||
| import refinedstorage.tile.grid.WirelessGrid; | ||||
| @@ -84,4 +88,19 @@ public class ContainerGrid extends ContainerBase { | ||||
|             ((WirelessGrid) grid).onClose(player); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public ItemStack func_184996_a(int id, int clickedButton, ClickType clickType, EntityPlayer player) { | ||||
|         Slot slot = id >= 0 ? getSlot(id) : null; | ||||
|  | ||||
|         if (player.worldObj.isRemote && slot instanceof SlotGridCraftingResult && slot.getHasStack()) { | ||||
|             if (GuiScreen.isShiftKeyDown()) { | ||||
|                 RefinedStorage.NETWORK.sendToServer(new MessageGridCraftingShift((TileGrid) grid)); | ||||
|  | ||||
|                 return null; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return super.func_184996_a(id, clickedButton, clickType, player); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -30,8 +30,4 @@ public class SlotGridCraftingResult extends SlotCrafting { | ||||
|  | ||||
|         grid.onCrafted(container); | ||||
|     } | ||||
|  | ||||
|     public void onShiftClick(EntityPlayer player) { | ||||
|         grid.onCraftedShift(container, player); | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										48
									
								
								src/main/java/refinedstorage/network/MessageGridCraftingShift.java
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										48
									
								
								src/main/java/refinedstorage/network/MessageGridCraftingShift.java
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,48 @@ | ||||
| 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.block.EnumGridType; | ||||
| import refinedstorage.container.ContainerGrid; | ||||
| import refinedstorage.tile.grid.TileGrid; | ||||
|  | ||||
| public class MessageGridCraftingShift extends MessageHandlerPlayerToServer<MessageGridCraftingShift> implements IMessage { | ||||
|     private int x; | ||||
|     private int y; | ||||
|     private int z; | ||||
|  | ||||
|     public MessageGridCraftingShift() { | ||||
|     } | ||||
|  | ||||
|     public MessageGridCraftingShift(TileGrid grid) { | ||||
|         this.x = grid.getPos().getX(); | ||||
|         this.y = grid.getPos().getY(); | ||||
|         this.z = grid.getPos().getZ(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void fromBytes(ByteBuf buf) { | ||||
|         x = buf.readInt(); | ||||
|         y = buf.readInt(); | ||||
|         z = buf.readInt(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void toBytes(ByteBuf buf) { | ||||
|         buf.writeInt(x); | ||||
|         buf.writeInt(y); | ||||
|         buf.writeInt(z); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void handle(MessageGridCraftingShift message, EntityPlayerMP player) { | ||||
|         TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.x, message.y, message.z)); | ||||
|  | ||||
|         if (tile instanceof TileGrid && ((TileGrid) tile).getType() == EnumGridType.CRAFTING && player.openContainer instanceof ContainerGrid) { | ||||
|             ((ContainerGrid) player.openContainer).getGrid().onCraftedShift((ContainerGrid) player.openContainer, player); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -48,6 +48,7 @@ public class CommonProxy { | ||||
|         RefinedStorage.NETWORK.registerMessage(MessageWirelessGridItems.class, MessageWirelessGridItems.class, 16, Side.CLIENT); | ||||
|         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); | ||||
|  | ||||
|         NetworkRegistry.INSTANCE.registerGuiHandler(RefinedStorage.INSTANCE, new GuiHandler()); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Raoul Van den Berge
					Raoul Van den Berge