Jump to content

Minecraft Server/Client Crashes Upon Great-Great-Grandfather Class Exception (MC Version 1.12.2)


StarMiner

Recommended Posts

Hey all,

 

I've been working on making it so a Giant will track a player from 200 blocks away, but since the game will lag if the giant has a range of even 100+ blocks, I decided to create a vector class and scale it by 18 blocks (does this every 5 seconds) so the Giant will go towards the player until the player is 20 blocks close. The problem is that there is an exception happening within Minecraft's class "Path", causing the game to crash everytime it has an ArrayIndexOutOfBounds error. I don't care much for the error happening, I would just like to surround a try/catch method around it so in the rare case it happens again, it won't make the Giant track the player for that instance and continue on afterwards. The problem is that the Path class is only readable. I've put try/catch methods everywhere in my code and it still doesn't seem to work. Please note that the mod runs perfectly fine for the first bit with everything intended as it should be. However, this exception happens randomly, and I believe it is due to one part of the game updating too fast and one part too slow, causing an array to go out of bounds.

Here is the crash log:

 

---- Minecraft Crash Report ----
// My bad.

Time: 3/19/23 10:37 PM
Description: Ticking entity

java.lang.ArrayIndexOutOfBoundsException: 17
    at net.minecraft.pathfinding.Path.func_75881_a(SourceFile:63)
    at net.minecraft.pathfinding.PathNavigate.func_75508_h(SourceFile:254)
    at net.minecraft.pathfinding.PathNavigate.func_75501_e(SourceFile:188)
    at net.minecraft.entity.EntityLiving.func_70626_be(EntityLiving.java:766)
    at net.minecraft.entity.EntityLivingBase.func_70636_d(EntityLivingBase.java:2359)
    at net.minecraft.entity.EntityLiving.func_70636_d(EntityLiving.java:577)
    at net.minecraft.entity.monster.EntityMob.func_70636_d(EntityMob.java:45)
    at net.minecraft.entity.EntityLivingBase.func_70071_h_(EntityLivingBase.java:2179)
    at net.minecraft.entity.EntityLiving.func_70071_h_(EntityLiving.java:295)
    at net.minecraft.entity.monster.EntityMob.func_70071_h_(EntityMob.java:50)
    at net.minecraft.world.World.func_72866_a(World.java:1996)
    at net.minecraft.world.WorldServer.func_72866_a(WorldServer.java:832)
    at net.minecraft.world.World.func_72870_g(World.java:1958)
    at net.minecraft.world.World.func_72939_s(World.java:1762)
    at net.minecraft.world.WorldServer.func_72939_s(WorldServer.java:613)
    at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:767)
    at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:397)
    at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:668)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526)
    at java.lang.Thread.run(Thread.java:750)


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

-- Head --
Thread: Server thread
Stacktrace:
    at net.minecraft.pathfinding.Path.func_75881_a(SourceFile:63)
    at net.minecraft.pathfinding.PathNavigate.func_75508_h(SourceFile:254)
    at net.minecraft.pathfinding.PathNavigate.func_75501_e(SourceFile:188)
    at net.minecraft.entity.EntityLiving.func_70626_be(EntityLiving.java:766)
    at net.minecraft.entity.EntityLivingBase.func_70636_d(EntityLivingBase.java:2359)
    at net.minecraft.entity.EntityLiving.func_70636_d(EntityLiving.java:577)
    at net.minecraft.entity.monster.EntityMob.func_70636_d(EntityMob.java:45)
    at net.minecraft.entity.EntityLivingBase.func_70071_h_(EntityLivingBase.java:2179)
    at net.minecraft.entity.EntityLiving.func_70071_h_(EntityLiving.java:295)
    at net.minecraft.entity.monster.EntityMob.func_70071_h_(EntityMob.java:50)
    at net.minecraft.world.World.func_72866_a(World.java:1996)
    at net.minecraft.world.WorldServer.func_72866_a(WorldServer.java:832)
    at net.minecraft.world.World.func_72870_g(World.java:1958)

