cn.nukkit.network.protocol.LevelSoundEventPacket Java Examples

The following examples show how to use cn.nukkit.network.protocol.LevelSoundEventPacket. 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: ChestInventory.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onOpen(Player who) {
    super.onOpen(who);

    if (this.getViewers().size() == 1) {
        BlockEventPacket pk = new BlockEventPacket();
        pk.x = (int) this.getHolder().getX();
        pk.y = (int) this.getHolder().getY();
        pk.z = (int) this.getHolder().getZ();
        pk.case1 = 1;
        pk.case2 = 2;

        Level level = this.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(LevelSoundEventPacket.SOUND_CHEST_OPEN, 1, -1, this.getHolder().add(0.5, 0.5, 0.5));
            level.addChunkPacket((int) this.getHolder().getX() >> 4, (int) this.getHolder().getZ() >> 4, pk);
        }
    }
}
 
Example #2
Source File: ChestInventory.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClose(Player who) {
    if (this.getViewers().size() == 1) {
        BlockEventPacket pk = new BlockEventPacket();
        pk.x = (int) this.getHolder().getX();
        pk.y = (int) this.getHolder().getY();
        pk.z = (int) this.getHolder().getZ();
        pk.case1 = 1;
        pk.case2 = 0;

        Level level = this.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(LevelSoundEventPacket.SOUND_CHEST_CLOSED, 1, -1, this.getHolder().add(0.5, 0.5, 0.5));
            level.addChunkPacket((int) this.getHolder().getX() >> 4, (int) this.getHolder().getZ() >> 4, pk);
        }
    }

    super.onClose(who);
}
 
Example #3
Source File: BlockEntityBeacon.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean updateCompoundTag(CompoundTag nbt, Player player) {
    if (!nbt.getString("id").equals(BlockEntity.BEACON)) {
        return false;
    }

    this.setPrimaryPower(nbt.getInt("primary"));
    this.setSecondaryPower(nbt.getInt("secondary"));

    this.getLevel().addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_BEACON_POWER);

    BeaconInventory inv = (BeaconInventory)player.getWindowById(Player.BEACON_WINDOW_ID);

    inv.setItem(0, new ItemBlock(Block.get(BlockID.AIR), 0, 0));
    return true;
}
 
Example #4
Source File: ShulkerBoxInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onOpen(Player who) {
    super.onOpen(who);

    if (this.getViewers().size() == 1) {
        BlockEventPacket pk = new BlockEventPacket();
        pk.x = (int) this.getHolder().getX();
        pk.y = (int) this.getHolder().getY();
        pk.z = (int) this.getHolder().getZ();
        pk.case1 = 1;
        pk.case2 = 2;

        Level level = this.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(this.getHolder().add(0.5, 0.5, 0.5), LevelSoundEventPacket.SOUND_SHULKERBOX_OPEN);
            level.addChunkPacket((int) this.getHolder().getX() >> 4, (int) this.getHolder().getZ() >> 4, pk);
        }
    }
}
 
Example #5
Source File: ShulkerBoxInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClose(Player who) {
    if (this.getViewers().size() == 1) {
        BlockEventPacket pk = new BlockEventPacket();
        pk.x = (int) this.getHolder().getX();
        pk.y = (int) this.getHolder().getY();
        pk.z = (int) this.getHolder().getZ();
        pk.case1 = 1;
        pk.case2 = 0;

        Level level = this.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(this.getHolder().add(0.5, 0.5, 0.5), LevelSoundEventPacket.SOUND_SHULKERBOX_CLOSED);
            level.addChunkPacket((int) this.getHolder().getX() >> 4, (int) this.getHolder().getZ() >> 4, pk);
        }
    }

    super.onClose(who);
}
 
Example #6
Source File: ChestInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onOpen(Player who) {
    super.onOpen(who);

    if (this.getViewers().size() == 1) {
        BlockEventPacket pk = new BlockEventPacket();
        pk.x = (int) this.getHolder().getX();
        pk.y = (int) this.getHolder().getY();
        pk.z = (int) this.getHolder().getZ();
        pk.case1 = 1;
        pk.case2 = 2;

        Level level = this.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(this.getHolder().add(0.5, 0.5, 0.5), LevelSoundEventPacket.SOUND_CHEST_OPEN);
            level.addChunkPacket((int) this.getHolder().getX() >> 4, (int) this.getHolder().getZ() >> 4, pk);
        }
    }
}
 
