
Luminaire
Members-
Posts
26 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
Luminaire's Achievements

Tree Puncher (2/8)
0
Reputation
-
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.
-
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.
-
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.
-
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.
-
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); } } } } }
-
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.
-
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 ); } } }
-
[1.15.2] world.getEntitiesWithinAABB locks world generation
Luminaire replied to Luminaire's topic in Modder Support
Do you know how I find out if it's during chunk generation? I tried event.getWorld().chunkExists(), but it always returns true -
[1.15.2] world.getEntitiesWithinAABB locks world generation
Luminaire replied to Luminaire's topic in Modder Support
I'll just got with what's suggested, and wait until after world generation to have the spawns replaced. -
[1.15.2] world.getEntitiesWithinAABB locks world generation
Luminaire replied to Luminaire's topic in Modder Support
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? -
[1.15.2] world.getEntitiesWithinAABB locks world generation
Luminaire replied to Luminaire's topic in Modder Support
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()); } } -
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; } }
-
[1.15.2] Create an animal entity from string name
Luminaire replied to Luminaire's topic in Modder Support
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 -
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.
-
Where the initial WorldEntitySpawner is initialized
Luminaire replied to Luminaire's topic in Modder Support
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.