Search in sources :

Example 1 with HardnessModifier

use of io.th0rgal.oraxen.utils.breaker.HardnessModifier 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 HardnessModifier

use of io.th0rgal.oraxen.utils.breaker.HardnessModifier in project oraxen by oraxen.

the class NoteBlockMechanicListener method getHardnessModifier.

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

        @Override
        @SuppressWarnings("deprecation")
        public boolean isTriggered(final Player player, final Block block, final ItemStack tool) {
            if (block.getType() != Material.NOTE_BLOCK)
                return false;
            final NoteBlock noteBlok = (NoteBlock) block.getBlockData();
            final int code = (int) (noteBlok.getInstrument().getType()) * 25 + (int) noteBlok.getNote().getId() + (noteBlok.isPowered() ? 400 : 0) - 26;
            final NoteBlockMechanic noteBlockMechanic = NoteBlockMechanicFactory.getBlockMechanic(code);
            return noteBlockMechanic != null && noteBlockMechanic.hasHardness;
        }

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

        @SuppressWarnings("deprecation")
        @Override
        public long getPeriod(final Player player, final Block block, final ItemStack tool) {
            final NoteBlock noteBlok = (NoteBlock) block.getBlockData();
            final NoteBlockMechanic noteBlockMechanic = NoteBlockMechanicFactory.getBlockMechanic((int) (noteBlok.getInstrument().getType()) * 25 + (int) noteBlok.getNote().getId() + (noteBlok.isPowered() ? 400 : 0) - 26);
            final long period = noteBlockMechanic.getPeriod();
            double modifier = 1;
            if (noteBlockMechanic.getDrop().canDrop(tool)) {
                modifier *= 0.4;
                final int diff = noteBlockMechanic.getDrop().getDiff(tool);
                if (diff >= 1)
                    modifier *= Math.pow(0.9, diff);
            }
            return (long) (period * modifier);
        }
    };
}
Also used : Player(org.bukkit.entity.Player) NoteBlock(org.bukkit.block.data.type.NoteBlock) HardnessModifier(io.th0rgal.oraxen.utils.breaker.HardnessModifier) Block(org.bukkit.block.Block) NoteBlock(org.bukkit.block.data.type.NoteBlock) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

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