Jump to content

Niksilp

Members
  • Posts

    1
  • Joined

  • Last visited

Niksilp's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. I'm making a mod to add new cats but I'm having trouble figuring out how to get them to spawn naturally in villages similar to the vanilla cat. I found this post that seems to be exactly what I'm looking for, but "Feature.VILLAGE.isPositionInStructure" doesn't seem to be valid in 1.16.1. I've looked at CatSpawner.class and tried replicating that, and my mod builds and the game launches with no errors but my custom entities still aren't spawning as expected. I am able to manually spawn them with the summon command. I don't necessarily need my custom cat entity to spawn following the same rules as the vanilla cats -- just being able to specify their spawn weight and min/max group size would be fine, e.g. biome.getSpawns(EntityClassification.CREATURE).add(new Biome.SpawnListEntry(ModEntityType.NEW_CAT.get(), 100, 1, 3)); Here's what I have currently: package morecats.world.spawner; import java.util.List; import morecats.MoreCats; import morecats.entity.passive.NewCatEntity; import morecats.init.ModEntityType; import net.minecraft.entity.EntityClassification; import net.minecraft.entity.ILivingEntityData; import net.minecraft.entity.SpawnReason; import net.minecraft.entity.passive.CatEntity; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.village.PointOfInterestManager; import net.minecraft.village.PointOfInterestType; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(modid = MoreCats.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class ModEntitySpawns { @SubscribeEvent public int generateNewCats(WorldEvent.PotentialSpawns event) { if (event.getType() == EntityClassification.CREATURE) { if (((ServerWorld) event.getWorld()).func_241119_a_(event.getPos(), 2)) { return this.func_221121_a((ServerWorld) event.getWorld(), event.getPos()); } } return 0; } private int func_221121_a(ServerWorld worldIn, BlockPos p_221121_2_) { int i = 48; if (worldIn.getPointOfInterestManager().getCountInRange(PointOfInterestType.HOME.getPredicate(), p_221121_2_, 48, PointOfInterestManager.Status.IS_OCCUPIED) > 4L) { List<CatEntity> list = worldIn.getEntitiesWithinAABB(CatEntity.class, (new AxisAlignedBB(p_221121_2_)).grow(48.0D, 8.0D, 48.0D)); if (list.size() < 5) { return this.spawnNewCat(p_221121_2_, worldIn); } } return 0; } private int spawnNewCat(BlockPos pos, World worldIn) { NewCatEntity newcatentity = ModEntityType.NEW_CAT.get().create(worldIn); if (newcatentity == null) { return 0; } else { newcatentity.onInitialSpawn(worldIn, worldIn.getDifficultyForLocation(pos), SpawnReason.NATURAL, (ILivingEntityData)null, (CompoundNBT)null); newcatentity.moveToBlockPosAndAngles(pos, 0.0F, 0.0F); worldIn.addEntity(newcatentity); return 1; } } } I'm new to modding and also (re-)learning Java, so I've been through a few tutorials on creating new entities (this tutorial was particularly helpful), I've looked at the source code for other mods that seemed like they might do something similar to what I was looking for, and I feel like I've looked through the Forge classes pretty thoroughly, but I'm struggling to figure this one out. Any help is appreciated! Let me know if there's any additional code I should share.
×
×
  • Create New...

Important Information

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