类org.bukkit.util.BlockVector源码实例Demo

下面列出了怎么用org.bukkit.util.BlockVector的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: ProjectAres   文件: BlockVectorSet.java
/**
 * Return an iterator that reuses a single BlockVector instance,
 * mutating it for each iteration.
 */
public Iterator<BlockVector> mutableIterator() {
    final TLongIterator iter = set.iterator();
    return new Iterator<BlockVector>() {
        final BlockVector value = new BlockVector();

        @Override
        public boolean hasNext() {
            return iter.hasNext();
        }

        @Override
        public BlockVector next() {
            return decodePos(iter.next(), value);
        }
    };
}
 
源代码2 项目: ProjectAres   文件: ControlPointBlockDisplay.java
/**
 * Change the controller display to the given team's color, or reset the display if team is null
 */
@SuppressWarnings("deprecation")
public void setController(Competitor controllingTeam) {
    if(!Objects.equals(this.controllingTeam, controllingTeam) && this.controllerDisplayRegion != null) {
        if(controllingTeam == null) {
            for(BlockVector block : this.controllerDisplayRegion.getBlockVectors()) {
                this.controllerDisplayImage.restore(block);
            }
        } else {
            byte blockData = BukkitUtils.chatColorToDyeColor(controllingTeam.getColor()).getWoolData();
            for(BlockVector pos : this.controllerDisplayRegion.getBlockVectors()) {
                BlockUtils.blockAt(match.getWorld(), pos).setData(blockData);
            }
        }
        this.controllingTeam = controllingTeam;
    }
}
 
源代码3 项目: CardinalPGM   文件: HillObjective.java
private void renderBlocks() {
    if (progress == null) return;
    byte color1 = capturingTeam != null ? MiscUtil.convertChatColorToDyeColor(capturingTeam.getColor()).getWoolData() : -1;
    byte color2 = team != null ? MiscUtil.convertChatColorToDyeColor(team.getColor()).getWoolData() : -1;
    Vector center = progress.getCenterBlock().getVector();
    double x = center.getX();
    double z = center.getZ();
    double percent = Math.toRadians(getPercent() * 3.6);
    for(Block block : progress.getBlocks()) {
        if (!visualMaterials.evaluate(block).equals(FilterState.ALLOW)) continue;
        double dx = block.getX() - x;
        double dz = block.getZ() - z;
        double angle = Math.atan2(dz, dx);
        if(angle < 0) angle += 2 * Math.PI;
        byte color = angle < percent ? color1 : color2;
        if (color == -1) {
            Pair<Material,Byte> oldBlock = oldProgress.getBlockAt(new BlockVector(block.getLocation().position()));
            if (oldBlock.getLeft().equals(block.getType())) color = oldBlock.getRight();
        }
        if (color != -1) block.setData(color);
    }
}
 
源代码4 项目: CardinalPGM   文件: RegionSave.java
public RegionSave(RegionModule region) {
    BlockVector min = blockAlign(region.getMin());
    BlockVector max = blockAlign(region.getMax());
    BlockVector size = max.minus(min).toBlockVector();

    this.min = min;
    this.size = size;

    List<Pair<Material,Byte>> blocks = new ArrayList<>();
    for (int z = min.getBlockZ(); z < max.getBlockZ(); z++) {
        for (int y = min.getBlockY(); y < max.getBlockY(); y++) {
            for (int x = min.getBlockX(); x < max.getBlockX(); x++) {
                Block block = new Location(GameHandler.getGameHandler().getMatchWorld(), x, y, z).getBlock();
                blocks.add(new ImmutablePair<>(block.getType(), block.getData()));
            }
        }
    }
    this.blocks = blocks;
}
 
源代码5 项目: ProjectAres   文件: BlockVectorSet.java
@Override
public Iterator<BlockVector> iterator() {
    final TLongIterator iter = this.set.iterator();

    return new Iterator<BlockVector>() {
        @Override
        public boolean hasNext() {
            return iter.hasNext();
        }

        @Override
        public BlockVector next() {
            return decodePos(iter.next());
        }

        @Override
        public void remove() {
            iter.remove();
        }
    };
}
 
源代码6 项目: PGM   文件: Renewable.java
boolean renew(BlockVector pos) {
  MaterialData material;
  if (isOriginalShuffleable(pos)) {
    // If position is shuffled, first try to find a nearby shuffleable block to swap with.
    // This helps to make shuffling less predictable when the world deficit is small or
    // out of proportion to the original distribution of world.
    material = sampleShuffledMaterial(pos);

    // If that fails, choose a random world, weighted by the current world deficits.
    if (material == null) material = chooseShuffledMaterial();
  } else {
    material = snapshot().getOriginalMaterial(pos);
  }

  if (material != null) {
    return renew(pos, material);
  }

  return false;
}
 
源代码7 项目: PGM   文件: SnapshotMatchModule.java
public MaterialData getOriginalMaterial(int x, int y, int z) {
  if (y < 0 || y >= 256) return new MaterialData(Material.AIR);

  ChunkVector chunkVector = ChunkVector.ofBlock(x, y, z);
  ChunkSnapshot chunkSnapshot = chunkSnapshots.get(chunkVector);
  if (chunkSnapshot != null) {
    BlockVector chunkPos = chunkVector.worldToChunk(x, y, z);
    return new MaterialData(
        chunkSnapshot.getBlockTypeId(
            chunkPos.getBlockX(), chunkPos.getBlockY(), chunkPos.getBlockZ()),
        (byte)
            chunkSnapshot.getBlockData(
                chunkPos.getBlockX(), chunkPos.getBlockY(), chunkPos.getBlockZ()));
  } else {
    return match.getWorld().getBlockAt(x, y, z).getState().getMaterialData();
  }
}
 
源代码8 项目: ProjectAres   文件: ControlPointBlockDisplay.java
protected void setProgress(Competitor controllingTeam, Competitor capturingTeam, double capturingProgress) {
    if(this.progressDisplayRegion != null) {
        Vector center = this.progressDisplayRegion.getBounds().center();

        // capturingProgress can be zero, but it can never be one, so invert it to avoid
        // a zero-area SectorRegion that can cause glitchy rendering
        SectorRegion sectorRegion = new SectorRegion(center.getX(), center.getZ(), 0, (1 - capturingProgress) * 2 * Math.PI);

        for(BlockVector pos : this.progressDisplayRegion.getBlockVectors()) {
            if(sectorRegion.contains(pos)) {
                this.setBlock(pos, controllingTeam);
            } else {
                this.setBlock(pos, capturingTeam);
            }
        }
    }
}
 
源代码9 项目: ProjectAres   文件: XMLUtils.java
public static BlockVector parseBlockVector(Node node, BlockVector def) throws InvalidXMLException {
    if(node == null) return def;

    String[] components = node.getValue().trim().split("\\s*,\\s*");
    if(components.length != 3) {
        throw new InvalidXMLException("Invalid block location", node);
    }
    try {
        return new BlockVector(Integer.parseInt(components[0]),
                               Integer.parseInt(components[1]),
                               Integer.parseInt(components[2]));
    }
    catch(NumberFormatException e) {
        throw new InvalidXMLException("Invalid block location", node);
    }
}
 
源代码10 项目: ProjectAres   文件: Renewable.java
boolean renew(BlockVector pos, MaterialData material) {
    // We need to do the entity check here rather than canRenew, because we are not
    // notified when entities move in our out of the way.
    if(!isClearOfEntities(pos)) return false;

    Location location = pos.toLocation(match.getWorld());
    Block block = location.getBlock();
    BlockState newState = location.getBlock().getState();
    newState.setMaterialData(material);

    BlockRenewEvent event = new BlockRenewEvent(block, newState, this);
    match.callEvent(event); // Our own handler will get this and remove the block from the pool
    if(event.isCancelled()) return false;

    newState.update(true, true);

    if(definition.particles) {
        NMSHacks.playBlockBreakEffect(match.getWorld(), pos, material.getItemType());
    }

    if(definition.sound) {
        NMSHacks.playBlockPlaceSound(match.getWorld(), pos, material.getItemType(), 1f);
    }

    return true;
}
 
源代码11 项目: ProjectAres   文件: Renewable.java
boolean renew(BlockVector pos) {
    MaterialData material;
    if(isOriginalShuffleable(pos)) {
        // If position is shuffled, first try to find a nearby shuffleable block to swap with.
        // This helps to make shuffling less predictable when the material deficit is small or
        // out of proportion to the original distribution of materials.
        material = sampleShuffledMaterial(pos);

        // If that fails, choose a random material, weighted by the current material deficits.
        if(material == null) material = chooseShuffledMaterial();
    } else {
        material = snapshot().getOriginalMaterial(pos);
    }

    if(material != null) {
        return renew(pos, material);
    }

    return false;
}
 
源代码12 项目: ProjectAres   文件: SnapshotMatchModule.java
public BlockState getOriginalBlock(int x, int y, int z) {
    BlockState state = getMatch().getWorld().getBlockAt(x, y, z).getState();
    if(y < 0 || y >= 256) return state;

    ChunkVector chunkVector = ChunkVector.ofBlock(x, y, z);
    ChunkSnapshot chunkSnapshot = chunkSnapshots.get(chunkVector);
    if(chunkSnapshot != null) {
        BlockVector chunkPos = chunkVector.worldToChunk(x, y, z);
        state.setMaterialData(new MaterialData(chunkSnapshot.getBlockTypeId(chunkPos.getBlockX(), chunkPos.getBlockY(), chunkPos.getBlockZ()),
                                               (byte) chunkSnapshot.getBlockData(chunkPos.getBlockX(), chunkPos.getBlockY(), chunkPos.getBlockZ())));
    }
    return state;
}
 
源代码13 项目: ProjectAres   文件: BlockUtils.java
public static TLongSet encodePosSet(Collection<?> vectors) {
    TLongSet encoded = new TLongHashSet(vectors.size());
    for(Object o : vectors) {
        if(o instanceof BlockVector) {
            encoded.add(encodePos((BlockVector) o));
        }
    }
    return encoded;
}
 
源代码14 项目: PGM   文件: BlockVectorSet.java
@Override
public boolean addAll(Collection<? extends BlockVector> vectors) {
  for (BlockVector v : vectors) {
    this.add(v);
  }
  return false;
}
 
源代码15 项目: ProjectAres   文件: Renewable.java
boolean isOriginalShuffleable(BlockVector pos) {
    if(!definition.region.contains(pos)) return false;
    Filter.QueryResponse response = shuffleableCache.get(pos);
    if(response == null) {
        response = definition.shuffleableBlocks.query(new BlockQuery(snapshot().getOriginalBlock(pos)));
    }
    return response.isAllowed();
}
 
源代码16 项目: ProjectAres   文件: BlockMaterialMap.java
@Override
Entry<BlockVector, MaterialData> castEntry(Object obj) {
    if(!(obj instanceof Entry)) return null;
    Entry entry = (Entry) obj;
    if(entry.getKey() instanceof BlockVector && entry.getValue() instanceof MaterialData) {
        return (Entry<BlockVector, MaterialData>) entry;
    } else {
        return null;
    }
}
 
源代码17 项目: PGM   文件: Bounds.java
public BlockVector getRandomBlock(Random random) {
  BlockVector min = this.getBlockMin();
  BlockVector size = this.getBlockSize();
  return new BlockVector(
      min.getX() + random.nextInt(size.getBlockX()),
      min.getY() + random.nextInt(size.getBlockY()),
      min.getZ() + random.nextInt(size.getBlockZ()));
}
 
源代码18 项目: PGM   文件: Bounds.java
/** Iterate over all the block locations within these bounds, in Z-major order. */
public Iterator<BlockVector> getBlockIterator() {
  if (!this.isBlockFinite()) {
    throw new UnsupportedOperationException("Cannot get all blocks from an infinite region");
  }
  return new CuboidBlockIterator(getBlockMin(), getBlockMaxOutside());
}
 
源代码19 项目: PGM   文件: Bounds.java
public Iterable<BlockVector> getBlocks() {
  return new Iterable<BlockVector>() {
    @Override
    public Iterator<BlockVector> iterator() {
      return getBlockIterator();
    }
  };
}
 
源代码20 项目: PGM   文件: AbstractRegion.java
@Override
public Iterator<BlockVector> getBlockVectorIterator() {
  return Iterators.filter(
      this.getBounds().getBlockIterator(),
      new Predicate<BlockVector>() {
        @Override
        public boolean apply(BlockVector vector) {
          return contains(vector);
        }
      });
}
 
