Search in sources :

Example 56 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockStateDelegate method backupBlockState.

/**
 * Backups a block state.
 *
 * @param block the block which state should be backup
 */
public void backupBlockState(Block block) {
    blockStateMap.remove(block.getLocation());
    blockStateBackupMap.put(block.getLocation(), new GlowBlockState((GlowBlock) block));
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowBlockState(net.glowstone.block.GlowBlockState)

Example 57 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockStateDelegate method setTypeAndData.

/**
     * Sets a block type and MaterialData, and add it to the BlockState list.
     *
     * @param world the world which contains the block
     * @param x     the x-coordinate of this block
     * @param y     the y-coordinate of this block
     * @param z     the z-coordinate of this block
     * @param type  the new type of this block
     * @param data  the new MaterialData of this block
     */
public void setTypeAndData(World world, int x, int y, int z, Material type, MaterialData data) {
    GlowBlockState state = (GlowBlockState) world.getBlockAt(x, y, z).getState();
    state.setType(type);
    state.setData(data);
    blockStateMap.put(world.getBlockAt(x, y, z).getLocation(), state);
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState)

Example 58 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockStateDelegate method setTypeAndRawData.

/**
     * Sets a block type, data and add it to the BlockState list.
     *
     * @param world the world which contains the block
     * @param x     the x-coordinate of this block
     * @param y     the y-coordinate of this block
     * @param z     the z-coordinate of this block
     * @param type  the new type of this block
     * @param data  the new data value of this block
     */
public void setTypeAndRawData(World world, int x, int y, int z, Material type, int data) {
    GlowBlockState state = (GlowBlockState) world.getBlockAt(x, y, z).getState();
    state.setType(type);
    state.setRawData((byte) data);
    blockStateMap.put(world.getBlockAt(x, y, z).getLocation(), state);
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState)

Example 59 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockSoil method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    if (isNearWater(block) || GlowBiomeClimate.isRainy(block)) {
        // set this block as fully wet
        block.setData((byte) 7);
    } else if (block.getData() > 0) {
        // if this block is wet, it becomes less wet
        block.setData((byte) (block.getData() - 1));
    } else if (!Arrays.asList(possibleCrops).contains(block.getRelative(BlockFace.UP).getType())) {
        // turns block back to dirt if nothing is planted on
        GlowBlockState state = block.getState();
        state.setType(Material.DIRT);
        state.setRawData((byte) 0);
        BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state);
        EventFactory.callEvent(fadeEvent);
        if (!fadeEvent.isCancelled()) {
            state.update(true);
        }
    }
}
Also used : BlockFadeEvent(org.bukkit.event.block.BlockFadeEvent) GlowBlockState(net.glowstone.block.GlowBlockState)

Example 60 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class ItemSeeds method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc) {
    if (target.getType() == soilType && target.getRelative(BlockFace.UP).getType() == Material.AIR && face == BlockFace.UP) {
        GlowBlockState state = target.getRelative(BlockFace.UP).getState();
        state.setType(cropsType);
        state.setRawData((byte) 0);
        state.update(true);
        // deduct from stack if not in creative mode
        if (player.getGameMode() != GameMode.CREATIVE) {
            holding.setAmount(holding.getAmount() - 1);
        }
    }
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState)

Aggregations

GlowBlockState (net.glowstone.block.GlowBlockState)60 GlowBlock (net.glowstone.block.GlowBlock)23 MaterialData (org.bukkit.material.MaterialData)20 BlockGrowEvent (org.bukkit.event.block.BlockGrowEvent)11 GlowWorld (net.glowstone.GlowWorld)10 BlockFadeEvent (org.bukkit.event.block.BlockFadeEvent)8 BlockFace (org.bukkit.block.BlockFace)6 Material (org.bukkit.Material)5 BlockSpreadEvent (org.bukkit.event.block.BlockSpreadEvent)5 ItemStack (org.bukkit.inventory.ItemStack)5 BlockType (net.glowstone.block.blocktype.BlockType)3 ItemType (net.glowstone.block.itemtype.ItemType)3 Block (org.bukkit.block.Block)3 Dispenser (org.bukkit.material.Dispenser)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 BlockEntity (net.glowstone.block.entity.BlockEntity)2 GlowDispenser (net.glowstone.block.entity.state.GlowDispenser)2 GlowFlowerPot (net.glowstone.block.entity.state.GlowFlowerPot)2 BlockBoundingBox (net.glowstone.entity.physics.BlockBoundingBox)2 Entity (org.bukkit.entity.Entity)2