Search in sources :

Example 1 with ClientboundRemoveEntityPacket

use of net.minecraft.network.protocol.game.ClientboundRemoveEntityPacket in project MagicPlugin by elBukkit.

the class CompatibilityUtils method spawnFireworkEffect.

@Override
public Entity spawnFireworkEffect(Material fireworkMaterial, Server server, Location location, FireworkEffect effect, int power, Vector direction, Integer expectedLifespan, Integer ticksFlown, boolean silent) {
    Entity entity = null;
    try {
        if (fireworkMaterial == null) {
            return null;
        }
        ServerLevel level = ((CraftWorld) location.getWorld()).getHandle();
        ItemStack itemStack = new ItemStack(fireworkMaterial);
        FireworkMeta meta = (FireworkMeta) itemStack.getItemMeta();
        meta.addEffect(effect);
        meta.setPower(power);
        itemStack.setItemMeta(meta);
        Object item = platform.getItemUtils().getHandle(platform.getItemUtils().makeReal(itemStack));
        final FireworkRocketEntity fireworkHandle = new FireworkRocketEntity(level, location.getX(), location.getY(), location.getZ(), (net.minecraft.world.item.ItemStack) item);
        fireworkHandle.setSilent(silent);
        if (direction != null) {
            fireworkHandle.setDeltaMovement(new Vec3(direction.getX(), direction.getY(), direction.getZ()));
        }
        if (ticksFlown != null) {
            ReflectionUtils.setPrivateNeedsFixing(platform.getLogger(), fireworkHandle, FireworkRocketEntity.class, "life", "e", ticksFlown);
        }
        if (expectedLifespan != null) {
            fireworkHandle.lifetime = expectedLifespan;
        }
        if (direction == null) {
            ClientboundAddEntityPacket fireworkPacket = new ClientboundAddEntityPacket(fireworkHandle, CompatibilityConstants.FIREWORK_TYPE);
            int fireworkId = fireworkHandle.getId();
            SynchedEntityData watcher = fireworkHandle.getEntityData();
            ClientboundSetEntityDataPacket metadataPacket = new ClientboundSetEntityDataPacket(fireworkId, watcher, true);
            ClientboundEntityEventPacket statusPacket = new ClientboundEntityEventPacket(fireworkHandle, (byte) 17);
            ClientboundRemoveEntityPacket destroyPacket = new ClientboundRemoveEntityPacket(fireworkId);
            Collection<? extends Player> players = server.getOnlinePlayers();
            sendPacket(server, location, players, fireworkPacket);
            sendPacket(server, location, players, metadataPacket);
            sendPacket(server, location, players, statusPacket);
            sendPacket(server, location, players, destroyPacket);
            return null;
        }
        level.addEntity(fireworkHandle, CreatureSpawnEvent.SpawnReason.CUSTOM);
        entity = fireworkHandle.getBukkitEntity();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return entity;
}
Also used : FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) Entity(org.bukkit.entity.Entity) HangingEntity(net.minecraft.world.entity.decoration.HangingEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) SignBlockEntity(net.minecraft.world.level.block.entity.SignBlockEntity) HumanEntity(org.bukkit.entity.HumanEntity) ServerLevel(net.minecraft.server.level.ServerLevel) SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData) ClientboundAddEntityPacket(net.minecraft.network.protocol.game.ClientboundAddEntityPacket) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) FireworkRocketEntity(net.minecraft.world.entity.projectile.FireworkRocketEntity) ClientboundRemoveEntityPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntityPacket) Vec3(net.minecraft.world.phys.Vec3) ClientboundEntityEventPacket(net.minecraft.network.protocol.game.ClientboundEntityEventPacket) ItemStack(org.bukkit.inventory.ItemStack) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) ClientboundSetEntityDataPacket(net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket)

Aggregations

ClientboundAddEntityPacket (net.minecraft.network.protocol.game.ClientboundAddEntityPacket)1 ClientboundEntityEventPacket (net.minecraft.network.protocol.game.ClientboundEntityEventPacket)1 ClientboundRemoveEntityPacket (net.minecraft.network.protocol.game.ClientboundRemoveEntityPacket)1 ClientboundSetEntityDataPacket (net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket)1 SynchedEntityData (net.minecraft.network.syncher.SynchedEntityData)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 HangingEntity (net.minecraft.world.entity.decoration.HangingEntity)1 FallingBlockEntity (net.minecraft.world.entity.item.FallingBlockEntity)1 ItemEntity (net.minecraft.world.entity.item.ItemEntity)1 FireworkRocketEntity (net.minecraft.world.entity.projectile.FireworkRocketEntity)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 SignBlockEntity (net.minecraft.world.level.block.entity.SignBlockEntity)1 Vec3 (net.minecraft.world.phys.Vec3)1 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)1 CraftEntity (org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity)1 CraftLivingEntity (org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity)1 Entity (org.bukkit.entity.Entity)1 HumanEntity (org.bukkit.entity.HumanEntity)1 LivingEntity (org.bukkit.entity.LivingEntity)1 ItemStack (org.bukkit.inventory.ItemStack)1