Jump to content

Recommended Posts

Posted

Hi All,

 

I'm working on a stupid mod about my cousin and I decided to add grenades to it (called brianades). The problem is, when I throw grenades and they land on an Entity the game crashes, if they land on a block there's an explosions and nearby entities take damage, but if the grenade touches an entity there is a crash.

 

Here is my EntityBrianade.java. You can tell I clumsily based it on the snowball.

package org.educraft.brianface.entityclasses;

import net.minecraft.block.BlockAir;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.datafix.walkers.BlockEntityTag;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class EntityBrianade extends EntityThrowable
{
    private EntityLivingBase throwerIn;
    private int throwerId;


    public EntityBrianade(World worldIn)
    {
        super(worldIn);
    }

    public EntityBrianade(World worldIn, EntityLivingBase throwerIn)
    {
        super(worldIn, throwerIn);
    }

    public EntityBrianade(World worldIn, double x, double y, double z)
    {
        super(worldIn, x, y, z);
    }

    public static void registerFixesBrianade(DataFixer fixer)
    {
        EntityThrowable.registerFixesThrowable(fixer, "Brianade");
    }

    @SideOnly(Side.CLIENT)
    public void handleStatusUpdate(byte id)
    {
        if (id == 3)
        {
            for (int i = 0; i < 8; ++i)
            {
                this.world.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, this.posX, this.posY, this.posZ, 1.0D, 1.0D, 1.0D, new int[0]);
            }
        }
    }

    /**
     * Called when this EntityThrowable hits a block or entity.
     */
    protected void onImpact(RayTraceResult result)
    {
        Entity entity = result.entityHit;

        if (!(result.getBlockPos().getClass().equals(BlockAir.class)))
        {
            world.createExplosion(throwerIn, result.hitVec.xCoord, result.hitVec.yCoord, result.hitVec.zCoord, 8F, true);
        }

        if (!this.world.isRemote)
        {
            this.world.setEntityState(this, (byte)3);
            this.setDead();
        }
    }
}

 

Here is the crash report. I know it's something about the onImpact() method but I can't figure it out.

 

A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Client thread
Stacktrace:
	at org.educraft.brianface.entityclasses.EntityBrianade.onImpact(EntityBrianade.java:63)
	at net.minecraft.entity.projectile.EntityThrowable.onUpdate(EntityThrowable.java:266)
	at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2108)
	at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:875)
	at net.minecraft.world.World.updateEntity(World.java:2075)

-- Entity being ticked --
Details:
	Entity Type: null (org.educraft.brianface.entityclasses.EntityBrianade)
	Entity ID: 2586
	Entity Name: unknown
	Entity's Exact location: -39.78, 65.70, 294.14
	Entity's Block location: World: (-40,65,294), Chunk: (at 8,4,6 in -3,18; contains blocks -48,0,288 to -33,255,303), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
	Entity's Momentum: -0.12, -0.77, -1.29
	Entity's Passengers: []
	Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
	at net.minecraft.world.World.updateEntities(World.java:1888)
	at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:647)

-- Affected level --
Details:
	Level name: New World
	All players: 1 total; [EntityPlayerMP['Player180'/990, l='New World', x=-38.41, y=70.63, z=308.47]]
	Chunk stats: ServerChunkCache: 644 Drop: 0
	Level seed: 1001640285474528145
	Level generator: ID 00 - default, ver 1. Features enabled: true
	Level generator options: 
	Level spawn location: World: (16,64,256), Chunk: (at 0,4,0 in 1,16; contains blocks 16,0,256 to 31,255,271), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
	Level time: 8430 game time, 8430 day time
	Level dimension: 0
	Level storage version: 0x04ABD - Anvil
	Level weather: Rain time: 31904 (now: false), thunder time: 44972 (now: false)
	Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
Stacktrace:
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:794)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547)
	at java.lang.Thread.run(Thread.java:745)

