Search in sources :

Example 1 with Door

use of org.bukkit.material.Door in project Citizens2 by CitizensDev.

the class AStarNavigationStrategy method update.

@Override
public boolean update() {
    if (!planned) {
        Location location = npc.getEntity().getLocation();
        VectorGoal goal = new VectorGoal(destination, (float) params.pathDistanceMargin());
        setPlan(ASTAR.runFully(goal, new VectorNode(goal, location, new ChunkBlockSource(location, params.range()), params.examiners()), Setting.MAXIMUM_ASTAR_ITERATIONS.asInt()));
    }
    if (getCancelReason() != null || plan == null || plan.isComplete()) {
        return true;
    }
    Location currLoc = npc.getEntity().getLocation(NPC_LOCATION);
    if (currLoc.toVector().distanceSquared(vector) <= params.distanceMargin()) {
        plan.update(npc);
        if (plan.isComplete()) {
            return true;
        }
        vector = plan.getCurrentVector();
    }
    double dX = vector.getBlockX() - currLoc.getX();
    double dZ = vector.getBlockZ() - currLoc.getZ();
    double dY = vector.getY() - currLoc.getY();
    double xzDistance = dX * dX + dZ * dZ;
    double distance = xzDistance + dY * dY;
    if (params.debug()) {
        npc.getEntity().getWorld().playEffect(vector.toLocation(npc.getEntity().getWorld()), Effect.ENDER_SIGNAL, 0);
    }
    if (distance > 0 && dY > NMS.getStepHeight(npc.getEntity()) && xzDistance <= 2.75) {
        NMS.setShouldJump(npc.getEntity());
    }
    double destX = vector.getX() + 0.5, destZ = vector.getZ() + 0.5;
    Block block = currLoc.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
    if (MinecraftBlockExaminer.isDoor(block.getType())) {
        Door door = (Door) block.getState().getData();
        if (door.isOpen()) {
            BlockFace targetFace = door.getFacing().getOppositeFace();
            destX = vector.getX() + targetFace.getModX();
            destZ = vector.getZ() + targetFace.getModZ();
        }
    }
    NMS.setDestination(npc.getEntity(), destX, vector.getY(), destZ, params.speed());
    params.run();
    plan.run(npc);
    return false;
}
Also used : VectorGoal(net.citizensnpcs.api.astar.pathfinder.VectorGoal) BlockFace(org.bukkit.block.BlockFace) ChunkBlockSource(net.citizensnpcs.api.astar.pathfinder.ChunkBlockSource) Block(org.bukkit.block.Block) VectorNode(net.citizensnpcs.api.astar.pathfinder.VectorNode) Door(org.bukkit.material.Door) Location(org.bukkit.Location)

Example 2 with Door

use of org.bukkit.material.Door in project Towny by ElgarL.

the class ProtectionRegenTask method replaceProtections.

public void replaceProtections() {
    try {
        Block block = state.getBlock();
        if (state.getData() instanceof Door) {
            Door door = (Door) state.getData();
            Block topHalf;
            Block bottomHalf;
            if (door.isTopHalf()) {
                topHalf = block;
                bottomHalf = block.getRelative(BlockFace.DOWN);
            } else {
                bottomHalf = block;
                topHalf = block.getRelative(BlockFace.UP);
            }
            door.setTopHalf(true);
            topHalf.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
            door.setTopHalf(false);
            bottomHalf.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
        } else if (state instanceof Sign) {
            block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
            Sign sign = (Sign) block.getState();
            int i = 0;
            for (String line : ((Sign) state).getLines()) sign.setLine(i++, line);
            sign.update(true);
        } else if (state instanceof CreatureSpawner) {
            block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
            ((CreatureSpawner) block.getState()).setSpawnedType(((CreatureSpawner) state).getSpawnedType());
        } else if (state instanceof InventoryHolder) {
            block.setTypeId(state.getTypeId(), false);
            // Container to receive the inventory
            Inventory container = ((InventoryHolder) block.getState()).getInventory();
            container.setContents(contents.toArray(new ItemStack[0]));
            block.setData(state.getData().getData(), false);
        } else if (state.getData() instanceof PistonExtensionMaterial) {
            PistonExtensionMaterial extension = (PistonExtensionMaterial) state.getData();
            Block piston = block.getRelative(extension.getAttachedFace());
            block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
            if (altState != null) {
                piston.setTypeIdAndData(altState.getTypeId(), altState.getData().getData(), false);
            }
        } else if (state.getData() instanceof Attachable) {
            Block attachedBlock = block.getRelative(((Attachable) state.getData()).getAttachedFace());
            if (attachedBlock.getTypeId() == 0) {
                attachedBlock.setTypeId(placeholder.getId(), false);
                TownyRegenAPI.addPlaceholder(attachedBlock);
            }
            block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
        } else {
            if (NeedsPlaceholder.contains(state.getType())) {
                Block blockBelow = block.getRelative(BlockFace.DOWN);
                if (blockBelow.getTypeId() == 0) {
                    if (state.getType().equals(Material.CROPS)) {
                        blockBelow.setTypeId(Material.SOIL.getId(), true);
                    } else {
                        blockBelow.setTypeId(placeholder.getId(), true);
                    }
                    TownyRegenAPI.addPlaceholder(blockBelow);
                }
            }
            block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), !NeedsPlaceholder.contains(state.getType()));
        }
        TownyRegenAPI.removePlaceholder(block);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : PistonExtensionMaterial(org.bukkit.material.PistonExtensionMaterial) Block(org.bukkit.block.Block) Sign(org.bukkit.block.Sign) Attachable(org.bukkit.material.Attachable) InventoryHolder(org.bukkit.inventory.InventoryHolder) Door(org.bukkit.material.Door) Inventory(org.bukkit.inventory.Inventory) CreatureSpawner(org.bukkit.block.CreatureSpawner)

Example 3 with Door

use of org.bukkit.material.Door 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) {
        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 4 with Door

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

the class BlockDoor method onBlockChanged.

@Override
public void onBlockChanged(GlowBlock block, Material oldType, byte oldData, Material newType, byte newData) {
    if (newType != Material.AIR) {
        return;
    }
    if (oldType.getData() == Door.class) {
        Door door = new Door(oldType);
        door.setData(oldData);
        if (door.isTopHalf()) {
            Block b = block.getRelative(BlockFace.DOWN);
            if (b.getState().getData() instanceof Door) {
                b.setType(Material.AIR);
            }
        } else {
            Block b = block.getRelative(BlockFace.UP);
            if (b.getState().getData() instanceof Door) {
                b.setType(Material.AIR);
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) Block(org.bukkit.block.Block) Door(org.bukkit.material.Door)

Example 5 with Door

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

the class BlockDoor method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    // place the door and calculate the facing
    super.placeBlock(player, state, face, holding, clickedLoc);
    MaterialData data = state.getData();
    if (!(data instanceof Door)) {
        warnMaterialData(Door.class, data);
        return;
    }
    BlockFace facing = player.getCardinalFacing();
    ((Door) data).setFacingDirection(facing.getOppositeFace());
    // modify facing for double-doors
    GlowBlock leftBlock = null;
    byte newDirectionData = 0;
    switch(facing) {
        case NORTH:
            leftBlock = state.getBlock().getRelative(BlockFace.WEST);
            newDirectionData = 6;
            break;
        case WEST:
            leftBlock = state.getBlock().getRelative(BlockFace.SOUTH);
            newDirectionData = 5;
            break;
        case SOUTH:
            leftBlock = state.getBlock().getRelative(BlockFace.EAST);
            newDirectionData = 4;
            break;
        case EAST:
            leftBlock = state.getBlock().getRelative(BlockFace.NORTH);
            newDirectionData = 7;
            break;
        default:
    }
    if (leftBlock != null && leftBlock.getState().getData() instanceof Door) {
        data.setData(newDirectionData);
    }
    // place top half of door
    GlowBlockState topState = state.getBlock().getRelative(BlockFace.UP).getState();
    topState.setType(state.getType());
    MaterialData topData = topState.getData();
    if (!(topData instanceof Door)) {
        warnMaterialData(Door.class, data);
    } else {
        ((Door) topData).setTopHalf(true);
        topState.update(true);
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockFace(org.bukkit.block.BlockFace) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData) Door(org.bukkit.material.Door)

Aggregations

Door (org.bukkit.material.Door)7 Block (org.bukkit.block.Block)4 GlowBlockState (net.glowstone.block.GlowBlockState)3 MaterialData (org.bukkit.material.MaterialData)3 GlowBlock (net.glowstone.block.GlowBlock)2 BlockFace (org.bukkit.block.BlockFace)2 ChunkBlockSource (net.citizensnpcs.api.astar.pathfinder.ChunkBlockSource)1 VectorGoal (net.citizensnpcs.api.astar.pathfinder.VectorGoal)1 VectorNode (net.citizensnpcs.api.astar.pathfinder.VectorNode)1 Location (org.bukkit.Location)1 CreatureSpawner (org.bukkit.block.CreatureSpawner)1 Sign (org.bukkit.block.Sign)1 Inventory (org.bukkit.inventory.Inventory)1 InventoryHolder (org.bukkit.inventory.InventoryHolder)1 Attachable (org.bukkit.material.Attachable)1 PistonExtensionMaterial (org.bukkit.material.PistonExtensionMaterial)1