Add new LivingConversionEvent to control mobs turning into other mobs. (#7386)

This commit is contained in:
poopoodice authored and GitHub committed 2020-12-28 12:03:11 -08:00
1 parent 1c98b29087
commit b64f4780c5
10 files changed
+309 -4

No files matched your search

@@ -0,0 +1,53 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2020.
*
* 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.debug.entity.living;
import net.minecraft.entity.merchant.villager.VillagerEntity;
import net.minecraft.entity.monster.piglin.PiglinEntity;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingConversionEvent;
import net.minecraftforge.fml.common.Mod;
@Mod("living_conversion_event_test")
public class LivingConversionEventTest
{
public LivingConversionEventTest()
{
MinecraftForge.EVENT_BUS.addListener(this::canLivingConversion);
MinecraftForge.EVENT_BUS.addListener(this::onLivingConversion);
}
public void canLivingConversion(LivingConversionEvent.Pre event)
{
if (event.getEntityLiving() instanceof PiglinEntity)
{
event.setCanceled(true);
event.setConversionTimer(0);
}
}
public void onLivingConversion(LivingConversionEvent.Post event)
{
if (event.getEntityLiving() instanceof VillagerEntity)
event.getEntityLiving().addPotionEffect(new EffectInstance(Effects.LUCK, 20));
}
}