Search in sources :

Example 56 with MaterialData

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

the class BlockButton 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 Button)) {
        warnMaterialData(Button.class, data);
        return false;
    }
    Button button = (Button) data;
    if (button.isPowered()) {
        return true;
    }
    button.setPowered(true);
    state.update();
    extraUpdate(block);
    // todo: switch to block scheduling system when one is available
    new BukkitRunnable() {

        @Override
        public void run() {
            button.setPowered(false);
            state.update();
            if (block.getType() == Material.WOOD_BUTTON || block.getType() == Material.STONE_BUTTON) {
                extraUpdate(block);
                block.getWorld().playSound(block.getLocation(), block.getType() == Material.WOOD_BUTTON ? Sound.BLOCK_WOOD_BUTTON_CLICK_OFF : Sound.BLOCK_STONE_BUTTON_CLICK_OFF, 0.3f, 0.5f);
            }
        }
    }.runTaskLater(null, block.getType() == Material.STONE_BUTTON ? 20 : 30);
    return true;
}
Also used : Button(org.bukkit.material.Button) GlowBlockState(net.glowstone.block.GlowBlockState) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) MaterialData(org.bukkit.material.MaterialData)

Example 57 with MaterialData

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

the class BlockBanner 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 Banner)) {
        warnMaterialData(Banner.class, data);
        return;
    }
    Banner banner = (Banner) data;
    if (banner.isWallBanner()) {
        banner.setFacingDirection(face);
    } else {
        banner.setFacingDirection(player.getFacing().getOppositeFace());
    }
}
Also used : GlowBanner(net.glowstone.block.state.GlowBanner) Banner(org.bukkit.material.Banner) MaterialData(org.bukkit.material.MaterialData)

Example 58 with MaterialData

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

the class BlockBed method getHead.

/**
     * Returns the head of a bed given one of its blocks.
     *
     * @param block part of the bed
     * @return The head of the bed
     */
public static GlowBlock getHead(GlowBlock block) {
    MaterialData data = block.getState().getData();
    if (!(data instanceof Bed)) {
        return null;
    }
    Bed bed = (Bed) data;
    if (bed.isHeadOfBed()) {
        return block;
    } else {
        return block.getRelative(bed.getFacing());
    }
}
Also used : Bed(org.bukkit.material.Bed) MaterialData(org.bukkit.material.MaterialData)

Example 59 with MaterialData

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

the class BlockBed method afterPlace.

@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
    if (block.getType() == Material.BED_BLOCK) {
        BlockFace direction = ((Bed) block.getState().getData()).getFacing();
        GlowBlock headBlock = block.getRelative(direction);
        headBlock.setType(Material.BED_BLOCK);
        GlowBlockState headBlockState = headBlock.getState();
        MaterialData data = headBlockState.getData();
        ((Bed) data).setHeadOfBed(true);
        ((Bed) data).setFacingDirection(direction);
        headBlockState.setData(data);
        headBlockState.update(true);
    }
}
Also used : Bed(org.bukkit.material.Bed) GlowBlock(net.glowstone.block.GlowBlock) BlockFace(org.bukkit.block.BlockFace) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData)

Example 60 with MaterialData

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

the class BlockBed method getFoot.

/**
     * Returns the foot of a bed given one of its blocks.
     *
     * @param block part of the bed
     * @return The foot of the bed
     */
public static GlowBlock getFoot(GlowBlock block) {
    MaterialData data = block.getState().getData();
    if (!(data instanceof Bed)) {
        return null;
    }
    Bed bed = (Bed) data;
    if (bed.isHeadOfBed()) {
        return block.getRelative(bed.getFacing().getOppositeFace());
    } else {
        return block;
    }
}
Also used : Bed(org.bukkit.material.Bed) MaterialData(org.bukkit.material.MaterialData)

Aggregations

MaterialData (org.bukkit.material.MaterialData)93 GlowBlockState (net.glowstone.block.GlowBlockState)20 ItemStack (org.bukkit.inventory.ItemStack)20 Material (org.bukkit.Material)13 Block (org.bukkit.block.Block)12 BlockState (org.bukkit.block.BlockState)12 GlowBlock (net.glowstone.block.GlowBlock)10 BlockFace (org.bukkit.block.BlockFace)10 MyPetBaby (de.Keyle.MyPet.api.entity.MyPetBaby)9 TagCompound (de.keyle.knbt.TagCompound)9 ArrayList (java.util.ArrayList)6 DoublePlant (org.bukkit.material.DoublePlant)6 Bed (org.bukkit.material.Bed)5 IOException (java.io.IOException)3 GlowDispenser (net.glowstone.block.state.GlowDispenser)3 Location (org.bukkit.Location)3 Player (org.bukkit.entity.Player)3 CocoaPlant (org.bukkit.material.CocoaPlant)3 Dispenser (org.bukkit.material.Dispenser)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3