diff --git a/src/main/java/com/sweetrpg/crafttracker/common/network/PacketHandler.java b/src/main/java/com/sweetrpg/crafttracker/common/network/PacketHandler.java index cc79a04..c6fc8eb 100644 --- a/src/main/java/com/sweetrpg/crafttracker/common/network/PacketHandler.java +++ b/src/main/java/com/sweetrpg/crafttracker/common/network/PacketHandler.java @@ -1,6 +1,8 @@ package com.sweetrpg.crafttracker.common.network; import com.sweetrpg.crafttracker.CraftTracker; +import com.sweetrpg.crafttracker.common.network.packet.AddToQueuePacket; +import com.sweetrpg.crafttracker.common.network.packet.data.AddToQueueData; import net.minecraftforge.network.PacketDistributor; public final class PacketHandler { @@ -8,7 +10,7 @@ public final class PacketHandler { private static int disc = 0; public static void init() { -// registerPacket(new CatModePacket(), CatModeData.class); + registerPacket(new AddToQueuePacket(), AddToQueueData.class); // registerPacket(new CatNamePacket(), CatNameData.class); // registerPacket(new CatObeyPacket(), CatObeyData.class); // registerPacket(new CatTalentPacket(), CatTalentData.class); diff --git a/src/main/java/com/sweetrpg/crafttracker/common/network/packet/AddToQueuePacket.java b/src/main/java/com/sweetrpg/crafttracker/common/network/packet/AddToQueuePacket.java new file mode 100644 index 0000000..8d12f59 --- /dev/null +++ b/src/main/java/com/sweetrpg/crafttracker/common/network/packet/AddToQueuePacket.java @@ -0,0 +1,40 @@ +package com.sweetrpg.crafttracker.common.network.packet; + +import com.sweetrpg.crafttracker.common.network.IPacket; +import com.sweetrpg.crafttracker.common.network.packet.data.AddToQueueData; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.network.NetworkEvent.Context; + +import java.util.function.Supplier; + +public class AddToQueuePacket implements IPacket { + + @Override + public void encode(AddToQueueData data, FriendlyByteBuf buf) { + buf.writeUtf(data.itemId); + } + + @Override + public AddToQueueData decode(FriendlyByteBuf buf) { + String itemId = buf.readUtf(); + return new AddToQueueData(itemId); + } + + @Override + public final void handle(AddToQueueData data, Supplier ctx) { + ctx.get().enqueueWork(() -> { +// Entity target = ctx.get().getSender().level.getEntity(data.entityId); +// +// if (!(target instanceof CatEntity)) { +// return; +// } +// +// this.handleCat((CatEntity) target, data, ctx); + }); + + ctx.get().setPacketHandled(true); + } + +// public abstract void handleCat(CatEntity catIn, T data, Supplier ctx); + +} diff --git a/src/main/java/com/sweetrpg/crafttracker/common/network/packet/CatPacket.java b/src/main/java/com/sweetrpg/crafttracker/common/network/packet/CatPacket.java deleted file mode 100644 index 664ef41..0000000 --- a/src/main/java/com/sweetrpg/crafttracker/common/network/packet/CatPacket.java +++ /dev/null @@ -1,39 +0,0 @@ -//package com.sweetrpg.crafttracker.common.network.packet; -// -//import com.sweetrpg.crafttracker.common.network.IPacket; -//import com.sweetrpg.crafttracker.common.network.packet.data.CatData; -//import com.sweetrpg.crafttracker.common.entity.CatEntity; -//import net.minecraft.network.FriendlyByteBuf; -//import net.minecraft.world.entity.Entity; -//import net.minecraftforge.network.NetworkEvent.Context; -// -//import java.util.function.Supplier; -// -//public abstract class CatPacket implements IPacket { -// -// @Override -// public void encode(T data, FriendlyByteBuf buf) { -// buf.writeInt(data.entityId); -// } -// -// @Override -// public abstract T decode(FriendlyByteBuf buf); -// -// @Override -// public final void handle(T data, Supplier ctx) { -// ctx.get().enqueueWork(() -> { -// Entity target = ctx.get().getSender().level.getEntity(data.entityId); -// -// if (!(target instanceof CatEntity)) { -// return; -// } -// -// this.handleCat((CatEntity) target, data, ctx); -// }); -// -// ctx.get().setPacketHandled(true); -// } -// -// public abstract void handleCat(CatEntity catIn, T data, Supplier ctx); -// -//} diff --git a/src/main/java/com/sweetrpg/crafttracker/common/network/packet/data/AddToQueueData.java b/src/main/java/com/sweetrpg/crafttracker/common/network/packet/data/AddToQueueData.java new file mode 100644 index 0000000..4aff2e3 --- /dev/null +++ b/src/main/java/com/sweetrpg/crafttracker/common/network/packet/data/AddToQueueData.java @@ -0,0 +1,10 @@ +package com.sweetrpg.crafttracker.common.network.packet.data; + +public class AddToQueueData { + + public String itemId; + + public AddToQueueData(String itemId) { + this.itemId = itemId; + } +} diff --git a/src/main/java/com/sweetrpg/crafttracker/common/network/packet/data/CatData.java b/src/main/java/com/sweetrpg/crafttracker/common/network/packet/data/CatData.java deleted file mode 100644 index d86ef78..0000000 --- a/src/main/java/com/sweetrpg/crafttracker/common/network/packet/data/CatData.java +++ /dev/null @@ -1,10 +0,0 @@ -//package com.sweetrpg.crafttracker.common.network.packet.data; -// -//public class CatData { -// -// public int entityId; -// -// public CatData(int entityId) { -// this.entityId = entityId; -// } -//}