Example #7
Source File: ChestInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClose(Player who) {
    if (this.getViewers().size() == 1) {
        BlockEventPacket pk = new BlockEventPacket();
        pk.x = (int) this.getHolder().getX();
        pk.y = (int) this.getHolder().getY();
        pk.z = (int) this.getHolder().getZ();
        pk.case1 = 1;
        pk.case2 = 0;

        Level level = this.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(this.getHolder().add(0.5, 0.5, 0.5), LevelSoundEventPacket.SOUND_CHEST_CLOSED);
            level.addChunkPacket((int) this.getHolder().getX() >> 4, (int) this.getHolder().getZ() >> 4, pk);
        }
    }

    super.onClose(who);
}
 
Example #8
Source File: PlayerEnderChestInventory.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClose(Player who) {
    ContainerClosePacket containerClosePacket = new ContainerClosePacket();
    containerClosePacket.windowId = who.getWindowId(this);
    who.dataPacket(containerClosePacket);
    super.onClose(who);

    BlockEnderChest chest = who.getViewingEnderChest();
    if (chest != null && chest.getViewers().size() == 1) {
        BlockEventPacket blockEventPacket = new BlockEventPacket();
        blockEventPacket.x = (int) chest.getX();
        blockEventPacket.y = (int) chest.getY();
        blockEventPacket.z = (int) chest.getZ();
        blockEventPacket.case1 = 1;
        blockEventPacket.case2 = 0;

        Level level = this.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(LevelSoundEventPacket.SOUND_CHEST_CLOSED, 1, -1, this.getHolder().add(0.5, 0.5, 0.5));
            level.addChunkPacket((int) this.getHolder().getX() >> 4, (int) this.getHolder().getZ() >> 4, blockEventPacket);
        }

        who.setViewingEnderChest(null);
    }

    super.onClose(who);
}
 
Example #9
Source File: DoubleChestInventory.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onOpen(Player who) {
    super.onOpen(who);
    this.left.viewers.add(who);
    this.right.viewers.add(who);

    if (this.getViewers().size() == 1) {
        BlockEventPacket pk1 = new BlockEventPacket();
        pk1.x = (int) this.left.getHolder().getX();
        pk1.y = (int) this.left.getHolder().getY();
        pk1.z = (int) this.left.getHolder().getZ();
        pk1.case1 = 1;
        pk1.case2 = 2;
        Level level = this.left.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(LevelSoundEventPacket.SOUND_CHEST_OPEN, 1, -1, this.left.getHolder().add(0.5, 0.5, 0.5));
            level.addChunkPacket((int) this.left.getHolder().getX() >> 4, (int) this.left.getHolder().getZ() >> 4, pk1);
        }

        BlockEventPacket pk2 = new BlockEventPacket();
        pk2.x = (int) this.right.getHolder().getX();
        pk2.y = (int) this.right.getHolder().getY();
        pk2.z = (int) this.right.getHolder().getZ();
        pk2.case1 = 1;
        pk2.case2 = 2;

        level = this.right.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(LevelSoundEventPacket.SOUND_CHEST_OPEN, 1, -1, this.right.getHolder().add(0.5, 0.5, 0.5));
            level.addChunkPacket((int) this.right.getHolder().getX() >> 4, (int) this.right.getHolder().getZ() >> 4, pk2);
        }
    }
}
 
