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

61 lines
1.8 KiB
Java
Raw Normal View History

2025-01-29 13:20:04 -05:00
package kamkeel.npcs.network;
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-30 18:13:04 -05:00
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.entity.EntityNPCInterface;
2025-01-28 13:39:46 -05:00
import java.io.IOException;
2025-01-29 18:25:34 -05:00
import java.util.Collections;
import java.util.List;
2025-01-28 13:39:46 -05:00
public abstract class AbstractPacket {
2025-01-30 18:13:04 -05:00
public EntityNPCInterface npc;
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-29 18:25:34 -05:00
return new FMLProxyPacket(buf, packetChannel.getChannelName());
} catch (Exception e) {
// For debugging, you might want to log it
e.printStackTrace();
}
2025-01-28 13:39:46 -05:00
return null;
}
2025-01-29 18:25:34 -05:00
public List<FMLProxyPacket> generatePackets() {
FMLProxyPacket single = generatePacket();
if (single == null) {
return Collections.emptyList();
}
return Collections.singletonList(single);
}
2025-01-28 14:37:07 -05:00
public abstract Enum getType();
public abstract PacketChannel getChannel();
2025-01-30 18:13:04 -05:00
public CustomNpcsPermissions.Permission getPermission(){
return null;
}
public boolean needsNPC(){
return false;
}
public void setNPC(EntityNPCInterface npc){
this.npc = npc;
}
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;
}