-- Entity being ticked --
Details:
    Entity Type: pd:giant_zombie (com.example.ProgressiveDifficulty.Giant.GiantZombie)
    Entity ID: 2778
    Entity Name: Giant
    Entity's Exact location: 35.77, 70.00, 180.68
    Entity's Block location: World: (35,70,180), Chunk: (at 3,4,4 in 2,11; contains blocks 32,0,176 to 47,255,191), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Entity's Momentum: -0.09, -0.08, 0.07
    Entity's Passengers: []
    Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
    at net.minecraft.world.World.func_72939_s(World.java:1762)
    at net.minecraft.world.WorldServer.func_72939_s(WorldServer.java:613)

-- Affected level --
Details:
    Level name: world
    All players: 1 total; [EntityPlayerMP['StarMiner'/2879, l='world', x=11.71, y=68.04, z=180.30]]
    Chunk stats: ServerChunkCache: 473 Drop: 0
    Level seed: -3001969648584247901
    Level generator: ID 00 - default, ver 1. Features enabled: true
    Level generator options: 
    Level spawn location: World: (-4,64,248), Chunk: (at 12,4,8 in -1,15; contains blocks -16,0,240 to -1,255,255), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
    Level time: 22777 game time, 22777 day time
    Level dimension: 0
    Level storage version: 0x04ABD - Anvil
    Level weather: Rain time: 93849 (now: false), thunder time: 12801 (now: false)
    Level game mode: Game mode: survival (ID 0). Hardcore: false. Cheats: false
Stacktrace:
    at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:767)
    at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:397)
    at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:668)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526)
    at java.lang.Thread.run(Thread.java:750)

-- System Details --
Details:
    Minecraft Version: 1.12.2
    Operating System: Linux (amd64) version 4.19-ovh-xxxx-std-ipv6-64
    Java Version: 1.8.0_333, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 3471014528 bytes (3310 MB) / 4294967296 bytes (4096 MB) up to 4294967296 bytes (4096 MB)
    JVM Flags: 20 total; -Xmx4096M -Xms4096M -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1
    IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94
    FML: MCP 9.42 Powered by Forge 14.23.5.2860 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

    | State  | ID        | Version      | Source           | Signature                                |
    |:------ |:--------- |:------------ |:---------------- |:---------------------------------------- |
    | LCHIJA | minecraft | 1.12.2       | minecraft.jar    | None                                     |
    | LCHIJA | mcp       | 9.42         | minecraft.jar    | None                                     |
    | LCHIJA | FML       | 8.0.99.99    | forge-1.12.2.jar | e3c3d50c7c986df74c645c0ac54639741c90a557 |
    | LCHIJA | forge     | 14.23.5.2860 | forge-1.12.2.jar | e3c3d50c7c986df74c645c0ac54639741c90a557 |
    | LCHIJA | pd        | 0.0.1-1.12   | modid-1.0.jar    | None                                     |

    Loaded coremods (and transformers): 
    Profiler Position: N/A (disabled)
    Player Count: 1 / 48; [EntityPlayerMP['StarMiner'/2879, l='world', x=11.71, y=68.04, z=180.30]]
    Is Modded: Definitely; Server brand changed to 'fml,forge'
    Type: Dedicated Server (map_server.txt)



And below here is my code:
 

package com.example.ProgressiveDifficulty.Giant;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.monster.EntityGiantZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;

