本文整理汇总了Java中net.minecraft.util.math.BlockPos.distanceSq方法的典型用法代码示例。如果您正苦于以下问题:Java BlockPos.distanceSq方法的具体用法?Java BlockPos.distanceSq怎么用?Java BlockPos.distanceSq使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.util.math.BlockPos
的用法示例。
在下文中一共展示了BlockPos.distanceSq方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TreeCache
import net.minecraft.util.math.BlockPos; //导入方法依赖的package包/类
public TreeCache(World world, BlockPos current) {
this.woodCache = new PriorityQueue<>(Comparator.comparingDouble(value -> ((BlockPos) value).distanceSq(((BlockPos) value).getX(), current.getY(), ((BlockPos) value).getZ())).reversed());
this.leavesCache = new PriorityQueue<>(Comparator.comparingDouble(value -> ((BlockPos) value).distanceSq(current.getX(), ((BlockPos) value).getY(), current.getZ())).reversed());
this.world = world;
Stack<BlockPos> tree = new Stack<>();
tree.push(current);
while (!tree.isEmpty()) {
BlockPos checking = tree.pop();
if (BlockUtils.isLog(world, checking) || BlockUtils.isLeaves(world, checking)) {
Iterable<BlockPos> area = BlockPos.getAllInBox(checking.offset(EnumFacing.DOWN).offset(EnumFacing.SOUTH).offset(EnumFacing.WEST), checking.offset(EnumFacing.UP).offset(EnumFacing.NORTH).offset(EnumFacing.EAST));
for (BlockPos blockPos : area) {
if (BlockUtils.isLog(world, blockPos) && !woodCache.contains(blockPos) && blockPos.distanceSq(current.getX(), current.getY(), current.getZ()) <= 1000) {
tree.push(blockPos);
woodCache.add(blockPos);
} else if (BlockUtils.isLeaves(world, blockPos) && !leavesCache.contains(blockPos) && blockPos.distanceSq(current.getX(), current.getY(), current.getZ()) <= 1000) {
tree.push(blockPos);
leavesCache.add(blockPos);
}
}
}
}
}
示例2: ChorusCache
import net.minecraft.util.math.BlockPos; //导入方法依赖的package包/类
public ChorusCache(World world, BlockPos current) {
this.world = world;
this.chorus = new ArrayList<>();
Stack<BlockPos> chorus = new Stack<>();
chorus.push(current);
while (!chorus.isEmpty()) {
BlockPos checking = chorus.pop();
if (BlockUtils.isChorus(world, checking)) {
Iterable<BlockPos> area = BlockPos.getAllInBox(checking.offset(EnumFacing.DOWN).offset(EnumFacing.SOUTH).offset(EnumFacing.WEST), checking.offset(EnumFacing.UP).offset(EnumFacing.NORTH).offset(EnumFacing.EAST));
for (BlockPos blockPos : area) {
if (BlockUtils.isChorus(world, blockPos) && !this.chorus.contains(blockPos) && blockPos.distanceSq(current.getX(), current.getY(), current.getZ()) <= 1000) {
chorus.push(blockPos);
this.chorus.add(blockPos);
}
}
}
}
}
示例3: detectBanner
import net.minecraft.util.math.BlockPos; //导入方法依赖的package包/类
public boolean detectBanner(){
Iterator<BlockPos> iterator=this.world.getCapability(TF2weapons.WORLD_CAP, null).banners.iterator();
while(iterator.hasNext()){
BlockPos pos=iterator.next();
if(pos.distanceSq(this.getPosition())<1200){
TileEntity banner=this.world.getTileEntity(pos);
if(banner != null && banner instanceof TileEntityBanner){
boolean fast=false;
for(BannerPattern pattern: TF2EventsCommon.getPatterns((TileEntityBanner)banner)){
if(pattern==TF2weapons.redPattern)
this.bannerTeam=0;
else if(pattern==TF2weapons.bluPattern)
this.bannerTeam=1;
else if(pattern==TF2weapons.fastSpawn)
fast=true;
}
return fast && pos.distanceSq(this.getPosition())<512;
}
else{
iterator.remove();
return false;
}
}
}
return false;
}
示例4: onBlockBreak
import net.minecraft.util.math.BlockPos; //导入方法依赖的package包/类
@SubscribeEvent
public void onBlockBreak(BlockEvent.BreakEvent event) {
World world = event.getWorld();
IBlockState state = world.getBlockState(event.getPos());
BlockPos pos = event.getPos();
if (!state.getBlock().isWood(world, pos)) {
return;
}
int radius = 16;
int dirX = Math.max(-1, Math.min(1, pos.getX() - (int)Math.round(event.getPlayer().posX - 0.5)));
int dirZ = Math.max(-1, Math.min(1, pos.getZ() - (int)Math.round(event.getPlayer().posZ - 0.5)));
LinkedList<BlockPos> queue = new LinkedList<BlockPos>();
HashMap<BlockPos, Integer> used = new HashMap<BlockPos, Integer>();
queue.add(pos);
int leaf = 5;
used.put(pos, leaf);
while (!queue.isEmpty()) {
BlockPos top = queue.pollFirst();
for (int dx = -1; dx <= 1; ++dx) {
for (int dy = -1; dy <= 1; ++dy) {
for (int dz = -1; dz <= 1; ++dz) {
BlockPos nPos = top.add(dx, dy, dz);
int step = used.get(top);
if (step <= 0 || nPos.distanceSq(pos) > radius * radius) {
continue;
}
IBlockState nState = world.getBlockState(nPos);
boolean log = nState.getBlock().isWood(world, nPos);
boolean leaves = nState.getBlock().isLeaves(nState, world, nPos);
if ((dy >= 0 && step == leaf && log) || leaves) {
step = step - (leaves ? 1 : 0);
if (!used.containsKey(nPos) || used.get(nPos) < step) {
used.put(nPos, step);
queue.push(nPos);
}
}
}
}
}
}
for (Map.Entry<BlockPos, Integer> entry : used.entrySet()) {
BlockPos blockPos = entry.getKey();
if (!pos.equals(blockPos) && isDraggable(world, blockPos.add(0, -1, 0))) {
int oy = blockPos.getY() - pos.getY();
drop(world, blockPos, blockPos.add(oy * dirX, 0, oy * dirZ));
}
}
}
示例5: getDistanceSq
import net.minecraft.util.math.BlockPos; //导入方法依赖的package包/类
@Override
public double getDistanceSq(BlockPos pos) {
if (m_modPrefix != null &&
pos.getX() == m_TargetBlockPos.getX() &&
pos.getY() == m_TargetBlockPos.getY() &&
pos.getZ() == m_TargetBlockPos.getZ() &&
Util.isPrefixInCallStack(m_modPrefix))
{
return pos.distanceSq(m_RemotePosX, m_RemotePosY, m_RemotePosZ);
}
else
{
return super.getDistanceSq(pos);
}
}
示例6: sendPacketWithinDistance
import net.minecraft.util.math.BlockPos; //导入方法依赖的package包/类
private void sendPacketWithinDistance(EntityPlayerMP player, boolean longDistance, double x, double y, double z, Packet<?> packetIn)
{
BlockPos blockpos = player.getPosition();
double d0 = blockpos.distanceSq(x, y, z);
if (d0 <= 1024.0D || longDistance && d0 <= 262144.0D)
{
player.connection.sendPacket(packetIn);
}
}
示例7: decorate
import net.minecraft.util.math.BlockPos; //导入方法依赖的package包/类
public void decorate(World worldIn, Random random, Biome biome, BlockPos pos)
{
BlockPos blockpos = worldIn.getSpawnPoint();
int i = 16;
double d0 = blockpos.distanceSq(pos.add(8, blockpos.getY(), 8));
if (d0 <= 1024.0D)
{
BlockPos blockpos1 = new BlockPos(blockpos.getX() - 16, blockpos.getY() - 1, blockpos.getZ() - 16);
BlockPos blockpos2 = new BlockPos(blockpos.getX() + 16, blockpos.getY() - 1, blockpos.getZ() + 16);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(blockpos1);
for (int j = pos.getZ(); j < pos.getZ() + 16; ++j)
{
for (int k = pos.getX(); k < pos.getX() + 16; ++k)
{
if (j >= blockpos1.getZ() && j <= blockpos2.getZ() && k >= blockpos1.getX() && k <= blockpos2.getX())
{
blockpos$mutableblockpos.setPos(k, blockpos$mutableblockpos.getY(), j);
if (blockpos.getX() == k && blockpos.getZ() == j)
{
worldIn.setBlockState(blockpos$mutableblockpos, Blocks.COBBLESTONE.getDefaultState(), 2);
}
else
{
worldIn.setBlockState(blockpos$mutableblockpos, Blocks.STONE.getDefaultState(), 2);
}
}
}
}
}
}
示例8: notifyBlockUpdate
import net.minecraft.util.math.BlockPos; //导入方法依赖的package包/类
public void notifyBlockUpdate(World worldIn, BlockPos pos, IBlockState oldState, IBlockState newState, int flags)
{
if (this.didBlockChange(worldIn, pos, oldState, newState))
{
int i = 0;
for (int j = this.navigations.size(); i < j; ++i)
{
PathNavigate pathnavigate = (PathNavigate)this.navigations.get(i);
if (pathnavigate != null && !pathnavigate.canUpdatePathOnTimeout())
{
Path path = pathnavigate.getPath();
if (path != null && !path.isFinished() && path.getCurrentPathLength() != 0)
{
PathPoint pathpoint = pathnavigate.currentPath.getFinalPathPoint();
double d0 = pos.distanceSq(((double)pathpoint.xCoord + pathnavigate.theEntity.posX) / 2.0D, ((double)pathpoint.yCoord + pathnavigate.theEntity.posY) / 2.0D, ((double)pathpoint.zCoord + pathnavigate.theEntity.posZ) / 2.0D);
int k = (path.getCurrentPathLength() - path.getCurrentPathIndex()) * (path.getCurrentPathLength() - path.getCurrentPathIndex());
if (d0 < (double)k)
{
pathnavigate.updatePath();
}
}
}
}
}
}
示例9: generate
import net.minecraft.util.math.BlockPos; //导入方法依赖的package包/类
public boolean generate(World worldIn, Random rand, BlockPos position)
{
while (true)
{
label0:
{
if (position.getY() > 3)
{
if (worldIn.isAirBlock(position.down()))
{
break label0;
}
Block block = worldIn.getBlockState(position.down()).getBlock();
if (block != Blocks.GRASS && block != Blocks.DIRT && block != Blocks.STONE)
{
break label0;
}
}
if (position.getY() <= 3)
{
return false;
}
int i1 = this.startRadius;
for (int i = 0; i1 >= 0 && i < 3; ++i)
{
int j = i1 + rand.nextInt(2);
int k = i1 + rand.nextInt(2);
int l = i1 + rand.nextInt(2);
float f = (float)(j + k + l) * 0.333F + 0.5F;
for (BlockPos blockpos : BlockPos.getAllInBox(position.add(-j, -k, -l), position.add(j, k, l)))
{
if (blockpos.distanceSq(position) <= (double)(f * f))
{
worldIn.setBlockState(blockpos, this.block.getDefaultState(), 4);
}
}
position = position.add(-(i1 + 1) + rand.nextInt(2 + i1 * 2), 0 - rand.nextInt(2), -(i1 + 1) + rand.nextInt(2 + i1 * 2));
}
return true;
}
position = position.down();
}
}
示例10: getDistanceSq
import net.minecraft.util.math.BlockPos; //导入方法依赖的package包/类
public double getDistanceSq(BlockPos pos)
{
return pos.distanceSq(this.posX, this.posY, this.posZ);
}
示例11: getDistanceToDoorBlockSq
import net.minecraft.util.math.BlockPos; //导入方法依赖的package包/类
public int getDistanceToDoorBlockSq(BlockPos pos)
{
return (int)pos.distanceSq(this.getDoorBlockPos());
}
示例12: getClosestStrongholdPos
import net.minecraft.util.math.BlockPos; //导入方法依赖的package包/类
public BlockPos getClosestStrongholdPos(World worldIn, BlockPos pos)
{
this.worldObj = worldIn;
this.initializeStructureData(worldIn);
this.rand.setSeed(worldIn.getSeed());
long i = this.rand.nextLong();
long j = this.rand.nextLong();
long k = (long)(pos.getX() >> 4) * i;
long l = (long)(pos.getZ() >> 4) * j;
this.rand.setSeed(k ^ l ^ worldIn.getSeed());
this.recursiveGenerate(worldIn, pos.getX() >> 4, pos.getZ() >> 4, 0, 0, (ChunkPrimer)null);
double d0 = Double.MAX_VALUE;
BlockPos blockpos = null;
for (StructureStart structurestart : this.structureMap.values())
{
if (structurestart.isSizeableStructure())
{
StructureComponent structurecomponent = (StructureComponent)structurestart.getComponents().get(0);
BlockPos blockpos1 = structurecomponent.getBoundingBoxCenter();
double d1 = blockpos1.distanceSq(pos);
if (d1 < d0)
{
d0 = d1;
blockpos = blockpos1;
}
}
}
if (blockpos != null)
{
return blockpos;
}
else
{
List<BlockPos> list = this.getCoordList();
if (list != null)
{
BlockPos blockpos2 = null;
for (BlockPos blockpos3 : list)
{
double d2 = blockpos3.distanceSq(pos);
if (d2 < d0)
{
d0 = d2;
blockpos2 = blockpos3;
}
}
return blockpos2;
}
else
{
return null;
}
}
}