Java 类org.bukkit.material.Directional 实例源码

项目:BedwarsRel    文件:Region.java   
@SuppressWarnings("deprecation")
public void addBreakedBlock(Block bedBlock) {
  if (bedBlock.getState().getData() instanceof Directional) {
    this.breakedBlockFace.put(bedBlock,
        ((Directional) bedBlock.getState().getData()).getFacing());
  }

  this.breakedBlockTypes.put(bedBlock, bedBlock.getTypeId());
  this.breakedBlockData.put(bedBlock, bedBlock.getData());

  if (bedBlock.getState().getData() instanceof Redstone) {
    this.breakedBlockPower.put(bedBlock, ((Redstone) bedBlock.getState().getData()).isPowered());
  }

  this.breakedBlocks.add(bedBlock);
}
项目:BedwarsRel    文件:Region.java   
@SuppressWarnings("deprecation")
public void addPlacedUnbreakableBlock(Block placed, BlockState replaced) {
  this.placedUnbreakableBlocks.add(placed);
  if (replaced != null) {
    if (replaced.getData() instanceof Directional) {
      this.breakedBlockFace.put(replaced.getBlock(),
          ((Directional) replaced.getData()).getFacing());
    }

    this.breakedBlockTypes.put(replaced.getBlock(), replaced.getTypeId());
    this.breakedBlockData.put(replaced.getBlock(), replaced.getData().getData());
    this.breakedBlocks.add(replaced.getBlock());

    if (replaced.getData() instanceof Redstone) {
      this.breakedBlockPower.put(placed, ((Redstone) replaced.getData()).isPowered());
    }
  }
}
项目:sensibletoolbox    文件:DirectionGadget.java   
public DirectionGadget(InventoryGUI gui, int slot, ItemStack mainTexture) {
    super(gui, slot);
    Validate.isTrue(gui.getOwningItem() instanceof Directional, "DirectionalGadget can only be used on a directional item!");
    Validate.isTrue(slot >= 9 && slot < gui.getInventory().getSize() - 9 && slot % 9 > 0 && slot % 9 < 8,
            "DirectionalGadget can't be placed at edge of inventory window!");
    this.mainTexture = mainTexture;
    this.allowSelf = true;
    directionSlots.put(slot - 10, BlockFace.UP);
    directionSlots.put(slot - 9, BlockFace.NORTH);
    directionSlots.put(slot - 1, BlockFace.WEST);
    directionSlots.put(slot + 1, BlockFace.EAST);
    directionSlots.put(slot + 8, BlockFace.DOWN);
    directionSlots.put(slot + 9, BlockFace.SOUTH);

    for (Map.Entry<Integer,BlockFace> e : directionSlots.entrySet()) {
        gui.addGadget(makeDirectionButton(gui, e.getKey(), e.getValue()));
    }
}
项目:sensibletoolbox    文件:DirectionGadget.java   
private ToggleButton makeDirectionButton(final InventoryGUI gui, final int slot, final BlockFace face) {
    ItemStack trueStack = GUIUtil.makeTexture(new Wool(DyeColor.ORANGE), ChatColor.YELLOW + face.toString());
    ItemStack falseStack = GUIUtil.makeTexture(new Wool(DyeColor.SILVER), ChatColor.YELLOW + face.toString());
    final Directional owner = (Directional) gui.getOwningItem();
    return new ToggleButton(gui, slot, owner.getFacing() == face, trueStack, falseStack, new ToggleButton.ToggleListener() {
        @Override
        public boolean run(boolean newValue) {
            // acts sort of like a radio button - switching one on switches all other
            // off, but switching one off leaves all switch off
            if (!newValue && !allowSelf) {
                return false;
            }
            if (newValue) {
                owner.setFacingDirection(face);
                for (int otherSlot : directionSlots.keySet()) {
                    if (slot != otherSlot) {
                        ((ToggleButton) gui.getGadget(otherSlot)).setValue(false);
                    }
                }
            } else {
                owner.setFacingDirection(BlockFace.SELF);
            }
            return true;
        }
    });
}
项目:Skript    文件:Direction.java   
@SuppressWarnings("deprecation")
public Vector getDirection(final Block b) {
    if (!relative)
        return new Vector(pitchOrX, yawOrY, lengthOrZ);
    final Material m = b.getType();
    if (!Directional.class.isAssignableFrom(m.getData()))
        return new Vector();
    final BlockFace f = ((Directional) m.getNewData(b.getData())).getFacing();
    return getDirection(pitchOrX == IGNORE_PITCH ? 0 : f.getModZ() * Math.PI / 2 /* only up and down have a z mod */, Math.atan2(f.getModZ(), f.getModX()));
}
项目:Skript    文件:Direction.java   
/**
 * @param b
 * @return The facing of the block or {@link BlockFace#SELF} if the block doesn't have a facing.
 */
@SuppressWarnings({"deprecation", "null"})
public final static BlockFace getFacing(final Block b) {
    final Material m = b.getType();
    if (!Directional.class.isAssignableFrom(m.getData()))
        return BlockFace.SELF;
    return ((Directional) m.getNewData(b.getData())).getFacing();
}
项目:Skript    文件:BlockUtils.java   
/**
 * @param b A block
 * @return Location of the block, including its direction
 */
@Nullable
public static Location getLocation(final @Nullable Block b) {
    if (b == null)
        return null;
    final Location l = b.getLocation().add(0.5, 0.5, 0.5);
    final Material m = b.getType();
    if (Directional.class.isAssignableFrom(m.getData())) {
        final BlockFace f = ((Directional) m.getNewData(b.getData())).getFacing();
        l.setPitch(Direction.getPitch(Math.sin(f.getModY())));
        l.setYaw(Direction.getYaw(Math.atan2(f.getModZ(), f.getModX())));
    }
    return l;
}
项目:BedwarsRel    文件:Region.java   
@SuppressWarnings("deprecation")
public void addPlacedBlock(Block placeBlock, BlockState replacedBlock) {
  this.placedBlocks.add(placeBlock);
  if (replacedBlock != null) {
    if (replacedBlock.getData() instanceof Directional) {
      this.breakedBlockFace.put(replacedBlock.getBlock(),
          ((Directional) replacedBlock.getData()).getFacing());
    }

    this.breakedBlockTypes.put(replacedBlock.getBlock(), replacedBlock.getTypeId());
    this.breakedBlockData.put(replacedBlock.getBlock(), replacedBlock.getData().getData());

    this.breakedBlocks.add(replacedBlock.getBlock());
  }
}
项目:LapisPortals    文件:PlayerListener.java   
@EventHandler
public void onPlayerPlace(BlockPlaceEvent event) {

    if ((event.getBlockPlaced().getType() == Material.WOODEN_DOOR || event
            .getBlockPlaced().getType() == Material.IRON_DOOR_BLOCK)
            && (VaultHook.hasPermission(event.getPlayer(),
                    VaultHook.Perm.CREATE))) {
        int facing = (((Directional) event.getBlockPlaced().getState()
                .getData()).getFacing().ordinal() + 2) % 4;
        Location tmp = event.getBlock().getLocation();
        Location loc = new Location(tmp.getWorld(), tmp.getX(),
                tmp.getY() - 1.0D, tmp.getZ());
        Player p = event.getPlayer();
        ValidPortalReturn returned = EnderPortal.validateLocation(loc,
                facing, this.plugin);
        if (returned.isValid()) {
            if (EnderPortals.getFileHandler().addPortal(
                    loc.getWorld().getName(), facing, loc.getX(),
                    loc.getY(), loc.getZ(), returned.getHash())) {
                Messenger.tell(p, Messenger.Phrase.CREATE_SUCCESS);
            } else {
                Messenger.tell(p, Messenger.Phrase.CREATE_FAIL);
            }
        } else if (returned.getHash() == -1) {
            Messenger.tell(p, Messenger.Phrase.CREATE_FAIL);
        }
    }
}
项目:BlockLocker    文件:SeparateContainersBlockFinder.java   
@Override
public List<Block> findContainerNeighbors(Block block) {
    // Currently only chests share an inventory
    // Minecraft connects two chests next to each other that have the same
    // direction. We simply check for that condition, taking both normal
    // and trapped chests into account
    if (!(BlockData.get(block) instanceof Chest)) {
        return Collections.singletonList(block);
    }

    Material chestMaterial = block.getType(); // CHEST or TRAPPED_CHEST
    BlockFace chestFacing = ((Directional) BlockData.get(block)).getFacing();

    for (BlockFace face : CARDINAL_FACES) {
        Block atPosition = block.getRelative(face);
        if (atPosition.getType() != chestMaterial) {
            continue;
        }

        MaterialData materialData = BlockData.get(atPosition);
        if (!(materialData instanceof Directional)) {
            continue;
        }

        BlockFace facing = ((Directional) materialData).getFacing();
        if (!facing.equals(chestFacing)) {
            if (!facing.equals(chestFacing.getOppositeFace())) {
                // ^ If the chest was carried over from older Minecraft
                // versions, block data can be a bit weird. So opposite
                // face is allowed too for chest connections
                continue;
            }
        }

        return ImmutableList.of(block, atPosition);
    }

    return Collections.singletonList(block);
}
项目:sensibletoolbox    文件:DirectionGadget.java   
@Override
public void onClicked(InventoryClickEvent event) {
    // this is just the central button click handler (clear direction)
    // specific direction handlers are dealt with in makeDirectionButton()
    if (allowSelf) {
        ((Directional) getGUI().getOwningItem()).setFacingDirection(BlockFace.SELF);
        for (int slot : directionSlots.keySet()) {
            ((ToggleButton) getGUI().getGadget(slot)).setValue(false);
        }
    }
}
项目:vanillacraft    文件:BlockHelper.java   
public static Block getConnectedSide(Location location, BlockFace side)
{
    //        int x = location.getBlockX();
    //        int y = location.getBlockY();
    //        int z = location.getBlockZ();
    Block block = location.getBlock().getRelative(side);
    Block b = location.getBlock();
    Bukkit.getLogger().info("Block: " + block.getX() + ", " + block.getY() + ", " + block.getZ());
    Bukkit.getLogger().info("Side block: " + b.getX() + ", " + b.getY() + ", " + b.getZ());
    switch (block.getType())
    {
        // case 50:
        //case 65:
        // case 75:
        //case 76:
        // case 68:
        // case 69:
        // case 77:
        // case 96:
        case TORCH:
        case LADDER:
        case WALL_SIGN:
        case LEVER:
        case REDSTONE_TORCH_ON:
        case REDSTONE_TORCH_OFF:
        case STONE_BUTTON:
        case WOOD_BUTTON:
        case TRAP_DOOR:
        case IRON_TRAPDOOR:
        case WALL_BANNER:
            BlockFace face = ((Attachable) (block.getState().getData())).getAttachedFace().getOppositeFace();
            if (b.getRelative(face).getX() == block.getX() && b.getRelative(face).getZ() == block.getZ())
            {
                return block;
            }
            return null;

        case TRIPWIRE_HOOK:
            BlockFace face2 = ((Directional) (block.getState().getData())).getFacing().getOppositeFace();
            if (b.getRelative(face2).getX() == block.getX() && b.getRelative(face2).getZ() == block.getZ())
            {
                return block;
            }
            return null;
        //case 27:
        //case 28:
        //case 66:
        case RAILS:
        case ACTIVATOR_RAIL:
        case DETECTOR_RAIL:
        case POWERED_RAIL:
            Rails rail = (Rails) block.getState().getData();
            if (rail.isOnSlope())
            {
                BlockFace face1 = rail.getDirection().getOppositeFace();
                if (b.getRelative(face1).getX() == block.getX() && b.getRelative(face1).getZ() == block.getZ())
                {
                    return block;
                }
            }

        default:
            return null;
    }
}
项目:sensibletoolbox    文件:MultiBuilder.java   
private boolean losesDataWhenBroken(MaterialData mat) {
    // If a material loses its data when in item form (i.e. the block data
    // is used to store the block's orientation), then we need to know that
    // to correctly match what the player has in inventory.
    return mat instanceof Directional;
}
项目:NucleusFramework    文件:SerializableFurnitureEntity.java   
/**
 * Constructor.
 *
 * @param entity  The {@link org.bukkit.entity.Entity} that needs to be serialized.
 */
