mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 16:54:22 +00:00
Add MobSpawnerBaseLogic reference to SpecialSpawn and CheckSpawn events (#4600)
This commit is contained in:
1 parent
ff8ba90da3
commit
1d48e06798
5 files changed
+176
-11
No files matched your search
@@ -42,6 +42,7 @@ import net.minecraft.entity.projectile.EntityThrowable;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.MobSpawnerBaseLogic;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.DamageSource;
|
||||
@@ -176,23 +177,52 @@ public class ForgeEventFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #canEntitySpawn(EntityLiving, World, float, float, float, boolean)} instead
|
||||
* @deprecated use {@link #canEntitySpawn(EntityLiving, World, float, float, float, MobSpawnerBaseLogic)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
@Deprecated // TODO remove in 1.13
|
||||
public static Result canEntitySpawn(EntityLiving entity, World world, float x, float y, float z)
|
||||
{
|
||||
return canEntitySpawn(entity, world, x, y, z, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #canEntitySpawn(EntityLiving, World, float, float, float, MobSpawnerBaseLogic)} instead
|
||||
*/
|
||||
@Deprecated // Still used in base game for non-spawner spawns, which is safe
|
||||
public static Result canEntitySpawn(EntityLiving entity, World world, float x, float y, float z, boolean isSpawner)
|
||||
{
|
||||
if (entity == null)
|
||||
return Result.DEFAULT;
|
||||
LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z, isSpawner);
|
||||
LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z, isSpawner); // TODO: replace isSpawner with null in 1.13
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getResult();
|
||||
}
|
||||
|
||||
public static Result canEntitySpawn(EntityLiving entity, World world, float x, float y, float z, MobSpawnerBaseLogic spawner)
|
||||
{
|
||||
if (entity == null)
|
||||
return Result.DEFAULT;
|
||||
LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z, spawner);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getResult();
|
||||
}
|
||||
|
||||
public static boolean canEntitySpawnSpawner(EntityLiving entity, World world, float x, float y, float z, MobSpawnerBaseLogic spawner)
|
||||
{
|
||||
Result result = canEntitySpawn(entity, world, x, y, z, spawner);
|
||||
if (result == Result.DEFAULT)
|
||||
{
|
||||
return entity.getCanSpawnHere() && entity.isNotColliding(); // vanilla logic
|
||||
}
|
||||
else
|
||||
{
|
||||
return result == Result.ALLOW;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #canEntitySpawnSpawner(EntityLiving, World, float, float, float, MobSpawnerBaseLogic)}
|
||||
*/
|
||||
@Deprecated // TODO remove in 1.13
|
||||
public static boolean canEntitySpawnSpawner(EntityLiving entity, World world, float x, float y, float z)
|
||||
{
|
||||
Result result = canEntitySpawn(entity, world, x, y, z, true);
|
||||
@@ -206,9 +236,18 @@ public class ForgeEventFactory
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #canEntitySpawnSpawner(EntityLiving, World, float, float, float, MobSpawnerBaseLogic)}
|
||||
*/
|
||||
@Deprecated // Still used in base game for non-spawner spawns, which is safe
|
||||
public static boolean doSpecialSpawn(EntityLiving entity, World world, float x, float y, float z)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z));
|
||||
return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z, null));
|
||||
}
|
||||
|
||||
public static boolean doSpecialSpawn(EntityLiving entity, World world, float x, float y, float z, MobSpawnerBaseLogic spawner)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z, spawner));
|
||||
}
|
||||
|
||||
public static Result canEntityDespawn(EntityLiving entity)
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.tileentity.MobSpawnerBaseLogic;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||
@@ -70,9 +73,31 @@ public class LivingSpawnEvent extends LivingEvent
|
||||
@HasResult
|
||||
public static class CheckSpawn extends LivingSpawnEvent
|
||||
{
|
||||
private final boolean isSpawner;
|
||||
private final boolean isSpawner; // TODO: remove in 1.13
|
||||
@Nullable
|
||||
private final MobSpawnerBaseLogic spawner;
|
||||
|
||||
|
||||
/**
|
||||
* CheckSpawn is fired when an Entity is about to be spawned.
|
||||
* @param entity the spawning entity
|
||||
* @param world the world to spawn in
|
||||
* @param x x coordinate
|
||||
* @param y y coordinate
|
||||
* @param z z coordinate
|
||||
* @param spawner position of the MobSpawner
|
||||
* null if it this spawn is coming from a WorldSpawner
|
||||
*/
|
||||
public CheckSpawn(EntityLiving entity, World world, float x, float y, float z, @Nullable MobSpawnerBaseLogic spawner)
|
||||
{
|
||||
super(entity, world, x, y, z);
|
||||
this.isSpawner = spawner != null;
|
||||
this.spawner = spawner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link CheckSpawn##CheckSpawn(EntityLiving, World, float, float, float, MobSpawnerBaseLogic)}
|
||||
* with a spawner instance, or null if not a spawner
|
||||
* CheckSpawn is fired when an Entity is about to be spawned.
|
||||
* @param entity the spawning entity
|
||||
* @param world the world to spawn in
|
||||
@@ -82,22 +107,33 @@ public class LivingSpawnEvent extends LivingEvent
|
||||
* @param isSpawner true if this spawn is done by a MobSpawner,
|
||||
* false if it this spawn is coming from a WorldSpawner
|
||||
*/
|
||||
@Deprecated // TODO: Remove in 1.13
|
||||
public CheckSpawn(EntityLiving entity, World world, float x, float y, float z, boolean isSpawner)
|
||||
{
|
||||
super(entity, world, x, y, z);
|
||||
this.isSpawner = isSpawner;
|
||||
spawner = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link CheckSpawn#CheckSpawn(EntityLiving, World, float, float, float, boolean)} instead
|
||||
* @deprecated Use {@link CheckSpawn#CheckSpawn(EntityLiving, World, float, float, float, MobSpawnerBaseLogic)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
@Deprecated // TODO: Remove in 1.13
|
||||
public CheckSpawn(EntityLiving entity, World world, float x, float y, float z)
|
||||
{
|
||||
this(entity, world, x, y, z, true);
|
||||
}
|
||||
|
||||
public boolean isSpawner() { return isSpawner; }
|
||||
public boolean isSpawner()
|
||||
{
|
||||
return isSpawner; // TODO: replace with spawner null check in 1.13
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MobSpawnerBaseLogic getSpawner()
|
||||
{
|
||||
return spawner;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,9 +152,33 @@ public class LivingSpawnEvent extends LivingEvent
|
||||
@Cancelable
|
||||
public static class SpecialSpawn extends LivingSpawnEvent
|
||||
{
|
||||
@Nullable
|
||||
private final MobSpawnerBaseLogic spawner;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link SpecialSpawn#SpecialSpawn(EntityLiving, World, float, float, float, MobSpawnerBaseLogic)}
|
||||
* with originating spawner instance or null
|
||||
*/
|
||||
@Deprecated // TODO: remove in 1.13
|
||||
public SpecialSpawn(EntityLiving entity, World world, float x, float y, float z)
|
||||
{
|
||||
super(entity, world, x, y, z);
|
||||
spawner = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param spawner the position of a tileentity or approximate position of an entity that initiated the spawn if any
|
||||
*/
|
||||
public SpecialSpawn(EntityLiving entity, World world, float x, float y, float z, @Nullable MobSpawnerBaseLogic spawner)
|
||||
{
|
||||
super(entity, world, x, y, z);
|
||||
this.spawner = spawner;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MobSpawnerBaseLogic getSpawner()
|
||||
{
|
||||
return spawner;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user