Problème npc
-
Bonjour la je travail sur un system de PNJ (npc) pour mon serveur rp j ai commencé faire comme il faut mais quand je tente de summon l entité sa marche pas sa me donne une erreur
Le code :
package fr.impuuu.havenrp.entity; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import fr.impuuu.havenrp.common.HavenRP; import net.minecraft.client.entity.EntityClientPlayerMP; import net.minecraft.client.resources.I18n; import net.minecraft.entity.DataWatcher; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.play.client.C17PacketCustomPayload; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; public class EntityNPC extends EntityLiving { public EntityNPC(World world) { super(world); } public boolean isMovementCeased() { return true; } public void onLivingUpdate() {} @SideOnly(Side.CLIENT) public boolean interact(EntityPlayer player) { EntityClientPlayerMP playerMP = (EntityClientPlayerMP)player; EENRestrained props = EENRestrained.get(player); DataWatcher dw = getDataWatcher(); ByteArrayDataOutput out = ByteStreams.newDataOutput(); if (!player.isSneaking()) { if (!dw.getWatchableObjectString(21).equalsIgnoreCase("Conces")) { out.writeUTF("chestcommands open " + dw.getWatchableObjectString(21)); out.writeUTF(dw.getWatchableObjectString(22)); if ((dw.getWatchableObjectString(22).equals("Player")) || (dw.getWatchableObjectString(22).equals(""))) { C17PacketCustomPayload packet = new C17PacketCustomPayload("ForgeToBukkit", out.toByteArray()); playerMP.sendQueue.addToSendQueue(packet); } else if (dw.getWatchableObjectString(22).equals("vip")) { if (props.vip) { C17PacketCustomPayload packet = new C17PacketCustomPayload("ForgeToBukkit", out.toByteArray()); playerMP.sendQueue.addToSendQueue(packet); } else { player.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.DARK_RED +"tes pas VIP !")); } } } } else { return false; } return true; } public boolean isEntityInvulnerable() { return true; } public void writeEntityToNBT(NBTTagCompound nbt) { super.writeEntityToNBT(nbt); DataWatcher dw = getDataWatcher(); nbt.setString("HavenRPTexture", dw.getWatchableObjectString(20)); nbt.setString("HavenRPAction", dw.getWatchableObjectString(21)); nbt.setString("HavenRPPerm", dw.getWatchableObjectString(22)); nbt.setString("HavenRPX", dw.getWatchableObjectString(23)); nbt.setString("HavenRPY", dw.getWatchableObjectString(24)); nbt.setString("HavenRPZ", dw.getWatchableObjectString(25)); nbt.setString("HavenRPDirection", dw.getWatchableObjectString(26)); nbt.setString("HavenRPNom", dw.getWatchableObjectString(27)); } public void readEntityFromNBT(NBTTagCompound nbt) { super.readEntityFromNBT(nbt); DataWatcher dw = getDataWatcher(); String tex = nbt.getString("HavenRPTexture"); String act = nbt.getString("HavenRPAction"); String perm = nbt.getString("HavenRPPerm"); String x = nbt.getString("HavenRPX"); String y = nbt.getString("HavenRPY"); String z = nbt.getString("HavenRPZ"); String dir = nbt.getString("HavenRPDirection"); String nom = nbt.getString("HavenRPNom"); dw.updateObject(20, tex); dw.updateObject(21, act); dw.updateObject(22, perm); dw.updateObject(23, x); dw.updateObject(24, y); dw.updateObject(25, z); dw.updateObject(26, dir); dw.updateObject(27, nom); } }
L’erreur:
[15:54:30] [Server thread/ERROR] [FML]: An Entity marketPNJ(fr.impuuu.havenrp.entity.EntityNPC) has thrown an exception during loading, its state cannot be restored. Report this to the mod author net.minecraft.util.ReportedException: Loading entity NBT at net.minecraft.entity.Entity.readFromNBT(Entity.java:1642) ~[Entity.class:?] at net.minecraft.entity.EntityList.createEntityFromNBT(EntityList.java:191) [EntityList.class:?] at net.minecraft.command.server.CommandSummon.processCommand(CommandSummon.java:96) [CommandSummon.class:?] at net.minecraft.command.CommandHandler.executeCommand(CommandHandler.java:96) [CommandHandler.class:?] at net.minecraft.network.NetHandlerPlayServer.handleSlashCommand(NetHandlerPlayServer.java:788) [NetHandlerPlayServer.class:?] at net.minecraft.network.NetHandlerPlayServer.processChatMessage(NetHandlerPlayServer.java:764) [NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.C01PacketChatMessage.processPacket(C01PacketChatMessage.java:47) [C01PacketChatMessage.class:?] at net.minecraft.network.play.client.C01PacketChatMessage.processPacket(C01PacketChatMessage.java:68) [C01PacketChatMessage.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?] at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [IntegratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?] Caused by: java.lang.NullPointerException at net.minecraft.entity.DataWatcher.updateObject(DataWatcher.java:153) ~[DataWatcher.class:?] at fr.impuuu.havenrp.entity.EntityNPC.readEntityFromNBT(EntityNPC.java:105) ~[EntityNPC.class:?] at net.minecraft.entity.Entity.readFromNBT(Entity.java:1630) ~[Entity.class:?] … 14 more [15:54:30] [Server thread/INFO]: [Player97: Unable to summon object] [15:54:30] [Client thread/INFO]: [CHAT] Unable to summon object
-
Ta variable tex semble être null, ce qui n’est pas étonnant puisque tu l’initialises avec un datawatcher, alors que si on regarde ta classe, elle n’override même pas la méthode init(), pourtant indispensable lorsqu’on se sert des datawatchers !
Soit tu essaies de résoudre ton bug tout seul en regardant le tuto sur les datawatchers sur minecraftforge.net + avec les classes de MC, soit tu attends une réponse plus détaillée d’un autre membre, ou mon tuto complet sur datawatchers & nbttag qqui sortira début de semaine prochaine -
Je vais attendre que un membre détails plus
-
Pas grand chose à dire : ta variable est nulle, il faut l’initialisée comme l’a dit Plaigon
-
Les npe ce n’est pas compliqué à résoudre …
-
je le résoud comment
-
Bah comme on te l’a dit : initialiser la varibale, Plaigon a mieux expliqué que moi