mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-22 13:09:59 +00:00
[1.19.x] Make LivingSetAttackTargetEvent compatible with the Brain/Behavior system. (Port of PR #8918) (#8954)
This commit is contained in:
1 parent
4e2d656e9d
commit
ed198f062c
7 files changed
+228
-10
No files matched your search
+44
@@ -0,0 +1,44 @@
|
||||
package net.minecraftforge.debug.entity.living;
|
||||
|
||||
import net.minecraft.world.entity.monster.piglin.AbstractPiglin;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.living.LivingChangeTargetEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod("living_set_attack_target_event_test")
|
||||
public class LivingSetAttackTargetEventTest
|
||||
{
|
||||
public static final boolean ENABLE = true;
|
||||
|
||||
public LivingSetAttackTargetEventTest()
|
||||
{
|
||||
if(ENABLE)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onLivingSetAttackTarget(LivingSetAttackTargetEvent event)
|
||||
{
|
||||
// Make piglins die when they start attacking a player who is not holding a stick in their main hand.
|
||||
if (event.getTarget() instanceof Player player && event.getEntity() instanceof AbstractPiglin piglin && player.getMainHandItem().getItem() != Items.STICK)
|
||||
{
|
||||
event.getEntity().kill();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onLivingChangeTargetEvent(LivingChangeTargetEvent event)
|
||||
{
|
||||
// Prevents the piglin from attacking the player if they hold a stick in their hands.
|
||||
if(event.getNewTarget() instanceof Player player && event.getEntity() instanceof AbstractPiglin piglin && player.getMainHandItem().getItem() == Items.STICK)
|
||||
{
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,6 +247,8 @@ modId="emissive_elements_test"
|
||||
[[mods]]
|
||||
modId="anvil_update_event_fix"
|
||||
[[mods]]
|
||||
modId="living_set_attack_target_event_test"
|
||||
[[mods]]
|
||||
modId="item_use_animation_test"
|
||||
[[mods]]
|
||||
modId="custom_color_resolver_test"
|
||||
@@ -254,5 +256,4 @@ modId="custom_color_resolver_test"
|
||||
modId="custom_item_decorations_test"
|
||||
|
||||
|
||||
|
||||
# ADD ABOVE THIS LINE
|
||||
Reference in new issue
Block a user