Pather and Mounter Packets

This commit is contained in:
Kam committed 2025-02-02 19:23:14 -05:00
1 parent b0e4d555ce
commit 42fe078efd
9 files changed
+269 -59

No files matched your search

@@ -44,6 +44,8 @@ import kamkeel.npcs.network.packets.request.naturalspawns.NaturalSpawnRemovePack
import kamkeel.npcs.network.packets.request.naturalspawns.NaturalSpawnSavePacket;
import kamkeel.npcs.network.packets.request.npc.*;
import kamkeel.npcs.network.packets.request.party.*;
import kamkeel.npcs.network.packets.request.pather.MovingPathGetPacket;
import kamkeel.npcs.network.packets.request.pather.MovingPathSavePacket;
import kamkeel.npcs.network.packets.request.playerdata.PlayerDataGetPacket;
import kamkeel.npcs.network.packets.request.playerdata.PlayerDataMapRegenPacket;
import kamkeel.npcs.network.packets.request.playerdata.PlayerDataRemovePacket;
@@ -264,17 +266,22 @@ public class PacketHandler {
REQUEST_PACKET.registerPacket(new AnimationGetPacket());
REQUEST_PACKET.registerPacket(new AnimationRemovePacket());
REQUEST_PACKET.registerPacket(new AnimationSavePacket());
REQUEST_PACKET.registerPacket(new AnimationCachePacket());
// Moving Path
REQUEST_PACKET.registerPacket(new MovingPathSavePacket());
REQUEST_PACKET.registerPacket(new MovingPathGetPacket());
// Other Packets
REQUEST_PACKET.registerPacket(new IsGuiOpenInform());
REQUEST_PACKET.registerPacket(new GuiRequestPacket());
REQUEST_PACKET.registerPacket(new DimensionsGetPacket());
REQUEST_PACKET.registerPacket(new AnimationCachePacket());
REQUEST_PACKET.registerPacket(new MerchantUpdatePacket());
REQUEST_PACKET.registerPacket(new ModelDataSavePacket());
REQUEST_PACKET.registerPacket(new MailOpenSetupPacket());
REQUEST_PACKET.registerPacket(new TileEntityGetPacket());
REQUEST_PACKET.registerPacket(new TileEntitySavePacket());
REQUEST_PACKET.registerPacket(new MountPacket());
}
public void registerDataPackets(){
@@ -84,8 +84,7 @@ public enum EnumRequestPacket {
NaturalSpawnGetAll,
MerchantUpdate,
PlayerRider,
SpawnRider,
MountPacket,
MovingPathSave,
MovingPathGet,
@@ -0,0 +1,97 @@
package kamkeel.npcs.network.packets.request;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.PacketUtil;
import kamkeel.npcs.network.enums.EnumItemPacketType;
import kamkeel.npcs.network.enums.EnumRequestPacket;
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
import kamkeel.npcs.network.packets.player.BankPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.Constants;
import noppes.npcs.CustomNpcsPermissions;
import noppes.npcs.ServerEventsHandler;
import java.io.IOException;
public final class MountPacket extends AbstractPacket {
public static final String packetName = "Request|MountPacket";
private Action action;
private NBTTagCompound compound;
public MountPacket() {}
public MountPacket(Action action, NBTTagCompound nbtTagCompound) {
this.action = action;
this.compound = nbtTagCompound;
}
@Override
public Enum getType() {
return EnumRequestPacket.MountPacket;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.REQUEST_PACKET;
}
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.TOOL_MOUNTER;
}
@SideOnly(Side.CLIENT)
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeInt(action.ordinal());
if(action == Action.Spawn)
ByteBufUtils.writeNBT(out, this.compound);
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
if (!PacketUtil.verifyItemPacket(EnumItemPacketType.MOUNTER, player))
return;
MountPacket.Action requestedAction = MountPacket.Action.values()[in.readInt()];
switch (requestedAction){
case Player:
player.mountEntity(ServerEventsHandler.mounted);
break;
case Spawn:
Entity entity = EntityList.createEntityFromNBT(ByteBufUtils.readNBT(in), player.worldObj);
player.worldObj.spawnEntityInWorld(entity);
entity.mountEntity(ServerEventsHandler.mounted);
break;
}
}
public static MountPacket Player() {
return new MountPacket(Action.Player, new NBTTagCompound());
}
public static MountPacket Spawn(NBTTagCompound compound) {
return new MountPacket(Action.Spawn, compound);
}
private enum Action {
Player,
Spawn,
}
}
@@ -0,0 +1,56 @@
package kamkeel.npcs.network.packets.request.pather;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.PacketUtil;
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.CustomNpcsPermissions;
import noppes.npcs.NBTTags;
import java.io.IOException;
public final class MovingPathGetPacket extends AbstractPacket {
public static String packetName = "Request|MovingPathGet";
public MovingPathGetPacket() {}
@Override
public Enum getType() {
return EnumRequestPacket.MovingPathGet;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.REQUEST_PACKET;
}
@Override
public boolean needsNPC() {
return true;
}
@SideOnly(Side.CLIENT)
@Override
public void sendData(ByteBuf out) throws IOException {}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
if (!PacketUtil.verifyItemPacket(EnumItemPacketType.PATHER, player))
return;
GuiDataPacket.sendGuiData((EntityPlayerMP) player, npc.ai.writeToNBT(new NBTTagCompound()));
}
}
@@ -0,0 +1,73 @@
package kamkeel.npcs.network.packets.request.pather;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.PacketUtil;
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.CustomNpcsPermissions;
import noppes.npcs.NBTTags;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.controllers.FactionController;
import noppes.npcs.controllers.data.Faction;
import java.io.IOException;
public final class MovingPathSavePacket extends AbstractPacket {
public static String packetName = "Request|MovingPathSave";
private NBTTagCompound saveNBT;
public MovingPathSavePacket(NBTTagCompound saveNBT) {
this.saveNBT = saveNBT;
}
public MovingPathSavePacket() {
}
@Override
public Enum getType() {
return EnumRequestPacket.MovingPathSave;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.REQUEST_PACKET;
}
@Override
public CustomNpcsPermissions.Permission getPermission() {
return CustomNpcsPermissions.TOOL_PATHER;
}
@Override
public boolean needsNPC() {
return true;
}
@SideOnly(Side.CLIENT)
@Override
public void sendData(ByteBuf out) throws IOException {
ByteBufUtils.writeNBT(out, saveNBT);
}
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
if (!(player instanceof EntityPlayerMP))
return;
if (!PacketUtil.verifyItemPacket(EnumItemPacketType.PATHER, player))
return;
npc.ai.setMovingPath(NBTTags.getIntegerArraySet(ByteBufUtils.readNBT(in).getTagList("MovingPathNew",10)));
}
}
@@ -72,9 +72,7 @@ public class PacketHandlerServer{
warn(player, "tried to use custom npcs without a tool in hand, probably a hacker");
else {
if (item != null) {
if (item.getItem() == CustomItems.moving)
movingPackets(type, in, player, npc);
else if (item.getItem() == CustomItems.mount)
if (item.getItem() == CustomItems.mount)
mountPackets(type, in, player);
else if (item.getItem() == CustomItems.cloner)
clonePackets(type, in, player);
@@ -351,25 +349,8 @@ public class PacketHandlerServer{
}
}
private void movingPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws IOException {
if(type == EnumPacketServer.MovingPathGet){
GuiDataPacket.sendGuiData(player, npc.ai.writeToNBT(new NBTTagCompound()));
}
else if(type == EnumPacketServer.MovingPathSave){
npc.ai.setMovingPath(NBTTags.getIntegerArraySet(ByteBufUtils.readNBT(buffer).getTagList("MovingPathNew",10)));
}
}
private void mountPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException{
if(type == EnumPacketServer.SpawnRider){
Entity entity = EntityList.createEntityFromNBT(ByteBufUtils.readNBT(buffer), player.worldObj);
player.worldObj.spawnEntityInWorld(entity);
entity.mountEntity(ServerEventsHandler.mounted);
}
else if(type == EnumPacketServer.PlayerRider){
player.mountEntity(ServerEventsHandler.mounted);
}
else if(type == EnumPacketServer.CloneList){
if(type == EnumPacketServer.CloneList){
NBTTagList list = new NBTTagList();
int tab = buffer.readInt();
for(String name : ServerCloneController.Instance.getClones(tab))
@@ -1,5 +1,6 @@
package noppes.npcs.client.gui;
import kamkeel.npcs.network.packets.request.MountPacket;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.Entity;
@@ -20,19 +21,19 @@ import java.util.List;
import java.util.Map;
public class GuiNpcMobSpawnerMounter extends GuiNPCInterface implements IGuiData{
private GuiCustomScroll scroll;
private int posX,posY,posZ;
private List<String> list;
private static int showingClones = 0;
private static String search = "";
private int activeTab = 1;
public GuiNpcMobSpawnerMounter(int i, int j, int k) {
super();
xSize = 256;
@@ -40,16 +41,16 @@ public class GuiNpcMobSpawnerMounter extends GuiNPCInterface implements IGuiData
posX = i;
posY = j;
posZ = k;
this.closeOnEsc = true;
setBackground("menubg.png");
}
public void initGui()
{
super.initGui();
guiTop += 10;
if(scroll == null){
scroll = new GuiCustomScroll(this,0);
scroll.setSize(165, 188);
@@ -59,7 +60,7 @@ public class GuiNpcMobSpawnerMounter extends GuiNPCInterface implements IGuiData
scroll.guiLeft = guiLeft + 4;
scroll.guiTop = guiTop + 26;
addScroll(scroll);
addTextField(new GuiNpcTextField(1, this, fontRendererObj, guiLeft + 4, guiTop + 4, 165, 20, search));
GuiMenuTopButton button;
@@ -90,7 +91,7 @@ public class GuiNpcMobSpawnerMounter extends GuiNPCInterface implements IGuiData
addSideButton(new GuiMenuSideButton(33,guiLeft - 90, this.guiTop + 170, 45,22, "13"));
addSideButton(new GuiMenuSideButton(34,guiLeft - 45, this.guiTop + 191, 45,22, "14"));
addSideButton(new GuiMenuSideButton(35,guiLeft - 90, this.guiTop + 191, 45,22, "15"));
getSideButton(20 + activeTab).active = true;
showClones();
}
@@ -109,7 +110,7 @@ public class GuiNpcMobSpawnerMounter extends GuiNPCInterface implements IGuiData
e.printStackTrace();
} catch (NoSuchMethodException e) {
}
}
}
this.list = list;
scroll.setList(getSearchList());
}
@@ -119,7 +120,7 @@ public class GuiNpcMobSpawnerMounter extends GuiNPCInterface implements IGuiData
Client.sendData(EnumPacketServer.CloneList, activeTab);
return;
}
ArrayList<String> list = new ArrayList<String>();
this.list = ClientCloneController.Instance.getClones(activeTab);
scroll.setList(getSearchList());
@@ -127,7 +128,7 @@ public class GuiNpcMobSpawnerMounter extends GuiNPCInterface implements IGuiData
public void keyTyped(char c, int i)
{
super.keyTyped(c, i);
if(search.equals(getTextField(1).getText()))
return;
search = getTextField(1).getText().toLowerCase();
@@ -147,7 +148,7 @@ public class GuiNpcMobSpawnerMounter extends GuiNPCInterface implements IGuiData
String sel = scroll.getSelected();
if(sel == null)
return null;
if(showingClones == 0){
return ClientCloneController.Instance.getCloneData(player, sel, activeTab);
}
@@ -159,9 +160,9 @@ public class GuiNpcMobSpawnerMounter extends GuiNPCInterface implements IGuiData
entity.writeToNBTOptional(compound);
return compound;
}
}
protected void actionPerformed(GuiButton guibutton)
{
int id = guibutton.id;
@@ -172,12 +173,12 @@ public class GuiNpcMobSpawnerMounter extends GuiNPCInterface implements IGuiData
NBTTagCompound compound = getCompound();
if(compound != null){
compound.setTag("Pos", this.newDoubleNBTList(new double[] {this.posX + 0.5, this.posY + 1, this.posZ + 0.5}));
Client.sendData(EnumPacketServer.SpawnRider, compound);
MountPacket.Spawn(compound);
close();
}
}
if(id == 2){
Client.sendData(EnumPacketServer.PlayerRider);
MountPacket.Player();
close();
}
if(id == 3){
@@ -211,11 +212,11 @@ public class GuiNpcMobSpawnerMounter extends GuiNPCInterface implements IGuiData
return nbttaglist;
}
@Override
public void save() {
// TODO Auto-generated method stub
}
@Override
public void setGuiData(NBTTagCompound compound) {
@@ -1,5 +1,8 @@
package noppes.npcs.client.gui;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.pather.MovingPathGetPacket;
import kamkeel.npcs.network.packets.request.pather.MovingPathSavePacket;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.DataAI;
@@ -17,11 +20,11 @@ import java.util.HashMap;
import java.util.List;
public class GuiNpcPather extends GuiNPCInterface implements IGuiData{
private GuiCustomScroll scroll;
private HashMap<String, Integer> data = new HashMap<String, Integer>();
private DataAI ai;
public GuiNpcPather(EntityNPCInterface npc) {
super();
drawDefaultBackground = false;
@@ -29,7 +32,7 @@ public class GuiNpcPather extends GuiNPCInterface implements IGuiData{
title = "Npc Pather";
setBackground("smallbg.png");
ai = npc.ai;
Client.sendData(EnumPacketServer.MovingPathGet);
PacketClient.sendClient(new MovingPathGetPacket());
}
@Override
public void initGui()
@@ -44,7 +47,7 @@ public class GuiNpcPather extends GuiNPCInterface implements IGuiData{
scroll.setUnsortedList(list);
scroll.guiLeft = guiLeft + 7;
scroll.guiTop = guiTop + 12;
addScroll(scroll);
this.addButton(new GuiNpcButton(0, guiLeft + 6, guiTop + 178,52,20, "gui.down"));
this.addButton(new GuiNpcButton(1, guiLeft + 62, guiTop + 178,52,20, "gui.up"));
@@ -55,7 +58,7 @@ public class GuiNpcPather extends GuiNPCInterface implements IGuiData{
{
if(scroll.selected < 0)
return;
int id = guibutton.id;
if(id == 0){
List<int[]> list = ai.getMovingPath();
@@ -109,12 +112,12 @@ public class GuiNpcPather extends GuiNPCInterface implements IGuiData{
close();
}
}
@Override
public void save() {
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("MovingPathNew", NBTTags.nbtIntegerArraySet(ai.getMovingPath()));
Client.sendData(EnumPacketServer.MovingPathSave, compound);
PacketClient.sendClient(new MovingPathSavePacket(compound));
}
@Override
@@ -37,13 +37,6 @@ public enum EnumPacketServer {
EventScriptDataSave(CustomNpcsPermissions.SCRIPT_NPC, true),
EventScriptDataGet(true),
FactionsGet,
FactionGet,
PlayerRider(CustomNpcsPermissions.TOOL_MOUNTER),
SpawnRider(CustomNpcsPermissions.TOOL_MOUNTER),
MovingPathSave(CustomNpcsPermissions.TOOL_PATHER,true),
MovingPathGet(true),
DimensionTeleport;
public CustomNpcsPermissions.Permission permission = null;