Jump to content

[SOLVED][1.7.10] A severe problem occurred during the spawning of an entity


Recommended Posts

Posted

Okay, I had my code working great -- in this case one entity can randomly spawn another entity. But then I made the mistake of doing a lot of code modifications without retesting this particular feature, now I checked it out and it is broken. I know I can go back to earlier code, but due to the extensiveness of my edits I'd like to see if I can just directly get some advise on what might be wrong.

 

Here is the error:

 

[14:59:51] [server thread/INFO] [sTDOUT]: [com.blogspot.jabelarminecraft.magicbeans.entities.EntityMysteriousStranger:<init>:58]: Extended constructor

[14:59:51] [server thread/INFO] [sTDOUT]: [com.blogspot.jabelarminecraft.magicbeans.utilities.Utilities:sendEntitySyncPacketToClient:218]: sendEntitySyncPacket from server

[14:59:51] [server thread/INFO] [sTDOUT]: [com.blogspot.jabelarminecraft.magicbeans.networking.MessageSyncEntityToClient:<init>:51]: SyncEntityToClient constructor

[14:59:51] [server thread/INFO] [sTDOUT]: [com.blogspot.jabelarminecraft.magicbeans.networking.MessageSyncEntityToClient:toBytes:69]: toBytes encoded

[14:59:51] [server thread/INFO] [sTDOUT]: [com.blogspot.jabelarminecraft.magicbeans.entities.EntityFamilyCow:onUpdate:113]: A mysterious stranger appears with Entity ID = 518 at -40.71654568693205, 64.0, 149.74317121505737

[14:59:51] [Client thread/INFO] [sTDOUT]: [com.blogspot.jabelarminecraft.magicbeans.entities.EntityMysteriousStranger:<init>:47]: Simple constructor

[14:59:51] [Client thread/ERROR] [FML]: A severe problem occurred during the spawning of an entity

java.lang.reflect.InvocationTargetException

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_11]

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_11]

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_11]

at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_11]

at cpw.mods.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:72) [EntitySpawnHandler.class:?]

at cpw.mods.fml.common.network.internal.EntitySpawnHandler.channelRead0(EntitySpawnHandler.java:34) [EntitySpawnHandler.class:?]

at cpw.mods.fml.common.network.internal.EntitySpawnHandler.channelRead0(EntitySpawnHandler.java:28) [EntitySpawnHandler.class:?]

at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) [simpleChannelInboundHandler.class:?]

at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]

at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?]

at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:?]

at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?]

at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?]

at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?]

at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?]

at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:317) [PlayerControllerMP.class:?]

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1682) [Minecraft.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028) [Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:951) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_11]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_11]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_11]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_11]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_11]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_11]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_11]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_11]

at GradleStart.bounce(GradleStart.java:107) [start/:?]

at GradleStart.startClient(GradleStart.java:100) [start/:?]

at GradleStart.main(GradleStart.java:65) [start/:?]

Caused by: java.lang.NullPointerException

at com.blogspot.jabelarminecraft.magicbeans.entities.EntityMysteriousStranger.initSyncDataCompound(EntityMysteriousStranger.java:218) ~[EntityMysteriousStranger.class:?]

at com.blogspot.jabelarminecraft.magicbeans.entities.EntityMysteriousStranger.<init>(EntityMysteriousStranger.java:49) ~[EntityMysteriousStranger.class:?]

... 36 more

 

 

