use of org.spongepowered.api.util.Direction in project Skree by Skelril.
the class CustomTerragu method process.
public void process(ChangeBlockEvent.Break event) {
if (event.getTransactions().size() > 1) {
return;
}
Optional<Player> optPlayer = event.getCause().first(Player.class);
if (optPlayer.isPresent()) {
Player player = optPlayer.get();
Optional<Direction> optClickedDir = Optional.ofNullable(clickMap.get(player));
Optional<org.spongepowered.api.item.inventory.ItemStack> optStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (optStack.isPresent() && optClickedDir.isPresent()) {
if (optStack.get().getItem() == this) {
ItemStack stack = tf(optStack.get());
for (Transaction<BlockSnapshot> snapshot : event.getTransactions()) {
if (!snapshot.getOriginal().getLocation().isPresent()) {
return;
}
int maxDist = getMaxEditDist(stack);
int dmg = destroyLine(player, optClickedDir.get(), maxDist - 1, snapshot.getOriginal());
stack.damageItem(dmg, tf(player));
player.setItemInHand(HandTypes.MAIN_HAND, tf(stack));
}
}
}
}
}
use of org.spongepowered.api.util.Direction in project Skree by Skelril.
the class Luminositor method onRightClick.
@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (optHeldItem.isPresent()) /* && optClickedPosition.isPresent() */
{
if (this.equals(optHeldItem.get().getItem())) {
Direction dir = event.getTargetSide();
Optional<Location<World>> optTargetBlockLoc = event.getTargetBlock().getLocation();
if (!optTargetBlockLoc.isPresent()) {
return;
}
Location<World> targetBlockLoc = optTargetBlockLoc.get();
Vector3i targPos = targetBlockLoc.getBlockPosition().add(dir.toVector3d().toInt());
Location<World> trueTargBlock = new Location<>(targetBlockLoc.getExtent(), targPos);
int lightLevel = LightLevelUtil.getMaxLightLevel(trueTargBlock).get();
TextColor color;
if (lightLevel >= 12) {
color = TextColors.GREEN;
} else if (lightLevel >= 8) {
color = TextColors.RED;
} else {
color = TextColors.DARK_RED;
}
// TODO system message.color(color)
player.sendMessage(Text.of(TextColors.YELLOW, "Light level: ", color, lightLevel));
event.setUseBlockResult(Tristate.FALSE);
}
}
}
Aggregations