Java源码示例:org.bukkit.util.BlockVector
示例1
/**
* 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
/**
* 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
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
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
@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
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
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
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
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
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
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
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
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
@Override
public boolean addAll(Collection<? extends BlockVector> vectors) {
for (BlockVector v : vectors) {
this.add(v);
}
return false;
}
示例15
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
@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
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
/** 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
public Iterable<BlockVector> getBlocks() {
return new Iterable<BlockVector>() {
@Override
public Iterator<BlockVector> iterator() {
return getBlockIterator();
}
};
}
示例20
@Override
public Iterator<BlockVector> getBlockVectorIterator() {
return Iterators.filter(
this.getBounds().getBlockIterator(),
new Predicate<BlockVector>() {
@Override
public boolean apply(BlockVector vector) {
return contains(vector);
}
});
}
示例21
@Override
public Iterable<BlockVector> getBlockVectors() {
return new Iterable<BlockVector>() {
@Override
public Iterator<BlockVector> iterator() {
return getBlockVectorIterator();
}
};
}
示例22
/**
* 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
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
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
/**
* 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
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
@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
@Deprecated
default Iterable<BlockVector> getBlockVectors() {
return this::getBlockVectorIterator;
}
示例29
public BlockVector chunkToWorld(int x, int y, int z) {
return new BlockVector(x + getBlockMinX(), y, z + getBlockMinZ());
}
示例30
public MaterialData put(BlockVector pos, int encodedMaterial) {
return decodeMaterial(putEncoded(pos, encodedMaterial));
}