Add AnimalTameEvent for handling animal taming (#3763)

This commit is contained in:
Ben Staddon authored and LexManos committed 2017-04-07 16:47:28 -07:00
1 parent f22874d3be
commit 901df8345c
6 files changed
+120

No files matched your search

@@ -35,6 +35,7 @@ import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayer.SleepResult;
import net.minecraft.init.Blocks;
@@ -80,6 +81,7 @@ import net.minecraftforge.event.entity.EntityMountEvent;
import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
import net.minecraftforge.event.entity.item.ItemExpireEvent;
import net.minecraftforge.event.entity.living.AnimalTameEvent;
import net.minecraftforge.event.entity.living.LivingDestroyBlockEvent;
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
import net.minecraftforge.event.entity.living.LivingExperienceDropEvent;
@@ -460,6 +462,11 @@ public class ForgeEventFactory
return true;
}
public static boolean onAnimalTame(EntityAnimal animal, EntityPlayer tamer)
{
return MinecraftForge.EVENT_BUS.post(new AnimalTameEvent(animal, tamer));
}
public static SleepResult onPlayerSleepInBed(EntityPlayer player, BlockPos pos)
{
PlayerSleepInBedEvent event = new PlayerSleepInBedEvent(player, pos);
@@ -0,0 +1,57 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
/**
* This event is fired when an {@link EntityAnimal} is tamed. <br>
* It is fired via {@link ForgeEventFactory#onAnimalTame(EntityAnimal, EntityPlayer)}.
* Forge fires this event for applicable vanilla animals, mods need to fire it themselves.
* This event is {@link Cancelable}. If canceled, taming the animal will fail.
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
*/
@Cancelable
public class AnimalTameEvent extends LivingEvent
{
private final EntityAnimal animal;
private final EntityPlayer tamer;
public AnimalTameEvent(EntityAnimal animal, EntityPlayer tamer)
{
super(animal);
this.animal = animal;
this.tamer = tamer;
}
public EntityAnimal getAnimal()
{
return animal;
}
public EntityPlayer getTamer()
{
return tamer;
}
}