Files
CustomNPC-Plus/src/main/java/kamkeel/network/AbstractPacket.java
T

34 lines
1.2 KiB
Java
Raw Normal View History

2025-01-28 13:39:46 -05:00
package kamkeel.network;
2025-01-28 14:37:07 -05:00
import cpw.mods.fml.common.network.NetworkRegistry;
2025-01-28 13:39:46 -05:00
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraft.entity.player.EntityPlayer;
2025-01-28 14:37:07 -05:00
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
2025-01-28 13:39:46 -05:00
import java.io.IOException;
public abstract class AbstractPacket {
2025-01-28 14:37:07 -05:00
public FMLProxyPacket generatePacket() {
PacketChannel packetChannel = getChannel();
2025-01-28 13:39:46 -05:00
ByteBuf buf = Unpooled.buffer();
try {
2025-01-28 14:37:07 -05:00
buf.writeInt(packetChannel.getChannelType().ordinal());
buf.writeInt(getType().ordinal());
2025-01-28 13:39:46 -05:00
sendData(buf);
2025-01-28 14:37:07 -05:00
return new FMLProxyPacket(buf, getChannel().getChannelName());
2025-01-28 13:39:46 -05:00
} catch (Exception ignored) {}
return null;
}
2025-01-28 14:37:07 -05:00
public abstract Enum getType();
public abstract PacketChannel getChannel();
2025-01-28 13:39:46 -05:00
public abstract void sendData(ByteBuf out) throws IOException;
//"player" on the server side is the client who sent this packet
//"player" on the client side is the client player
public abstract void receiveData(ByteBuf in, EntityPlayer player) throws IOException;
}