package info.u_team.u_team_core.intern.network;

import java.util.Optional;
import java.util.function.Supplier;

import info.u_team.u_team_core.container.FluidContainer;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent.Context;

public class FluidClickContainerMessage {
	
	private final int id;
	private final int slot;
	private final ItemStack stack;
	
	public FluidClickContainerMessage(int id, int slot, ItemStack stack) {
		this.id = id;
		this.slot = slot;
		this.stack = stack;
	}
	
	public static void encode(FluidClickContainerMessage message, PacketBuffer sendBuffer) {
		sendBuffer.writeByte(message.id);
		sendBuffer.writeShort(message.slot);
		sendBuffer.writeItemStack(message.stack, false);
	}
	
	public static FluidClickContainerMessage decode(PacketBuffer sendBuffer) {
		final int id = sendBuffer.readByte();
		final int slot = sendBuffer.readShort();
		final ItemStack stack = sendBuffer.readItemStack();
		
		return new FluidClickContainerMessage(id, slot, stack);
	}
	
	public static class Handler {
		
		public static void handle(FluidClickContainerMessage message, Supplier<Context> contextSupplier) {
			final Context context = contextSupplier.get();
			context.enqueueWork(() -> {
				final ServerPlayerEntity player = context.getSender();
				getFluidContainer(player.openContainer, message.id).ifPresent(container -> container.fluidSlotClick(player, message.slot, message.stack));
			});
			context.setPacketHandled(true);
		}
		
		private static final Optional<FluidContainer> getFluidContainer(Container container, int id) {
			if (container instanceof FluidContainer && container.windowId == id) {
				return Optional.of((FluidContainer) container);
			}
			return Optional.empty();
		}
	}
	
}

@@ -503,16 +503,46 @@
 t slot;%0A
+%09private final boolean shift;%0A
 %09private
@@ -619,16 +619,31 @@
 nt slot,
+ boolean shift,
  ItemSta
@@ -690,16 +690,38 @@
 = slot;%0A
+%09%09this.shift = shift;%0A
 %09%09this.s
@@ -904,16 +904,58 @@
 .slot);%0A
+%09%09sendBuffer.writeBoolean(message.shift);%0A
 %09%09sendBu
@@ -1157,24 +1157,74 @@
 eadShort();%0A
+%09%09final boolean shift = sendBuffer.readBoolean();%0A
 %09%09final Item
@@ -1317,16 +1317,23 @@
 d, slot,
+ shift,
  stack);

Add shift boolean to the fluid click container message