Magic Get Packet

This commit is contained in:
Kam committed 2025-03-04 02:49:19 -05:00
1 parent debbd25f18
commit 82bad818f9
4 files changed
+157 -62

No files matched your search

@@ -341,6 +341,7 @@ public class PacketHandler {
REQUEST_PACKET.registerPacket(new MagicGetAllPacket());
REQUEST_PACKET.registerPacket(new MagicSavePacket());
REQUEST_PACKET.registerPacket(new MagicRemovePacket());
REQUEST_PACKET.registerPacket(new MagicGetPacket());
// Other Packets
REQUEST_PACKET.registerPacket(new IsGuiOpenInform());
@@ -201,5 +201,5 @@ public enum EnumRequestPacket {
MagicCycleSave,
MagicGetAll,
MagicRemove,
MagicSave
MagicGet, MagicSave
}
@@ -0,0 +1,92 @@
package kamkeel.npcs.network.packets.request.magic;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.*;
import kamkeel.npcs.network.enums.EnumItemPacketType;
import kamkeel.npcs.network.enums.EnumRequestPacket;
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.controllers.LinkedItemController;
import noppes.npcs.controllers.LinkedNpcController;
import noppes.npcs.controllers.MagicController;
import noppes.npcs.controllers.data.LinkedItem;
import noppes.npcs.controllers.data.Magic;
import noppes.npcs.controllers.data.MagicCycle;
import java.io.IOException;
public final class MagicGetPacket extends AbstractPacket {
public static String packetName = "Request|MagicGet";
private Action action;
private int id;
public MagicGetPacket() {}
public MagicGetPacket(Action action, int id) {
this.action = action;
this.id = id;
}
@Override
public Enum getType() {
return EnumRequestPacket.MagicGet;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.REQUEST_PACKET;
}
@SideOnly(Side.CLIENT)
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(this.action.ordinal());
out.writeInt(this.id);
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
if (!PacketUtil.verifyItemPacket(EnumItemPacketType.WAND, player))
return;
Action action = Action.values()[in.readInt()];
int id = in.readInt();
if(action == Action.MAGIC){
Magic magic = MagicController.getInstance().getMagic(id);
NBTTagCompound compound = new NBTTagCompound();
NBTTagCompound magicCompound = new NBTTagCompound();
magic.writeNBT(magicCompound);
compound.setTag("Magic", magicCompound);
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
} else if (action == Action.CYCLE) {
MagicCycle cycle = MagicController.getInstance().getCycle(id);
NBTTagCompound compound = new NBTTagCompound();
NBTTagCompound magicCompound = new NBTTagCompound();
cycle.writeNBT(magicCompound);
compound.setTag("MagicCycle", magicCompound);
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
}
}
public static void GetMagic(int id) {
PacketClient.sendClient(new MagicGetPacket(Action.MAGIC, id));
}
public static void GetCycle(int id) {
PacketClient.sendClient(new MagicGetPacket(Action.CYCLE, id));
}
private enum Action {
MAGIC,
CYCLE
}
}