Example #10
Source File: DoubleChestInventory.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClose(Player who) {
    if (this.getViewers().size() == 1) {
        BlockEventPacket pk1 = new BlockEventPacket();
        pk1.x = (int) this.right.getHolder().getX();
        pk1.y = (int) this.right.getHolder().getY();
        pk1.z = (int) this.right.getHolder().getZ();
        pk1.case1 = 1;
        pk1.case2 = 0;

        Level level = this.right.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(LevelSoundEventPacket.SOUND_CHEST_CLOSED, 1, -1, this.right.getHolder().add(0.5, 0.5, 0.5));
            level.addChunkPacket((int) this.right.getHolder().getX() >> 4, (int) this.right.getHolder().getZ() >> 4, pk1);
        }

        BlockEventPacket pk2 = new BlockEventPacket();
        pk2.x = (int) this.left.getHolder().getX();
        pk2.y = (int) this.left.getHolder().getY();
        pk2.z = (int) this.left.getHolder().getZ();
        pk2.case1 = 1;
        pk2.case2 = 0;

        level = this.left.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(LevelSoundEventPacket.SOUND_CHEST_CLOSED, 1, -1, this.left.getHolder().add(0.5, 0.5, 0.5));
            level.addChunkPacket((int) this.left.getHolder().getX() >> 4, (int) this.left.getHolder().getZ() >> 4, pk2);
        }
    }

    this.left.viewers.remove(who);
    this.right.viewers.remove(who);
    super.onClose(who);
}
 
Example #11
Source File: PlayerEnderChestInventory.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onOpen(Player who) {
    if (who != this.getHolder()) {
        return;
    }
    super.onOpen(who);
    ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
    containerOpenPacket.windowId = who.getWindowId(this);
    containerOpenPacket.type = this.getType().getNetworkType();
    BlockEnderChest chest = who.getViewingEnderChest();
    if (chest != null) {
        containerOpenPacket.x = (int) chest.getX();
        containerOpenPacket.y = (int) chest.getY();
        containerOpenPacket.z = (int) chest.getZ();
    } else {
        containerOpenPacket.x = containerOpenPacket.y = containerOpenPacket.z = 0;
    }

    who.dataPacket(containerOpenPacket);

    this.sendContents(who);

    if (chest != null && chest.getViewers().size() == 1) {
        BlockEventPacket blockEventPacket = new BlockEventPacket();
        blockEventPacket.x = (int) chest.getX();
        blockEventPacket.y = (int) chest.getY();
        blockEventPacket.z = (int) chest.getZ();
        blockEventPacket.case1 = 1;
        blockEventPacket.case2 = 2;

        Level level = this.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(LevelSoundEventPacket.SOUND_CHEST_OPEN, 1, -1, this.getHolder().add(0.5, 0.5, 0.5));
            level.addChunkPacket((int) this.getHolder().getX() >> 4, (int) this.getHolder().getZ() >> 4, blockEventPacket);
        }
    }
}
 
Example #12
Source File: BlockLiquid.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected boolean liquidCollide(Block cause, Block result) {
    BlockFromToEvent event = new BlockFromToEvent(this, result);
    this.level.getServer().getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return false;
    }
    this.level.setBlock(this, event.getTo(), true, true);
    this.getLevel().addLevelSoundEvent(this.add(0.5, 0.5, 0.5), LevelSoundEventPacket.SOUND_FIZZ);
    return true;
}
 
Example #13
Source File: BlockEntityJukebox.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void play() {
    if (this.recordItem instanceof ItemRecord) {
        LevelSoundEventPacket pk = new LevelSoundEventPacket();
        pk.sound = ((ItemRecord) this.recordItem).getSoundId();
        pk.pitch = 1;
        pk.extraData = -1;
        pk.x = (float) this.x;
        pk.y = (float) this.y;
        pk.z = (float) this.z;

        Server.broadcastPacket(this.level.getPlayers().values(), pk);
    }
}
 
Example #14
Source File: BlockNoteblock.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void emitSound() {
    if (this.up().getId() != AIR) return;

    Instrument instrument = this.getInstrument();

    this.level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_NOTE, instrument.ordinal() << 8 | this.getStrength());

    BlockEventPacket pk = new BlockEventPacket();
    pk.x = this.getFloorX();
    pk.y = this.getFloorY();
    pk.z = this.getFloorZ();
    pk.case1 = instrument.ordinal();
    pk.case2 = this.getStrength();
    this.getLevel().addChunkPacket(this.getFloorX() >> 4, this.getFloorZ() >> 4, pk);
}
 