-- System Details --
Details:
	Minecraft Version: 1.11.2
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 1.8.0_91, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 976158360 bytes (930 MB) / 1883766784 bytes (1796 MB) up to 3806855168 bytes (3630 MB)
	JVM Flags: 0 total; 
	IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94
	FML: MCP 9.38 Powered by Forge 13.20.0.2228 5 mods loaded, 5 mods active
	States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
	UCHIJAAAA	minecraft{1.11.2} [Minecraft] (minecraft.jar) 
	UCHIJAAAA	mcp{9.19} [Minecraft Coder Pack] (minecraft.jar) 
	UCHIJAAAA	FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.11.2-13.20.0.2228.jar) 
	UCHIJAAAA	forge{13.20.0.2228} [Minecraft Forge] (forgeSrc-1.11.2-13.20.0.2228.jar) 
	UCHIJAAAA	brianface{1.0} [Brian Face] (brianmod_main) 
	Loaded coremods (and transformers): 
	GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
	Profiler Position: N/A (disabled)
	Player Count: 1 / 8; [EntityPlayerMP['Player180'/990, l='New World', x=-38.41, y=70.63, z=308.47]]
	Type: Integrated Server (map_client.txt)
	Is Modded: Definitely; Client brand changed to 'fml,forge'
[22:14:56] [Client thread/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:600]: #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2017-07-12_22.14.56-server.txt
[22:14:56] [Client thread/INFO] [FML]: Waiting for the server to terminate/save.
[22:14:56] [Server thread/INFO]: Saving worlds
[22:14:56] [Server thread/INFO]: Saving chunks for level 'New World'/Overworld
[22:14:56] [Server thread/INFO]: Saving chunks for level 'New World'/Nether
[22:14:56] [Server thread/INFO]: Saving chunks for level 'New World'/The End
[22:14:57] [Server thread/INFO] [FML]: Unloading dimension 0
[22:14:57] [Server thread/INFO] [FML]: Unloading dimension -1
[22:14:57] [Server thread/INFO] [FML]: Unloading dimension 1
[22:14:57] [Server thread/INFO] [FML]: Applying holder lookups
[22:14:57] [Server thread/INFO] [FML]: Holder lookups applied
[22:14:57] [Server thread/INFO] [FML]: The state engine was in incorrect state SERVER_STOPPING and forced into state SERVER_STOPPED. Errors may have been discarded.
[22:14:57] [Client thread/INFO] [FML]: Server terminated.
[22:14:57] [Client Shutdown Thread/INFO]: Stopping server
[22:14:57] [Client Shutdown Thread/INFO]: Saving players
AL lib: (EE) alc_cleanup: 1 device not closed

Process finished with exit code -1

 

Thanks for any help!

Posted

You didn't post the full crash report, you cut off the actual exception.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Oops! Here's the full stuff! Sorry.

 

[22:19:15] [Server thread/ERROR]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Ticking entity
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:800) ~[MinecraftServer.class:?]
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698) ~[MinecraftServer.class:?]
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) ~[IntegratedServer.class:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547) [MinecraftServer.class:?]
	at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91]
Caused by: java.lang.NullPointerException
	at org.educraft.brianface.entityclasses.EntityBrianade.onImpact(EntityBrianade.java:63) ~[EntityBrianade.class:?]
	at net.minecraft.entity.projectile.EntityThrowable.onUpdate(EntityThrowable.java:266) ~[EntityThrowable.class:?]
	at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2108) ~[World.class:?]
	at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:875) ~[WorldServer.class:?]
	at net.minecraft.world.World.updateEntity(World.java:2075) ~[World.class:?]
	at net.minecraft.world.World.updateEntities(World.java:1888) ~[World.class:?]
	at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:647) ~[WorldServer.class:?]
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:794) ~[MinecraftServer.class:?]
	... 4 more
