移动DamageProcedure
This commit is contained in:
parent
bc776aaf56
commit
b18c68d581
2 changed files with 34 additions and 50 deletions
|
@ -5,14 +5,18 @@ import net.mcreator.target.init.TargetModItems;
|
||||||
import net.mcreator.target.init.TargetModSounds;
|
import net.mcreator.target.init.TargetModSounds;
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
import net.mcreator.target.network.TargetModVariables;
|
||||||
import net.mcreator.target.procedures.Target1DangShiTiGengXinKeShiProcedure;
|
import net.mcreator.target.procedures.Target1DangShiTiGengXinKeShiProcedure;
|
||||||
|
import net.minecraft.commands.CommandSource;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
||||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||||
import net.minecraft.network.syncher.SynchedEntityData;
|
import net.minecraft.network.syncher.SynchedEntityData;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.DifficultyInstance;
|
import net.minecraft.world.DifficultyInstance;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
|
@ -32,6 +36,9 @@ import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.ServerLevelAccessor;
|
import net.minecraft.world.level.ServerLevelAccessor;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.network.NetworkHooks;
|
import net.minecraftforge.network.NetworkHooks;
|
||||||
import net.minecraftforge.network.PlayMessages;
|
import net.minecraftforge.network.PlayMessages;
|
||||||
import software.bernie.geckolib.animatable.GeoEntity;
|
import software.bernie.geckolib.animatable.GeoEntity;
|
||||||
|
@ -45,6 +52,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber
|
||||||
public class Target1Entity extends PathfinderMob implements GeoEntity, AnimatedEntity {
|
public class Target1Entity extends PathfinderMob implements GeoEntity, AnimatedEntity {
|
||||||
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(Target1Entity.class, EntityDataSerializers.BOOLEAN);
|
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(Target1Entity.class, EntityDataSerializers.BOOLEAN);
|
||||||
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(Target1Entity.class, EntityDataSerializers.STRING);
|
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(Target1Entity.class, EntityDataSerializers.STRING);
|
||||||
|
@ -308,4 +316,30 @@ public class Target1Entity extends PathfinderMob implements GeoEntity, AnimatedE
|
||||||
public AnimatableInstanceCache getAnimatableInstanceCache() {
|
public AnimatableInstanceCache getAnimatableInstanceCache() {
|
||||||
return this.cache;
|
return this.cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onTarget1Down(LivingDeathEvent event) {
|
||||||
|
if (event.getEntity() == null) return;
|
||||||
|
|
||||||
|
var entity = event.getEntity();
|
||||||
|
var sourceEntity = event.getSource().getEntity();
|
||||||
|
|
||||||
|
if (entity == null || sourceEntity == null) return;
|
||||||
|
|
||||||
|
if (entity instanceof Target1Entity target1) {
|
||||||
|
target1.setHealth(target1.getMaxHealth());
|
||||||
|
|
||||||
|
// TODO 修改为正确的音效播放方法
|
||||||
|
// sourceEntity.level().playSound(null, sourceEntity.blockPosition(), TargetModSounds.TARGETDOWN.get(), SoundSource.PLAYERS, 100, 1);
|
||||||
|
if (sourceEntity.getServer() != null) {
|
||||||
|
sourceEntity.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, sourceEntity.position(), sourceEntity.getRotationVector(), sourceEntity.level() instanceof ServerLevel ? (ServerLevel) sourceEntity.level() : null, 4,
|
||||||
|
sourceEntity.getName().getString(), sourceEntity.getDisplayName(), sourceEntity.level().getServer(), sourceEntity), "playsound target:targetdown player @s ~ ~ ~ 100 1");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sourceEntity instanceof Player player)
|
||||||
|
player.displayClientMessage(Component.literal(("Target Down " + new java.text.DecimalFormat("##.#").format((entity.position()).distanceTo((sourceEntity.position()))) + "M")), true);
|
||||||
|
entity.getPersistentData().putDouble("targetdown", 201);
|
||||||
|
event.setCanceled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
package net.mcreator.target.procedures;
|
|
||||||
|
|
||||||
import net.mcreator.target.entity.Target1Entity;
|
|
||||||
import net.minecraft.commands.CommandSource;
|
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
|
||||||
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 DamageProcedure {
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onEntityDeath(LivingDeathEvent event) {
|
|
||||||
if (event != null && event.getEntity() != null) {
|
|
||||||
execute(event, event.getEntity(), event.getSource().getEntity());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void execute(Entity entity, Entity sourceentity) {
|
|
||||||
execute(null, entity, sourceentity);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void execute(@Nullable Event event, Entity entity, Entity sourceentity) {
|
|
||||||
if (entity == null || sourceentity == null)
|
|
||||||
return;
|
|
||||||
if (entity instanceof Target1Entity entity1) {
|
|
||||||
entity1.setHealth(entity1.getMaxHealth());
|
|
||||||
{
|
|
||||||
if (!sourceentity.level().isClientSide() && sourceentity.getServer() != null) {
|
|
||||||
sourceentity.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, sourceentity.position(), sourceentity.getRotationVector(), sourceentity.level() instanceof ServerLevel ? (ServerLevel) sourceentity.level() : null, 4,
|
|
||||||
sourceentity.getName().getString(), sourceentity.getDisplayName(), sourceentity.level().getServer(), sourceentity), "playsound target:targetdown player @s ~ ~ ~ 100 1");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sourceentity instanceof Player _player && !_player.level().isClientSide())
|
|
||||||
_player.displayClientMessage(Component.literal(("Target Down " + new java.text.DecimalFormat("##.#").format((entity.position()).distanceTo((sourceentity.position()))) + "M")), true);
|
|
||||||
entity.getPersistentData().putDouble("targetdown", 201);
|
|
||||||
if (event != null && event.isCancelable()) {
|
|
||||||
event.setCanceled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue