Posted March 14, 201510 yr Hello All! I recently updated my code from 1.6 to 1.7, which meant completely changing the way packets were sent. I finally got all of the errors fixed so I tried to run the client, got to the main screen, but crashed with "Ticking Memory Connection" when I tried to join a world. The error log pointed me to my "magicPlayer" file, which houses extended properties for my player class. I read up on the error and it said it had something to do with packets sending incorrectly. However I only ran the client, and the only packets sent in that file only send if !world.isRemote(), so I'm not sure how that can be the case. I also tried running both the client and server but there was no difference. here is the class in question: package com.InnerPower; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import com.InnerPower.networking.propsPacket; import com.InnerPower.spells.holySpellList; import com.InnerPower.spells.mageSpellList; import com.InnerPower.spells.spell; import com.InnerPower.spells.unholySpellList; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.Minecraft; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.EnchantmentThorns; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IEntityMultiPart; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.boss.EntityDragonPart; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; import net.minecraft.stats.AchievementList; import net.minecraft.stats.StatList; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.entity.player.AttackEntityEvent; public class magicPlayer implements IExtendedEntityProperties { //variables public static final String EXT_PROP_NAME= "magicPlayer"; private final EntityPlayer player; public static final int MANA_WATCHER = 20; private int maxMana; private int maxTimer; private int manaTimer=maxTimer; public mageSpellList mageList; public unholySpellList necroList; public holySpellList holyList; //Stores id's to send via packets public int[] mageIDs =new int[mageList.listOfSpells.length]; public int[] necroIDs =new int[necroList.listOfSpells.length]; public int[] holyIDs =new int[holyList.listOfSpells.length]; public int activeSpellID; public int activeSpellID2; public int activeSpellID3; public int activeSpellID4; public boolean isMage; public boolean isUnholy; public boolean isHoly; public Entity entityLookedAt; //constructor public magicPlayer( EntityPlayer player) { this.maxTimer=250; this.player = player; this.maxMana=100; this.isMage=false; // This adds the new object at our defined index and sets the value to max mana, // since we should have full mana when first constructing this.player.getDataWatcher().addObject(MANA_WATCHER, this.maxMana); this.setActiveSpellID(0,1); this.setActiveSpellID(0,2); this.setActiveSpellID(0,3); this.setActiveSpellID(0,4); this.mageList= new mageSpellList(); this.necroList= new unholySpellList(); this.holyList= new holySpellList(); //System.out.print("Initializing list IDs!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); for(int i=0; i<this.holyList.listOfSpells.length; i++) { holyIDs=0; mageIDs=0; necroIDs=0; } } // useless function @Override public void init(Entity entity, World world) { } //registers magicPlayer to player on EntityConstructing event. public static final void register(EntityPlayer player) { player.registerExtendedProperties(magicPlayer.EXT_PROP_NAME, new magicPlayer(player)); } //returns magicPLayer properties public static final magicPlayer get(EntityPlayer player) { return (magicPlayer) player.getExtendedProperties(EXT_PROP_NAME); } //SAVE DATA ------- ADD EXT PROPS HERE but figure out why it crashed first @Override public void saveNBTData(NBTTagCompound compound) { // We need to create a new tag compound that will save everything for our Extended Properties NBTTagCompound properties = new NBTTagCompound(); // We only have 2 variables currently; save them both to the new tag properties.setInteger("CurrentMana",this.player.getDataWatcher().getWatchableObjectInt(MANA_WATCHER)); properties.setInteger("MaxMana", this.maxMana); for(int i=0; i<this.mageList.listOfSpells.length; i++) { properties.setInteger("MlistOfSpells["+i+"]", this.mageList.listOfSpells.id); } for(int i=0; i<this.necroList.listOfSpells.length; i++) { properties.setInteger("NlistOfSpells["+i+"]", this.necroList.listOfSpells.id); } for(int i=0; i<this.holyList.listOfSpells.length; i++) { properties.setInteger("HlistOfSpells["+i+"]", this.holyList.listOfSpells.id); } System.out.println("Active ID Saved: "+this.activeSpellID); properties.setInteger("activeSpellID", this.activeSpellID); properties.setInteger("activeSpellID2", this.activeSpellID2); properties.setInteger("activeSpellID3", this.activeSpellID3); properties.setInteger("activeSpellID4", this.activeSpellID4); properties.setBoolean("isMage", this.isMage); properties.setBoolean("isUnholy", this.isUnholy); properties.setBoolean("isHoly", this.isHoly); compound.setTag(EXT_PROP_NAME, properties); } //LOAD DATA @Override public void loadNBTData(NBTTagCompound compound) { // Here we fetch the unique tag compound we set for this class of Extended Properties NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); // Get our data from the custom tag compound this.player.getDataWatcher().updateObject(MANA_WATCHER, properties.getInteger("CurrentMana")); this.maxMana = properties.getInteger("MaxMana"); // Just so you know it's working, add this line: System.out.println("[TUT PROPS] Mana from NBT: " + this.player.getDataWatcher().getWatchableObjectInt(MANA_WATCHER) + "/" + this.maxMana); int idNum; for(int i=0; i<this.mageList.listOfSpells.length; i++) { idNum=properties.getInteger("MlistOfSpells["+i+"]"); spell s= this.mageList.getSpellFromID(idNum); this.mageList.addSpellToList(s); } for(int i=0; i<this.necroList.listOfSpells.length; i++) { idNum=properties.getInteger("NlistOfSpells["+i+"]"); spell s= this.necroList.getSpellFromID(idNum); this.necroList.addSpellToList(s); } for(int i=0; i<this.holyList.listOfSpells.length; i++) { idNum=properties.getInteger("HlistOfSpells["+i+"]"); spell s= this.holyList.getSpellFromID(idNum); this.holyList.addSpellToList(s); } this.setActiveSpellID(properties.getInteger("activeSpellID"), 1); this.setActiveSpellID(properties.getInteger("activeSpellID2"), 2); this.setActiveSpellID(properties.getInteger("activeSpellID3"), 3); this.setActiveSpellID(properties.getInteger("activeSpellID4"), 4); this.isMage= properties.getBoolean("isMage"); this.isUnholy= properties.getBoolean("isUnholy"); this.isHoly= properties.getBoolean("isHoly"); } //consume mana function public final boolean consumeMana(int amount) { // This variable makes it easier to write the rest of the method int mana = this.player.getDataWatcher().getWatchableObjectInt(MANA_WATCHER); //return without consuming mana if player is in creatve if( this.player.capabilities.isCreativeMode== true) { return true; } // These two lines are the same as before boolean sufficient = amount <= mana; if(sufficient== true) { mana -= (amount < mana ? amount : mana); // Update the data watcher object with the new value //this.player.getDataWatcher().updateObject(MANA_WATCHER, mana); this.setCurrentMana(mana); } // note that we no longer need to call 'sync()' to update the client return sufficient; } public int getMaxMana() { return this.maxMana; } public int getCurrentMana() { return this.player.getDataWatcher().getWatchableObjectInt(MANA_WATCHER); } /** * Sets current mana to amount or maxMana, whichever is lesser */ public void setCurrentMana(int amount) { this.player.getDataWatcher().updateObject(MANA_WATCHER, (amount < this.maxMana ? amount : this.maxMana)); this.sync(); } /** * Sets max mana to amount or 0 if amount is less than 0 */ public void setMaxMana(int amount) { this.maxMana = (amount > 0 ? amount : 0); this.sync(); } /** * Sends a packet to the client containing information stored on the server * for ExtendedPlayer */ public final void sync() { // We'll write max mana first so when we set current mana client // side, it doesn't get set to 0 (see methods below) for(int i=0; i<this.mageList.listOfSpells.length; i++) { this.mageIDs=this.mageList.listOfSpells.id; } for(int i=0; i<this.necroList.listOfSpells.length; i++) { this.necroIDs=this.necroList.listOfSpells.id; } for(int i=0; i<this.holyList.listOfSpells.length; i++) { this.holyIDs=this.holyList.listOfSpells.id; } // We only want to send from the server to the client if (!player.worldObj.isRemote) { EntityPlayerMP player1 = (EntityPlayerMP) player; BaseClass.propsChannel.sendTo(new propsPacket(this.maxMana, this.getCurrentMana(), this.activeSpellID, this.activeSpellID2, this.activeSpellID3, this.activeSpellID4, this.isMage, this.isUnholy, this.isHoly, this.necroList.iceTouch, this.mageIDs, this.necroIDs, this.holyIDs), player1); } } @SubscribeEvent public void onEntityJoinWorld(EntityJoinWorldEvent event) { //Only need to synchronize when the world is remote (i.e. we're on the server side) // and only for player entities, as that's what we need for the GuiManaBar if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer) { magicPlayer.get((EntityPlayer) event.entity).sync(); } } //replenish mana public void replenishMana(int addNum) { final int addMana= this.player.getDataWatcher().getWatchableObjectInt(MANA_WATCHER)+addNum; this.setCurrentMana(addMana); } public void setActiveSpellID(int id, int slotNum) { if(slotNum== 1) { this.activeSpellID=id; } if(slotNum==2) { this.activeSpellID2=id; } if(slotNum==3) { this.activeSpellID3=id; } if(slotNum==4) { this.activeSpellID4=id; } } public int getActiveSpellID() { return this.activeSpellID; } public void onUpdate() { if(this.player.getDataWatcher().getWatchableObjectInt(MANA_WATCHER) < this.maxMana) { if(manaTimer != 0) { manaTimer--; } if(manaTimer== 0) { this.replenishMana(5); manaTimer=maxTimer; } } this.necroList.handleIceTouchCounter(); this.holyList.handleFireCounter(this.player); } private static String getSaveKey(EntityPlayer player) { return player.PERSISTED_NBT_TAG + ":" + EXT_PROP_NAME; } public static void saveProxyData(EntityPlayer player) { magicPlayer playerData = magicPlayer.get(player); NBTTagCompound savedData = new NBTTagCompound(); savedData=CommonProxy.getEntityData(player.PERSISTED_NBT_TAG); playerData.saveNBTData(savedData); // Note that we made the CommonProxy method storeEntityData static, // so now we don't need an instance of CommonProxy to use it! Great! CommonProxy.storeEntityData(getSaveKey(player), savedData); } public static void loadProxyData(EntityPlayer player) { magicPlayer playerData= magicPlayer.get(player); NBTTagCompound savedData = CommonProxy.getEntityData(getSaveKey(player)); if(savedData != null) { playerData.loadNBTData(savedData); } // note we renamed 'syncExtendedProperties' to 'syncProperties' because yay, it's shorter playerData.sync(); } public void changeClass(int classNum) { this.activeSpellID=0; this.activeSpellID2=0; this.activeSpellID3=0; this.activeSpellID4=0; if(classNum == 1) { this.isMage=true; this.isUnholy=false; this.isHoly=false; } if(classNum == 2) { this.isMage=false; this.isUnholy=true; this.isHoly=false; } if(classNum == 3) { this.isMage=false; this.isUnholy=false; this.isHoly=true; } } } here is the packet class it uses: package com.InnerPower.networking; import com.InnerPower.spells.holySpellList; import com.InnerPower.spells.mageSpellList; import com.InnerPower.spells.unholySpellList; import io.netty.buffer.ByteBuf; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.simpleimpl.IMessage; public class propsPacket implements IMessage { public int id1,id2,id3,id4,maxMana, currentMana; public boolean isMage, isHoly, isUnholy, iceTouch; mageSpellList m= new mageSpellList(); unholySpellList n= new unholySpellList(); holySpellList p=new holySpellList(); public int[] mageIDs =new int[m.listOfSpells.length]; public int[] necroIDs =new int[n.listOfSpells.length]; public int[] holyIDs =new int[p.listOfSpells.length]; public propsPacket() { } public propsPacket(int maxM, int curM, int idA,int idB, int idC, int idD, boolean mage, boolean nec, boolean pal, boolean ice, int[] mID, int[] nID, int[] hID) { //mana amount this.maxMana=maxM; this.currentMana=curM; //active spell id's this.id1=idA; this.id2=idB; this.id3=idC; this.id4=idD; //class booleans this.isMage=mage; this.isUnholy=nec; this.isHoly=pal; //spell booleans this.iceTouch=ice; //spell id's this.mageIDs=mID; this.necroIDs=nID; this.holyIDs=hID; } @Override public void fromBytes(ByteBuf buf) { buf.writeInt(this.maxMana); buf.writeInt(this.currentMana); buf.writeInt(id1); buf.writeInt(id2); buf.writeInt(id3); buf.writeInt(id4); buf.writeBoolean(this.isMage); buf.writeBoolean(this.isUnholy); buf.writeBoolean(this.isHoly); buf.writeBoolean(this.iceTouch); } @Override public void toBytes(ByteBuf buf) { this.maxMana=buf.readInt(); this.currentMana=buf.readInt(); this.id1=buf.readInt(); this.id2=buf.readInt(); this.id3=buf.readInt(); this.id4=buf.readInt(); //booleans this.isMage=buf.readBoolean(); this.isUnholy=buf.readBoolean(); this.isHoly=buf.readBoolean(); this.iceTouch=buf.readBoolean(); //arrays if needed } } and here's the packet handler: package com.InnerPower.networking; import io.netty.buffer.ByteBuf; import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; import net.minecraft.entity.player.EntityPlayer; import com.InnerPower.BaseClass; import com.InnerPower.magicPlayer; import com.InnerPower.spells.spell; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; public class propsPacketHandler implements IMessageHandler <propsPacket, IMessage> { @Override public IMessage onMessage(propsPacket message, MessageContext ctx) { handleExtendedProperties(message, ctx); return null; } private void handleExtendedProperties(propsPacket message, MessageContext ctx) { EntityPlayer player=BaseClass.proxy.getPlayerEntity(ctx); magicPlayer props = magicPlayer.get((EntityPlayer) player); int idNum; //sync mana props.setMaxMana(message.maxMana); props.setCurrentMana(message.currentMana); //sync spell List boolean hasLearned=false; for(int i=0; i<props.mageList.listOfSpells.length; i++) { idNum= message.mageIDs; hasLearned= props.mageList.checkIfSpellKnown(idNum); if(!hasLearned) { spell s= props.mageList.getSpellFromID(idNum); props.mageList.addSpellToList(s); } } for(int i=0; i<props.necroList.listOfSpells.length; i++) { idNum= message.necroIDs; hasLearned= props.necroList.checkIfSpellKnown(idNum); if(!hasLearned) { spell s= props.necroList.getSpellFromID(idNum); props.necroList.addSpellToList(s); } } for(int i=0; i<props.holyList.listOfSpells.length; i++) { idNum= message.holyIDs; hasLearned= props.holyList.checkIfSpellKnown(idNum); if(!hasLearned) { spell s= props.holyList.getSpellFromID(idNum); props.holyList.addSpellToList(s); } } //sync active IDs props.setActiveSpellID(message.id1, 1); props.setActiveSpellID(message.id2, 2); props.setActiveSpellID(message.id3, 3); props.setActiveSpellID(message.id4, 4); //sync isMage props.isMage= message.isMage; props.isUnholy= message.isUnholy; props.isHoly=message.isHoly; props.necroList.iceTouch= message.iceTouch; } } error report: ---- Minecraft Crash Report ---- // Surprise! Haha. Well, this is awkward. Time: 3/14/15 1:19 PM Description: Ticking memory connection java.lang.NullPointerException: Ticking memory connection at com.InnerPower.magicPlayer.<init>(magicPlayer.java:57) at com.InnerPower.magicPlayer.register(magicPlayer.java:112) at com.InnerPower.manaHandler.onEntityConstructing(manaHandler.java:38) at cpw.mods.fml.common.eventhandler.ASMEventHandler_6_manaHandler_onEntityConstructing_EntityConstructing.invoke(.dynamic) at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:51) at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:122) at net.minecraft.entity.Entity.<init>(Entity.java:250) at net.minecraft.entity.EntityLivingBase.<init>(EntityLivingBase.java:167) at net.minecraft.entity.player.EntityPlayer.<init>(EntityPlayer.java:179) at net.minecraft.entity.player.EntityPlayerMP.<init>(EntityPlayerMP.java:162) at net.minecraft.server.management.ServerConfigurationManager.createPlayerForUser(ServerConfigurationManager.java:434) at net.minecraft.server.network.NetHandlerLoginServer.func_147326_c(NetHandlerLoginServer.java:105) at net.minecraft.server.network.NetHandlerLoginServer.onNetworkTick(NetHandlerLoginServer.java:64) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:250) at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:736) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:624) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:495) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at com.InnerPower.magicPlayer.<init>(magicPlayer.java:57) at com.InnerPower.magicPlayer.register(magicPlayer.java:112) at com.InnerPower.manaHandler.onEntityConstructing(manaHandler.java:38) at cpw.mods.fml.common.eventhandler.ASMEventHandler_6_manaHandler_onEntityConstructing_EntityConstructing.invoke(.dynamic) at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:51) at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:122) at net.minecraft.entity.Entity.<init>(Entity.java:250) at net.minecraft.entity.EntityLivingBase.<init>(EntityLivingBase.java:167) at net.minecraft.entity.player.EntityPlayer.<init>(EntityPlayer.java:179) at net.minecraft.entity.player.EntityPlayerMP.<init>(EntityPlayerMP.java:162) at net.minecraft.server.management.ServerConfigurationManager.createPlayerForUser(ServerConfigurationManager.java:434) at net.minecraft.server.network.NetHandlerLoginServer.func_147326_c(NetHandlerLoginServer.java:105) at net.minecraft.server.network.NetHandlerLoginServer.onNetworkTick(NetHandlerLoginServer.java:64) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:250) -- Ticking connection -- Details: Connection: net.minecraft.network.NetworkManager@6c38d55c Stacktrace: at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:736) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:624) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:495) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762) -- System Details -- Details: Minecraft Version: 1.7.10 Operating System: Windows 7 (amd64) version 6.1 Java Version: 1.7.0_45, Oracle Corporation Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 835509664 bytes (796 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used IntCache: cache: 15, tcache: 0, allocated: 13, tallocated: 95 FML: MCP v9.05 FML v7.10.18.1180 Minecraft Forge 10.13.0.1180 4 mods loaded, 4 mods active mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available FML{7.10.18.1180} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.0.1180.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Forge{10.13.0.1180} [Minecraft Forge] (forgeSrc-1.7.10-10.13.0.1180.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available AthInrPwr{Alpha 1.0.3} [inner Power] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Profiler Position: N/A (disabled) Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Player Count: 0 / 8; [] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge' #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2015-03-14_13.19.53-server.txt [13:19:53] [Client thread/INFO] [FML]: Waiting for the server to terminate/save. [13:19:53] [server thread/INFO]: Saving chunks for level '1'/Nether [13:19:53] [server thread/INFO]: Saving chunks for level '1'/The End [13:19:54] [server thread/INFO] [FML]: Unloading dimension 0 [13:19:54] [server thread/INFO] [FML]: Unloading dimension -1 [13:19:54] [server thread/INFO] [FML]: Unloading dimension 1 [13:19:54] [server thread/INFO] [FML]: Applying holder lookups [13:19:54] [server thread/INFO] [FML]: Holder lookups applied [13:19:54] [server thread/INFO] [FML]: The state engine was in incorrect state SERVER_STOPPING and forced into state SERVER_STOPPED. Errors may have been discarded. [13:19:54] [Client thread/INFO] [FML]: Server terminated. AL lib: (EE) alc_cleanup: 1 device not closed Thank you for any help you can give!
March 14, 201510 yr Hi The error has nothing to do with packet handling. public mageSpellList mageList; public unholySpellList necroList; public holySpellList holyList; //Stores id's to send via packets public int[] mageIDs =new int[mageList.listOfSpells.length]; // NPE here These links might help http://frequal.com/java/DebuggingNullPointerExceptions.html http://www.terryanderson.ca/debugging/run.html -TGG
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.