use of net.minecraft.network.protocol.game.ClientboundEntityEventPacket 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;
}
use of net.minecraft.network.protocol.game.ClientboundEntityEventPacket 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);
ClientboundRemoveEntitiesPacket destroyPacket = new ClientboundRemoveEntitiesPacket(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.addFreshEntity(fireworkHandle, CreatureSpawnEvent.SpawnReason.CUSTOM);
entity = fireworkHandle.getBukkitEntity();
} catch (Exception ex) {
ex.printStackTrace();
}
return entity;
}
use of net.minecraft.network.protocol.game.ClientboundEntityEventPacket 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);
ClientboundRemoveEntitiesPacket destroyPacket = new ClientboundRemoveEntitiesPacket(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.addFreshEntity(fireworkHandle, CreatureSpawnEvent.SpawnReason.CUSTOM);
entity = fireworkHandle.getBukkitEntity();
} catch (Exception ex) {
ex.printStackTrace();
}
return entity;
}
use of net.minecraft.network.protocol.game.ClientboundEntityEventPacket 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);
ClientboundRemoveEntitiesPacket destroyPacket = new ClientboundRemoveEntitiesPacket(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;
}
use of net.minecraft.network.protocol.game.ClientboundEntityEventPacket 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);
ClientboundRemoveEntitiesPacket destroyPacket = new ClientboundRemoveEntitiesPacket(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.addFreshEntity(fireworkHandle, CreatureSpawnEvent.SpawnReason.CUSTOM);
entity = fireworkHandle.getBukkitEntity();
} catch (Exception ex) {
ex.printStackTrace();
}
return entity;
}
Aggregations