Here is the code that tries to spawn the entity:

 

    @Override

    public void onUpdate()

    {

    super.onUpdate();

    if (getLeashed() && !worldObj.isRemote && !getHasSpawnedMysteriousStranger())

    {

    // chance mysterious stranger will appear

    if (!getHasSpawnedMysteriousStranger() && (rand.nextFloat() < (1.0F / (30 * 20))))

    {

        Entity entityLeashedTo = getLeashedToEntity();

        if (entityLeashedTo instanceof EntityPlayer)

        {

        EntityPlayer playerLeashedTo = (EntityPlayer) entityLeashedTo;

        Vec3 playerLookVector = playerLeashedTo.getLookVec();

            EntityMysteriousStranger entityToSpawn = new EntityMysteriousStranger(worldObj, this, playerLeashedTo);

                double spawnX = playerLeashedTo.posX+5*playerLookVector.xCoord;

                double spawnZ = playerLeashedTo.posZ+5*playerLookVector.zCoord;

                double spawnY = worldObj.getHeightValue((int)spawnX, (int)spawnZ);

               

                // check to ensure there is open area for stranger to spawn, not underground

                if (worldObj.canBlockSeeTheSky(MathHelper.floor_double(spawnX), MathHelper.floor_double(spawnY), MathHelper.floor_double(spawnZ)))

                {

                entityToSpawn.setLocationAndAngles(spawnX, spawnY, spawnZ,

                      MathHelper.wrapAngleTo180_float(rand.nextFloat()

                      * 360.0F), 0.0F);

                worldObj.spawnEntityInWorld(entityToSpawn);

                entityToSpawn.playLivingSound();

                setHasSpawnedMysteriousStranger(true);

        playerLeashedTo.addChatMessage(new ChatComponentText(Utilities.stringToRainbow("A mysterious stranger appears!")));

        // DEBUG

        System.out.println("A mysterious stranger appears with Entity ID = "+entityToSpawn.getEntityId()+" at "

              +entityToSpawn.posX+", "+entityToSpawn.posY+", "+entityToSpawn.posZ);

                }

        }

    }

    }

    }

 

 

 

The code runs, as you can see by the console statements I show in the error log.

 

Lastly, here is the constructor code for the entity I'm trying to spawn:

 

public class EntityMysteriousStranger extends EntityCreature implements IEntityMagicBeans

{

    private NBTTagCompound syncDataCompound = new NBTTagCompound();

    private EntityFamilyCow cowSummonedBy = null;

    private EntityPlayer thePlayer = null;

 

    public EntityMysteriousStranger(World parWorld)

    {

    super(parWorld);

   

    // DEBUG

    System.out.println("Simple constructor");

   

    initSyncDataCompound();

    setupAI();

    }

   

public EntityMysteriousStranger(World parWorld, EntityFamilyCow parCowSummonedBy, EntityPlayer parPlayer)

{

super(parWorld);

 

// DEBUG

System.out.println("Extended constructor");

 

cowSummonedBy = parCowSummonedBy;

thePlayer = parPlayer;

 

initSyncDataCompound();

setupAI();

}

 

 

 

You can see that my EntityMysteriousStranger constructor call happens on the server (console says "extended constructor").

 

The sync messages after that are for the entity that is trying to spawn the entity (it is supposed to set flag indicating that it has spawned, to prevent it from spawning in future).

 

the EntityMysteriousStranger seems to have had an ID assigned and position set correctly.

 

Then the client calls the simple constructor (the one that only take World parameter), and then it crashes.

 

I thought it might be due to the registry, but I have plenty of other entities working in the mod. But in case it matters, my entity registration code looks like:

 

            EntityRegistry.registerModEntity(EntityMysteriousStranger.class, "mysterious_stranger", ++modEntityID, MagicBeans.instance, 80, 3, false);

 

 

 

Any ideas of what is causing that crash?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Hmmm, that's weird... the error message changed a bit. It previously was just complaining about the <init> which didn't give me much to go on.

 

Okay, the null pointer exception is fairly obvious -- the entity is supposed to remember the entity that summoned it and I'm referencing that when it is null. But I need some advice on how to prevent that.

 

In my "extended constructor" which I use when spawning the entity on the server side, I pass the summoning entity into the constructor. But it seems that the client calls the "simple constructor" -- which only sets this to null.

 

What is best way to pass this extra data so that when client gets instruction to create the entity it also gets this extra data? I'm guessing I should use the additional spawn data interface?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.