From 05c2164bafa20b4165de585c73af745d3172ad13 Mon Sep 17 00:00:00 2001 From: "Luis C.M." <42545778+c0508383@users.noreply.github.com> Date: Mon, 5 Aug 2024 19:35:59 -0500 Subject: [PATCH] Added an entity field to the CNPC natural spawn event. --- src/main/java/noppes/npcs/NPCSpawning.java | 22 +++++++++---------- .../npcs/scripted/event/CustomNPCsEvent.java | 11 +++++++++- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/noppes/npcs/NPCSpawning.java b/src/main/java/noppes/npcs/NPCSpawning.java index f6e28878f..e95622242 100644 --- a/src/main/java/noppes/npcs/NPCSpawning.java +++ b/src/main/java/noppes/npcs/NPCSpawning.java @@ -82,12 +82,12 @@ public class NPCSpawning { SpawnData data = SpawnController.Instance.getRandomSpawnData(name, world.provider.dimensionId); if (data == null || !canCreatureTypeSpawnAtLocation(data, world, x, y, z) || world.getClosestPlayer(x, y, z, 24.0D) != null) continue; - + spawnData(data, world, x, y, z); } } } - + public static int countNPCs(World world){ int count = 0; List list = world.loadedEntityList; @@ -106,16 +106,16 @@ public class NPCSpawning { int i1 = world.rand.nextInt(chunk == null ? world.getActualHeight() : chunk.getTopFilledSegment() + 16 - 1); return new ChunkPosition(k, i1, l); } - + public static void performWorldGenSpawning(World world, int x, int z, Random rand){ BiomeGenBase biome = world.getBiomeGenForCoords(x + 8, z + 8); while (rand.nextFloat() < biome.getSpawningChance()){ SpawnData data = SpawnController.Instance.getRandomSpawnData(biome.biomeName, world.provider.dimensionId); if(data == null) continue; - + int size = 16; - + int j1 = x + rand.nextInt(size); int k1 = z + rand.nextInt(size); int l1 = j1; @@ -139,11 +139,11 @@ public class NPCSpawning { } else if(spawnData(data, world, j1, l2, k1)) break; - + } } } - + private static boolean spawnData(SpawnData data, World world, int x, int y, int z){ EntityLiving entityliving; @@ -177,7 +177,7 @@ public class NPCSpawning { } entityliving = (EntityLiving) spawnEntity; - + if(spawnEntity instanceof EntityCustomNpc){ EntityCustomNpc npc = (EntityCustomNpc) spawnEntity; npc.stats.spawnCycle = 3; @@ -198,14 +198,14 @@ public class NPCSpawning { if (canSpawn == Result.DENY || (canSpawn == Result.DEFAULT && !canEntitySpawn(data,entityliving))) return false; - CustomNPCsEvent.CNPCNaturalSpawnEvent event = new CustomNPCsEvent.CNPCNaturalSpawnEvent(data, NpcAPI.Instance().getIPos(new BlockPos(x,y,z)), NPCSpawning.animalSpawn, NPCSpawning.monsterSpawn, NPCSpawning.liquidSpawn, NPCSpawning.airSpawn); + CustomNPCsEvent.CNPCNaturalSpawnEvent event = new CustomNPCsEvent.CNPCNaturalSpawnEvent(entityliving, data, NpcAPI.Instance().getIPos(new BlockPos(x,y,z)), NPCSpawning.animalSpawn, NPCSpawning.monsterSpawn, NPCSpawning.liquidSpawn, NPCSpawning.airSpawn); if (EventHooks.onCNPCNaturalSpawn(event)) { return false; } entityliving.setPosition(event.attemptPosition.getX(),event.attemptPosition.getY(),event.attemptPosition.getZ()); world.spawnEntityInWorld(entityliving); - + return true; } @@ -216,7 +216,7 @@ public class NPCSpawning { return entityLiving.worldObj.checkNoEntityCollision(entityLiving.boundingBox) && entityLiving.worldObj.getCollidingBoundingBoxes(entityLiving, entityLiving.boundingBox).isEmpty(); } } - + public static boolean canCreatureTypeSpawnAtLocation(SpawnData data, World world, int x, int y, int z){ Block block = world.getBlock(x, y - 1, z); boolean hasSolidSurface = World.doesBlockHaveSolidTopSurface(world, x, y - 1, z); diff --git a/src/main/java/noppes/npcs/scripted/event/CustomNPCsEvent.java b/src/main/java/noppes/npcs/scripted/event/CustomNPCsEvent.java index 0a0dfd2bb..1f95ec760 100644 --- a/src/main/java/noppes/npcs/scripted/event/CustomNPCsEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/CustomNPCsEvent.java @@ -2,12 +2,15 @@ package noppes.npcs.scripted.event; import cpw.mods.fml.common.eventhandler.Cancelable; import cpw.mods.fml.common.eventhandler.Event; +import net.minecraft.entity.EntityLivingBase; import noppes.npcs.api.AbstractNpcAPI; import noppes.npcs.api.IPos; import noppes.npcs.api.IWorld; +import noppes.npcs.api.entity.IEntityLivingBase; import noppes.npcs.api.event.ICustomNPCsEvent; import noppes.npcs.api.handler.data.INaturalSpawn; import noppes.npcs.constants.EnumScriptType; +import noppes.npcs.scripted.NpcAPI; public class CustomNPCsEvent extends Event implements ICustomNPCsEvent { public final AbstractNpcAPI API = AbstractNpcAPI.Instance(); @@ -27,6 +30,7 @@ public class CustomNPCsEvent extends Event implements ICustomNPCsEvent { @Cancelable public static class CNPCNaturalSpawnEvent extends CustomNPCsEvent implements ICustomNPCsEvent.CNPCNaturalSpawnEvent { + public final IEntityLivingBase entity; public final INaturalSpawn naturalSpawn; public IPos attemptPosition; public final boolean animalSpawnPassed; @@ -34,7 +38,8 @@ public class CustomNPCsEvent extends Event implements ICustomNPCsEvent { public final boolean liquidSpawnPassed; public final boolean airSpawnPassed; - public CNPCNaturalSpawnEvent(INaturalSpawn naturalSpawn, IPos attemptPosition, boolean animalSpawnPassed, boolean monsterSpawnPassed, boolean liquidSpawnPassed, boolean airSpawnPassed) { + public CNPCNaturalSpawnEvent(EntityLivingBase entity, INaturalSpawn naturalSpawn, IPos attemptPosition, boolean animalSpawnPassed, boolean monsterSpawnPassed, boolean liquidSpawnPassed, boolean airSpawnPassed) { + this.entity = (IEntityLivingBase) NpcAPI.Instance().getIEntity(entity); this.naturalSpawn = naturalSpawn; this.attemptPosition = attemptPosition; @@ -48,6 +53,10 @@ public class CustomNPCsEvent extends Event implements ICustomNPCsEvent { return EnumScriptType.CNPC_NATURAL_SPAWN.function; } + public IEntityLivingBase getEntity() { + return entity; + } + public INaturalSpawn getNaturalSpawn() { return this.naturalSpawn; }