public SerializableFurnitureEntity(Entity entity) {
    PreCon.notNull(entity);

    _location = entity.getLocation();
    _type = entity.getType();

    if (entity instanceof Directional) {
        Directional directional = (Directional)entity;

        _facing = directional.getFacing();
        _canSerialize = true;
    }

    if (entity instanceof Painting) {
        Painting painting = (Painting)entity;

        _art = painting.getArt();
        _canSerialize = true;
    }

    if (entity instanceof ItemFrame) {
        ItemFrame frame = (ItemFrame)entity;

        _frameItem = frame.getItem();
        _frameRotation = frame.getRotation();
    }

    if (entity instanceof ArmorStand) {
        ArmorStand stand = (ArmorStand)entity;

        _hasArmorStand = true;
        _itemInHand = stand.getItemInHand();
        _helmet = stand.getHelmet();
        _chestplate = stand.getChestplate();
        _leggings = stand.getLeggings();
        _boots = stand.getBoots();
        _headPose = stand.getHeadPose();
        _bodyPose = stand.getBodyPose();
        _leftArmPose = stand.getLeftArmPose();
        _rightArmPose = stand.getRightArmPose();
        _leftLegPose = stand.getLeftLegPose();
        _rightLegPose = stand.getRightLegPose();
        _hasArmorBasePlate = stand.hasBasePlate();
        _hasArmorGravity = stand.hasGravity();
        _isArmorVisible = stand.isVisible();
        _hasArmorArms = stand.hasArms();
        _isArmorSmall = stand.isSmall();
    }
}
项目:NucleusFramework    文件:SerializableFurnitureEntity.java   
private boolean applyToEntity(Entity entity) {

        entity.teleport(_location);

        if (entity instanceof Directional && _facing != null) {

            Directional directional = (Directional)entity;
            directional.setFacingDirection(_facing);
        }

        if (entity instanceof Painting && _art != null) {
            Painting painting = (Painting)entity;

            painting.setArt(_art);
        }

        if (entity instanceof ItemFrame && _frameItem != null) {
            ItemFrame frame = (ItemFrame)entity;

            frame.setItem(_frameItem);
            frame.setRotation(_frameRotation);
        }

        if (entity instanceof ArmorStand && _hasArmorStand) {
            ArmorStand stand = (ArmorStand)entity;

            stand.setItemInHand(_itemInHand);
            stand.setHelmet(_helmet);
            stand.setChestplate(_chestplate);
            stand.setLeggings(_leggings);
            stand.setBoots(_boots);
            stand.setHeadPose(_headPose);
            stand.setBodyPose(_bodyPose);
            stand.setLeftArmPose(_leftArmPose);
            stand.setRightArmPose(_rightArmPose);
            stand.setLeftLegPose(_leftLegPose);
            stand.setRightLegPose(_rightLegPose);
            stand.setBasePlate(_hasArmorBasePlate);
            stand.setGravity(_hasArmorGravity);
            stand.setVisible(_isArmorVisible);
            stand.setArms(_hasArmorArms);
            stand.setSmall(_isArmorSmall);
        }

        if (_facing == null)
            return false;

        return true;
    }
项目:Kineticraft    文件:Utils.java   
/**
 * Get the direction a block is facing.
 * @param bk
 * @return facing
 */
public static BlockFace getDirection(Block bk) {
    return bk.getState().getData() instanceof Directional ? ((Directional) bk.getState().getData()).getFacing() : BlockFace.SELF;
}