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);
}
};
}
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);
}
};
}