内联ArrowDamage
This commit is contained in:
parent
5951a1aa7e
commit
c7a6477d7d
2 changed files with 12 additions and 42 deletions
|
@ -1,5 +1,6 @@
|
||||||
package net.mcreator.target.event;
|
package net.mcreator.target.event;
|
||||||
|
|
||||||
|
import net.mcreator.target.entity.BocekarrowEntity;
|
||||||
import net.mcreator.target.entity.Target1Entity;
|
import net.mcreator.target.entity.Target1Entity;
|
||||||
import net.mcreator.target.init.TargetModTags;
|
import net.mcreator.target.init.TargetModTags;
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
import net.mcreator.target.network.TargetModVariables;
|
||||||
|
@ -13,6 +14,7 @@ import net.minecraft.world.damagesource.DamageSource;
|
||||||
import net.minecraft.world.damagesource.DamageTypes;
|
import net.minecraft.world.damagesource.DamageTypes;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
||||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||||
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
||||||
|
@ -33,6 +35,7 @@ public class LivingEntityEventHandler {
|
||||||
public static void onEntityAttacked(LivingAttackEvent event) {
|
public static void onEntityAttacked(LivingAttackEvent event) {
|
||||||
if (event == null || event.getEntity() == null) return;
|
if (event == null || event.getEntity() == null) return;
|
||||||
arrowDamageImmuneForMine(event, event.getSource(), event.getSource().getEntity());
|
arrowDamageImmuneForMine(event, event.getSource(), event.getSource().getEntity());
|
||||||
|
arrowDamage(event, event.getEntity().level(), event.getSource(), event.getEntity(), event.getSource().getDirectEntity(), event.getSource().getEntity(), event.getAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
@ -48,6 +51,15 @@ public class LivingEntityEventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO 把伤害逻辑移植到箭类中
|
||||||
|
private static void arrowDamage(LivingAttackEvent event, LevelAccessor world, DamageSource damagesource, Entity entity, Entity immediatesourceentity, Entity sourceentity, double amount) {
|
||||||
|
if (damagesource == null || entity == null || immediatesourceentity == null || sourceentity == null) return;
|
||||||
|
if (damagesource.is(DamageTypes.ARROW) && immediatesourceentity instanceof BocekarrowEntity) {
|
||||||
|
event.setCanceled(true);
|
||||||
|
entity.hurt(new DamageSource(world.registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation("target:arrow_in_brain"))), sourceentity), (float) amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void killIndication(Entity sourceEntity) {
|
private static void killIndication(Entity sourceEntity) {
|
||||||
if (sourceEntity == null) return;
|
if (sourceEntity == null) return;
|
||||||
if (sourceEntity instanceof Player player && player.getMainHandItem().is(TargetModTags.Items.GUN)) {
|
if (sourceEntity instanceof Player player && player.getMainHandItem().is(TargetModTags.Items.GUN)) {
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
package net.mcreator.target.procedures;
|
|
||||||
|
|
||||||
import net.mcreator.target.entity.BocekarrowEntity;
|
|
||||||
import net.minecraft.core.registries.Registries;
|
|
||||||
import net.minecraft.resources.ResourceKey;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.world.damagesource.DamageSource;
|
|
||||||
import net.minecraft.world.damagesource.DamageTypes;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
|
||||||
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.Event;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
// TODO 把伤害逻辑移植到箭类中
|
|
||||||
@Mod.EventBusSubscriber
|
|
||||||
public class ArrowdamageProcedure {
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onEntityAttacked(LivingAttackEvent event) {
|
|
||||||
if (event != null && event.getEntity() != null) {
|
|
||||||
execute(event, event.getEntity().level(), event.getSource(), event.getEntity(), event.getSource().getDirectEntity(), event.getSource().getEntity(), event.getAmount());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void execute(LevelAccessor world, DamageSource damagesource, Entity entity, Entity immediatesourceentity, Entity sourceentity, double amount) {
|
|
||||||
execute(null, world, damagesource, entity, immediatesourceentity, sourceentity, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void execute(@Nullable Event event, LevelAccessor world, DamageSource damagesource, Entity entity, Entity immediatesourceentity, Entity sourceentity, double amount) {
|
|
||||||
if (damagesource == null || entity == null || immediatesourceentity == null || sourceentity == null)
|
|
||||||
return;
|
|
||||||
if (damagesource.is(DamageTypes.ARROW) && immediatesourceentity instanceof BocekarrowEntity) {
|
|
||||||
if (event != null && event.isCancelable()) {
|
|
||||||
event.setCanceled(true);
|
|
||||||
}
|
|
||||||
entity.hurt(new DamageSource(world.registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation("target:arrow_in_brain"))), sourceentity), (float) amount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue