Search in sources :

Example 76 with BlockFace

use of org.bukkit.block.BlockFace in project BKCommonLib by bergerhealer.

the class MapResourcePack method createPlaceholderModel.

/**
 * Creates a placeholder model. Used when models can not be loaded.
 *
 * @return placeholder model
 */
protected final Model createPlaceholderModel(RenderOptions renderOptions) {
    Model model = new Model();
    Model.Element element = new Model.Element();
    for (BlockFace face : FaceUtil.BLOCK_SIDES) {
        element.faces.put(face, createPlaceholderFace());
    }
    element.buildQuads();
    model.placeholder = true;
    model.elements.add(element);
    model.name = renderOptions.lookupModelName();
    return model;
}
Also used : BlockFace(org.bukkit.block.BlockFace) Model(com.bergerkiller.bukkit.common.map.util.Model) GeneratedModel(com.bergerkiller.bukkit.common.internal.resources.builtin.GeneratedModel)

Example 77 with BlockFace

use of org.bukkit.block.BlockFace in project BKCommonLib by bergerhealer.

the class BlockDataTest method testButtons.

@Test
public void testButtons() {
    for (String buttonMaterialName : new String[] { "STONE_BUTTON", "ACACIA_BUTTON", "BIRCH_BUTTON", "DARK_OAK_BUTTON", "JUNGLE_BUTTON", "OAK_BUTTON", "SPRUCE_BUTTON", // 1.16
    "CRIMSON_BUTTON", // 1.16
    "WARPED_BUTTON", // 1.16
    "POLISHED_BLACKSTONE_BUTTON", // 1.17
    "POLISHED_BLACKSTONE_BUTTON" }) {
        Material material = MaterialUtil.getMaterial(buttonMaterialName);
        if (material == null) {
            continue;
        }
        BlockData d = BlockData.fromMaterial(material);
        // Facing
        for (BlockFace facing : FaceUtil.BLOCK_SIDES) {
            if (facing == BlockFace.UP) {
                d = d.setState("face", "ceiling");
            } else if (facing == BlockFace.DOWN) {
                d = d.setState("face", "floor");
            } else {
                d = d.setState("face", "wall");
                d = d.setState("facing", facing);
            }
            d = d.setState("powered", false);
            assertFalse("isPowered()==false failed for " + facing + " material " + material, ((org.bukkit.material.Button) d.getMaterialData()).isPowered());
            d = d.setState("powered", true);
            assertTrue("isPowered()==true failed for " + facing + " material " + material, ((org.bukkit.material.Button) d.getMaterialData()).isPowered());
        }
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) Material(org.bukkit.Material) BlockData(com.bergerkiller.bukkit.common.wrappers.BlockData) MaterialDataToIBlockData(com.bergerkiller.bukkit.common.internal.legacy.MaterialDataToIBlockData) Test(org.junit.Test)

Example 78 with BlockFace

use of org.bukkit.block.BlockFace in project BKCommonLib by bergerhealer.

the class BlockDataTest method testWaterloggedRails.

@Test
public void testWaterloggedRails() {
    if (!Common.evaluateMCVersion(">=", "1.17")) {
        return;
    }
    String[] shapes = new String[] { "north_south", "east_west", "ascending_east", "ascending_west", "ascending_north", "ascending_south", "south_east", "south_west", "north_west", "north_east" };
    BlockFace[] directions = new BlockFace[] { BlockFace.SOUTH, BlockFace.EAST, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.NORTH_WEST, BlockFace.NORTH_EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH_WEST };
    Material material;
    BlockData d;
    for (boolean waterlogged : new boolean[] { false, true }) {
        material = MaterialUtil.getMaterial("RAIL");
        d = BlockData.fromMaterial(material);
        d = d.setState("waterlogged", waterlogged);
        for (String railMaterialName : new String[] { "RAIL", "DETECTOR_RAIL", "POWERED_RAIL", "ACTIVATOR_RAIL" }) {
            material = MaterialUtil.getMaterial(railMaterialName);
            d = BlockData.fromMaterial(material);
            d = d.setState("waterlogged", waterlogged);
            // Skip curve values for non-curvable rails
            int shapeLim = railMaterialName.equals("RAIL") ? shapes.length : (shapes.length - 4);
            // Check all possible shapes
            for (int i = 0; i < shapeLim; i++) {
                d = d.setState("shape", shapes[i]);
                org.bukkit.material.Rails rail = (org.bukkit.material.Rails) d.getMaterialData();
                assertEquals("BlockData " + d + " expected direction = " + directions[i] + " but was " + rail.getDirection(), directions[i], rail.getDirection());
                boolean isSlope = shapes[i].contains("ascending");
                if (isSlope != rail.isOnSlope()) {
                    fail("BlockData " + d + " expected isSlope = " + isSlope + " but was " + rail.isOnSlope());
                }
            }
        }
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) Material(org.bukkit.Material) BlockData(com.bergerkiller.bukkit.common.wrappers.BlockData) MaterialDataToIBlockData(com.bergerkiller.bukkit.common.internal.legacy.MaterialDataToIBlockData) Test(org.junit.Test)

Example 79 with BlockFace

use of org.bukkit.block.BlockFace in project BKCommonLib by bergerhealer.

the class BlockDataTest method testLever.

@Test
public void testLever() {
    BlockData d = BlockData.fromMaterial(MaterialsByName.getMaterial("LEVER"));
    // Attached face
    for (String face : new String[] { "ceiling", "floor", "wall" }) {
        d = d.setState("face", face);
        // Facing (rotation when ceiling/floor)
        for (BlockFace facing : new BlockFace[] { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST }) {
            d = d.setState("facing", facing);
            d = d.setState("powered", false);
            assertFalse("isPowered()==false failed for " + facing, ((org.bukkit.material.Lever) d.getMaterialData()).isPowered());
            d = d.setState("powered", true);
            assertTrue("isPowered()==true failed for " + facing, ((org.bukkit.material.Lever) d.getMaterialData()).isPowered());
        }
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) BlockData(com.bergerkiller.bukkit.common.wrappers.BlockData) MaterialDataToIBlockData(com.bergerkiller.bukkit.common.internal.legacy.MaterialDataToIBlockData) Test(org.junit.Test)

Example 80 with BlockFace

use of org.bukkit.block.BlockFace in project BKCommonLib by bergerhealer.

the class BlockDataOpacityTest method testOpaqueFaces.

@Test
public void testOpaqueFaces() {
    assertOpaqueFaces(BlockFaceSet.NONE, BlockData.fromMaterial(Material.GLASS));
    assertOpaqueFaces(BlockFaceSet.NONE, BlockData.fromMaterial(Material.AIR));
    assertOpaqueFaces(BlockFaceSet.NONE, BlockData.fromMaterial(Material.ACACIA_FENCE));
    assertOpaqueFaces(BlockFaceSet.ALL, BlockData.fromMaterial(Material.OAK_WOOD));
    assertOpaqueFaces(BlockFaceSet.ALL, BlockData.fromMaterial(Material.OBSIDIAN));
    // Weird. Says all faces are opaque? Still works since opacity is 0
    // assertOpaqueFaces(BlockFaceSet.NONE, BlockData.fromMaterial(Material.GLASS));
    // Slabs top/bottom half should be opaque
    assertOpaqueFaces(BlockFaceSet.of(BlockFace.UP), BlockData.fromMaterial(Material.OAK_SLAB).setState("type", "top"));
    assertOpaqueFaces(BlockFaceSet.of(BlockFace.DOWN), BlockData.fromMaterial(Material.OAK_SLAB).setState("type", "bottom"));
    // We should see the bottom and the backside be opaque
    for (BlockFace facing : FaceUtil.AXIS) {
        BlockFaceSet expected = BlockFaceSet.of(BlockFace.DOWN, facing);
        assertOpaqueFaces(expected, BlockData.fromMaterial(Material.OAK_STAIRS).setState("facing", facing).setState("half", "bottom").setState("shape", "straight"));
    }
    // We should see the top and the backside be opaque
    for (BlockFace facing : FaceUtil.AXIS) {
        BlockFaceSet expected = BlockFaceSet.of(BlockFace.UP, facing);
        assertOpaqueFaces(expected, BlockData.fromMaterial(Material.OAK_STAIRS).setState("facing", facing).setState("half", "top").setState("shape", "straight"));
    }
    // Stairs using inner_left should see two faces be opaque
    {
        BlockFaceSet expected = BlockFaceSet.of(BlockFace.UP, BlockFace.NORTH, BlockFace.WEST);
        assertOpaqueFaces(expected, BlockData.fromMaterial(Material.OAK_STAIRS).setState("facing", BlockFace.NORTH).setState("half", "top").setState("shape", "inner_left"));
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) BlockFaceSet(com.bergerkiller.bukkit.common.collections.BlockFaceSet) Test(org.junit.Test)

Aggregations

BlockFace (org.bukkit.block.BlockFace)136 Block (org.bukkit.block.Block)53 GlowBlock (net.glowstone.block.GlowBlock)32 Location (org.bukkit.Location)23 Material (org.bukkit.Material)23 Vector (org.bukkit.util.Vector)18 ArrayList (java.util.ArrayList)12 ItemStack (org.bukkit.inventory.ItemStack)12 Sign (org.bukkit.block.Sign)10 BlockState (org.bukkit.block.BlockState)9 EventHandler (org.bukkit.event.EventHandler)8 MaterialData (org.bukkit.material.MaterialData)8 List (java.util.List)7 ItemTable (net.glowstone.block.ItemTable)7 Player (org.bukkit.entity.Player)7 GlowBlockState (net.glowstone.block.GlowBlockState)6 GlowPlayer (net.glowstone.entity.GlowPlayer)6 UUID (java.util.UUID)5 BlockType (net.glowstone.block.blocktype.BlockType)5 PulseTask (net.glowstone.scheduler.PulseTask)5