Search in sources :

Example 81 with BlockState

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

the class BlockChest method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    BlockState state = block.getState();
    if (state instanceof org.bukkit.block.Chest) {
        org.bukkit.block.Chest chest = (org.bukkit.block.Chest) state;
        player.openInventory(chest.getInventory());
        player.incrementStatistic(Statistic.CHEST_OPENED);
        return true;
    }
    ConsoleMessages.Warn.Block.Chest.INTERACT_WRONG_CLASS.log(state);
    return false;
}
Also used : Chest(org.bukkit.material.Chest) BlockState(org.bukkit.block.BlockState) GlowBlockState(net.glowstone.block.GlowBlockState)

Example 82 with BlockState

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

the class BlockChest method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);
    MaterialData data = state.getData();
    if (data instanceof Chest) {
        Chest chest = (Chest) data;
        GlowBlock chestBlock = state.getBlock();
        BlockFace normalFacing = getOppositeBlockFace(player.getLocation(), false);
        Collection<BlockFace> attachedChests = searchChests(chestBlock);
        switch(attachedChests.size()) {
            case 0:
                chest.setFacingDirection(normalFacing);
                state.setData(chest);
                return;
            case 1:
                break;
            default:
                ConsoleMessages.Warn.Block.Chest.TRIPLE_MIDDLE.log();
                return;
        }
        BlockFace otherPart = attachedChests.iterator().next();
        GlowBlock otherPartBlock = chestBlock.getRelative(otherPart);
        if (getAttachedChest(otherPartBlock) != null) {
            ConsoleMessages.Warn.Block.Chest.TRIPLE_END.log();
            return;
        }
        BlockState otherPartState = otherPartBlock.getState();
        MaterialData otherPartData = otherPartState.getData();
        if (otherPartData instanceof Chest) {
            Chest otherChest = (Chest) otherPartData;
            BlockFace facing = getFacingDirection(normalFacing, otherChest.getFacing(), otherPart, player);
            chest.setFacingDirection(facing);
            state.setData(chest);
            otherChest.setFacingDirection(facing);
            otherPartState.setData(otherChest);
            otherPartState.update();
        } else {
            warnMaterialData(Chest.class, otherPartData);
        }
    } else {
        warnMaterialData(Chest.class, data);
    }
}
Also used : Chest(org.bukkit.material.Chest) GlowBlock(net.glowstone.block.GlowBlock) BlockState(org.bukkit.block.BlockState) GlowBlockState(net.glowstone.block.GlowBlockState) BlockFace(org.bukkit.block.BlockFace) MaterialData(org.bukkit.material.MaterialData)

Example 83 with BlockState

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

the class BlockEnderPortalFrame method createPortal.

/**
 * Spawn the portal and call the {@link EntityCreatePortalEvent}.
 */
