Java Code Examples for cn.nukkit.entity.Entity#spawnToAll()
The following examples show how to use
cn.nukkit.entity.Entity#spawnToAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockTNT.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public void prime(int fuse) { this.getLevel().setBlock(this, new BlockAir(), true); double mot = (new NukkitRandom()).nextSignedFloat() * Math.PI * 2; CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", this.x + 0.5)) .add(new DoubleTag("", this.y)) .add(new DoubleTag("", this.z + 0.5))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", -Math.sin(mot) * 0.02)) .add(new DoubleTag("", 0.2)) .add(new DoubleTag("", -Math.cos(mot) * 0.02))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", 0)) .add(new FloatTag("", 0))) .putByte("Fuse", fuse); Entity tnt = new EntityPrimedTNT( this.getLevel().getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt ); tnt.spawnToAll(); this.level.addSound(new TNTPrimeSound(this)); }
Example 2
Source File: Level.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void dropExpOrb(Vector3 source, int exp, Vector3 motion, int delay) { Random rand = ThreadLocalRandom.current(); for (int split : EntityXPOrb.splitIntoOrbSizes(exp)) { CompoundTag nbt = Entity.getDefaultNBT(source, motion == null ? new Vector3( (rand.nextDouble() * 0.2 - 0.1) * 2, rand.nextDouble() * 0.4, (rand.nextDouble() * 0.2 - 0.1) * 2) : motion, rand.nextFloat() * 360f, 0); nbt.putShort("Value", split); nbt.putShort("PickupDelay", delay); Entity entity = Entity.createEntity("XpOrb", this.getChunk(source.getChunkX(), source.getChunkZ()), nbt); if (entity != null) { entity.spawnToAll(); } } }
Example 3
Source File: BlockTNT.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void prime(int fuse, Entity source) { this.getLevel().setBlock(this, Block.get(BlockID.AIR), true); double mot = (new NukkitRandom()).nextSignedFloat() * Math.PI * 2; CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", this.x + 0.5)) .add(new DoubleTag("", this.y)) .add(new DoubleTag("", this.z + 0.5))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", -Math.sin(mot) * 0.02)) .add(new DoubleTag("", 0.2)) .add(new DoubleTag("", -Math.cos(mot) * 0.02))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", 0)) .add(new FloatTag("", 0))) .putShort("Fuse", fuse); Entity tnt = Entity.createEntity("PrimedTnt", this.getLevel().getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt, source ); if(tnt == null) { return; } tnt.spawnToAll(); this.level.addSound(this, Sound.RANDOM_FUSE); }
Example 4
Source File: ProjectileDispenseBehavior.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public void dispense(BlockDispenser source, Item item) { Position dispensePos = Position.fromObject(source.getDispensePosition(), source.getLevel()); CompoundTag nbt = Entity.getDefaultNBT(dispensePos); this.correctNBT(nbt); BlockFace face = source.getFacing(); Entity projectile = Entity.createEntity(getEntityType(), dispensePos.getLevel().getChunk(dispensePos.getFloorX(), dispensePos.getFloorZ()), nbt); if (projectile == null) { return; } projectile.setMotion(new Vector3(face.getXOffset(), face.getYOffset() + 0.1f, face.getZOffset()).multiply(6)); projectile.spawnToAll(); }
Example 5
Source File: BlockTNT.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void prime(int fuse) { this.getLevel().setBlock(this, new BlockAir(), true); double mot = (new NukkitRandom()).nextSignedFloat() * Math.PI * 2; CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", this.x + 0.5)) .add(new DoubleTag("", this.y)) .add(new DoubleTag("", this.z + 0.5))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", -Math.sin(mot) * 0.02)) .add(new DoubleTag("", 0.2)) .add(new DoubleTag("", -Math.cos(mot) * 0.02))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", 0)) .add(new FloatTag("", 0))) .putShort("Fuse", fuse); Entity tnt = new EntityPrimedTNT( this.getLevel().getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt ); tnt.spawnToAll(); this.level.addSound(this, Sound.RANDOM_FUSE); }
Example 6
Source File: ProjectileDispenseBehavior.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public void dispense(BlockDispenser source, Item item) { Position dispensePos = Position.fromObject(source.getDispensePosition(), source.getLevel()); CompoundTag nbt = Entity.getDefaultNBT(dispensePos); this.correctNBT(nbt); BlockFace face = source.getFacing(); Entity projectile = Entity.createEntity(getEntityType(), dispensePos.getLevel().getChunk(dispensePos.getFloorX(), dispensePos.getFloorZ()), nbt); if (projectile == null) { return; } projectile.setMotion(new Vector3(face.getXOffset(), face.getYOffset() + 0.1f, face.getZOffset()).multiply(6)); projectile.spawnToAll(); }
Example 7
Source File: ItemArmorStand.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4); if (chunk == null) { return false; } CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", block.getX() + 0.5)) .add(new DoubleTag("", block.getY())) .add(new DoubleTag("", block.getZ() + 0.5))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", this.getDirection(player.yaw))) .add(new FloatTag("", 0))); if (this.hasCustomName()) { nbt.putString("CustomName", this.getCustomName()); } Entity entity = Entity.createEntity("ArmorStand", chunk, nbt); if (entity != null) { if (player.isSurvival()) { Item item = player.getInventory().getItemInHand(); item.setCount(item.getCount() - 1); player.getInventory().setItemInHand(item); } entity.spawnToAll(); return true; } return false; }
Example 8
Source File: ProjectileItem.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public boolean onClickAir(Player player, Vector3 directionVector) { CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", player.x)) .add(new DoubleTag("", player.y + player.getEyeHeight())) .add(new DoubleTag("", player.z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", directionVector.x)) .add(new DoubleTag("", directionVector.y)) .add(new DoubleTag("", directionVector.z))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (float) player.yaw)) .add(new FloatTag("", (float) player.pitch))); this.correctNBT(nbt); Entity projectile = Entity.createEntity(this.getProjectileEntityType(), player.getLevel().getChunk(player.getFloorX() >> 4, player.getFloorZ() >> 4), nbt, player); if (projectile != null) { projectile.setMotion(projectile.getMotion().multiply(this.getThrowForce())); this.count--; if (projectile instanceof EntityProjectile) { ProjectileLaunchEvent ev = new ProjectileLaunchEvent((EntityProjectile) projectile); player.getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { projectile.kill(); } else { projectile.spawnToAll(); player.getLevel().addSound(new LaunchSound(player), player.getViewers().values()); } } else { projectile.spawnToAll(); } } else { return false; } return true; }
Example 9
Source File: ItemSpawnEgg.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4); if (chunk == null) { return false; } CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", block.getX() + 0.5)) .add(new DoubleTag("", block.getY())) .add(new DoubleTag("", block.getZ() + 0.5))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", new Random().nextFloat() * 360)) .add(new FloatTag("", 0))); if (this.hasCustomName()) { nbt.putString("CustomName", this.getCustomName()); } Entity entity = Entity.createEntity(this.meta, chunk, nbt); if (entity != null) { if (player.isSurvival()) { Item item = player.getInventory().getItemInHand(); item.setCount(item.getCount() - 1); player.getInventory().setItemInHand(item); } entity.spawnToAll(); return true; } return false; }
Example 10
Source File: SummonCommand.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { if (!this.testPermission(sender)) { return true; } if (sender instanceof ConsoleCommandSender) { sender.sendMessage(new TranslationContainer("commands.generic.ingame")); return true; } if (args.length < 2) { sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage)); return false; } Position pos = new Position(Double.parseDouble(args[1]), Double.parseDouble(args[2]), Double.parseDouble(args[3]), ((Player) sender).getLevel()); CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", pos.getX() + 0.5)) .add(new DoubleTag("", pos.getY())) .add(new DoubleTag("", pos.getZ() + 0.5))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", new Random().nextFloat() * 360)) .add(new FloatTag("", 0))); Entity entity = Entity.createEntity(args[0], pos.getLevel().getChunk((int) pos.getX() >> 4, (int) pos.getZ() >> 4, true), nbt); entity.spawnToAll(); return true; }
Example 11
Source File: ItemEndCrystal.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (!(target instanceof BlockBedrock) && !(target instanceof BlockObsidian)) return false; FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4); if (chunk == null) { return false; } CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", block.getX() + 0.5)) .add(new DoubleTag("", block.getY())) .add(new DoubleTag("", block.getZ() + 0.5))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", new Random().nextFloat() * 360)) .add(new FloatTag("", 0))); if (this.hasCustomName()) { nbt.putString("CustomName", this.getCustomName()); } Entity entity = Entity.createEntity("EndCrystal", chunk, nbt); if (entity != null) { if (player.isSurvival()) { Item item = player.getInventory().getItemInHand(); item.setCount(item.getCount() - 1); player.getInventory().setItemInHand(item); } entity.spawnToAll(); return true; } return false; }
Example 12
Source File: ProjectileItem.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public boolean onClickAir(Player player, Vector3 directionVector) { CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", player.x)) .add(new DoubleTag("", player.y + player.getEyeHeight())) .add(new DoubleTag("", player.z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", directionVector.x)) .add(new DoubleTag("", directionVector.y)) .add(new DoubleTag("", directionVector.z))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (float) player.yaw)) .add(new FloatTag("", (float) player.pitch))); this.correctNBT(nbt); Entity projectile = Entity.createEntity(this.getProjectileEntityType(), player.getLevel().getChunk(player.getFloorX() >> 4, player.getFloorZ() >> 4), nbt, player); if (projectile != null) { projectile.setMotion(projectile.getMotion().multiply(this.getThrowForce())); this.count--; if (projectile instanceof EntityProjectile) { ProjectileLaunchEvent ev = new ProjectileLaunchEvent((EntityProjectile) projectile); player.getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { projectile.kill(); } else { projectile.spawnToAll(); player.getLevel().addSound(player, Sound.RANDOM_BOW, 1, 1, player.getViewers().values()); } } else { projectile.spawnToAll(); } } else { return false; } return true; }
Example 13
Source File: ItemSpawnEgg.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4); if (chunk == null) { return false; } CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", block.getX() + 0.5)) .add(new DoubleTag("", block.getY())) .add(new DoubleTag("", block.getZ() + 0.5))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", new Random().nextFloat() * 360)) .add(new FloatTag("", 0))); if (this.hasCustomName()) { nbt.putString("CustomName", this.getCustomName()); } Entity entity = Entity.createEntity(this.meta, chunk, nbt); if (entity != null) { if (player.isSurvival()) { Item item = player.getInventory().getItemInHand(); item.setCount(item.getCount() - 1); player.getInventory().setItemInHand(item); } entity.spawnToAll(); return true; } return false; }
Example 14
Source File: BlockEntityMobSpawner.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public boolean onUpdate() { if (this.closed) { return false; } this.timing.startTiming(); if (!(this.chunk instanceof Chunk)) { return false; } if (!(this.canUpdate())) { return false; } if (this.namedTag.getInt("Delay") <= 0) { int success = 0; NukkitRandom random = new NukkitRandom(); for (int i = 0; i < this.namedTag.getInt("SpawnCount"); ++i) { Vector3 pos = this.add( this.getRandomSpawn(), NukkitMath.randomRange(random, -1, 1), this.getRandomSpawn()); Block target = this.getLevel().getBlock(pos); Block ground = target.down(); if (target.getId() == Block.AIR && ground.isSolid()) { ++success; CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", pos.x)) .add(new DoubleTag("", pos.y)) .add(new DoubleTag("", pos.z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (float) Math.random() * 360)) .add(new FloatTag("", (float) 0))); Entity entity = Entity.createEntity(this.getNetworkId(), this.chunk, nbt); entity.spawnToAll(); } } if (success > 0) { this.namedTag.putInt("Delay", NukkitMath.randomRange(random, this.namedTag.getInt("MinSpawnDelay"), this.namedTag.getInt("MaxSpawnDelay"))); } } else { this.namedTag.putInt("Delay", this.namedTag.getInt("Delay") - 1); } this.timing.stopTiming(); return true; }
Example 15
Source File: ProjectileItem.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean onClickAir(Player player, Vector3 directionVector) { CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", player.x)) .add(new DoubleTag("", player.y + player.getEyeHeight() - 0.30000000149011612)) .add(new DoubleTag("", player.z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", directionVector.x)) .add(new DoubleTag("", directionVector.y)) .add(new DoubleTag("", directionVector.z))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (float) player.yaw)) .add(new FloatTag("", (float) player.pitch))); this.correctNBT(nbt); Entity projectile = Entity.createEntity(this.getProjectileEntityType(), player.getLevel().getChunk(player.getFloorX() >> 4, player.getFloorZ() >> 4), nbt, player); if (projectile != null) { if (projectile instanceof EntityEnderPearl) { if (player.getServer().getTick() - player.getLastEnderPearlThrowingTick() < 20) { projectile.kill(); return false; } } projectile.setMotion(projectile.getMotion().multiply(this.getThrowForce())); if (projectile instanceof EntityProjectile) { ProjectileLaunchEvent ev = new ProjectileLaunchEvent((EntityProjectile) projectile); player.getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { projectile.kill(); } else { if (!player.isCreative()) { this.count--; } if (projectile instanceof EntityEnderPearl) { player.onThrowEnderPearl(); } projectile.spawnToAll(); player.getLevel().addLevelSoundEvent(player, LevelSoundEventPacket.SOUND_BOW); } } } else { return false; } return true; }
Example 16
Source File: ItemSpawnEgg.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4); if (chunk == null) { return false; } CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", block.getX() + 0.5)) .add(new DoubleTag("", target.getBoundingBox() == null ? block.getY() : target.getBoundingBox().getMaxY() + 0.0001f)) .add(new DoubleTag("", block.getZ() + 0.5))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", new Random().nextFloat() * 360)) .add(new FloatTag("", 0))); if (this.hasCustomName()) { nbt.putString("CustomName", this.getCustomName()); } CreatureSpawnEvent ev = new CreatureSpawnEvent(this.meta, block, nbt, SpawnReason.SPAWN_EGG); level.getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { return false; } Entity entity = Entity.createEntity(this.meta, chunk, nbt); if (entity != null) { if (player.isSurvival()) { player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); } entity.spawnToAll(); return true; } return false; }