Search in sources :

Example 1 with LightningBolt

use of net.minecraft.world.entity.LightningBolt in project MyPet by xXKeyleXx.

the class PlatformHelper method strikeLightning.

@Override
public void strikeLightning(Location loc, float distance) {
    ServerLevel world = ((CraftWorld) loc.getWorld()).getHandle();
    LightningBolt lightning = new LightningBolt(EntityType.LIGHTNING_BOLT, world);
    lightning.setVisualOnly(true);
    lightning.moveTo(loc.getX(), loc.getY(), loc.getZ(), 0.0F, 0.0F);
    /*world.getCraftServer()
                .getServer()
                .getPlayerList()
                .broadcast(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.dimension(),
                        new ClientboundAddEntityPacket(lightning));
        world.getCraftServer()
                .getServer()
                .getPlayerList()
                .broadcast(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.dimension(),
                        new ClientboundSoundPacket(SoundEvents.LIGHTNING_BOLT_THUNDER, SoundSource.WEATHER, loc.getX(), loc.getY(), loc.getZ(), distance, 1F));
        */
    // Thank you wrong mappings for this workaround
    DedicatedServer server = world.getCraftServer().getServer();
    Method getPlayerListReflect = ReflectionUtil.getMethod(DedicatedServer.class, "getPlayerList");
    try {
        DedicatedPlayerList playerList = (DedicatedPlayerList) getPlayerListReflect.invoke(server, null);
        playerList.broadcast(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.dimension(), new ClientboundAddEntityPacket(lightning));
        playerList.broadcast(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.dimension(), new ClientboundSoundPacket(SoundEvents.LIGHTNING_BOLT_THUNDER, SoundSource.WEATHER, loc.getX(), loc.getY(), loc.getZ(), distance, 1F));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LightningBolt(net.minecraft.world.entity.LightningBolt) ClientboundAddEntityPacket(net.minecraft.network.protocol.game.ClientboundAddEntityPacket) DedicatedPlayerList(net.minecraft.server.dedicated.DedicatedPlayerList) DedicatedServer(net.minecraft.server.dedicated.DedicatedServer) Method(java.lang.reflect.Method) ClientboundSoundPacket(net.minecraft.network.protocol.game.ClientboundSoundPacket) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) InvocationTargetException(java.lang.reflect.InvocationTargetException) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Example 2 with LightningBolt

use of net.minecraft.world.entity.LightningBolt in project MyPet by xXKeyleXx.

the class PlatformHelper method strikeLightning.

@Override
public void strikeLightning(Location loc, float distance) {
    ServerLevel world = ((CraftWorld) loc.getWorld()).getHandle();
    LightningBolt lightning = new LightningBolt(EntityType.LIGHTNING_BOLT, world);
    lightning.setVisualOnly(true);
    lightning.moveTo(loc.getX(), loc.getY(), loc.getZ(), 0.0F, 0.0F);
    world.getCraftServer().getServer().getPlayerList().broadcast(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.dimension(), new ClientboundAddEntityPacket(lightning));
    world.getCraftServer().getServer().getPlayerList().broadcast(null, loc.getX(), loc.getY(), loc.getZ(), distance, world.dimension(), new ClientboundSoundPacket(SoundEvents.LIGHTNING_BOLT_THUNDER, SoundSource.WEATHER, loc.getX(), loc.getY(), loc.getZ(), distance, 1F));
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LightningBolt(net.minecraft.world.entity.LightningBolt) ClientboundAddEntityPacket(net.minecraft.network.protocol.game.ClientboundAddEntityPacket) ClientboundSoundPacket(net.minecraft.network.protocol.game.ClientboundSoundPacket) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Aggregations

ClientboundAddEntityPacket (net.minecraft.network.protocol.game.ClientboundAddEntityPacket)2 ClientboundSoundPacket (net.minecraft.network.protocol.game.ClientboundSoundPacket)2 ServerLevel (net.minecraft.server.level.ServerLevel)2 LightningBolt (net.minecraft.world.entity.LightningBolt)2 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 DedicatedPlayerList (net.minecraft.server.dedicated.DedicatedPlayerList)1 DedicatedServer (net.minecraft.server.dedicated.DedicatedServer)1 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)1 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)1