private void createPortal(GlowPlayer player, GlowBlock center) {
    List<BlockState> blocks = new ArrayList<>(9);
    for (int i = -1; i <= 1; i++) {
        for (int j = -1; j <= 1; j++) {
            BlockState state = center.getRelative(i, 0, j).getState();
            state.setType(Material.END_PORTAL);
            blocks.add(state);
        }
    }
    if (!EventFactory.getInstance().callEvent(new EntityCreatePortalEvent(player, blocks, PortalType.ENDER)).isCancelled()) {
        for (BlockState state : blocks) {
            state.update(true);
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) GlowBlockState(net.glowstone.block.GlowBlockState) ArrayList(java.util.ArrayList) EntityCreatePortalEvent(org.bukkit.event.entity.EntityCreatePortalEvent)

Example 84 with BlockState

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

the class BlockSapling method generateTree.

private void generateTree(TreeType type, GlowBlock block, GlowPlayer player) {
    // get data but filters sapling age
    int data = block.getData() & 0x7;
    // replaces the sapling block(s)
    block.setType(Material.AIR);
    if (type == TreeType.JUNGLE || type == TreeType.MEGA_REDWOOD || type == TreeType.DARK_OAK) {
        block.getRelative(BlockFace.SOUTH).setType(Material.AIR);
        block.getRelative(BlockFace.EAST).setType(Material.AIR);
        block.getRelative(BlockFace.SOUTH_EAST).setType(Material.AIR);
    }
    // try to generate a tree
    Location loc = block.getLocation();
    BlockStateDelegate blockStateDelegate = new BlockStateDelegate();
    boolean canGrow = false;
    if (GlowTree.newInstance(type, ThreadLocalRandom.current(), blockStateDelegate).generate(loc)) {
        List<BlockState> blockStates = new ArrayList<>(blockStateDelegate.getBlockStates());
        StructureGrowEvent growEvent = new StructureGrowEvent(loc, type, player != null, player, blockStates);
        EventFactory.getInstance().callEvent(growEvent);
        if (!growEvent.isCancelled()) {
            canGrow = true;
            for (BlockState state : blockStates) {
                state.update(true);
            }
        }
    }
    if (!canGrow) {
        // places the sapling block(s) back if the tree was not generated
        // the sapling ages are overwritten but this is an expected
        // vanilla behavior
        // TODO: 1.13 sapling types
        block.setType(Material.LEGACY_SAPLING);
        block.setData((byte) data);
        if (type == TreeType.JUNGLE || type == TreeType.MEGA_REDWOOD || type == TreeType.DARK_OAK) {
            block.getRelative(BlockFace.SOUTH).setType(Material.LEGACY_SAPLING);
            block.getRelative(BlockFace.SOUTH).setData((byte) data);
            block.getRelative(BlockFace.EAST).setType(Material.LEGACY_SAPLING);
            block.getRelative(BlockFace.EAST).setData((byte) data);
            block.getRelative(BlockFace.SOUTH_EAST).setType(Material.LEGACY_SAPLING);
            block.getRelative(BlockFace.SOUTH_EAST).setData((byte) data);
        }
    }
}
Also used : BlockStateDelegate(net.glowstone.util.BlockStateDelegate) BlockState(org.bukkit.block.BlockState) ArrayList(java.util.ArrayList) StructureGrowEvent(org.bukkit.event.world.StructureGrowEvent) Location(org.bukkit.Location)

Example 85 with BlockState

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

the class GlowstoneDecorator method decorate.

@Override
public void decorate(World world, Random random, Chunk source) {
    int amount = variableAmount ? 1 + random.nextInt(1 + random.nextInt(10)) : 10;
    for (int i = 0; i < amount; i++) {
        int sourceX = (source.getX() << 4) + random.nextInt(16);
        int sourceZ = (source.getZ() << 4) + random.nextInt(16);
        int sourceY = 4 + random.nextInt(120);
        Block block = world.getBlockAt(sourceX, sourceY, sourceZ);
        if (!block.isEmpty() || block.getRelative(BlockFace.UP).getType() != Material.NETHERRACK) {
            continue;
        }
        BlockState state = block.getState();
        state.setType(Material.GLOWSTONE);
        state.update(true);
        for (int j = 0; j < 1500; j++) {
            int x = sourceX + random.nextInt(8) - random.nextInt(8);
            int z = sourceZ + random.nextInt(8) - random.nextInt(8);
            int y = sourceY - random.nextInt(12);
            block = world.getBlockAt(x, y, z);
            if (!block.isEmpty()) {
                continue;
            }
            int glowstoneBlockCount = 0;
            for (BlockFace face : SIDES) {
                if (block.getRelative(face).getType() == Material.GLOWSTONE) {
                    glowstoneBlockCount++;
                }
            }
            if (glowstoneBlockCount == 1) {
                state = block.getState();
                state.setType(Material.GLOWSTONE);
                state.update(true);
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block)

Aggregations

BlockState (org.bukkit.block.BlockState)127 Block (org.bukkit.block.Block)54 EventHandler (org.bukkit.event.EventHandler)35 Sign (org.bukkit.block.Sign)17 Location (org.bukkit.Location)16 World (org.bukkit.World)15 InventoryHolder (org.bukkit.inventory.InventoryHolder)14 Material (org.bukkit.Material)13 MaterialData (org.bukkit.material.MaterialData)13 ItemStack (org.bukkit.inventory.ItemStack)11 ArrayList (java.util.ArrayList)10 CreatureSpawner (org.bukkit.block.CreatureSpawner)10 Player (org.bukkit.entity.Player)10 BlockFace (org.bukkit.block.BlockFace)9 BlockStateChangeImpl (me.botsko.prism.events.BlockStateChangeImpl)7 Vector (org.bukkit.util.Vector)7 ChangeResultImpl (me.botsko.prism.appliers.ChangeResultImpl)5 Chunk (org.bukkit.Chunk)5 CommandBlock (org.bukkit.block.CommandBlock)5 Skull (org.bukkit.block.Skull)5