Example #15
Source File: EntityMinecartTNT.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onInteract(Player player, Item item, Vector3 clickedPos) {
    boolean interact = super.onInteract(player, item, clickedPos);
    if (item.getId() == Item.FLINT_AND_STEEL || item.getId() == Item.FIRE_CHARGE) {
        level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_IGNITE);
        this.fuse = 79;
        return true;
    }

    return interact;
}
 
Example #16
Source File: BlockPistonBase.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private void checkState() {
    BlockFace facing = getFacing();
    boolean isPowered = this.isPowered();

    if (isPowered && !isExtended()) {
        if ((new BlocksCalculator(this.level, this, facing, true)).canMove()) {
            if (!this.doMove(true)) {
                return;
            }

            this.getLevel().addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_PISTON_OUT);
        } else {
        }
    } else if (!isPowered && isExtended()) {
        //this.level.setBlock() TODO: set piston extension?

        if (this.sticky) {
            Vector3 pos = this.add(facing.getXOffset() * 2, facing.getYOffset() * 2, facing.getZOffset() * 2);
            Block block = this.level.getBlock(pos);

            if (block.getId() == AIR) {
                this.level.setBlock(this.getLocation().getSide(facing), Block.get(BlockID.AIR), true, true);
            }
            if (canPush(block, facing.getOpposite(), false) && (!(block instanceof BlockFlowable) || block.getId() == PISTON || block.getId() == STICKY_PISTON)) {
                this.doMove(false);
            }
        } else {
            this.level.setBlock(getLocation().getSide(facing), Block.get(BlockID.AIR), true, false);
        }

        this.getLevel().addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_PISTON_IN);
    }
}
 
Example #17
Source File: EntityPrimedTNT.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void initEntity() {
    super.initEntity();

    if (namedTag.contains("Fuse")) {
        fuse = namedTag.getByte("Fuse");
    } else {
        fuse = 80;
    }

    this.setDataFlag(DATA_FLAGS, DATA_FLAG_IGNITED, true);
    this.setDataProperty(new IntEntityData(DATA_FUSE_LENGTH, fuse));

    this.getLevel().addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_FIZZ);
}
 
Example #18
Source File: BlockTripWireHook.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private void addSound(Vector3 pos, boolean canConnect, boolean nextPowered, boolean attached, boolean powered) {
    if (nextPowered && !powered) {
        this.level.addLevelSoundEvent(pos, LevelSoundEventPacket.SOUND_POWER_ON);
        this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 0, 15));
    } else if (!nextPowered && powered) {
        this.level.addLevelSoundEvent(pos, LevelSoundEventPacket.SOUND_POWER_OFF);
        this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 15, 0));
    } else if (canConnect && !attached) {
        this.level.addLevelSoundEvent(pos, LevelSoundEventPacket.SOUND_ATTACH);
    } else if (!canConnect && attached) {
        this.level.addLevelSoundEvent(pos, LevelSoundEventPacket.SOUND_DETACH);
    }
}
 
Example #19
Source File: EntityThrownTrident.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onUpdate(int currentTick) {
    if (this.closed) {
        return false;
    }

    this.timing.startTiming();

    if (this.isCollided && !this.hadCollision) {
        this.getLevel().addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_ITEM_TRIDENT_HIT_GROUND);
    }

    boolean hasUpdate = super.onUpdate(currentTick);

    if (this.onGround || this.hadCollision) {
        this.setCritical(false);
    }

    if (this.age > 1200) {
        this.close();
        hasUpdate = true;
    }

    this.timing.stopTiming();

    return hasUpdate;
}
 