import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class GiantZombie extends EntityGiantZombie {
    private ScheduledExecutorService executor;
    private ScheduledExecutorService executorInit;

    private EntityPlayerMP player;

    public GiantZombie(World world) {
        super(world);
        if (!world.isRemote) {
            try {
                this.setSize(1.95F, 6.0F);
                executor = Executors.newSingleThreadScheduledExecutor();
                executor.scheduleAtFixedRate(this::doUpdate, 2500, 5000, TimeUnit.MILLISECONDS);
                executorInit = Executors.newSingleThreadScheduledExecutor();
                executorInit.scheduleAtFixedRate(this::doUpdateInit, 1000, 1000, TimeUnit.MILLISECONDS);
                if(player != null){
                    player.sendMessage(new TextComponentString("GiantZombie Spawned In!"));
                }
            }
            catch (Exception e) {
                String message = e.getMessage();
                if(player != null) {
                    player.sendMessage(new TextComponentString(message + "A"));
                }
                e.printStackTrace();
            }
        }
    }


    public void doUpdate() {
        try {
            EntityPlayerMP nearestPlayer = (EntityPlayerMP) world.getClosestPlayerToEntity(this, 1000);
            if (nearestPlayer != null) {
                if (!nearestPlayer.isDead) {
                    double distanceToPlayer = this.getDistanceSq(nearestPlayer);

                    if(distanceToPlayer >= 400) {
                        this.getLookHelper().setLookPositionWithEntity(nearestPlayer, 10.0F, 10.0F);

                        Vec3d vectorToPlayer = nearestPlayer.getPositionVector().subtract(this.getPositionVector()).normalize();
                        try {
                            BlockPos targetPos = new BlockPos(this.getPositionVector().add(vectorToPlayer.scale(15)));
                            if (world.isAreaLoaded(new BlockPos(targetPos.getX(), targetPos.getY(), targetPos.getZ()), 18)) {
                                this.getNavigator().tryMoveToXYZ(targetPos.getX(), targetPos.getY(), targetPos.getZ(), 1.0);

                            }
                            else{
                                if(nearestPlayer != null) {
                                    nearestPlayer.sendMessage(new TextComponentString("Not Loaded!" + "R"));
                                }
                            }
                        } catch (Exception e) {
                            String message = e.getMessage();
                            if (nearestPlayer != null) {


                                nearestPlayer.sendMessage(new TextComponentString(message + "R"));
                                nearestPlayer.sendMessage(new TextComponentString("Error Message Above"));
                            }
                            e.printStackTrace();
                        }
                    }
                }


            }
        }
        catch (Exception e) {
            String message = e.getMessage();
            if(player != null) {
                player.sendMessage(new TextComponentString(message + "B"));
            }
            e.printStackTrace();
        }
    }

    public void doUpdateInit() {
        try {
            EntityPlayerMP nearestPlayer = (EntityPlayerMP) world.getClosestPlayerToEntity(this, 1000);

            if(nearestPlayer != null) {
                double distanceToPlayer = this.getDistanceSq(nearestPlayer);
                if (distanceToPlayer < 400) { // 20 blocks squared
                    this.getLookHelper().setLookPositionWithEntity(nearestPlayer, 10.0F, 10.0F);

                    this.getNavigator().tryMoveToEntityLiving(nearestPlayer, 1.0);
                    this.attackEntity(nearestPlayer);
                }
            }
        }
        catch(Exception e) {
            String message = e.getMessage();
            if(player != null) {
                player.sendMessage(new TextComponentString(message + "H"));
            }
            e.printStackTrace();
        }
    }

    public void attackEntity(EntityPlayer player) {
        try {
            if(player != null) {
                if (this.getDistance(player) < 4F) {
                    player.attackEntityFrom(DamageSource.causeMobDamage(this), 10.0F);
                }
            }
        }
        catch (Exception e) {
            String message = e.getMessage();
            if(player != null) {
                player.sendMessage(new TextComponentString(message + "C"));
            }
            e.printStackTrace();
        }
    }
    @Override
    public void applyEntityAttributes() {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(100.0D);
        this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.2D);
        this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(50.0D);
        this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(19.0D);
    }

    @Override
    public String getName() {
        return "Giant";
    }


    @Override
    public boolean isChild() {
        return false;
    }

    @Override
    protected boolean canDespawn() {
        return false;
    }

    @Override
    public boolean getCanSpawnHere() {
        boolean flag = super.getCanSpawnHere() && this.world.checkNoEntityCollision(this.getEntityBoundingBox())
                && this.world.getCollisionBoxes(this, this.getEntityBoundingBox()).isEmpty()
                && !this.world.containsAnyLiquid(this.getEntityBoundingBox());
        if(player != null){
            player.sendMessage(new TextComponentString("CanSpawnHere: " + flag));
        }
        return flag;
    }

    @Override
    public boolean canBePushed() {
        return false;
    }

    @Override
    public boolean canBeCollidedWith() {
        return true;
    }
    @Override
    public void onRemovedFromWorld() {
        try {
            super.onRemovedFromWorld();
            executorInit.shutdownNow(); // Stop the scheduled task when the entity is removed
            executor.shutdownNow(); // Stop the scheduled task when the entity is removed
            if(player != null) {
                player.sendMessage(new TextComponentString("Removed from world"));
            }

        }
        catch (Exception e) {
            String message = e.getMessage();
            if(player != null) {
                player.sendMessage(new TextComponentString(message + "D"));
            }
            e.printStackTrace();
        }
    }
}






The bolded part is where the problem occurs.

Any help is appreciated! Thanks

- StarMiner







 

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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