[22:19:16] [Server thread/ERROR]: This crash report has been saved to: C:\minecraftmodding\brianmod\run\.\crash-reports\crash-2017-07-12_22.19.15-server.txt
[22:19:16] [Server thread/INFO]: Stopping server
[22:19:16] [Server thread/INFO]: Saving players
[22:19:16] [Client thread/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:600]: ---- Minecraft Crash Report ----
// Don't be sad, have a hug! <3

Time: 7/12/17 10:19 PM
Description: Ticking entity

java.lang.NullPointerException: Ticking entity
	at org.educraft.brianface.entityclasses.EntityBrianade.onImpact(EntityBrianade.java:63)
	at net.minecraft.entity.projectile.EntityThrowable.onUpdate(EntityThrowable.java:266)
	at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2108)
	at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:875)
	at net.minecraft.world.World.updateEntity(World.java:2075)
	at net.minecraft.world.World.updateEntities(World.java:1888)
	at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:647)
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:794)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547)
	at java.lang.Thread.run(Thread.java:745)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Client thread
Stacktrace:
	at org.educraft.brianface.entityclasses.EntityBrianade.onImpact(EntityBrianade.java:63)
	at net.minecraft.entity.projectile.EntityThrowable.onUpdate(EntityThrowable.java:266)
	at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2108)
	at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:875)
	at net.minecraft.world.World.updateEntity(World.java:2075)

-- Entity being ticked --
Details:
	Entity Type: null (org.educraft.brianface.entityclasses.EntityBrianade)
	Entity ID: 3117
	Entity Name: unknown
	Entity's Exact location: -34.44, 75.25, 320.67
	Entity's Block location: World: (-35,75,320), Chunk: (at 13,4,0 in -3,20; contains blocks -48,0,320 to -33,255,335), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
	Entity's Momentum: 1.04, -0.57, -0.86
	Entity's Passengers: []
	Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
	at net.minecraft.world.World.updateEntities(World.java:1888)
	at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:647)

-- Affected level --
Details:
	Level name: New World
	All players: 1 total; [EntityPlayerMP['Player48'/1185, l='New World', x=-44.15, y=77.75, z=328.60]]
	Chunk stats: ServerChunkCache: 644 Drop: 0
	Level seed: 1001640285474528145
	Level generator: ID 00 - default, ver 1. Features enabled: true
	Level generator options: 
	Level spawn location: World: (16,64,256), Chunk: (at 0,4,0 in 1,16; contains blocks 16,0,256 to 31,255,271), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
	Level time: 9126 game time, 9126 day time
	Level dimension: 0
	Level storage version: 0x04ABD - Anvil
	Level weather: Rain time: 31208 (now: false), thunder time: 44276 (now: false)
	Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
Stacktrace:
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:794)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:698)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:547)
	at java.lang.Thread.run(Thread.java:745)

-- System Details --
Details:
	Minecraft Version: 1.11.2
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 1.8.0_91, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 745188160 bytes (710 MB) / 1848639488 bytes (1763 MB) up to 3806855168 bytes (3630 MB)
	JVM Flags: 0 total; 
	IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94
	FML: MCP 9.38 Powered by Forge 13.20.0.2228 5 mods loaded, 5 mods active
	States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
	UCHIJAAAA	minecraft{1.11.2} [Minecraft] (minecraft.jar) 
	UCHIJAAAA	mcp{9.19} [Minecraft Coder Pack] (minecraft.jar) 
	UCHIJAAAA	FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.11.2-13.20.0.2228.jar) 
	UCHIJAAAA	forge{13.20.0.2228} [Minecraft Forge] (forgeSrc-1.11.2-13.20.0.2228.jar) 
	UCHIJAAAA	brianface{1.0} [Brian Face] (brianmod_main) 
	Loaded coremods (and transformers): 
	GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
	Profiler Position: N/A (disabled)
	Player Count: 1 / 8; [EntityPlayerMP['Player48'/1185, l='New World', x=-44.15, y=77.75, z=328.60]]
	Type: Integrated Server (map_client.txt)
	Is Modded: Definitely; Client brand changed to 'fml,forge'
