Search in sources :

Example 11 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockDoor method blockInteract.

/**
     * Opens and closes the door when right-clicked by the player.
     */
@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    // handles opening and closing the door
    if (block.getType() == Material.IRON_DOOR_BLOCK) {
        return false;
    }
    GlowBlockState state = block.getState();
    MaterialData data = state.getData();
    if (data instanceof Door) {
        Door door = (Door) data;
        if (door.isTopHalf()) {
            door = null;
            block = block.getWorld().getBlockAt(block.getX(), block.getY() - 1, block.getZ());
            state = block.getState();
            data = state.getData();
            if (data instanceof Door) {
                door = (Door) data;
            }
        }
        if (door != null) {
            door.setOpen(!door.isOpen());
        }
        state.update(true);
    }
    return true;
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData) Door(org.bukkit.material.Door)

Example 12 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockDoublePlant method blockDestroy.

@Override
public void blockDestroy(GlowPlayer player, GlowBlock block, BlockFace face) {
    MaterialData data = block.getState().getData();
    if (data instanceof DoublePlant) {
        DoublePlantSpecies species = ((DoublePlant) data).getSpecies();
        if (species == DoublePlantSpecies.PLANT_APEX) {
            GlowBlock blockUnder = block.getRelative(BlockFace.DOWN);
            if (!(blockUnder.getState().getData() instanceof DoublePlant)) {
                return;
            }
            blockUnder.setType(Material.AIR);
        } else {
            GlowBlock blockTop = block.getRelative(BlockFace.UP);
            if (!(blockTop.getState().getData() instanceof DoublePlant)) {
                return;
            }
            blockTop.setType(Material.AIR);
        }
    } else {
        warnMaterialData(DoublePlant.class, data);
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) DoublePlantSpecies(org.bukkit.material.types.DoublePlantSpecies) MaterialData(org.bukkit.material.MaterialData) DoublePlant(org.bukkit.material.DoublePlant)

Example 13 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockDoublePlant method canAbsorb.

@Override
public boolean canAbsorb(GlowBlock block, BlockFace face, ItemStack holding) {
    MaterialData data = block.getState().getData();
    BlockType holdingType = ItemTable.instance().getBlock(holding.getType());
    if (data instanceof DoublePlant) {
        DoublePlantSpecies species = ((DoublePlant) data).getSpecies();
        if (species == DoublePlantSpecies.DOUBLE_TALLGRASS || species == DoublePlantSpecies.LARGE_FERN) {
            if (holdingType != null && holdingType.canPlaceAt(block, face)) {
                block.getRelative(BlockFace.UP).setType(Material.AIR, (byte) 0, false);
            }
            return true;
        }
        if (species == DoublePlantSpecies.PLANT_APEX) {
            GlowBlock under = block.getRelative(BlockFace.DOWN);
            MaterialData underData = under.getState().getData();
            if (underData instanceof DoublePlant) {
                DoublePlantSpecies underSpecies = ((DoublePlant) underData).getSpecies();
                if (underSpecies == DoublePlantSpecies.DOUBLE_TALLGRASS || underSpecies == DoublePlantSpecies.LARGE_FERN) {
                    if (holdingType != null && holdingType.canPlaceAt(block, face)) {
                        under.setType(Material.AIR, (byte) 0, false);
                    }
                    return true;
                }
            }
        }
    } else {
        warnMaterialData(DoublePlant.class, data);
    }
    return false;
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) DoublePlantSpecies(org.bukkit.material.types.DoublePlantSpecies) MaterialData(org.bukkit.material.MaterialData) DoublePlant(org.bukkit.material.DoublePlant)

Example 14 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockEnderChest 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 EnderChest) {
        ((EnderChest) data).setFacingDirection(getOppositeBlockFace(player.getLocation(), false));
        state.setData(data);
    } else {
        warnMaterialData(EnderChest.class, data);
    }
}
Also used : MaterialData(org.bukkit.material.MaterialData) EnderChest(org.bukkit.material.EnderChest)

Example 15 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockLever method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    GlowBlockState state = block.getState();
    MaterialData data = state.getData();
    if (!(data instanceof Lever)) {
        warnMaterialData(Lever.class, data);
        return false;
    }
    Lever lever = (Lever) data;
    lever.setPowered(!lever.isPowered());
    block.getWorld().playSound(block.getLocation(), Sound.BLOCK_LEVER_CLICK, 0.3F, lever.isPowered() ? 0.6F : 0.5F);
    state.update();
    extraUpdate(block);
    return true;
}
Also used : Lever(org.bukkit.material.Lever) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData)

Aggregations

MaterialData (org.bukkit.material.MaterialData)75 GlowBlockState (net.glowstone.block.GlowBlockState)20 BlockState (org.bukkit.block.BlockState)12 GlowBlock (net.glowstone.block.GlowBlock)10 Material (org.bukkit.Material)10 Block (org.bukkit.block.Block)9 BlockFace (org.bukkit.block.BlockFace)9 ItemStack (org.bukkit.inventory.ItemStack)8 DoublePlant (org.bukkit.material.DoublePlant)6 Bed (org.bukkit.material.Bed)5 GlowDispenser (net.glowstone.block.state.GlowDispenser)3 BlockFadeEvent (org.bukkit.event.block.BlockFadeEvent)3 BlockGrowEvent (org.bukkit.event.block.BlockGrowEvent)3 CocoaPlant (org.bukkit.material.CocoaPlant)3 Dispenser (org.bukkit.material.Dispenser)3 ArrayList (java.util.ArrayList)2 GlowWorld (net.glowstone.GlowWorld)2 GlowFlowerPot (net.glowstone.block.state.GlowFlowerPot)2 GlowSkull (net.glowstone.block.state.GlowSkull)2 Location (org.bukkit.Location)2