Search in sources :

Example 96 with BlockFace

use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.

the class BlockLiquid method updatePhysicsAfterEvent.

@Override
public void updatePhysicsAfterEvent(GlowBlock me) {
    super.updatePhysicsAfterEvent(me);
    if (isStationary(me.getType())) {
    // TODO: set flowing
    // me.setType(getOpposite(me.getType()), me.getData(), false);
    }
    boolean isWater = isWater(me.getType());
    if (me.getState().getRawData() != STRENGTH_SOURCE) {
        BlockFace[] faces = { UP, NORTH, EAST, SOUTH, WEST };
        boolean connected = false;
        int count = 0;
        for (BlockFace face : faces) {
            if (me.getRelative(face).getType() == me.getType()) {
                if (isWater && count < 2 && face != UP && me.getRelative(face).getState().getRawData() == STRENGTH_SOURCE) {
                    count++;
                }
                if (!connected && face == UP || me.getRelative(face).getState().getRawData() < me.getState().getRawData()) {
                    connected = true;
                    if (me.getWorld().getServer().getClassicWater()) {
                        me.getState().setRawData(STRENGTH_SOURCE);
                    }
                }
                if (me.getWorld().getServer().getClassicWater() && me.getRelative(face).getState().getRawData() == STRENGTH_SOURCE) {
                    me.getRelative(face).setType(Material.AIR);
                }
            }
        }
        if (!connected) {
            me.setType(Material.AIR);
            return;
        }
        if (count == 2) {
            me.getState().setRawData(STRENGTH_SOURCE);
            return;
        }
    }
    if (!(me.getState().getRawData() == (isWater || me.getWorld().getEnvironment() == World.Environment.NETHER ? STRENGTH_MIN_WATER : STRENGTH_MIN_LAVA)) || me.getRelative(DOWN).getType() == Material.AIR) {
        calculateFlow(me);
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace)

Example 97 with BlockFace

use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.

the class BlockNeedsAttached method updatePhysicsAfterEvent.

@Override
public void updatePhysicsAfterEvent(GlowBlock me) {
    super.updatePhysicsAfterEvent(me);
    BlockFace attachedTo = getAttachedFace(me);
    if (attachedTo == null) {
        return;
    }
    if (me.getRelative(attachedTo).getType() == Material.AIR || !canPlaceAt(null, me, attachedTo.getOppositeFace())) {
        dropMe(me);
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace)

Example 98 with BlockFace

use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.

the class BlockButton method extraUpdate.

private void extraUpdate(GlowBlock block) {
    Button button = (Button) block.getState().getData();
    ItemTable itemTable = ItemTable.instance();
    GlowBlock target = block.getRelative(button.getAttachedFace());
    if (target.getType().isSolid()) {
        for (BlockFace face2 : ADJACENT) {
            GlowBlock target2 = target.getRelative(face2);
            BlockType notifyType = itemTable.getBlock(target2.getType());
            if (notifyType != null) {
                if (target2.getFace(block) == null) {
                    notifyType.onNearBlockChanged(target2, BlockFace.SELF, block, block.getType(), block.getData(), block.getType(), block.getData());
                }
                notifyType.onRedstoneUpdate(target2);
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) Button(org.bukkit.material.Button) ItemTable(net.glowstone.block.ItemTable) BlockFace(org.bukkit.block.BlockFace)

Example 99 with BlockFace

use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.

the class BlockFence method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    super.blockInteract(player, block, face, clickedLoc);
    if (!player.getLeashedEntities().isEmpty()) {
        LeashHitch leashHitch = GlowLeashHitch.getLeashHitchAt(block);
        ImmutableList.copyOf(player.getLeashedEntities()).stream().filter(e -> !(EventFactory.getInstance().callEvent(new PlayerLeashEntityEvent(e, leashHitch, player)).isCancelled())).forEach(e -> e.setLeashHolder(leashHitch));
        return true;
    }
    return false;
}
Also used : Vector(org.bukkit.util.Vector) GlowBlock(net.glowstone.block.GlowBlock) ImmutableList(com.google.common.collect.ImmutableList) GlowLeashHitch(net.glowstone.entity.objects.GlowLeashHitch) MaterialMatcher(net.glowstone.inventory.MaterialMatcher) EventFactory(net.glowstone.EventFactory) PlayerLeashEntityEvent(org.bukkit.event.entity.PlayerLeashEntityEvent) GlowPlayer(net.glowstone.entity.GlowPlayer) BlockFace(org.bukkit.block.BlockFace) LeashHitch(org.bukkit.entity.LeashHitch) Material(org.bukkit.Material) PlayerLeashEntityEvent(org.bukkit.event.entity.PlayerLeashEntityEvent) GlowLeashHitch(net.glowstone.entity.objects.GlowLeashHitch) LeashHitch(org.bukkit.entity.LeashHitch)

Example 100 with BlockFace

use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.

the class BlockDirectional method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);
    // the direction of the block
    BlockFace faceHead = calculateFace(player, state);
    state.setRawData((byte) getRawFace(opposite ? faceHead.getOppositeFace() : faceHead));
}
Also used : BlockFace(org.bukkit.block.BlockFace)

Aggregations

BlockFace (org.bukkit.block.BlockFace)136 Block (org.bukkit.block.Block)53 GlowBlock (net.glowstone.block.GlowBlock)32 Location (org.bukkit.Location)23 Material (org.bukkit.Material)23 Vector (org.bukkit.util.Vector)18 ArrayList (java.util.ArrayList)12 ItemStack (org.bukkit.inventory.ItemStack)12 Sign (org.bukkit.block.Sign)10 BlockState (org.bukkit.block.BlockState)9 EventHandler (org.bukkit.event.EventHandler)8 MaterialData (org.bukkit.material.MaterialData)8 List (java.util.List)7 ItemTable (net.glowstone.block.ItemTable)7 Player (org.bukkit.entity.Player)7 GlowBlockState (net.glowstone.block.GlowBlockState)6 GlowPlayer (net.glowstone.entity.GlowPlayer)6 UUID (java.util.UUID)5 BlockType (net.glowstone.block.blocktype.BlockType)5 PulseTask (net.glowstone.scheduler.PulseTask)5