Posted April 11, 20205 yr I've been having issues with trying to get the DifficultyInstance in the event's position in the world during EntityJoinWorldEvent. I've recreated the method getDifficultyForLocation below and started debugging it by using it my event handler instead of the original method: public DifficultyInstance getDifficultyAtPosition(World world, BlockPos pos) { long inhabitedTime = 0L; float moonPhaseFactor = 0.0F; HardSteel.logger.info("Inhabited Time is " + inhabitedTime); HardSteel.logger.info("Current Moon Phase Factor is " + moonPhaseFactor); if (world.isBlockLoaded(pos)) { HardSteel.logger.info("Inside isBlockLoaded check"); moonPhaseFactor = world.getCurrentMoonPhaseFactor(); HardSteel.logger.info("Current Moon Phase Factor is " + moonPhaseFactor); // world.getChunkAt(pos) // returns this.getChunk(pos.getX() >> 4, pos.getZ() >> 4); // which means it gets the chunk at (X / 2^4), (Z / 2^4) Chunk chunk = world.getChunkAt(pos); inhabitedTime = chunk.getInhabitedTime(); HardSteel.logger.info("Inhabited Time is " + inhabitedTime); } HardSteel.logger.info("Done with isBlockLoaded check"); HardSteel.logger.info("Inhabited Time is " + inhabitedTime); HardSteel.logger.info("Current Moon Phase Factor is " + moonPhaseFactor); return new DifficultyInstance(world.getDifficulty(), world.getDayTime(), inhabitedTime, moonPhaseFactor); } I notice that when opening an old world - meaning, a world that was created before I started ever handling EntityJoinWorldEvent - I can't get past "Chunk chunk = world.getChunkAt(pos)" during world load, causing the world loading process to never finish even though it says "100%" on the screen. Is there a work around I can use, or someway I can account for not being able to get the chunk? I do notice that isBlockLoaded is a deprecated method, but I don't know how to replace it if it's necessary. Edited April 11, 20205 yr by the_infamous_1
April 11, 20205 yr Author I want to (re-)arm mobs with my modded armors and weapons instead of vanilla armors and weapons. I'm attempting to achieve this by recreating almost exactly how vanilla arms mobs, by using difficulty instances. I can do this just fine by using LivingEntitySpawn.SpecialSpawn (which also works for old worlds), but then I cannot get the Nether mobs (zombie pigmen and wither skeleton) to naturally spawn with modded stuff, so I am forced to use EntityJoinWorldEvent instead.
April 11, 20205 yr Author I created a new world just now using LivingSpawnEvent.SpecialSpawn handling instead of EntityJoinWorldEvent. I went into the Nether, and every single Zombie Pigman and Wither Skeleton spawned with the vanilla swords instead of modded ones. The only time they ever spawn with modded swords are when they are spawned with a spawn egg and when they teleport to the Overworld via Nether Portal. Overworld mobs do spawn naturally with modded stuff. Edited April 11, 20205 yr by the_infamous_1
April 12, 20205 yr Author Okay, found a workaround! (I think) public DifficultyInstance getDifficultyAtPosition(World world, BlockPos pos) { long inhabitedTime = 0L; float moonPhaseFactor = 0.0F; //HardSteel.logger.info("Inhabited Time is " + inhabitedTime); //HardSteel.logger.info("Current Moon Phase Factor is " + moonPhaseFactor); if (world.isBlockLoaded(pos)) { //HardSteel.logger.info("Inside isBlockLoaded check"); moonPhaseFactor = world.getCurrentMoonPhaseFactor(); //HardSteel.logger.info("Current Moon Phase Factor is " + moonPhaseFactor); // world.getChunkAt(pos) // returns this.getChunk(pos.getX() >> 4, pos.getZ() >> 4); // which means it gets the chunk at (X / 2^4), (Z / 2^4) if(world.getChunkProvider().chunkExists(pos.getX() >> 4, pos.getZ() >> 4)){ HardSteel.logger.info("Chunk Exists"); Chunk chunk = world.getChunkAt(pos); inhabitedTime = chunk.getInhabitedTime(); //HardSteel.logger.info("Inhabited Time is " + inhabitedTime); } } //HardSteel.logger.info("Done with isBlockLoaded check"); //HardSteel.logger.info("Inhabited Time is " + inhabitedTime); //HardSteel.logger.info("Current Moon Phase Factor is " + moonPhaseFactor); return new DifficultyInstance(world.getDifficulty(), world.getDayTime(), inhabitedTime, moonPhaseFactor); } As long as I check for the chunk actually existing at the position before I try to get it, everything works fine and I don't get caught in that infinite loop I would get caught in previously.
April 12, 20205 yr 15 hours ago, diesieben07 said: Why is this? I am not sure what made you come to this conclusion. WorldEntitySpawner::func_226701_a_(still not renamed in the latest mappings) posts the event, but afterwards calls MobEntity::onInitialSpawn which is where Mobs give themselves equipment. I do believe the infamous's idea is to prevent them from having the default equipment. Especially Wither Skeletons and Zombie Pigmen. Edited April 12, 20205 yr by Animefan8888 VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
April 12, 20205 yr Author That's correct. I do try to check to see if the mob was already armed by the vanilla onInitialSpawn function and then re-arm them, but I don't know if that's actually working because I can still get mobs spawning in with vanilla equipment. I imagine I can just run an additional check to see if the mob currently has vanilla armor/weapons, and then run them through the re-arming process an additional time, but that seems wasteful. Edited April 12, 20205 yr by the_infamous_1
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.