Example #20
Source File: ItemFlintSteel.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (block.getId() == AIR && (target instanceof BlockSolid || target instanceof BlockSolidMeta)) {
        if (target.getId() == OBSIDIAN) {
            if (level.createPortal(target)) {
                return true;
            }
        }

        BlockFire fire = (BlockFire) Block.get(BlockID.FIRE);
        fire.x = block.x;
        fire.y = block.y;
        fire.z = block.z;
        fire.level = level;

        if (fire.isBlockTopFacingSurfaceSolid(fire.down()) || fire.canNeighborBurn()) {
            BlockIgniteEvent e = new BlockIgniteEvent(block, null, player, BlockIgniteEvent.BlockIgniteCause.FLINT_AND_STEEL);
            block.getLevel().getServer().getPluginManager().callEvent(e);

            if (!e.isCancelled()) {
                level.setBlock(fire, fire, true);
                level.addLevelSoundEvent(block, LevelSoundEventPacket.SOUND_IGNITE);
                level.scheduleUpdate(fire, fire.tickRate() + ThreadLocalRandom.current().nextInt(10));
            }
            return true;
        }

        if ((player.gamemode & 0x01) == 0 && this.useOn(block)) {
            if (this.getDamage() >= this.getMaxDurability()) {
                this.count = 0;
            } else {
                this.meta++;
            }
        }
        return true;
    }
    return false;
}
 
Example #21
Source File: PlayerEnderChestInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onOpen(Player who) {
    if (who != this.getHolder()) {
        return;
    }
    super.onOpen(who);
    ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
    containerOpenPacket.windowId = who.getWindowId(this);
    containerOpenPacket.type = this.getType().getNetworkType();
    BlockEnderChest chest = who.getViewingEnderChest();
    if (chest != null) {
        containerOpenPacket.x = (int) chest.getX();
        containerOpenPacket.y = (int) chest.getY();
        containerOpenPacket.z = (int) chest.getZ();
    } else {
        containerOpenPacket.x = containerOpenPacket.y = containerOpenPacket.z = 0;
    }

    who.dataPacket(containerOpenPacket);

    this.sendContents(who);

    if (chest != null && chest.getViewers().size() == 1) {
        BlockEventPacket blockEventPacket = new BlockEventPacket();
        blockEventPacket.x = (int) chest.getX();
        blockEventPacket.y = (int) chest.getY();
        blockEventPacket.z = (int) chest.getZ();
        blockEventPacket.case1 = 1;
        blockEventPacket.case2 = 2;

        Level level = this.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(this.getHolder().add(0.5, 0.5, 0.5), LevelSoundEventPacket.SOUND_ENDERCHEST_OPEN);
            level.addChunkPacket((int) this.getHolder().getX() >> 4, (int) this.getHolder().getZ() >> 4, blockEventPacket);
        }
    }
}
 
Example #22
Source File: BlockTripWireHook.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private void addSound(Vector3 pos, boolean canConnect, boolean nextPowered, boolean attached, boolean powered) {
    if (nextPowered && !powered) {
        this.level.addLevelSoundEvent(pos, LevelSoundEventPacket.SOUND_POWER_ON, 1, -1);
        this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 0, 15));
    } else if (!nextPowered && powered) {
        this.level.addLevelSoundEvent(pos, LevelSoundEventPacket.SOUND_POWER_OFF, 1, -1);
        this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 15, 0));
    } else if (canConnect && !attached) {
        this.level.addLevelSoundEvent(pos, LevelSoundEventPacket.SOUND_ATTACH, 1, -1);
    } else if (!canConnect && attached) {
        this.level.addLevelSoundEvent(pos, LevelSoundEventPacket.SOUND_DETACH, 1, -1);
    }
}
 
Example #23
Source File: PlayerEnderChestInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClose(Player who) {
    ContainerClosePacket containerClosePacket = new ContainerClosePacket();
    containerClosePacket.windowId = who.getWindowId(this);
    who.dataPacket(containerClosePacket);
    super.onClose(who);

    BlockEnderChest chest = who.getViewingEnderChest();
    if (chest != null && chest.getViewers().size() == 1) {
        BlockEventPacket blockEventPacket = new BlockEventPacket();
        blockEventPacket.x = (int) chest.getX();
        blockEventPacket.y = (int) chest.getY();
        blockEventPacket.z = (int) chest.getZ();
        blockEventPacket.case1 = 1;
        blockEventPacket.case2 = 0;

        Level level = this.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(this.getHolder().add(0.5, 0.5, 0.5), LevelSoundEventPacket.SOUND_ENDERCHEST_CLOSED);
            level.addChunkPacket((int) this.getHolder().getX() >> 4, (int) this.getHolder().getZ() >> 4, blockEventPacket);
        }

        who.setViewingEnderChest(null);
    }

    super.onClose(who);
}
 
