52 lines
2.4 KiB
Java
52 lines
2.4 KiB
Java
package net.mcreator.target.procedures;
|
|
|
|
import net.mcreator.target.network.TargetModVariables;
|
|
import net.minecraft.commands.CommandSource;
|
|
import net.minecraft.commands.CommandSourceStack;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.tags.ItemTags;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.item.ItemStack;
|
|
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 KillindicationProcedure {
|
|
@SubscribeEvent
|
|
public static void onEntityDeath(LivingDeathEvent event) {
|
|
if (event != null && event.getEntity() != null) {
|
|
execute(event, event.getSource().getEntity());
|
|
}
|
|
}
|
|
|
|
public static void execute(Entity sourceentity) {
|
|
execute(null, sourceentity);
|
|
}
|
|
|
|
private static void execute(@Nullable Event event, Entity sourceentity) {
|
|
if (sourceentity == null)
|
|
return;
|
|
if (sourceentity instanceof Player && (sourceentity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).is(ItemTags.create(new ResourceLocation("target:gun")))) {
|
|
{
|
|
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");
|
|
}
|
|
}
|
|
{
|
|
double _setval = 40;
|
|
sourceentity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
capability.killind = _setval;
|
|
capability.syncPlayerVariables(sourceentity);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|