Search in sources :

Example 96 with MaterialData

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

the class BlockSkull method afterPlace.

@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
    GlowSkull skull = (GlowSkull) block.getState();
    skull.setSkullType(getType(holding.getDurability()));
    if (skull.getSkullType() == SkullType.PLAYER) {
        SkullMeta meta = (SkullMeta) holding.getItemMeta();
        if (meta != null) {
            skull.setOwner(meta.getOwner());
        }
    }
    MaterialData data = skull.getData();
    if (!(data instanceof Skull)) {
        warnMaterialData(Skull.class, data);
        return;
    }
    Skull skullData = (Skull) data;
    if (canRotate(skullData)) {
        // Can be rotated
        skull.setRotation(player.getFacing().getOppositeFace());
    }
    skull.update();
    // Wither
    for (int i = 0; i < 3; i++) {
        if (WITHER_PATTERN.matches(block.getLocation().clone(), true, i, 0)) {
            block.getWorld().spawnEntity(block.getLocation().clone().subtract(0, 2, 0), EntityType.WITHER);
            break;
        }
    }
}
Also used : GlowSkull(net.glowstone.block.entity.state.GlowSkull) GlowSkull(net.glowstone.block.entity.state.GlowSkull) Skull(org.bukkit.material.Skull) SkullMeta(org.bukkit.inventory.meta.SkullMeta) MaterialData(org.bukkit.material.MaterialData)

Example 97 with MaterialData

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

the class BlockSponge method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    // TODO: Move this to a new method when physics works and run this on neighbour change too.
    MaterialData data = holding.getData();
    boolean absorbedWater = false;
    if (data.getItemType() == Material.SPONGE) {
        GlowBlock block = state.getBlock();
        TaxicabBlockIterator iterator = new TaxicabBlockIterator(block);
        iterator.setMaxDistance(7);
        iterator.setMaxBlocks(66);
        iterator.setPredicate(b -> b.getType() == Material.WATER);
        if (iterator.hasNext()) {
            absorbedWater = true;
            do {
                iterator.next().setType(Material.AIR);
            } while (iterator.hasNext());
        }
    }
    state.setType(absorbedWater ? Material.WET_SPONGE : Material.SPONGE);
}
Also used : TaxicabBlockIterator(net.glowstone.util.TaxicabBlockIterator) GlowBlock(net.glowstone.block.GlowBlock) MaterialData(org.bukkit.material.MaterialData)

Example 98 with MaterialData

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

the class BlockVine method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    if (ThreadLocalRandom.current().nextInt(4) == 0) {
        GlowBlockState state = block.getState();
        MaterialData data = state.getData();
        if (!(data instanceof Vine)) {
            warnMaterialData(Vine.class, data);
            return;
        }
        Vine vine = (Vine) data;
        boolean hasNearVineBlocks = hasNearVineBlocks(block);
        BlockFace face = ADJACENT[ThreadLocalRandom.current().nextInt(ADJACENT.length)];
        if (block.getY() < 255 && face == BlockFace.UP && block.getRelative(face).isEmpty()) {
            if (!hasNearVineBlocks) {
                Vine v = (Vine) data;
                for (BlockFace f : HORIZONTAL_FACES) {
                    if (ThreadLocalRandom.current().nextInt(2) == 0 || !block.getRelative(f).getRelative(face).getType().isSolid()) {
                        v.removeFromFace(f);
                    }
                }
                putVineOnHorizontalBlockFace(block.getRelative(face), v, block);
            }
        } else if (Arrays.asList(HORIZONTAL_FACES).contains(face) && !vine.isOnFace(face)) {
            if (!hasNearVineBlocks) {
                GlowBlock b = block.getRelative(face);
                if (b.isEmpty()) {
                    BlockFace clockwiseFace = getClockwiseFace(face);
                    BlockFace counterClockwiseFace = getCounterClockwiseFace(face);
                    GlowBlock clockwiseBlock = b.getRelative(clockwiseFace);
                    GlowBlock counterClockwiseBlock = b.getRelative(counterClockwiseFace);
                    boolean isOnCwFace = vine.isOnFace(clockwiseFace);
                    boolean isOnCcwFace = vine.isOnFace(counterClockwiseFace);
                    if (isOnCwFace && clockwiseBlock.getType().isSolid()) {
                        putVine(b, new Vine(clockwiseFace), block);
                    } else if (isOnCcwFace && counterClockwiseBlock.getType().isSolid()) {
                        putVine(b, new Vine(counterClockwiseFace), block);
                    } else if (isOnCwFace && clockwiseBlock.isEmpty() && block.getRelative(clockwiseFace).getType().isSolid()) {
                        putVine(clockwiseBlock, new Vine(face.getOppositeFace()), block);
                    } else if (isOnCcwFace && counterClockwiseBlock.isEmpty() && block.getRelative(counterClockwiseFace).getType().isSolid()) {
                        putVine(counterClockwiseBlock, new Vine(face.getOppositeFace()), block);
                    } else if (b.getRelative(BlockFace.UP).getType().isSolid()) {
                        putVine(b, new Vine(), block);
                    }
                } else if (b.getType().isOccluding()) {
                    vine.putOnFace(face);
                    putVine(block, vine, null);
                }
            }
        } else if (block.getY() > 1) {
            GlowBlock b = block.getRelative(BlockFace.DOWN);
            Vine v = (Vine) data;
            if (b.getType() == Material.VINE || b.isEmpty()) {
                for (BlockFace f : HORIZONTAL_FACES) {
                    if (ThreadLocalRandom.current().nextInt(2) == 0) {
                        v.removeFromFace(f);
                    }
                }
                putVineOnHorizontalBlockFace(b, v, b.isEmpty() ? block : null);
            }
        }
    }
}
Also used : Vine(org.bukkit.material.Vine) GlowBlock(net.glowstone.block.GlowBlock) GlowBlockState(net.glowstone.block.GlowBlockState) BlockFace(org.bukkit.block.BlockFace) MaterialData(org.bukkit.material.MaterialData)