源代码21 项目: PGM   文件: AbstractRegion.java
@Override
public Iterable<BlockVector> getBlockVectors() {
  return new Iterable<BlockVector>() {
    @Override
    public Iterator<BlockVector> iterator() {
      return getBlockVectorIterator();
    }
  };
}
 
源代码22 项目: ProjectAres   文件: BlockImage.java
/**
 * Copy the block at the given position from the image to the world
 * @param pos   Block position in world coordinates
 */
@SuppressWarnings("deprecation")
public void restore(BlockVector pos) {
    int offset = this.offset(pos);
    pos.toLocation(this.world).getBlock().setTypeIdAndData(this.blockIds[offset],
                                                           this.blockData[offset],
                                                           true);
}
 
源代码23 项目: PGM   文件: Renewable.java
boolean isOriginalRenewable(BlockVector pos) {
  if (!definition.region.contains(pos)) return false;
  Filter.QueryResponse response = renewableCache.get(pos);
  if (response == null) {
    response = definition.renewableBlocks.query(new BlockQuery(snapshot().getOriginalBlock(pos)));
  }
  return response.isAllowed();
}
 
源代码24 项目: PGM   文件: Renewable.java
boolean isClearOfEntities(BlockVector pos) {
  if (definition.avoidPlayersRange > 0d) {
    double rangeSquared = definition.avoidPlayersRange * definition.avoidPlayersRange;
    pos = BlockVectors.center(pos);
    for (MatchPlayer player : match.getParticipants()) {
      Location location = player.getBukkit().getLocation().add(0, 1, 0);
      if (location.toVector().distanceSquared(pos) < rangeSquared) {
        return false;
      }
    }
  }
  return true;
}
 
源代码25 项目: PGM   文件: BlockImage.java
/**
 * Copy the block at the given position from the image to the world
 *
 * @param pos Block position in world coordinates
 */
@SuppressWarnings("deprecation")
public void restore(BlockVector pos) {
  int offset = this.offset(pos);
  pos.toLocation(this.world)
      .getBlock()
      .setTypeIdAndData(this.blockIds[offset], this.blockData[offset], true);
}
 
源代码26 项目: CardinalPGM   文件: HillObjective.java
private void renderCaptured() {
    if (captured == null) return;
    for(Block block : captured.getBlocks()) {
        if (!visualMaterials.evaluate(block).equals(FilterState.ALLOW)) continue;
        byte color = team != null ? MiscUtil.convertChatColorToDyeColor(team.getColor()).getWoolData() : -1;
        if (color == -1) {
            Pair<Material,Byte> oldBlock = oldCaptured.getBlockAt(new BlockVector(block.getLocation().position()));
            if (oldBlock.getLeft().equals(block.getType())) color = oldBlock.getRight();
        }
        if (color != -1) block.setData(color);
    }
}
 
源代码27 项目: Kettle   文件: CraftStructureBlock.java
@Override
public void setRelativePosition(BlockVector vector) {
    Validate.isTrue(isBetween(vector.getBlockX(), -MAX_SIZE, MAX_SIZE), "Structure Size (X) must be between -" + MAX_SIZE + " and " + MAX_SIZE);
    Validate.isTrue(isBetween(vector.getBlockY(), -MAX_SIZE, MAX_SIZE), "Structure Size (Y) must be between -" + MAX_SIZE + " and " + MAX_SIZE);
    Validate.isTrue(isBetween(vector.getBlockZ(), -MAX_SIZE, MAX_SIZE), "Structure Size (Z) must be between -" + MAX_SIZE + " and " + MAX_SIZE);
    getSnapshot().position = new BlockPos(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); // PAIL: rename relativePosition
}
 
源代码28 项目: ProjectAres   文件: Region.java
@Deprecated
default Iterable<BlockVector> getBlockVectors() {
    return this::getBlockVectorIterator;
}
 
源代码29 项目: ProjectAres   文件: ChunkVector.java
public BlockVector chunkToWorld(int x, int y, int z) {
    return new BlockVector(x + getBlockMinX(), y, z + getBlockMinZ());
}
 
源代码30 项目: ProjectAres   文件: BlockMaterialMap.java
public MaterialData put(BlockVector pos, int encodedMaterial) {
    return decodeMaterial(putEncoded(pos, encodedMaterial));
}
 
 类所在包
 同包方法