Search in sources :

Example 1 with Direction

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));
                }
            }
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Player(org.spongepowered.api.entity.living.player.Player) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ItemStack(net.minecraft.item.ItemStack) Direction(org.spongepowered.api.util.Direction)

Example 2 with Direction

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);
        }
    }
}
Also used : Vector3i(com.flowpowered.math.vector.Vector3i) TextColor(org.spongepowered.api.text.format.TextColor) ItemStack(org.spongepowered.api.item.inventory.ItemStack) World(org.spongepowered.api.world.World) Direction(org.spongepowered.api.util.Direction) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Aggregations

Direction (org.spongepowered.api.util.Direction)2 Vector3i (com.flowpowered.math.vector.Vector3i)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 Player (org.spongepowered.api.entity.living.player.Player)1 Listener (org.spongepowered.api.event.Listener)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 TextColor (org.spongepowered.api.text.format.TextColor)1 Location (org.spongepowered.api.world.Location)1 World (org.spongepowered.api.world.World)1