aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/anthonyhilyard/iceberg/network/NewItemPickupEventPacket.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/anthonyhilyard/iceberg/network/NewItemPickupEventPacket.java')
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/network/NewItemPickupEventPacket.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/network/NewItemPickupEventPacket.java b/src/main/java/com/anthonyhilyard/iceberg/network/NewItemPickupEventPacket.java
new file mode 100644
index 0000000..23df08b
--- /dev/null
+++ b/src/main/java/com/anthonyhilyard/iceberg/network/NewItemPickupEventPacket.java
@@ -0,0 +1,45 @@
+package com.anthonyhilyard.iceberg.network;
+
+import net.minecraft.item.ItemStack;
+import net.minecraft.network.PacketBuffer;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.fml.network.NetworkEvent;
+
+import java.util.UUID;
+import java.util.function.Supplier;
+
+import com.anthonyhilyard.iceberg.events.NewItemPickupEvent;
+
+
+public final class NewItemPickupEventPacket
+{
+ private final UUID playerUUID;
+ private final ItemStack item;
+
+ public NewItemPickupEventPacket(final UUID playerUUID, final ItemStack item)
+ {
+ this.playerUUID = playerUUID;
+ this.item = item;
+ }
+
+ public static void encode(final NewItemPickupEventPacket msg, final PacketBuffer packetBuffer)
+ {
+ packetBuffer.writeUUID(msg.playerUUID);
+ packetBuffer.writeItem(msg.item);
+ }
+
+ public static NewItemPickupEventPacket decode(final PacketBuffer packetBuffer)
+ {
+ return new NewItemPickupEventPacket(packetBuffer.readUUID(), packetBuffer.readItem());
+ }
+
+ public static void handle(final NewItemPickupEventPacket msg, final Supplier<NetworkEvent.Context> contextSupplier)
+ {
+ final NetworkEvent.Context context = contextSupplier.get();
+ context.enqueueWork(() -> {
+ MinecraftForge.EVENT_BUS.post(new NewItemPickupEvent(msg.playerUUID, msg.item));
+ });
+ context.setPacketHandled(true);
+ }
+
+} \ No newline at end of file