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