Example #24
Source File: BlockTripWireHook.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
private void addSound(Vector3 pos, boolean canConnect, boolean nextPowered, boolean attached, boolean powered) {
    if (nextPowered && !powered) {
        this.level.addLevelSoundEvent(LevelSoundEventPacket.SOUND_POWER_ON, 1, -1, pos);
        this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 0, 15));
    } else if (!nextPowered && powered) {
        this.level.addLevelSoundEvent(LevelSoundEventPacket.SOUND_POWER_OFF, 1, -1, pos);
        this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 15, 0));
    } else if (canConnect && !attached) {
        this.level.addLevelSoundEvent(LevelSoundEventPacket.SOUND_ATTACH, 1, -1, pos);
    } else if (!canConnect && attached) {
        this.level.addLevelSoundEvent(LevelSoundEventPacket.SOUND_DETACH, 1, -1, pos);
    }
}
 
Example #25
Source File: DoubleChestInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClose(Player who) {
    if (this.getViewers().size() == 1) {
        BlockEventPacket pk1 = new BlockEventPacket();
        pk1.x = (int) this.right.getHolder().getX();
        pk1.y = (int) this.right.getHolder().getY();
        pk1.z = (int) this.right.getHolder().getZ();
        pk1.case1 = 1;
        pk1.case2 = 0;

        Level level = this.right.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(this.right.getHolder().add(0.5, 0.5, 0.5), LevelSoundEventPacket.SOUND_CHEST_CLOSED);
            level.addChunkPacket((int) this.right.getHolder().getX() >> 4, (int) this.right.getHolder().getZ() >> 4, pk1);
        }

        BlockEventPacket pk2 = new BlockEventPacket();
        pk2.x = (int) this.left.getHolder().getX();
        pk2.y = (int) this.left.getHolder().getY();
        pk2.z = (int) this.left.getHolder().getZ();
        pk2.case1 = 1;
        pk2.case2 = 0;

        level = this.left.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(this.left.getHolder().add(0.5, 0.5, 0.5), LevelSoundEventPacket.SOUND_CHEST_CLOSED);
            level.addChunkPacket((int) this.left.getHolder().getX() >> 4, (int) this.left.getHolder().getZ() >> 4, pk2);
        }
    }

    this.left.viewers.remove(who);
    this.right.viewers.remove(who);
    super.onClose(who);
}
 
Example #26
Source File: DoubleChestInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onOpen(Player who) {
    super.onOpen(who);
    this.left.viewers.add(who);
    this.right.viewers.add(who);

    if (this.getViewers().size() == 1) {
        BlockEventPacket pk1 = new BlockEventPacket();
        pk1.x = (int) this.left.getHolder().getX();
        pk1.y = (int) this.left.getHolder().getY();
        pk1.z = (int) this.left.getHolder().getZ();
        pk1.case1 = 1;
        pk1.case2 = 2;
        Level level = this.left.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(this.left.getHolder().add(0.5, 0.5, 0.5), LevelSoundEventPacket.SOUND_CHEST_OPEN);
            level.addChunkPacket((int) this.left.getHolder().getX() >> 4, (int) this.left.getHolder().getZ() >> 4, pk1);
        }

        BlockEventPacket pk2 = new BlockEventPacket();
        pk2.x = (int) this.right.getHolder().getX();
        pk2.y = (int) this.right.getHolder().getY();
        pk2.z = (int) this.right.getHolder().getZ();
        pk2.case1 = 1;
        pk2.case2 = 2;

        level = this.right.getHolder().getLevel();
        if (level != null) {
            level.addLevelSoundEvent(this.right.getHolder().add(0.5, 0.5, 0.5), LevelSoundEventPacket.SOUND_CHEST_OPEN);
            level.addChunkPacket((int) this.right.getHolder().getX() >> 4, (int) this.right.getHolder().getZ() >> 4, pk2);
        }
    }
}
 
