當前位置: 首頁>>代碼示例>>Java>>正文


Java BlockPos.distanceSq方法代碼示例

本文整理匯總了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);
                }
            }
        }
    }
}
 
開發者ID:Buuz135,項目名稱:Industrial-Foregoing,代碼行數:23,代碼來源:TreeCache.java

示例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);
                }
            }
        }
    }
}
 
開發者ID:Buuz135,項目名稱:Industrial-Foregoing,代碼行數:19,代碼來源:ChorusCache.java

示例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;
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:27,代碼來源:EntityTF2Character.java

示例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));
        }
    }
}
 
開發者ID:ternsip,項目名稱:ChopDown,代碼行數:49,代碼來源:ChopDown.java

示例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);
	}
}
 
開發者ID:orbwoi,項目名稱:UniversalRemote,代碼行數:16,代碼來源:HookedEntityPlayerMP.java

示例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);
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:11,代碼來源:WorldServer.java

示例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);
                    }
                }
            }
        }
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:34,代碼來源:BiomeVoidDecorator.java

示例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();
                    }
                }
            }
        }
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:30,代碼來源:PathWorldListener.java

示例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();
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:52,代碼來源:WorldGenBlockBlob.java

示例10: getDistanceSq

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
public double getDistanceSq(BlockPos pos)
{
    return pos.distanceSq(this.posX, this.posY, this.posZ);
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:5,代碼來源:Entity.java

示例11: getDistanceToDoorBlockSq

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
public int getDistanceToDoorBlockSq(BlockPos pos)
{
    return (int)pos.distanceSq(this.getDoorBlockPos());
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:5,代碼來源:VillageDoorInfo.java

示例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;
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:62,代碼來源:MapGenStructure.java


注:本文中的net.minecraft.util.math.BlockPos.distanceSq方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。