Example 99 with MaterialData

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

the class BlockWater method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    super.updateBlock(block);
    if (block.getLightFromBlocks() <= 11 - block.getMaterialValues().getLightOpacity()) {
        if (block.getRelative(BlockFace.UP).isEmpty() && hasNearSolidBlock(block) && GlowBiomeClimate.isCold(block)) {
            GlowBlockState state = block.getState();
            state.setType(Material.ICE);
            state.setData(new MaterialData(Material.ICE));
            BlockSpreadEvent spreadEvent = new BlockSpreadEvent(state.getBlock(), block, state);
            EventFactory.getInstance().callEvent(spreadEvent);
            if (!spreadEvent.isCancelled()) {
                state.update(true);
            }
        }
    }
}
Also used : BlockSpreadEvent(org.bukkit.event.block.BlockSpreadEvent) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData)

Example 100 with MaterialData

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

the class BlockOpenable method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    GlowBlockState blockState = block.getState();
    MaterialData materialData = blockState.getData();
    if (materialData instanceof Openable) {
        Openable toOpen = (Openable) materialData;
        boolean wasOpen = toOpen.isOpen();
        toOpen.setOpen(!wasOpen);
        if (wasOpen) {
            onClosed(player, block, face, clickedLoc, blockState, materialData);
        } else {
            onOpened(player, block, face, clickedLoc, blockState, materialData);
        }
        blockState.update(true);
        return true;
    } else {
        warnMaterialData(Openable.class, materialData);
        return false;
    }
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData) Openable(org.bukkit.material.Openable)

Aggregations

MaterialData (org.bukkit.material.MaterialData)125 ItemStack (org.bukkit.inventory.ItemStack)32 Material (org.bukkit.Material)24 GlowBlockState (net.glowstone.block.GlowBlockState)20 Block (org.bukkit.block.Block)15 BlockState (org.bukkit.block.BlockState)13 ArrayList (java.util.ArrayList)12 GlowBlock (net.glowstone.block.GlowBlock)10 MyPetBaby (de.Keyle.MyPet.api.entity.MyPetBaby)9 TagCompound (de.keyle.knbt.TagCompound)9 Location (org.bukkit.Location)8 BlockFace (org.bukkit.block.BlockFace)8 EventHandler (org.bukkit.event.EventHandler)6 GlowBed (net.glowstone.block.entity.state.GlowBed)5 Player (org.bukkit.entity.Player)5 Entry (com.google.common.collect.Multiset.Entry)4 List (java.util.List)4 Entity (org.bukkit.entity.Entity)4 ItemMeta (org.bukkit.inventory.meta.ItemMeta)4 Dispenser (org.bukkit.material.Dispenser)4