Example #27
Source File: BlockEndPortalFrame.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Item item, Player player) {
    if((this.getDamage() & 0x04) == 0 && player != null && item.getId() == Item.ENDER_EYE) {
        this.setDamage(this.getDamage() + 4);
        this.getLevel().setBlock(this, this, true, true);
        this.getLevel().addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_BLOCK_END_PORTAL_FRAME_FILL);
        this.createPortal();
        return true;
    }
    return false;
}
 
Example #28
Source File: LevelSoundEventSound.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public DataPacket[] encode() {
    LevelSoundEventPacket pk = new LevelSoundEventPacket();
    pk.sound = this.type;
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.extraData = this.extraData;
    pk.pitch = this.pitch;

    return new DataPacket[]{pk};
}
 
Example #29
Source File: Level.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void addLevelSoundEvent(int type, int pitch, int data, Vector3 pos, boolean isGlobal) {
    LevelSoundEventPacket pk = new LevelSoundEventPacket();
    pk.sound = type;
    pk.pitch = pitch;
    pk.extraData = data;
    pk.x = (float) pos.x;
    pk.y = (float) pos.y;
    pk.z = (float) pos.z;
    pk.isGlobal = isGlobal;

    this.addChunkPacket(pos.getFloorX() >> 4, pos.getFloorZ() >> 4, pk);
}
 
Example #30
Source File: AnvilInventory.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean onRename(Player player, Item resultItem) {
    Item local = getItem(TARGET);
    Item second = getItem(SACRIFICE);

    if (!resultItem.equals(local, true, false) || resultItem.getCount() != local.getCount()) {
        //Item does not match target item. Everything must match except the tags.
        return false;
    }

    if (local.equals(resultItem)) {
        //just item transaction
        return true;
    }

    if (local.getId() != 0 && second.getId() == 0) { //only rename
        local.setCustomName(resultItem.getCustomName());
        setItem(RESULT, local);
        player.getInventory().addItem(local);
        clearAll();
        player.getInventory().sendContents(player);
        sendContents(player);

        player.getLevel().addLevelSoundEvent(player, LevelSoundEventPacket.SOUND_RANDOM_ANVIL_USE);
        return true;
    } else if (local.getId() != 0 && second.getId() != 0) { //enchants combining
        if (!local.equals(second, true, false)) {
            return false;
        }

        if (local.getId() != 0 && second.getId() != 0) {
            Item result = local.clone();
            int enchants = 0;

            ArrayList<Enchantment> enchantments = new ArrayList<>(Arrays.asList(second.getEnchantments()));

            ArrayList<Enchantment> baseEnchants = new ArrayList<>();

            for (Enchantment ench : local.getEnchantments()) {
                if (ench.isMajor()) {
                    baseEnchants.add(ench);
                }
            }

            for (Enchantment enchantment : enchantments) {
                if (enchantment.getLevel() < 0 || enchantment.getId() < 0) {
                    continue;
                }

                if (enchantment.isMajor()) {
                    boolean same = false;
                    boolean another = false;

                    for (Enchantment baseEnchant : baseEnchants) {
                        if (baseEnchant.getId() == enchantment.getId())
                            same = true;
                        else {
                            another = true;
                        }
                    }

                    if (!same && another) {
                        continue;
                    }
                }

                Enchantment localEnchantment = local.getEnchantment(enchantment.getId());

                if (localEnchantment != null) {
                    int level = Math.max(localEnchantment.getLevel(), enchantment.getLevel());

                    if (localEnchantment.getLevel() == enchantment.getLevel())
                        level++;

                    enchantment.setLevel(level);
                    result.addEnchantment(enchantment);
                    continue;
                }

                result.addEnchantment(enchantment);
                enchants++;
            }

            result.setCustomName(resultItem.getCustomName());

            player.getInventory().addItem(result);
            player.getInventory().sendContents(player);
            clearAll();
            sendContents(player);

            player.getLevel().addLevelSoundEvent(player, LevelSoundEventPacket.SOUND_RANDOM_ANVIL_USE);
            return true;
        }
    }

    return false;
}