diff options
author | Anthony Hilyard <anthony.hilyard@gmail.com> | 2021-09-20 14:47:21 -0700 |
---|---|---|
committer | Anthony Hilyard <anthony.hilyard@gmail.com> | 2021-09-20 14:47:21 -0700 |
commit | 3d17eb42809b793e3684d089a3d2bbfd748422cf (patch) | |
tree | 712892544201ea9240e9d2650198b85db89bcaee /src/main/java/com/anthonyhilyard/iceberg/network | |
parent | b8f63f66ddf9915bf8fc4f261339f603b2a63222 (diff) | |
download | Iceberg-3d17eb42809b793e3684d089a3d2bbfd748422cf.tar.gz Iceberg-3d17eb42809b793e3684d089a3d2bbfd748422cf.tar.bz2 Iceberg-3d17eb42809b793e3684d089a3d2bbfd748422cf.zip |
Updated tooltip handling, added remote pre-item pickup event and network
protocol.
Diffstat (limited to 'src/main/java/com/anthonyhilyard/iceberg/network')
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/network/IcebergNetworkProtocol.java | 30 | ||||
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/network/NewItemPickupEventPacket.java | 45 |
2 files changed, 75 insertions, 0 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/network/IcebergNetworkProtocol.java b/src/main/java/com/anthonyhilyard/iceberg/network/IcebergNetworkProtocol.java new file mode 100644 index 0000000..d0dd1c8 --- /dev/null +++ b/src/main/java/com/anthonyhilyard/iceberg/network/IcebergNetworkProtocol.java @@ -0,0 +1,30 @@ +package com.anthonyhilyard.iceberg.network; + +import com.anthonyhilyard.iceberg.Loader; + +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.network.NetworkRegistry; +import net.minecraftforge.fml.network.simple.SimpleChannel; + +public class IcebergNetworkProtocol +{ + private static final String NETWORK_PROTOCOL_VERSION = "1"; + + public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( + new ResourceLocation(Loader.MODID, "main"), () -> NETWORK_PROTOCOL_VERSION, + NETWORK_PROTOCOL_VERSION::equals, NETWORK_PROTOCOL_VERSION::equals + ); + + public static final void register() + { + int messageID = 0; + + CHANNEL.registerMessage( + messageID++, + NewItemPickupEventPacket.class, + NewItemPickupEventPacket::encode, + NewItemPickupEventPacket::decode, + NewItemPickupEventPacket::handle + ); + } +} 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 |