Search in sources :

Example 36 with MaterialData

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

the class BlockRedstoneRepeater 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 Diode) {
        ((Diode) data).setFacingDirection(player.getDirection());
        state.setData(data);
    } else {
        warnMaterialData(Diode.class, data);
    }
    state.getWorld().requestPulse(state.getBlock());
}
Also used : Diode(org.bukkit.material.Diode) MaterialData(org.bukkit.material.MaterialData)

Example 37 with MaterialData

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

the class BlockRedstoneTorch 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 RedstoneTorch) {
        ((RedstoneTorch) data).setFacingDirection(face);
    } else {
        warnMaterialData(RedstoneTorch.class, data);
    }
}
Also used : RedstoneTorch(org.bukkit.material.RedstoneTorch) SimpleAttachableMaterialData(org.bukkit.material.SimpleAttachableMaterialData) MaterialData(org.bukkit.material.MaterialData)

Example 38 with MaterialData

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

the class BlockSapling method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    if (block.getRelative(BlockFace.UP).getLightLevel() >= 9 && random.nextInt(7) == 0) {
        int dataValue = block.getData();
        if ((dataValue & 8) == 0) {
            block.setData((byte) (dataValue | 8));
        } else {
            MaterialData data = block.getState().getData();
            if (data instanceof Sapling) {
                Sapling sapling = (Sapling) data;
                TreeType type = getTreeType(sapling.getSpecies());
                block.setType(Material.AIR);
                int saplingData = block.getData() & 0x7;
                if (!block.getWorld().generateTree(block.getLocation(), type)) {
                    block.setType(Material.SAPLING);
                    block.setData((byte) saplingData);
                }
            } else {
                warnMaterialData(Sapling.class, data);
            }
        }
    }
}
Also used : Sapling(org.bukkit.material.Sapling) TreeType(org.bukkit.TreeType) MaterialData(org.bukkit.material.MaterialData)

Example 39 with MaterialData

use of org.bukkit.material.MaterialData in project BKCommonLib by bergerhealer.

the class BlockData method newMaterialData.

/**
     * Creates a new MaterialData instance appropriate for this Block
     * 
     * @return Block Material Data
     */
@SuppressWarnings("deprecation")
public final MaterialData newMaterialData() {
    Material type = this.getType();
    // Null: return AIR
    if (type == null) {
        return new MaterialData(0, (byte) 0);
    }
    // Create new MaterialData + some fixes.
    final MaterialData mdata;
    if (type == Material.GOLD_PLATE || type == Material.IRON_PLATE) {
        // Bukkit bugfix.
        mdata = new org.bukkit.material.PressurePlate(type, (byte) this.getRawData());
    } else {
        mdata = type.getNewData((byte) this.getRawData());
    }
    // Fix attachable face returning NULL sometimes
    if (mdata instanceof Attachable) {
        Attachable att = (Attachable) mdata;
        if (att.getAttachedFace() == null) {
            att.setFacingDirection(BlockFace.NORTH);
        }
    }
    return mdata;
}
Also used : Material(org.bukkit.Material) MaterialData(org.bukkit.material.MaterialData) Attachable(org.bukkit.material.Attachable)

Example 40 with MaterialData

use of org.bukkit.material.MaterialData in project BKCommonLib by bergerhealer.

the class BlockUtil method setFacing.

/**
 * Sets the facing direction of a Directional block
 *
 * @param block to set
 * @param facing direction to set to
 */
public static void setFacing(org.bukkit.block.Block block, BlockFace facing) {
    MaterialData data = getData(block);
    if (data != null && data instanceof Directional) {
        ((Directional) data).setFacingDirection(facing);
        setData(block, data, true);
    }
}
Also used : MaterialData(org.bukkit.material.MaterialData) Directional(org.bukkit.material.Directional)

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