Jump to content

esgeroth

Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by esgeroth

  1. Thank you, adding this keeps the game from crashing on start up. StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); for( StackTraceElement element : stackTrace ) { if( element.toString().contains("loadEntities") ) { return; } }
  2. Thanks for looking into this. I would prefer that already existing spiders were not replaced so I will give that a try.
  3. I have created a custom spider mob that has a small percent chance to replace a normal spider when one is spawned. To do this I have subscribed to the EntityJoinWorldEvent. I check that the event is going to spawn a spider, then cancel the event and spawn my own spider instead. Like this: @SubscribeEvent public void onEntityJoinWorld( EntityJoinWorldEvent event ) { World world = event.world; Entity entity = event.entity; if( entity instanceof EntitySpider && Math.random() < 0.25 ) { event.setCanceled( true ); if( !world.isRemote ) { EntityBigSpider bigSpider = new EntityBigSpider( world ); bigSpider.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, 0.0F, 0.0F); world.spawnEntityInWorld( bigSpider ); } } } So far this works fine, my spiders are spawned as expected. The problem comes when I close the game and start it back up. When the game starts respawning all entities as the chunk is reloaded, the EntityJoinWorldEvent event is triggered and I get a ConcurrentModificationException crash. java.util.ConcurrentModificationException at java.util.HashMap$HashIterator.nextNode(Unknown Source) at java.util.HashMap$KeyIterator.next(Unknown Source) at com.google.common.collect.AbstractMapBasedMultimap$WrappedCollection$WrappedIterator.next(AbstractMapBasedMultimap.java:486) at net.minecraft.util.ClassInheritanceMultiMap$2.computeNext(Unknown Source) at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143) at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138) at net.minecraft.world.World.loadEntities(Unknown Source) at net.minecraft.world.chunk.Chunk.onChunkLoad(Unknown Source) at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(Unknown Source) at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(Unknown Source) at net.minecraftforge.common.util.AsynchronousExecutor.skipQueue(Unknown Source) at net.minecraftforge.common.util.AsynchronousExecutor.getSkipQueue(Unknown Source) at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(Unknown Source) at net.minecraft.world.gen.ChunkProviderServer.loadChunk(Unknown Source) at net.minecraft.world.gen.ChunkProviderServer.loadChunk(Unknown Source) at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(Unknown Source) at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(Unknown Source) at net.minecraft.server.integrated.IntegratedServer.startServer(Unknown Source) at net.minecraft.server.MinecraftServer.run(Unknown Source) at java.lang.Thread.run(Unknown Source) I need to find a way to prevent my code from running until the world has finished with its loadEntities method. Is there maybe some indicator I can check to make sure its safe to start spawning my own entities? Event better would be if I can test if an entity is being spawned for the first time and not being respawned as the chunk is being reloaded. Also, I tried to use the code button but it doesn't seem to do anything. Does it not work in chrome maybe?
  4. Thanks, I found the problem. Apparently if I don't use setLocationAndAngles to assign rotation angles as well as position, the server must think that the entity is invalid and deletes it. Also LivingSpawnEvent.CheckSpawn was not the right event to use as this is called constantly as the server searches for a valid spawn position. It worked but I ended up with a million bats on the screen. EntityJoinWorldEvent is fired only after a valid spawn point has been found and an entity is actually about to spawn there. After fixing my original problem and adding in suggestions above, here is my working code to spawn a custom mob in place of a vanilla mob: @SubscribeEvent public void onMobSpawnEvent( EntityJoinWorldEvent event ) { if( event.entity instanceof EntitySpider && Math.random() < 0.3 ) { event.setCanceled( true ); if( !event.world.isRemote ) { EntityBigSpider bigSpider = new EntityBigSpider( event.world ); bigSpider.setLocationAndAngles(event.entity.posX, event.entity.posY, event.entity.posZ, 0.0F, 0.0F); event.world.spawnEntityInWorld( bigSpider ); } } }
  5. I am trying to spawn a custom mob I made using spawnEntityInWorld. To do so I am using the LivingSpawnEvent.CheckSpawn event to detect when a certain mob is spawned and then replace it with my own. My mob is spawned but doesn't do anything and then disappears after a few seconds. The mob works fine when spawned with an egg. Just to make sure that my mob is not the problem I have tried spawning vanilla mobs instead with the same result. Here is the code I am using. @SubscribeEvent public void onMobSpawnEvent( LivingSpawnEvent.CheckSpawn event ) { if( EntityList.getEntityString( event.entity ) == "Spider" ) { if( !event.world.isRemote ) { EntityBat bat = new EntityBat( event.world ); bat.posX = event.entity.posX; bat.posY = event.entity.posY; bat.posZ = event.entity.posZ; event.world.spawnEntityInWorld( bat ); event.setResult( Result.DENY ); } } } Using this a bat is spawned in place of a spider. But the bat does not move and despawns after a few seconds.
×
×
  • Create New...

Important Information

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