mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-21 13:52:23 +00:00
Book & Sign packets
This commit is contained in:
1 parent
4143298da3
commit
3d2a6954f9
5 files changed
+203
-40
No files matched your search
@@ -281,44 +281,44 @@ public class PacketHandlerPlayer{
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
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())));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user