Jump to content

Code freezing server during world load, really cannot understand why


Mad Alchemist

Recommended Posts

I have added an option to replace all skeletons in overworld with zombies, but it may (exactly, MAY and not WILL) crash server during world load.
Here is a problemmatic piece of code:
 

/* This code is inside EntityJoinWorldEvent event handler */
/* Replace skeletons with zombies? */


        if (ConfigHandler.GENERAL.noSkeletons.get()) {
                //Zombienation.LOGGER.debug("Attempting to replace skeleton with zombie...");
                if (event.getEntity() instanceof SkeletonEntity || event.getEntity() instanceof StrayEntity) {
                    if (event.getEntity().level.dimension().location().toString().equals("minecraft:overworld")) {
                        /* Random zombie randomly turns into any other zombie from vanilla or my mod on spawn */
                        /* Zombie itself isn't a problem - I have tried vanilla zombies or even pigs */
                        RandomZombie zombie = new RandomZombie(ZombiesRegistry.RANDOM_ZOMBIE.get(), event.getEntity().level);
                        zombie.setPos(event.getEntity().getX(), event.getEntity().getY(), event.getEntity().getZ());
                        event.getEntity().level.addFreshEntity(zombie); //Server freezes at this line
                        /* Line below is never reached if server freezes, so it can't be an issue? */
                        event.setCanceled(true);
                        //Zombienation.LOGGER.debug("Done!");
                    }
                }
        }

 

Edited by Mad Alchemist
Fixed a typo in code piece
Link to comment
Share on other sites

23 hours ago, diesieben07 said:

This should really check the entity type instead, not the class.

Leaving it "as is", it will also replace everything that extends SkeletonEntity or StrayEntity classes?
Not sure if I want it... It may be desired behavior if some mod adds skeletons by extending vanilla ones...

And thanks for help, I probably would never find out it myself...

 

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.

Announcements



×
×
  • Create New...

Important Information

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