Jump to content

Luminaire

Members
  • Posts

    26
  • Joined

  • Last visited

Everything posted by Luminaire

  1. My initial goal was to only allow farm animals (cows, chickens, pigs, sheep) near a village, and not allow them away from a village. I wanted the wilds to feel wild, and farm animals to only be near villages where it makes sense. This was supposed to go along with mods that add mobs so away from villages you'll find deer and wolves and bears, etc. Unfortunately the most important part of this (stopping farm animals from spawning away from villages) can't use the new jigsaw pieces unless I don't understand their use.
  2. Looked more into this, and tried tracing the code. It appears that the LivingSpawnEvent.CheckSpawn event cannot reliably get any information about the world around it, because during the time the chunk is loading if you attempt to do anything that affects the chunks (such as spawn a creature, or find a village) it will eventually lock up. The function ServerChunkProvider#getChunk uses multithreading and doesn't return. This apparently was introduced as part of the 1.14 update, because before that you could do those things (such as how animania replaces animal spawns with it's own animals). It appears that the entity spawning events became useless after 1.12 except for basic things. I'm not sure what the replacement option is that can let me stop mob spawns, or replace mob spawns during generation based on the world, but I'm back to the drawing board. Even if I could figure out in the CheckSpawn event when the chunks have loaded, most of the mobs the user would see would already be there. I wonder what the minecraft developers would do here, and whether they came up with some alternate method.
  3. Any thoughts on how I can figure out why entityWorld.findNearestStructure never returns? I'm really not sure what's going on. Such a simple in theory mod to make animals only spawn near villages that is turning out to be really hard.
  4. Once I have it actually working I will clean up the code. I shoved everything into one class as well for this example, but I'll break it up into better pieces that can be reused if/when I add more features to the mod.
  5. Here is the full code block for the event, that demonstrates all the functionality I am going for. If you run this and walk into the nearby town, all the mobs will stop moving at that one sheep. package com.luminairefarmanimals; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.gen.feature.Feature; import net.minecraft.world.server.ServerWorld; import net.minecraftforge.event.entity.living.LivingSpawnEvent; import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.eventbus.api.SubscribeEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.ArrayList; public class TestVillage { private static final Logger LOGGER = LogManager.getLogger(); @SubscribeEvent public void checkSpawns(LivingSpawnEvent.CheckSpawn event) { ArrayList<String> animals = new ArrayList<String>(); animals.add("minecraft:pig"); animals.add("minecraft:sheep"); animals.add("minecraft:cow"); animals.add("minecraft:chicken"); Entity entity = event.getEntity(); BlockPos pos = entity.getPosition(); LOGGER.info("Entity Type:" + entity.getEntityString() + " - at: " + pos.getX() + ":" + pos.getZ()+ ":" + pos.getY()); if (event.getWorld().isRemote()) { return; } if (!(entity instanceof LivingEntity)) { return; } if (entity instanceof AnimalEntity){ ServerWorld entityWorld = (ServerWorld) entity.getEntityWorld(); //The following will lock on one sheep after about 20 animals BlockPos block = entityWorld.findNearestStructure(Feature.VILLAGE.getStructureName(), pos, 70, false ); if (block != null){ if (!animals.contains(entity.getEntityString())){ event.setResult(Event.Result.DENY); } } else { if (animals.contains(entity.getEntityString())){ event.setResult(Event.Result.DENY); } } } } }
  6. My goal is to only allow certain animals to spawn when they are close to a village. That’s why I check each spawning entity to see if they are close to the village, and then deny any that aren’t close. The problem is for that sheep the findNearestStructure function just never returns, and all the entities just stop moving. I’m not sure why the function works fine for a bunch of animals, and then just never returns for one.
  7. The following is a sample event handler. One the following seed '45343', if you immediately walk towards the town in view from spawn, it will work for about 20 animals, and then always lock on one specific sheep, and all entities stop functioning forever. Any idea how to accomplish below without jamming the server? Thanks. public class TestVillage { @SubscribeEvent public void checkSpawns(LivingSpawnEvent.CheckSpawn event) { Entity entity = event.getEntity(); if (event.getWorld().isRemote()) { return; } if (!(entity instanceof LivingEntity)) { return; } if (entity instanceof AnimalEntity){ BlockPos pos = entity.getPosition(); ServerWorld entityWorld = (ServerWorld) entity.getEntityWorld(); //The following will lock on one sheep after about 20 animals BlockPos block = entityWorld.findNearestStructure(Feature.VILLAGE.getStructureName(), pos, 70, false ); } } }
  8. Do you know how I find out if it's during chunk generation? I tried event.getWorld().chunkExists(), but it always returns true
  9. I'll just got with what's suggested, and wait until after world generation to have the spawns replaced.
  10. Thanks, well that explains why it’s locking. Maybe there is some other way to accomplish what I want. I am trying to make a mod that makes it so farm animals (cows, sheep, pigs, and chickens) will only spawn near villages. I was worried that if there are other animal mods installed, if I just denied those spawns in the village radius farm animals would be extremely rare, so I was trying to replace any non farm animal spawn near villages with farm animals, even at world creation when larger numbers of passive spawns are created. The reason for the get in radius was so I could detect animal groups and replace them all with one type of animal. Is there possibly a way to detect when a spawn is part of a group of mobs? Or is there some other way to accomplish the spirit of what I’m trying to do, so that farm animals spawn in a good number near villages?
  11. It's definitely gets called. I removed them to make my snippet simpler, but I added a bunch of log statements to see where it was stopping, and this statement runs: AxisAlignedBB axis = new AxisAlignedBB(pos.getX() - range, pos.getY() - range, pos.getZ() - range, pos.getX() + range, pos.getY() + range, pos.getZ() + range); It stops right after that on the List<T> list = world.getEntitiesWithinAABB(filterEntity, axis); Here is my event subscriber, but I know it's running: public class EventSubscriber { @SubscribeEvent public void checkSpawns(LivingSpawnEvent.CheckSpawn event){ Entity entity = event.getEntity(); if (event.getWorld().isRemote()) { return; } if (!(entity instanceof LivingEntity)) { return; } if (entity instanceof AnimalEntity){ HandleAnimalSpawns handler = new HandleAnimalSpawns(); handler.handleSpawns(event); } } } and to complete my example: @Mod(FarmAnimals.MODID) public class FarmAnimals { private static final Logger LOGGER = LogManager.getLogger(); public static final String MODID = "luminairefarmanimals"; public FarmAnimals(){ MinecraftForge.EVENT_BUS.register(new EventSubscriber()); } }
  12. The following is a code snippet that is my attempt to get the list of entities around a spawning entity. I want to do this to find what animals are nearby, so I can replace the spawning entity with one of that type instead. Unfortunately as soon as I call it, the world generation stops completely at 16%. public class HandleAnimalSpawns { public void handleSpawns(LivingSpawnEvent.CheckSpawn event){ Entity entity = event.getEntity(); World world = event.getWorld().getWorld(); List<LivingEntity> entities = WorldHelper.getEntitiesInRange(LivingEntity.class, 10, world, entity.getPosition()); } public class WorldHelper { public static <T extends LivingEntity> List<T> getEntitiesInRange(Class<? extends T> filterEntity, int range, World world, BlockPos pos) { AxisAlignedBB axis = new AxisAlignedBB(pos.getX() - range, pos.getY() - range, pos.getZ() - range, pos.getX() + range, pos.getY() + range, pos.getZ() + range); List<T> list = world.getEntitiesWithinAABB(filterEntity, axis); //This log entry will never get called LOGGER.info("Got List"); return list; } }
  13. So something like this? EntityType entityType = EntityType.byKey("pig").get(); Entity replacementEntity = entityType.create(world); replacementEntity.setPosition(event.getX(), event.getY(), event.getZ()); I noticed the entity types don't have the minecraft: part of the name, however entity.getEntityString() would come back as 'minecraft:pig'. Am I missing something? Will modded animals have the mod: part of the name? Thanks
  14. I am trying to create an animal entity during a spawn event from the animal name (such as 'minecraft:pig'), however I am having a hard time finding a method to do so. I want to use the name strings so I can support config files and modded animals, although I am open any method to achieve the same goal. Any idea how I can accomplish this? Thanks.
  15. I looked into the patrols. I can't use the exact logic they use because they made the patrol grouping as part of the base class of the pillagers, but I can create my own spawner similar to the patrols pretty easily on world tick, and I found another mod that groups mobs together, and I can use a variation of the concept they use to manage the patrols, and I just have to insert my own AI similar to the patrol to handle the pathing.
  16. Thanks I'll take a look at those. That's exactly what I was looking for. I am going to make a mod that adds some variety to the spawns in minecraft, so zombies will more often spawn with some form of armor, or items in their hands, or riding horses for example. I plan to add lots of variety of minor changes to spawns that are not necessarily harder, but just different. I also plan to have those varieties sometimes drop different items on player kill, so for example a zombie with a pickaxe might drop an iron ore with a low chance. I also intend to expand the concept of patrols that the pillagers use and create zombie or skeleton patrols.
  17. Thanks. I think I defeated myself here by asking the wrong questions. I was trying to figure out how to create some of the custom mobs that are rarely created, such as skeleton's or zombies riding horses, or charged creepers, or baby zombies riding chickens. I figured the spawn rules would answer that, but it just defines the chances for the general mob to spawn and how many. Any idea how I can do that?
  18. In that function is this line: List<SpawnListEntry> list = biomeIn.getSpawns(EntityClassification.CREATURE); I'm trying to figure out where that list is defined (ie what mobs spawn where, and with what chances)
  19. Is there an easy way to tell if an entity can see the sky? Thanks.
  20. Do you know where the minecraft code initial WorldEntitySpawner is defined? I want to see how they set up the initial spawn chances of the Zombie, Baby Zombie, and the Chicken Baby Zombie, among other things. Thanks.
  21. I am familiar with java, and understand the code for creating a new mob, but I'm trying to figure out what are the best tools for creating the look of a new mob. I want to do the modeling, animation, and textures, and my googling did not provide a lot of good information. What tools do you recommend for those, and is there any updated tutorials somewhere on using them? Thanks.
  22. When spawning a mob, I'd like to determine the distance to the nearest town. Any idea how that can be accomplished? Thanks
  23. I'd like to know the answer to this question, because I am thinking of replacing a block on generation of normal trees as a possible mod.
×
×
  • Create New...

Important Information

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