[22:19:16] [Client thread/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:600]: #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2017-07-12_22.19.15-server.txt
[22:19:16] [Client thread/INFO] [FML]: Waiting for the server to terminate/save.
[22:19:16] [Server thread/INFO]: Saving worlds
[22:19:16] [Server thread/INFO]: Saving chunks for level 'New World'/Overworld
[22:19:16] [Server thread/INFO]: Saving chunks for level 'New World'/Nether
[22:19:16] [Server thread/INFO]: Saving chunks for level 'New World'/The End
[22:19:16] [Server thread/INFO] [FML]: Unloading dimension 0
[22:19:16] [Server thread/INFO] [FML]: Unloading dimension -1
[22:19:16] [Server thread/INFO] [FML]: Unloading dimension 1
[22:19:16] [Server thread/INFO] [FML]: Applying holder lookups
[22:19:16] [Server thread/INFO] [FML]: Holder lookups applied
[22:19:16] [Server thread/INFO] [FML]: The state engine was in incorrect state SERVER_STOPPING and forced into state SERVER_STOPPED. Errors may have been discarded.
[22:19:16] [Client thread/INFO] [FML]: Server terminated.
[22:19:16] [Client Shutdown Thread/INFO]: Stopping server
[22:19:16] [Client Shutdown Thread/INFO]: Saving players
AL lib: (EE) alc_cleanup: 1 device not closed

Process finished with exit code -1

 

Posted
1 minute ago, admiralmattbar said:

java.lang.NullPointerException: Ticking entity
    at org.educraft.brianface.entityclasses.EntityBrianade.onImpact(EntityBrianade.java:63)

 

Something was null on line 63 of EntityBrianade, most likely the return of RayTraceResult#getBlockPos.

 

RayTraceResult#getBlockPos will only return a non-null value when RayTraceResult#typeOfHit is RayTraceResult.Type.BLOCK (i.e. the raytrace hit a block).

 

Calling Object#getClass on a BlockPos will never return a Class that's equal to BlockAir.class, the two are incompatible types. Use World#getBlockState to get the IBlockState at the specified BlockPos, then use IBlockSate#getBlock to get the Block and Block#isAir to check if the block is air.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I was worried that the onImpact() method would call if the entity hit an air block. It doesn't seem like that's a problem and the conditional was unnecessary to begin with. This code no longer crashes.

 

package org.educraft.brianface.entityclasses;

import net.minecraft.block.BlockAir;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.datafix.walkers.BlockEntityTag;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class EntityBrianade extends EntityThrowable
{
    private EntityLivingBase throwerIn;
    private int throwerId;


    public EntityBrianade(World worldIn)
    {
        super(worldIn);
    }

    public EntityBrianade(World worldIn, EntityLivingBase throwerIn)
    {
        super(worldIn, throwerIn);
    }

    public EntityBrianade(World worldIn, double x, double y, double z)
    {
        super(worldIn, x, y, z);
    }

    public static void registerFixesBrianade(DataFixer fixer)
    {
        EntityThrowable.registerFixesThrowable(fixer, "Brianade");
    }

    @SideOnly(Side.CLIENT)
    public void handleStatusUpdate(byte id)
    {
        if (id == 3)
        {
            for (int i = 0; i < 8; ++i)
            {
                this.world.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, this.posX, this.posY, this.posZ, 1.0D, 1.0D, 1.0D, new int[0]);
            }
        }
    }

    /**
     * Called when this EntityThrowable hits a block or entity.
     */
    protected void onImpact(RayTraceResult result)
    {
        Entity entity = result.entityHit;
       
        world.createExplosion(throwerIn, result.hitVec.xCoord, result.hitVec.yCoord, result.hitVec.zCoord, 8F, true);
        

        if (!this.world.isRemote)
        {
            this.world.setEntityState(this, (byte)3);
            this.setDead();
        }
    }
}

 

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.