mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 15:27:29 +00:00
Merge branch 'packet' of https://github.com/KAMKEEL/CustomNPC-Plus into packet
This commit is contained in:
commit
04fc429a53
11 files changed
+274
-56
No files matched your search
@@ -362,8 +362,13 @@ public class PacketHandler {
|
||||
PLAYER_PACKET.registerPacket(new MailActionPacket());
|
||||
PLAYER_PACKET.registerPacket(new MailActionPacket.MailSendPacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new SaveSignPacket());
|
||||
PLAYER_PACKET.registerPacket(new SaveBookPacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new CompanionActionPacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new GetNPCRole());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new InputDevicePacket());
|
||||
|
||||
PLAYER_PACKET.registerPacket(new ScreenSizePacket());
|
||||
|
||||
@@ -8,10 +8,10 @@ public enum EnumPlayerPacket {
|
||||
GetPlayerValue,
|
||||
MailBoxAction,
|
||||
MailSend,
|
||||
SaveSign, // TODO
|
||||
SaveBook, // TODO
|
||||
CompanionAction, // TODO: OpenInv, TalentExp
|
||||
GetRole, // TODO
|
||||
SaveSign,
|
||||
SaveBook,
|
||||
CompanionAction,
|
||||
GetRole,
|
||||
InputDevice,
|
||||
ScreenSize
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package kamkeel.npcs.network.packets.player;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumPlayerPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.constants.EnumRoleType;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GetNPCRole extends AbstractPacket {
|
||||
public static final String packetName = "Player|GetNPCRole";
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumPlayerPacket.GetRole;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.PLAYER_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsNPC() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if(!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
if (npc.advanced.role == EnumRoleType.None)
|
||||
return;
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, npc.roleInterface.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package kamkeel.npcs.network.packets.player;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import kamkeel.npcs.network.LargeAbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumPlayerPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemEditableBook;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemWritableBook;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import noppes.npcs.blocks.tiles.TileBook;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class SaveBookPacket extends LargeAbstractPacket {
|
||||
public static final String packetName = "Player|SaveBook";
|
||||
|
||||
private int x, y, z;
|
||||
private boolean sign;
|
||||
private NBTTagCompound compound;
|
||||
|
||||
public SaveBookPacket() {
|
||||
|
||||
}
|
||||
|
||||
public SaveBookPacket(int x, int y, int z, boolean sign, NBTTagCompound compound) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.sign = sign;
|
||||
this.compound = compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] getData() throws IOException {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
buffer.writeInt(x);
|
||||
buffer.writeInt(y);
|
||||
buffer.writeInt(z);
|
||||
buffer.writeBoolean(sign);
|
||||
ByteBufUtils.writeBigNBT(buffer, compound);
|
||||
return buffer.array();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
|
||||
int x = data.readInt(), y = data.readInt(), z = data.readInt();
|
||||
|
||||
if (player.worldObj.blockExists(x, y, z)) {
|
||||
TileEntity tileentity = player.worldObj.getTileEntity(x, y, z);
|
||||
if (!(tileentity instanceof TileBook))
|
||||
return;
|
||||
TileBook tile = (TileBook) tileentity;
|
||||
if (tile.book.getItem() == Items.written_book)
|
||||
return;
|
||||
boolean sign = data.readBoolean();
|
||||
ItemStack book = ItemStack.loadItemStackFromNBT(ByteBufUtils.readBigNBT(data));
|
||||
if (book == null)
|
||||
return;
|
||||
if (book.getItem() == Items.writable_book && !sign && ItemWritableBook.func_150930_a(book.getTagCompound())) {
|
||||
tile.book.setTagInfo("pages", book.getTagCompound().getTagList("pages", 8));
|
||||
}
|
||||
if (book.getItem() == Items.written_book && sign && ItemEditableBook.validBookTagContents(book.getTagCompound())) {
|
||||
tile.book.setTagInfo("author", new NBTTagString(player.getCommandSenderName()));
|
||||
tile.book.setTagInfo("title", new NBTTagString(book.getTagCompound().getString("title")));
|
||||
tile.book.setTagInfo("pages", book.getTagCompound().getTagList("pages", 8));
|
||||
tile.book.func_150996_a(Items.written_book);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumPlayerPacket.SaveBook;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.PLAYER_PACKET;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package kamkeel.npcs.network.packets.player;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import kamkeel.npcs.network.LargeAbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumPlayerPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import noppes.npcs.blocks.tiles.TileBigSign;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class SaveSignPacket extends LargeAbstractPacket {
|
||||
public static final String packetName = "Player|SaveSign";
|
||||
private int x, y, z;
|
||||
private String text;
|
||||
|
||||
public SaveSignPacket() {
|
||||
|
||||
}
|
||||
|
||||
public SaveSignPacket(int x, int y, int z, String text) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] getData() throws IOException {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
buffer.writeInt(x);
|
||||
buffer.writeInt(y);
|
||||
buffer.writeInt(z);
|
||||
ByteBufUtils.writeString(buffer, text);
|
||||
return buffer.array();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
|
||||
int x = data.readInt(), y = data.readInt(), z = data.readInt();
|
||||
if (player.worldObj.blockExists(x, y, z)) {
|
||||
TileEntity tile = player.worldObj.getTileEntity(x, y, z);
|
||||
if(!(tile instanceof TileBigSign))
|
||||
return;
|
||||
TileBigSign sign = (TileBigSign) tile;
|
||||
if (sign.canEdit) {
|
||||
sign.setText(ByteBufUtils.readString(data));
|
||||
sign.canEdit = false;
|
||||
player.worldObj.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumPlayerPacket.SaveSign;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.PLAYER_PACKET;
|
||||
}
|
||||
}
|
||||
@@ -146,12 +146,12 @@ public class PacketHandlerPlayer{
|
||||
// NoppesUtilPlayer.changeFollowerState(player,npc);
|
||||
// GuiDataPacket.sendGuiData(player, npc.roleInterface.writeToNBT(new NBTTagCompound()));
|
||||
// }
|
||||
if(type == EnumPlayerPacket.RoleGet){
|
||||
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
if(npc == null || npc.advanced.role == EnumRoleType.None)
|
||||
return;
|
||||
GuiDataPacket.sendGuiData(player, npc.roleInterface.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
// if(type == EnumPlayerPacket.RoleGet){
|
||||
// EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
// if(npc == null || npc.advanced.role == EnumRoleType.None)
|
||||
// return;
|
||||
// GuiDataPacket.sendGuiData(player, npc.roleInterface.writeToNBT(new NBTTagCompound()));
|
||||
// }
|
||||
// else if(type == EnumPlayerPacket.Transport){
|
||||
// EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
|
||||
// if(npc == null || npc.advanced.role != EnumRoleType.Transporter)
|
||||
@@ -281,44 +281,44 @@ public class PacketHandlerPlayer{
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
else if(type == EnumPlayerPacket.SignSave) {
|
||||
int x = buffer.readInt(), y = buffer.readInt(), z = buffer.readInt();
|
||||
if (player.worldObj.blockExists(x, y, z)) {
|
||||
TileEntity tile = player.worldObj.getTileEntity(x, y, z);
|
||||
if(!(tile instanceof TileBigSign))
|
||||
return;
|
||||
TileBigSign sign = (TileBigSign) tile;
|
||||
if (sign.canEdit) {
|
||||
sign.setText(ByteBufUtils.readString(buffer));
|
||||
sign.canEdit = false;
|
||||
player.worldObj.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(type == EnumPlayerPacket.SaveBook) {
|
||||
int x = buffer.readInt(), y = buffer.readInt(), z = buffer.readInt();
|
||||
if (player.worldObj.blockExists(x, y, z)) {
|
||||
TileEntity tileentity = player.worldObj.getTileEntity(x, y, z);
|
||||
if (!(tileentity instanceof TileBook))
|
||||
return;
|
||||
TileBook tile = (TileBook) tileentity;
|
||||
if (tile.book.getItem() == Items.written_book)
|
||||
return;
|
||||
boolean sign = buffer.readBoolean();
|
||||
ItemStack book = ItemStack.loadItemStackFromNBT(ByteBufUtils.readNBT(buffer));
|
||||
if (book == null)
|
||||
return;
|
||||
if (book.getItem() == Items.writable_book && !sign && ItemWritableBook.func_150930_a(book.getTagCompound())) {
|
||||
tile.book.setTagInfo("pages", book.getTagCompound().getTagList("pages", 8));
|
||||
}
|
||||
if (book.getItem() == Items.written_book && sign && ItemEditableBook.validBookTagContents(book.getTagCompound())) {
|
||||
tile.book.setTagInfo("author", new NBTTagString(player.getCommandSenderName()));
|
||||
tile.book.setTagInfo("title", new NBTTagString(book.getTagCompound().getString("title")));
|
||||
tile.book.setTagInfo("pages", book.getTagCompound().getTagList("pages", 8));
|
||||
tile.book.func_150996_a(Items.written_book);
|
||||
}
|
||||
}
|
||||
}
|
||||
// else if(type == EnumPlayerPacket.SignSave) {
|
||||
// int x = buffer.readInt(), y = buffer.readInt(), z = buffer.readInt();
|
||||
// if (player.worldObj.blockExists(x, y, z)) {
|
||||
// TileEntity tile = player.worldObj.getTileEntity(x, y, z);
|
||||
// if(!(tile instanceof TileBigSign))
|
||||
// return;
|
||||
// TileBigSign sign = (TileBigSign) tile;
|
||||
// if (sign.canEdit) {
|
||||
// sign.setText(ByteBufUtils.readString(buffer));
|
||||
// sign.canEdit = false;
|
||||
// player.worldObj.markBlockForUpdate(x, y, z);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if(type == EnumPlayerPacket.SaveBook) {
|
||||
// int x = buffer.readInt(), y = buffer.readInt(), z = buffer.readInt();
|
||||
// if (player.worldObj.blockExists(x, y, z)) {
|
||||
// TileEntity tileentity = player.worldObj.getTileEntity(x, y, z);
|
||||
// if (!(tileentity instanceof TileBook))
|
||||
// return;
|
||||
// TileBook tile = (TileBook) tileentity;
|
||||
// if (tile.book.getItem() == Items.written_book)
|
||||
// return;
|
||||
// boolean sign = buffer.readBoolean();
|
||||
// ItemStack book = ItemStack.loadItemStackFromNBT(ByteBufUtils.readNBT(buffer));
|
||||
// if (book == null)
|
||||
// return;
|
||||
// if (book.getItem() == Items.writable_book && !sign && ItemWritableBook.func_150930_a(book.getTagCompound())) {
|
||||
// tile.book.setTagInfo("pages", book.getTagCompound().getTagList("pages", 8));
|
||||
// }
|
||||
// if (book.getItem() == Items.written_book && sign && ItemEditableBook.validBookTagContents(book.getTagCompound())) {
|
||||
// tile.book.setTagInfo("author", new NBTTagString(player.getCommandSenderName()));
|
||||
// tile.book.setTagInfo("title", new NBTTagString(book.getTagCompound().getString("title")));
|
||||
// tile.book.setTagInfo("pages", book.getTagCompound().getTagList("pages", 8));
|
||||
// tile.book.func_150996_a(Items.written_book);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if(type == EnumPlayerPacket.ScreenSize){
|
||||
// int width = buffer.readInt(), height = buffer.readInt();
|
||||
// PlayerDataController.Instance.getPlayerData(player).screenSize.setSize(width,height);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package noppes.npcs.client.gui.player;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.player.SaveSignPacket;
|
||||
import noppes.npcs.NoppesUtilPlayer;
|
||||
import noppes.npcs.blocks.tiles.TileBigSign;
|
||||
import noppes.npcs.client.gui.SubGuiNpcTextArea;
|
||||
@@ -16,6 +18,6 @@ public class GuiBigSign extends SubGuiNpcTextArea{
|
||||
@Override
|
||||
public void close(){
|
||||
super.close();
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.SignSave, tile.xCoord, tile.yCoord, tile.zCoord, text);
|
||||
PacketClient.sendClient(new SaveSignPacket(tile.xCoord, tile.yCoord, tile.zCoord, text));
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package noppes.npcs.client.gui.player;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.player.SaveBookPacket;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -178,7 +180,7 @@ public class GuiBook extends GuiScreen
|
||||
this.bookObj.func_150996_a(Items.written_book);
|
||||
}
|
||||
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.SaveBook, x, y, z, sign, bookObj.writeToNBT(new NBTTagCompound()));
|
||||
PacketClient.sendClient(new SaveBookPacket(x, y, z, sign, bookObj.writeToNBT(new NBTTagCompound())));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package noppes.npcs.client.gui.player;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.player.FollowerPacket;
|
||||
import kamkeel.npcs.network.packets.player.GetNPCRole;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -31,7 +32,7 @@ public class GuiNpcFollower extends GuiContainerNPCInterface implements IGuiDat
|
||||
role = (RoleFollower) npc.roleInterface;
|
||||
closeOnEsc = true;
|
||||
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.RoleGet);
|
||||
PacketClient.sendClient(new GetNPCRole());
|
||||
}
|
||||
@Override
|
||||
public void initGui(){
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package noppes.npcs.client.gui.player.companion;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.player.CompanionActionPacket;
|
||||
import kamkeel.npcs.network.packets.player.GetNPCRole;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -29,7 +31,7 @@ public class GuiNpcCompanionStats extends GuiNPCInterface implements IGuiData {
|
||||
setBackground("companion.png");
|
||||
xSize = 171;
|
||||
ySize = 166;
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.RoleGet);
|
||||
PacketClient.sendClient(new GetNPCRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,7 +90,7 @@ public class GuiNpcCompanionStats extends GuiNPCInterface implements IGuiData {
|
||||
public void drawScreen(int i, int j, float f) {
|
||||
super.drawScreen(i, j, f);
|
||||
if(isEating && !role.isEating()){
|
||||
NoppesUtilPlayer.sendData(EnumPlayerPacket.RoleGet);
|
||||
PacketClient.sendClient(new GetNPCRole());
|
||||
}
|
||||
|
||||
isEating = role.isEating();
|
||||
|
||||
@@ -18,10 +18,10 @@ public enum EnumPlayerPacket {
|
||||
// MailSend,
|
||||
// MailRead,
|
||||
// MailboxOpenMail,
|
||||
SignSave,
|
||||
SaveBook,
|
||||
// SignSave,
|
||||
// SaveBook,
|
||||
// CompanionOpenInv,
|
||||
RoleGet,
|
||||
// RoleGet,
|
||||
// KeyPressed,
|
||||
// MouseClicked,
|
||||
// CompanionTalentExp,
|
||||
|
||||
Reference in new issue
Block a user