内联ClaymoreDamage
This commit is contained in:
parent
c7a6477d7d
commit
129460f8a8
2 changed files with 12 additions and 40 deletions
|
@ -36,6 +36,7 @@ public class LivingEntityEventHandler {
|
||||||
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());
|
arrowDamage(event, event.getEntity().level(), event.getSource(), event.getEntity(), event.getSource().getDirectEntity(), event.getSource().getEntity(), event.getAmount());
|
||||||
|
claymoreDamage(event, event.getEntity().level(), event.getSource(), event.getEntity(), event.getSource().getEntity(), event.getAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
@ -51,6 +52,17 @@ public class LivingEntityEventHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void claymoreDamage(LivingAttackEvent event, LevelAccessor world, DamageSource damagesource, Entity entity, Entity sourceentity, double amount) {
|
||||||
|
if (damagesource == null || entity == null || sourceentity == null)
|
||||||
|
return;
|
||||||
|
if ((damagesource.is(DamageTypes.EXPLOSION) || damagesource.is(DamageTypes.PLAYER_EXPLOSION)) && entity.getPersistentData().getDouble("claymore") > 0) {
|
||||||
|
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:mine"))), sourceentity), (float) amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO 把伤害逻辑移植到箭类中
|
// TODO 把伤害逻辑移植到箭类中
|
||||||
private static void arrowDamage(LivingAttackEvent event, LevelAccessor world, DamageSource damagesource, Entity entity, Entity immediatesourceentity, Entity sourceentity, double amount) {
|
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 == null || entity == null || immediatesourceentity == null || sourceentity == null) return;
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
package net.mcreator.target.procedures;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber
|
|
||||||
public class ClaymoreDamageProcedure {
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onEntityAttacked(LivingAttackEvent event) {
|
|
||||||
if (event != null && event.getEntity() != null) {
|
|
||||||
execute(event, event.getEntity().level(), event.getSource(), event.getEntity(), event.getSource().getEntity(), event.getAmount());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void execute(LevelAccessor world, DamageSource damagesource, Entity entity, Entity sourceentity, double amount) {
|
|
||||||
execute(null, world, damagesource, entity, sourceentity, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void execute(@Nullable Event event, LevelAccessor world, DamageSource damagesource, Entity entity, Entity sourceentity, double amount) {
|
|
||||||
if (damagesource == null || entity == null || sourceentity == null)
|
|
||||||
return;
|
|
||||||
if ((damagesource.is(DamageTypes.EXPLOSION) || damagesource.is(DamageTypes.PLAYER_EXPLOSION)) && entity.getPersistentData().getDouble("claymore") > 0) {
|
|
||||||
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:mine"))), sourceentity), (float) amount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue