@EventHandler public void onBlockFall(EntityChangeBlockEvent event) { if (event.getEntity() instanceof FallingBlock) { if (BlockStorage.hasBlockInfo(event.getBlock())) { event.setCancelled(true); FallingBlock fb = (FallingBlock) event.getEntity(); if (fb.getDropItem()) { fb.getWorld().dropItemNaturally(fb.getLocation(), new ItemStack(fb.getBlockData().getMaterial(), 1)); } } } }
public EntityFallingBlockData(FallingBlock fallingBlock) { byte data = NMSUtils.getBlockData(fallingBlock); material = new com.elmakers.mine.bukkit.block.MaterialAndData(fallingBlock.getMaterial(), data); fallingBlock.setDropItem(dropItems); fallingBlock.setHurtEntities(hurtEntities); }
public void run() { Iterator<Location> l = fallLocs.iterator(); while (l.hasNext()) { Location loc = l.next(); if (random.nextBoolean()) { Block b = loc.getBlock(); if ((isFire && b.getType() == Material.FIRE) || (!isFire && Tag.WOOL.isTagged(b.getType()))) { loc.getWorld().playEffect(loc, Effect.STEP_SOUND, b.getType()); b.setType(Material.AIR); } l.remove(); } if (random.nextInt(5) == 0) { break; } } Iterator<FallingBlock> it = blocks.iterator(); while (it.hasNext()) { FallingBlock block = it.next(); if (block.isDead()) { fallLocs.add(block.getLocation()); it.remove(); } } if (fallLocs.isEmpty() && blocks.isEmpty()) { cancel(); } } }).runTaskTimer(RPGItems.plugin, 0, 5);
block = player.getWorld().spawnFallingBlock(player.getLocation().add(0, 1.8, 0), Material.FIRE.createBlockData()); block.setVelocity(player.getLocation().getDirection().multiply(new Vector(random.nextDouble() * 2d + 0.5, random.nextDouble() * 2d + 0.5, random.nextDouble() * 2d + 0.5))); block.setDropItem(false); blocks.add(block);
public void run() { World world = block.getWorld(); final Random random = new Random(); if (block.isDead()) { block.remove(); if (block.getLocation().getBlock().getType().equals(Material.TORCH)) block.setMetadata("RPGItems.Torch", new FixedMetadataValue(RPGItems.plugin, null)); cancel(); final HashMap<Location, Material> changedBlocks = new HashMap<>(); for (int y = -2; y <= 3; y++) { for (int z = -2; z <= 2; z++) { Location loc = block.getLocation().add(x, y, z); Block b = world.getBlockAt(loc); if (b.getType().equals(Material.AIR) && random.nextInt(100) < 20) {
entity.setMetadata("GP_FALLINGBLOCK", new FixedMetadataValue(GriefPrevention.instance, block.getLocation())); List<MetadataValue> values = entity.getMetadata("GP_FALLINGBLOCK"); if (entity.hasMetadata("GP_FELLTHROUGHPORTAL")) return; ItemStack itemStack = new ItemStack(entity.getMaterial(), 1, entity.getBlockData()); Item item = block.getWorld().dropItem(entity.getLocation(), itemStack); item.setVelocity(new Vector());
fb.setDropItem(false); fb.setVelocity(new Vector(v, v, v)); b.setBlockData(TARDISConstants.AIR); f.getLocation().getBlock().setBlockData(TARDISConstants.AIR); f.remove(); }), 10L); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
this.lastTime = curTime; for (final FallingBlock fblock : this.fallingBlocks) { ParticleEffect.LAVA.display(fblock.getLocation(), 0, 0, 0, 0, 1); z = (this.random.nextBoolean()) ? -z : z; fbs.setVelocity(this.direction.clone().add(new Vector(x, 0.2, z)).multiply(1.2)); fbs.setDropItem(false); ALL_FALLING_BLOCKS.add(fb); this.fallingBlocks.add(fb); fb.setVelocity(this.direction.clone().add(new Vector(this.random.nextDouble() / 10, 0.1, this.random.nextDouble() / 10)).multiply(1.2)); fb.setDropItem(false); for (final Entity e : GeneralMethods.getEntitiesAroundPoint(fb.getLocation(), 2)) { if (e instanceof LivingEntity) { if (e.getEntityId() != this.player.getEntityId()) {
@Override public void setDropItem(boolean drop) { f.setDropItem(drop); }
falling.setDropItem(false); if (fallingBlockSpeed != 0) { Vector direction = this.fallingDirection != null ? this.fallingDirection : falling.getLocation().subtract(center).toVector(); direction = direction.normalize().multiply(fallingBlockSpeed); SafetyUtils.setVelocity(falling, direction);
falling.setDropItem(false); CompatibilityUtils.setFallingBlockDamage(falling, fallDamage, maxDamage); } else { falling.setHurtEntities(hurts);
if (ground.getBlock().getRelative(BlockFace.UP).getType() == null || ground.getBlock().getRelative(BlockFace.UP).getType() == Material.AIR) { FallingBlock block = ground.getWorld().spawnFallingBlock(ground.getBlock().getRelative(BlockFace.UP).getLocation(), ground.getBlock().getType(), ground.getBlock().getData()); block.setDropItem(false); block.setVelocity(new Vector(0, 0.4 + i * 0.01, 0)); Variables.blocks.add(block.getUniqueId());
ItemStack itemStack = new ItemStack(fallingBlock.getBlockData().getMaterial(), 1); Item item = block.getWorld().dropItem(fallingBlock.getLocation(), itemStack); item.setVelocity(new Vector()); if (Events.fireAndTestCancel(new SpawnEntityEvent(event, create(block, entity), item))) {
if (block.isDead()) { block.remove(); if (block.getLocation().getBlock().getType().equals(Material.FIRE)) block.getLocation().getBlock().setType(Material.AIR); blockDead = true; List<Entity> ents = getNearbyEntities(PowerFire.this, block.getLocation(), player, 1,0, 1, 0); for (Entity ent : ents) if (ent instanceof Damageable)
/** * Gets the lower-cased name of a given Entity<br> * - Items will get the name 'item' with the item type appended to it<br> * - Falling blocks will get the name 'falling' with the block type appended to it * * @param entity to get the name of * @return Entity name */ public static String getName(Entity entity) { if (entity == null) { return ""; } else if (entity instanceof Item) { Material mat = ((Item) entity).getItemStack().getType(); if (mat == null || mat == Material.AIR) { return "item"; } else { return "item" + mat.toString().toLowerCase(Locale.ENGLISH); } } else if (entity instanceof FallingBlock) { Material mat = ((FallingBlock) entity).getMaterial(); if (mat == null || mat == Material.AIR) { return "fallingblock"; } else { return "falling" + mat.toString().toLowerCase(Locale.ENGLISH); } } else { return getName(entity.getType()); } }
@Override public MCMaterial getMaterial() { return new BukkitMCMaterial(f.getBlockData().getMaterial()); }
@Override public boolean getDropItem() { return f.getDropItem(); }
block.setVelocity(player.getLocation().getDirection().multiply(2d)); block.setDropItem(false);
public void run() { boolean hit = false; World world = block.getWorld(); List<Entity> entities = getNearbyEntities(PowerIce.this, block.getLocation(), player, 1); for (Entity e : entities) { if (e != player && e != block) { if (block.isDead() || hit) { Location landingLoc = block.getLocation(); boolean hitBlock = block.isDead(); block.remove(); if (hitBlock) { if (landingLoc.getBlock().getType().equals(Material.PACKED_ICE)) {
@Override public void fall(Entity fallingBlock, Block block) { if (isScheduled() && fallingBlock instanceof FallingBlock) { ((FallingBlock)fallingBlock).setDropItem(false); } add(fallingBlock); add(block); modifiedTime = System.currentTimeMillis(); }