mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-23 21:49:46 +00:00
Added event hooks to control to allow mod control of mob spawning. PR: #337
Deprecated LivingSpecialSpawnEvent in favor of new LivingSpawnEvent.SpecialSpawn
This commit is contained in:
1 parent
3e484deafc
commit
3a9c7b4532
4 files changed
+94
-5
No files matched your search
@@ -1,12 +1,18 @@
|
||||
package net.minecraftforge.event;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.Event.Result;
|
||||
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingSpecialSpawnEvent;
|
||||
import net.minecraftforge.event.entity.player.*;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ForgeEventFactory
|
||||
{
|
||||
public static boolean doPlayerHarvestCheck(EntityPlayer player, Block block, boolean success)
|
||||
@@ -33,4 +39,24 @@ public class ForgeEventFactory
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, stack));
|
||||
}
|
||||
|
||||
public static Result canEntitySpawn(EntityLiving entity, World world, float x, float y, float z)
|
||||
{
|
||||
LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getResult();
|
||||
}
|
||||
|
||||
public static boolean doSpecialSpawn(EntityLiving entity, World world, float x, float y, float z)
|
||||
{
|
||||
boolean result = MinecraftForge.EVENT_BUS.post(new LivingSpecialSpawnEvent(entity, world, x, y, z));
|
||||
LivingSpawnEvent.SpecialSpawn nEvent = new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z);
|
||||
|
||||
if (result) //For the time being, copy the canceled state from the old legacy event
|
||||
{ // Remove when we remove LivingSpecialSpawnEvent.
|
||||
nEvent.setCanceled(true);
|
||||
}
|
||||
|
||||
return MinecraftForge.EVENT_BUS.post(nEvent);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user