mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 20:52:34 +00:00
Add spawn reason to spawn events (#6096)
This commit is contained in:
1 parent
c09fe57031
commit
b5b43a5a36
5 files changed
+29
-13
No files matched your search
@@ -52,6 +52,7 @@ import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.MobEntity;
|
||||
import net.minecraft.entity.SpawnReason;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.item.minecart.ContainerMinecartEntity;
|
||||
@@ -1052,8 +1053,8 @@ public class ForgeHooks
|
||||
return event.getVanillaNoteId();
|
||||
}
|
||||
|
||||
public static int canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, AbstractSpawner spawner) {
|
||||
Result res = ForgeEventFactory.canEntitySpawn(entity, world, x, y, z, null);
|
||||
public static int canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, AbstractSpawner spawner, SpawnReason spawnReason) {
|
||||
Result res = ForgeEventFactory.canEntitySpawn(entity, world, x, y, z, null, spawnReason);
|
||||
return res == Result.DEFAULT ? 0 : res == Result.DENY ? -1 : 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -175,27 +175,27 @@ public class ForgeEventFactory
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, stack, hand));
|
||||
}
|
||||
|
||||
public static Result canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, AbstractSpawner spawner)
|
||||
public static Result canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, AbstractSpawner spawner, SpawnReason spawnReason)
|
||||
{
|
||||
if (entity == null)
|
||||
return Result.DEFAULT;
|
||||
LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z, spawner);
|
||||
LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z, spawner, spawnReason);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getResult();
|
||||
}
|
||||
|
||||
public static boolean canEntitySpawnSpawner(MobEntity entity, World world, float x, float y, float z, AbstractSpawner spawner)
|
||||
{
|
||||
Result result = canEntitySpawn(entity, world, x, y, z, spawner);
|
||||
Result result = canEntitySpawn(entity, world, x, y, z, spawner, SpawnReason.SPAWNER);
|
||||
if (result == Result.DEFAULT)
|
||||
return entity.canSpawn(world, SpawnReason.SPAWNER) || !entity.isNotColliding(world); // vanilla logic
|
||||
else
|
||||
return result == Result.ALLOW;
|
||||
}
|
||||
|
||||
public static boolean doSpecialSpawn(MobEntity entity, World world, float x, float y, float z, AbstractSpawner spawner)
|
||||
public static boolean doSpecialSpawn(MobEntity entity, World world, float x, float y, float z, AbstractSpawner spawner, SpawnReason spawnReason)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z, spawner));
|
||||
return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z, spawner, spawnReason));
|
||||
}
|
||||
|
||||
public static Result canEntityDespawn(MobEntity entity)
|
||||
|
||||
@@ -25,6 +25,7 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraft.entity.MobEntity;
|
||||
import net.minecraft.entity.SpawnReason;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -76,6 +77,7 @@ public class LivingSpawnEvent extends LivingEvent
|
||||
{
|
||||
@Nullable
|
||||
private final AbstractSpawner spawner;
|
||||
private final SpawnReason spawnReason;
|
||||
|
||||
/**
|
||||
* CheckSpawn is fired when an Entity is about to be spawned.
|
||||
@@ -87,10 +89,11 @@ public class LivingSpawnEvent extends LivingEvent
|
||||
* @param spawner position of the MobSpawner
|
||||
* null if it this spawn is coming from a WorldSpawner
|
||||
*/
|
||||
public CheckSpawn(MobEntity entity, IWorld world, double x, double y, double z, @Nullable AbstractSpawner spawner)
|
||||
public CheckSpawn(MobEntity entity, IWorld world, double x, double y, double z, @Nullable AbstractSpawner spawner, SpawnReason spawnReason)
|
||||
{
|
||||
super(entity, world, x, y, z);
|
||||
this.spawner = spawner;
|
||||
this.spawnReason = spawnReason;
|
||||
}
|
||||
|
||||
public boolean isSpawner()
|
||||
@@ -103,6 +106,11 @@ public class LivingSpawnEvent extends LivingEvent
|
||||
{
|
||||
return spawner;
|
||||
}
|
||||
|
||||
public SpawnReason getSpawnReason()
|
||||
{
|
||||
return spawnReason;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,14 +131,16 @@ public class LivingSpawnEvent extends LivingEvent
|
||||
{
|
||||
@Nullable
|
||||
private final AbstractSpawner spawner;
|
||||
private final SpawnReason spawnReason;
|
||||
|
||||
/**
|
||||
* @param spawner the position of a tileentity or approximate position of an entity that initiated the spawn if any
|
||||
*/
|
||||
public SpecialSpawn(MobEntity entity, World world, double x, double y, double z, @Nullable AbstractSpawner spawner)
|
||||
public SpecialSpawn(MobEntity entity, World world, double x, double y, double z, @Nullable AbstractSpawner spawner, SpawnReason spawnReason)
|
||||
{
|
||||
super(entity, world, x, y, z);
|
||||
this.spawner = spawner;
|
||||
this.spawnReason = spawnReason;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -138,6 +148,11 @@ public class LivingSpawnEvent extends LivingEvent
|
||||
{
|
||||
return spawner;
|
||||
}
|
||||
|
||||
public SpawnReason getSpawnReason()
|
||||
{
|
||||
return spawnReason;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user