Search in sources :

Example 1 with Tripwire

use of org.bukkit.block.data.type.Tripwire in project oraxen by oraxen.

the class StringBlockMechanicListener method getHardnessModifier.

private HardnessModifier getHardnessModifier() {
    return new HardnessModifier() {

        @Override
        public boolean isTriggered(final Player player, final Block block, final ItemStack tool) {
            if (block.getType() != Material.TRIPWIRE)
                return false;
            final Tripwire tripwire = (Tripwire) block.getBlockData();
            final int code = StringBlockMechanicFactory.getCode(tripwire);
            final StringBlockMechanic tripwireMechanic = StringBlockMechanicFactory.getBlockMechanic(code);
            return tripwireMechanic != null && tripwireMechanic.hasHardness;
        }

        @Override
        public void breakBlock(final Player player, final Block block, final ItemStack tool) {
            block.setType(Material.AIR);
        }

        @Override
        public long getPeriod(final Player player, final Block block, final ItemStack tool) {
            final Tripwire tripwire = (Tripwire) block.getBlockData();
            final StringBlockMechanic tripwireMechanic = StringBlockMechanicFactory.getBlockMechanic(StringBlockMechanicFactory.getCode(tripwire));
            final long period = tripwireMechanic.getPeriod();
            double modifier = 1;
            if (tripwireMechanic.getDrop().canDrop(tool)) {
                modifier *= 0.4;
                final int diff = tripwireMechanic.getDrop().getDiff(tool);
                if (diff >= 1)
                    modifier *= Math.pow(0.9, diff);
            }
            return (long) (period * modifier);
        }
    };
}
Also used : Player(org.bukkit.entity.Player) HardnessModifier(io.th0rgal.oraxen.utils.breaker.HardnessModifier) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) Tripwire(org.bukkit.block.data.type.Tripwire)

Example 2 with Tripwire

use of org.bukkit.block.data.type.Tripwire in project oraxen by oraxen.

the class StringBlockMechanicListener method onBreakingCustomBlock.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBreakingCustomBlock(final BlockBreakEvent event) {
    final Block block = event.getBlock();
    if (block.getType() != Material.TRIPWIRE || event.isCancelled() || !event.isDropItems())
        return;
    final Tripwire tripwire = (Tripwire) block.getBlockData();
    final StringBlockMechanic stringBlockMechanic = StringBlockMechanicFactory.getBlockMechanic(StringBlockMechanicFactory.getCode(tripwire));
    if (stringBlockMechanic == null)
        return;
    if (stringBlockMechanic.hasBreakSound())
        block.getWorld().playSound(block.getLocation(), stringBlockMechanic.getBreakSound(), 1.0f, 0.8f);
    if (stringBlockMechanic.getLight() != -1)
        WrappedLightAPI.removeBlockLight(block.getLocation());
    stringBlockMechanic.getDrop().spawns(block.getLocation(), event.getPlayer().getInventory().getItemInMainHand());
    event.setDropItems(false);
}
Also used : Block(org.bukkit.block.Block) Tripwire(org.bukkit.block.data.type.Tripwire) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Tripwire

use of org.bukkit.block.data.type.Tripwire in project oraxen by oraxen.

the class StringBlockMechanicFactory method createTripwireData.

/**
 * Generate a Tripwire blockdata from its id
 *
 * @param code The block id.
 */
public static BlockData createTripwireData(final int code) {
    Tripwire data = ((Tripwire) Bukkit.createBlockData(Material.TRIPWIRE));
    int i = 0;
    for (BlockFace face : new BlockFace[] { BlockFace.EAST, BlockFace.WEST, BlockFace.SOUTH, BlockFace.NORTH }) data.setFace(face, (code & 0x1 << i++) != 0);
    data.setAttached((code & 0x1 << i++) != 0);
    data.setDisarmed((code & 0x1 << i++) != 0);
    data.setPowered((code & 0x1 << i) != 0);
    return data;
}
Also used : BlockFace(org.bukkit.block.BlockFace) Tripwire(org.bukkit.block.data.type.Tripwire)

Aggregations

Tripwire (org.bukkit.block.data.type.Tripwire)3 Block (org.bukkit.block.Block)2 HardnessModifier (io.th0rgal.oraxen.utils.breaker.HardnessModifier)1 BlockFace (org.bukkit.block.BlockFace)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 ItemStack (org.bukkit.inventory.ItemStack)1