net.minecraft.util.math.BlockPos#Mutable ( )源码实例Demo

下面列出了net.minecraft.util.math.BlockPos#Mutable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: the-hallow   文件: StoneCircleFeature.java
private void generateStone(ModifiableWorld world, Random rand, final BlockPos centre, BlockPos.Mutable mutable, int height, int lowY) {
	final int posX = centre.getX();
	final int posZ = centre.getZ();
	
	for (int xOffset = -3; xOffset < 4; ++xOffset) {
		mutable.setX(posX + xOffset);
		for (int zOffset = -3; zOffset < 4; ++zOffset) {
			mutable.setZ(posZ + zOffset);
			mutable.setY(0);
			
			double squaredDistanceTo = centre.getSquaredDistance(mutable) / 9D;
			
			int localHeight = (int) offsetNoise.sample(mutable.getX(), mutable.getZ()) + (int) MathHelper.lerp(squaredDistanceTo, height, 0D) + lowY;
			
			for (int y = lowY - 5; y < localHeight + 1; ++y) {
				mutable.setY(y);
				world.setBlockState(mutable, rand.nextInt(3) == 0 ? COBBLESTONE : STONE, 19);
			}
		}
	}
}
 
源代码2 项目: the-hallow   文件: LargeDeadwoodTreeFeature.java
private boolean doesTreeFit(TestableWorld world, BlockPos pos, int height) {
	int x = pos.getX();
	int y = pos.getY();
	int z = pos.getZ();
	BlockPos.Mutable mutablePos = new BlockPos.Mutable();
	
	for (int localY = 0; localY <= height + 1; ++localY) {
		int leafSize = 1;
		if (localY == 0) {
			leafSize = 0;
		}
		
		if (localY >= height - 1) {
			leafSize = 2;
		}
		
		for (int localX = -leafSize; localX <= leafSize; ++localX) {
			for (int localZ = -leafSize; localZ <= leafSize; ++localZ) {
				if (!canTreeReplace(world, mutablePos.set(x + localX, y + localY, z + localZ))) {
					return false;
				}
			}
		}
	}
	return true;
}
 
源代码3 项目: the-hallow   文件: BarrowFeature.java
private void generateBarrowColumn(IWorld world, Random rand, int lowY, int heightOffset, BlockPos.Mutable pos, SurfaceConfig surfaceConfig) {
	int upperY = lowY + heightOffset;
	
	for (int y = upperY; y >= lowY; --y) {
		pos.setY(y);
		if (y == upperY) {
			world.setBlockState(pos, surfaceConfig.getTopMaterial(), 19);
		} else if (y > upperY - 3) {
			world.setBlockState(pos, surfaceConfig.getUnderMaterial(), 19);
		} else if (y == lowY + 2 && rand.nextInt(32) == 0) {
			if (rand.nextInt(3) == 0) {
				setLootChest(world, pos, LOOT_TABLE, rand);
			} else {
				setSpawner(world, pos, BARROW_WIGHT);
			}
		} else {
			world.setBlockState(pos, y <= lowY + 1 ? STONE : AIR, 19);
		}
	}
}
 
源代码4 项目: fabric-carpet   文件: DrawCommand.java
private static int setBlock(
        ServerWorld world, BlockPos.Mutable mbpos, int x, int y, int z,
        BlockStateArgument block, Predicate<CachedBlockPosition> replacement,
        List<BlockPos> list
)
{
    mbpos.set(x, y, z);
    int success=0;
    if (replacement == null || replacement.test(new CachedBlockPosition(world, mbpos, true)))
    {
        BlockEntity tileentity = world.getBlockEntity(mbpos);
        if (tileentity instanceof Inventory)
        {
            ((Inventory) tileentity).clear();
        }
        if (block.setBlockState(world, mbpos, 2))
        {
            list.add(mbpos.toImmutable());
            ++success;
        }
    }

    return success;
}
 
源代码5 项目: the-hallow   文件: BarrowFeature.java
private boolean generate(IWorld world, Random rand, BlockPos pos, CoordinateFunction<SurfaceConfig> configFunction) {
	int centreX = pos.getX() + rand.nextInt(16) - 8;
	int centreZ = pos.getZ() + rand.nextInt(16) - 8;
	int lowY = pos.getY() - 3;
	
	int radius = rand.nextInt(6) + 7;
	int height = rand.nextInt(4) + 6;
	
	double radiusSquared = radius * radius;
	
	Vec3d origin = new Vec3d(centreX, 0, centreZ);
	
	BlockPos.Mutable posMutable = new BlockPos.Mutable();
	
	for (int xOffset = -radius; xOffset <= radius; ++xOffset) {
		int x = centreX + xOffset;
		
		for (int zOffset = -radius; zOffset <= radius; ++zOffset) {
			int z = centreZ + zOffset;
			
			Vec3d position = new Vec3d(x, 0, z);
			double sqrDistTo = position.squaredDistanceTo(origin);
			if (sqrDistTo <= radiusSquared) {
				double progress = MathHelper.perlinFade(sqrDistTo / radiusSquared);
				int heightOffset = (int) MathHelper.lerp(progress, height, 0);
				heightOffset += (int) MathHelper.lerp(progress, offsetNoise.sample(x, z), 0);
				
				posMutable.setX(x);
				posMutable.setZ(z);
				
				this.generateBarrowColumn(world, rand, lowY, heightOffset, posMutable, configFunction.get(posMutable));
			}
		}
	}
	return true;
}
 
源代码6 项目: Galacticraft-Rewoven   文件: GCOreFeature.java
@SuppressWarnings("PointlessArithmeticExpression")
protected boolean generateVeinPart(WorldAccess world, Random random, GCOreFeatureConfig config, double startX, double endX, double startZ, double endZ, double startY, double endY, int x, int y, int z, int size, int i) {
    int j = 0;
    BitSet bitSet = new BitSet(size * i * size);
    BlockPos.Mutable mutable = new BlockPos.Mutable();
    double[] ds = new double[config.size * 4];

    int m;
    double o;
    double p;
    double q;
    double r;
    for (m = 0; m < config.size; ++m) {
        float f = (float) m / (float) config.size;
        o = MathHelper.lerp(f, startX, endX);
        p = MathHelper.lerp(f, startY, endY);
        q = MathHelper.lerp(f, startZ, endZ);
        r = random.nextDouble() * (double) config.size / 16.0D;
        double l = ((double) (MathHelper.sin(3.1415927F * f) + 1.0F) * r + 1.0D) / 2.0D;
        ds[m * 4 + 0] = o;
        ds[m * 4 + 1] = p;
        ds[m * 4 + 2] = q;
        ds[m * 4 + 3] = l;
    }

    for (m = 0; m < config.size - 1; ++m) {
        if (ds[m * 4 + 3] > 0.0D) {
            for (int n = m + 1; n < config.size; ++n) {
                if (ds[n * 4 + 3] > 0.0D) {
                    o = ds[m * 4 + 0] - ds[n * 4 + 0];
                    p = ds[m * 4 + 1] - ds[n * 4 + 1];
                    q = ds[m * 4 + 2] - ds[n * 4 + 2];
                    r = ds[m * 4 + 3] - ds[n * 4 + 3];
                    if (r * r > o * o + p * p + q * q) {
                        if (r > 0.0D) {
                            ds[n * 4 + 3] = -1.0D;
                        } else {
                            ds[m * 4 + 3] = -1.0D;
                        }
                    }
                }
            }
        }
    }

    for (m = 0; m < config.size; ++m) {
        double t = ds[m * 4 + 3];
        if (t >= 0.0D) {
            double u = ds[m * 4 + 0];
            double v = ds[m * 4 + 1];
            double w = ds[m * 4 + 2];
            int aa = Math.max(MathHelper.floor(u - t), x);
            int ab = Math.max(MathHelper.floor(v - t), y);
            int ac = Math.max(MathHelper.floor(w - t), z);
            int ad = Math.max(MathHelper.floor(u + t), aa);
            int ae = Math.max(MathHelper.floor(v + t), ab);
            int af = Math.max(MathHelper.floor(w + t), ac);

            for (int ag = aa; ag <= ad; ++ag) {
                double ah = ((double) ag + 0.5D - u) / t;
                if (ah * ah < 1.0D) {
                    for (int ai = ab; ai <= ae; ++ai) {
                        double aj = ((double) ai + 0.5D - v) / t;
                        if (ah * ah + aj * aj < 1.0D) {
                            for (int ak = ac; ak <= af; ++ak) {
                                double al = ((double) ak + 0.5D - w) / t;
                                if (ah * ah + aj * aj + al * al < 1.0D) {
                                    int am = ag - x + (ai - y) * size + (ak - z) * size * i;
                                    if (!bitSet.get(am)) {
                                        bitSet.set(am);
                                        mutable.set(ag, ai, ak);
                                        if (config.target.predicate.test(world.getBlockState(mutable))) {
                                            world.setBlockState(mutable, config.state, 2);
                                            ++j;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return j > 0;
}
 
源代码7 项目: Galacticraft-Rewoven   文件: MoonSurfaceBuilder.java
public void generate(Random random, Chunk chunk, Biome biome, int x, int z, int height, double noise, BlockState defaultBlock, BlockState fluidBlock, int seaLevel, long seed, TernarySurfaceConfig ternarySurfaceConfig) {
    BlockState blockState = ternarySurfaceConfig.getTopMaterial();
    BlockState blockState2 = ternarySurfaceConfig.getUnderMaterial();
    BlockPos.Mutable mutable = new BlockPos.Mutable();
    int i = -1;
    int j = (int) (noise / 3.0D + 3.0D + random.nextDouble() * 0.25D);
    int k = x & 15;
    int l = z & 15;

    for (int m = height; m >= 0; --m) {
        mutable.set(k, m, l);
        BlockState blockState3 = chunk.getBlockState(mutable);
        if (blockState3.isAir()) {
            i = -1;
        } else if (blockState3.isOf(defaultBlock.getBlock())) {
            if (i == -1) {
                if (j <= 0) {
                    blockState = Blocks.AIR.getDefaultState();
                    blockState2 = defaultBlock;
                } else if (m >= seaLevel - 4 && m <= seaLevel + 1) {
                    blockState = ternarySurfaceConfig.getTopMaterial();
                    blockState2 = ternarySurfaceConfig.getUnderMaterial();
                }

                if (m < seaLevel && (blockState == null || blockState.isAir())) {
                    if (biome.getTemperature(mutable.set(x, m, z)) < 0.15F) {
                        blockState = Blocks.ICE.getDefaultState();
                    } else {
                        blockState = fluidBlock;
                    }

                    mutable.set(k, m, l);
                }

                i = j;
                if (m >= seaLevel - 1) {
                    chunk.setBlockState(mutable, blockState, false);
                } else if (m < seaLevel - 7 - j) {
                    blockState = Blocks.AIR.getDefaultState();
                    blockState2 = defaultBlock;
                    chunk.setBlockState(mutable, ternarySurfaceConfig.getUnderwaterMaterial(), false);
                } else {
                    chunk.setBlockState(mutable, blockState2, false);
                }
            } else if (i > 0) {
                --i;
                chunk.setBlockState(mutable, blockState2, false);
                if (i == 0 && blockState2.isOf(GalacticraftBlocks.MOON_TURF) && j > 1) {
                    i = random.nextInt(4) + Math.max(0, m - 63);
                    blockState2 = GalacticraftBlocks.MOON_ROCK.getDefaultState();
                }
            }
        }
    }
}
 
protected void generate(Random random, Chunk chunk, Biome biome, int x, int z, int height, double noise, BlockState defaultBlock, BlockState fluidBlock, MultiBlockSurfaceConfig multiBlockSurfaceConfig, int seaLevel) {
    BlockState blockState = multiBlockSurfaceConfig.getTopMaterial();
    BlockState blockState2 = multiBlockSurfaceConfig.getUnderMaterial();
    BlockPos.Mutable mutable = new BlockPos.Mutable();
    int i = -1;
    int j = (int) (noise / 3.0D + 3.0D + random.nextDouble() * 0.25D);
    int k = x & 15;
    int l = z & 15;

    for (int m = height; m >= 0; --m) {
        mutable.set(k, m, l);
        BlockState blockState3 = chunk.getBlockState(mutable);
        if (blockState3.isAir()) {
            i = -1;
        } else if (blockState3.getBlock() == defaultBlock.getBlock()) {
            if (i == -1) {
                if (j <= 0) {
                    blockState = Blocks.AIR.getDefaultState();
                    blockState2 = multiBlockSurfaceConfig.getUnderMaterial();
                } else if (m >= seaLevel - 4 && m <= seaLevel + 1) {
                    blockState = multiBlockSurfaceConfig.getTopMaterial();
                    blockState2 = multiBlockSurfaceConfig.getUnderMaterial();
                }

                if (m < seaLevel && (blockState == null || blockState.isAir())) {
                    if (biome.getTemperature(mutable.set(x, m, z)) < 0.15F) {
                        blockState = Blocks.ICE.getDefaultState();
                    } else {
                        blockState = fluidBlock;
                    }

                    mutable.set(k, m, l);
                }

                i = j;
                if (m >= seaLevel - 1) {
                    chunk.setBlockState(mutable, blockState, false);
                } else if (m < seaLevel - 7 - j) {
                    blockState = Blocks.AIR.getDefaultState();
                    blockState2 = multiBlockSurfaceConfig.getTopMaterial();
                    chunk.setBlockState(mutable, multiBlockSurfaceConfig.getUnderwaterMaterial(), false);
                } else {
                    chunk.setBlockState(mutable, blockState2, false);
                }
            } else if (i > 0) {
                --i;
                chunk.setBlockState(mutable, blockState2, false);
                if (i == 0 && blockState2.getBlock() == Blocks.SAND && j > 1) {
                    i = random.nextInt(4) + Math.max(0, m - 63);
                    blockState2 = blockState2.getBlock() == Blocks.RED_SAND ? Blocks.RED_SANDSTONE.getDefaultState() : Blocks.SANDSTONE.getDefaultState();
                }
            }
        }
    }
}
 
源代码9 项目: multiconnect   文件: ChunkUpgrader.java
public static UpgradeData fixChunk(WorldChunk chunk) {
    IntList centerIndicesToUpgrade = new IntArrayList();
    int sidesToUpgrade = 0;

    BlockPos.Mutable otherPos = new BlockPos.Mutable();
    for (BlockPos pos : BlockPos.iterate(chunk.getPos().getStartX(), 0, chunk.getPos().getStartZ(),
            chunk.getPos().getEndX(), chunk.getHighestNonEmptySectionYOffset() + 15, chunk.getPos().getEndZ())) {
        BlockState state = chunk.getBlockState(pos);
        Block block = state.getBlock();
        inPlaceFix(chunk, state, pos, otherPos);

        int blockId = Registry.BLOCK.getRawId(block) & 4095;
        if (ChunkPalettedStorageFixAccessor.getBlocksNeedingSideUpdate().get(blockId)) {
            boolean west = (pos.getX() & 15) == 0;
            boolean east = (pos.getX() & 15) == 15;
            boolean north = (pos.getZ() & 15) == 0;
            boolean south = (pos.getZ() & 15) == 15;
            if (north) {
                if (east) {
                    sidesToUpgrade |= 2;
                } else if (west) {
                    sidesToUpgrade |= 128;
                } else {
                    sidesToUpgrade |= 1;
                }
            } else if (south) {
                if (west) {
                    sidesToUpgrade |= 32;
                } else if (east) {
                    sidesToUpgrade |= 8;
                } else {
                    sidesToUpgrade |= 16;
                }
            } else if (east) {
                sidesToUpgrade |= 4;
            } else if (west) {
                sidesToUpgrade |= 64;
            } else {
                centerIndicesToUpgrade.add(pos.getY() << 8 | (pos.getZ() & 15) << 4 | (pos.getX() & 15));
            }
        }
    }

    if (centerIndicesToUpgrade.isEmpty() && sidesToUpgrade == 0)
        return null;

    CompoundTag upgradeData = new CompoundTag();
    upgradeData.putInt("Sides", sidesToUpgrade);
    CompoundTag centerIndices = new CompoundTag();
    centerIndicesToUpgrade.forEach((IntConsumer) index -> {
        int low = index & 4095;
        int high = index >>> 12;
        Tag tag = centerIndices.get(String.valueOf(high));
        if (tag == null)
            centerIndices.put(String.valueOf(high), tag = new ListTag());
        ((ListTag) tag).add(IntTag.of(low));
    });
    for (String key : centerIndices.getKeys()) {
        //noinspection ConstantConditions
        centerIndices.put(key, new IntArrayTag(((ListTag) centerIndices.get(key)).stream().mapToInt(val -> ((IntTag) val).getInt()).toArray()));
    }
    upgradeData.put("Indices", centerIndices);
    return new UpgradeData(upgradeData);
}
 
源代码10 项目: multiconnect   文件: MixinEntity.java
@Inject(method = "updateMovementInFluid", at = @At("HEAD"), cancellable = true)
private void modifyFluidMovementBoundingBox(Tag<Fluid> fluidTag, double d, CallbackInfoReturnable<Boolean> ci) {
    if (ConnectionInfo.protocolVersion > Protocols.V1_12_2)
        return;

    Box box = getBoundingBox().expand(0, -0.4, 0).contract(0.001);
    int minX = MathHelper.floor(box.minX);
    int maxX = MathHelper.ceil(box.maxX);
    int minY = MathHelper.floor(box.minY);
    int maxY = MathHelper.ceil(box.maxY);
    int minZ = MathHelper.floor(box.minZ);
    int maxZ = MathHelper.ceil(box.maxZ);

    if (!world.isRegionLoaded(minX, minY, minZ, maxX, maxY, maxZ))
        ci.setReturnValue(false);

    double waterHeight = 0;
    boolean foundFluid = false;
    Vec3d pushVec = Vec3d.ZERO;

    BlockPos.Mutable mutable = new BlockPos.Mutable();

    for (int x = minX; x < maxX; x++) {
        for (int y = minY - 1; y < maxY; y++) {
            for (int z = minZ; z < maxZ; z++) {
                mutable.set(x, y, z);
                FluidState state = world.getFluidState(mutable);
                if (state.isIn(fluidTag)) {
                    double height = y + state.getHeight(world, mutable);
                    if (height >= box.minY - 0.4)
                        waterHeight = Math.max(height - box.minY + 0.4, waterHeight);
                    if (y >= minY && maxY >= height) {
                        foundFluid = true;
                        pushVec = pushVec.add(state.getVelocity(world, mutable));
                    }
                }
            }
        }
    }

    if (pushVec.length() > 0) {
        pushVec = pushVec.normalize().multiply(0.014);
        setVelocity(getVelocity().add(pushVec));
    }

    this.fluidHeight.put(fluidTag, waterHeight);
    ci.setReturnValue(foundFluid);
}
 
源代码11 项目: Sandbox   文件: FunctionsImpl.java
@Override
public Position.Mutable createMutablePosition(int x, int y, int z) {
    return (Position.Mutable) new BlockPos.Mutable(x, y, z);
}
 
源代码12 项目: Sandbox   文件: MixinBlockPos.java
public Mutable sbx$toMutable() {
    return (Mutable) new BlockPos.Mutable((BlockPos) (Object) this);
}
 
源代码13 项目: fabric-carpet   文件: DrawCommand.java
private static int drawSphere(CommandContext<ServerCommandSource> ctx, boolean solid) throws CommandSyntaxException
{
    BlockPos pos;
    int radius;
    BlockStateArgument block;
    Predicate<CachedBlockPosition> replacement;
    try
    {
        pos = getArg(ctx, BlockPosArgumentType::getBlockPos, "center");
        radius = getArg(ctx, IntegerArgumentType::getInteger, "radius");
        block = getArg(ctx, BlockStateArgumentType::getBlockState, "block");
        replacement = getArg(ctx, BlockPredicateArgumentType::getBlockPredicate, "filter", true);
    }
    catch (ErrorHandled ignored) { return 0; }

    int affected = 0;
    ServerWorld world = ctx.getSource().getWorld();

    double radiusX = radius+0.5;
    double radiusY = radius+0.5;
    double radiusZ = radius+0.5;

    final double invRadiusX = 1 / radiusX;
    final double invRadiusY = 1 / radiusY;
    final double invRadiusZ = 1 / radiusZ;

    final int ceilRadiusX = (int) Math.ceil(radiusX);
    final int ceilRadiusY = (int) Math.ceil(radiusY);
    final int ceilRadiusZ = (int) Math.ceil(radiusZ);

    BlockPos.Mutable mbpos = new BlockPos.Mutable(pos);
    List<BlockPos> list = Lists.newArrayList();

    double nextXn = 0;

    forX: for (int x = 0; x <= ceilRadiusX; ++x)
    {
        final double xn = nextXn;
        nextXn = (x + 1) * invRadiusX;
        double nextYn = 0;
        forY: for (int y = 0; y <= ceilRadiusY; ++y)
        {
            final double yn = nextYn;
            nextYn = (y + 1) * invRadiusY;
            double nextZn = 0;
            forZ: for (int z = 0; z <= ceilRadiusZ; ++z)
            {
                final double zn = nextZn;
                nextZn = (z + 1) * invRadiusZ;

                double distanceSq = lengthSq(xn, yn, zn);
                if (distanceSq > 1)
                {
                    if (z == 0)
                    {
                        if (y == 0)
                        {
                            break forX;
                        }
                        break forY;
                    }
                    break forZ;
                }

                if (!solid && lengthSq(nextXn, yn, zn) <= 1 && lengthSq(xn, nextYn, zn) <= 1 && lengthSq(xn, yn, nextZn) <= 1)
                {
                    continue;
                }

                CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates;
                for (int xmod = -1; xmod < 2; xmod += 2)
                {
                    for (int ymod = -1; ymod < 2; ymod += 2)
                    {
                        for (int zmod = -1; zmod < 2; zmod += 2)
                        {
                            affected+= setBlock(world, mbpos,
                                    pos.getX() + xmod * x, pos.getY() + ymod * y, pos.getZ() + zmod * z,
                                    block, replacement, list
                            );
                        }
                    }
                }
                CarpetSettings.impendingFillSkipUpdates = false;
            }
        }
    }
    if (CarpetSettings.fillUpdates)
    {
        list.forEach(blockpos1 -> world.updateNeighbors(blockpos1, world.getBlockState(blockpos1).getBlock()));
    }
    Messenger.m(ctx.getSource(), "gi Filled " + affected + " blocks");
    return affected;
}
 
源代码14 项目: fabric-carpet   文件: DrawCommand.java
private static int drawDiamond(CommandContext<ServerCommandSource> ctx, boolean solid) throws CommandSyntaxException
{
    BlockPos pos;
    int radius;
    BlockStateArgument block;
    Predicate<CachedBlockPosition> replacement;
    try
    {
        pos = getArg(ctx, BlockPosArgumentType::getBlockPos, "center");
        radius = getArg(ctx, IntegerArgumentType::getInteger, "radius");
        block = getArg(ctx, BlockStateArgumentType::getBlockState, "block");
        replacement = getArg(ctx, BlockPredicateArgumentType::getBlockPredicate, "filter", true);
    }
    catch (ErrorHandled ignored) { return 0; }

    ServerCommandSource source = ctx.getSource();

    int affected=0;

    BlockPos.Mutable mbpos = new BlockPos.Mutable(pos);
    List<BlockPos> list = Lists.newArrayList();

    ServerWorld world = source.getWorld();

    CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates;

    for (int r = 0; r < radius; ++r)
    {
        int y=r-radius+1;
        for (int x = -r; x <= r; ++x)
        {
            int z=r-Math.abs(x);

            affected+= setBlock(world, mbpos, pos.getX()+x, pos.getY()-y, pos.getZ()+z, block, replacement, list);
            affected+= setBlock(world, mbpos, pos.getX()+x, pos.getY()-y, pos.getZ()-z, block, replacement, list);
            affected+= setBlock(world, mbpos, pos.getX()+x, pos.getY()+y, pos.getZ()+z, block, replacement, list);
            affected+= setBlock(world, mbpos, pos.getX()+x, pos.getY()+y, pos.getZ()-z, block, replacement, list);
        }
    }

    CarpetSettings.impendingFillSkipUpdates = false;

    if (CarpetSettings.fillUpdates)
    {
        list.forEach(p -> world.updateNeighbors(p, world.getBlockState(p).getBlock()));
    }

    Messenger.m(source, "gi Filled " + affected + " blocks");

    return affected;
}
 
源代码15 项目: fabric-carpet   文件: DrawCommand.java
private static int fillFlat(
        ServerWorld world, BlockPos pos, int offset, double dr, boolean rectangle, String orientation,
        BlockStateArgument block, Predicate<CachedBlockPosition> replacement,
        List<BlockPos> list, BlockPos.Mutable mbpos
)
{
    int successes=0;
    int r = MathHelper.floor(dr);
    double drsq = dr*dr;
    if (orientation.equalsIgnoreCase("x"))
    {
        for(int a=-r; a<=r; ++a) for(int b=-r; b<=r; ++b) if(rectangle || a*a + b*b <= drsq)
        {
            successes += setBlock(
                    world, mbpos,pos.getX()+offset, pos.getY()+a, pos.getZ()+b,
                    block, replacement, list
            );
        }
        return successes;
    }
    if (orientation.equalsIgnoreCase("y"))
    {
        for(int a=-r; a<=r; ++a) for(int b=-r; b<=r; ++b) if(rectangle || a*a + b*b <= drsq)
        {
            successes += setBlock(
                    world, mbpos,pos.getX()+a, pos.getY()+offset, pos.getZ()+b,
                    block, replacement, list
            );
        }
        return successes;
    }
    if (orientation.equalsIgnoreCase("z"))
    {
        for(int a=-r; a<=r; ++a) for(int b=-r; b<=r; ++b) if(rectangle || a*a + b*b <= drsq)
        {
            successes += setBlock(
                    world, mbpos,pos.getX()+b, pos.getY()+a, pos.getZ()+offset,
                    block, replacement, list
            );
        }
        return successes;
    }
    return 0;
}
 
源代码16 项目: fabric-carpet   文件: DrawCommand.java
private static int drawPyramid(CommandContext<ServerCommandSource> ctx, String base, boolean solid) throws CommandSyntaxException
{
    BlockPos pos;
    double radius;
    int height;
    boolean pointup;
    String orientation;
    BlockStateArgument block;
    Predicate<CachedBlockPosition> replacement;
    try
    {
        pos = getArg(ctx, BlockPosArgumentType::getBlockPos, "center");
        radius = getArg(ctx, IntegerArgumentType::getInteger, "radius")+0.5D;
        height = getArg(ctx, IntegerArgumentType::getInteger, "height");
        pointup = getArg(ctx, StringArgumentType::getString, "pointing").equalsIgnoreCase("up");
        orientation = getArg(ctx, StringArgumentType::getString,"orientation");
        block = getArg(ctx, BlockStateArgumentType::getBlockState, "block");
        replacement = getArg(ctx, BlockPredicateArgumentType::getBlockPredicate, "filter", true);
    }
    catch (ErrorHandled ignored) { return 0; }

    ServerCommandSource source = ctx.getSource();

    int affected = 0;
    BlockPos.Mutable mbpos = new BlockPos.Mutable(pos);

    List<BlockPos> list = Lists.newArrayList();

    ServerWorld world = source.getWorld();

    CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates;

    boolean isSquare = base.equalsIgnoreCase("square");

    for(int i =0; i<height;++i)
    {
        double r = pointup ? radius - radius * i / height - 1 : radius * i / height;
        affected+= fillFlat(world, pos, i, r, isSquare, orientation, block, replacement, list, mbpos);
    }
    
    CarpetSettings.impendingFillSkipUpdates = false;

    if (CarpetSettings.fillUpdates) {

        for (BlockPos blockpos1 : list) {
            Block blokc = world.getBlockState(blockpos1).getBlock();
            world.updateNeighbors(blockpos1, blokc);
        }
    }

    Messenger.m(source, "gi Filled " + affected + " blocks");

    return affected;
}
 
源代码17 项目: fabric-carpet   文件: DrawCommand.java
private static int drawPrism(CommandContext<ServerCommandSource> ctx, String base){
    BlockPos pos;
    double radius;
    int height;
    String orientation;
    BlockStateArgument block;
    Predicate<CachedBlockPosition> replacement;
    try
    {
        pos = getArg(ctx, BlockPosArgumentType::getBlockPos, "center");
        radius = getArg(ctx, IntegerArgumentType::getInteger, "radius")+0.5D;
        height = getArg(ctx, IntegerArgumentType::getInteger, "height");
        orientation = getArg(ctx, StringArgumentType::getString,"orientation");
        block = getArg(ctx, BlockStateArgumentType::getBlockState, "block");
        replacement = getArg(ctx, BlockPredicateArgumentType::getBlockPredicate, "filter", true);
    }
    catch (ErrorHandled | CommandSyntaxException ignored) { return 0; }

    ServerCommandSource source = ctx.getSource();

    int affected = 0;
    BlockPos.Mutable mbpos = new BlockPos.Mutable(pos);

    List<BlockPos> list = Lists.newArrayList();

    ServerWorld world = source.getWorld();

    CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates;

    boolean isSquare = base.equalsIgnoreCase("square");

    for(int i =0; i<height;++i)
    {
        affected+= fillFlat(world, pos, i, radius, isSquare, orientation, block, replacement, list, mbpos);
    }

    CarpetSettings.impendingFillSkipUpdates = false;

    if (CarpetSettings.fillUpdates) {

        for (BlockPos blockpos1 : list) {
            Block blokc = world.getBlockState(blockpos1).getBlock();
            world.updateNeighbors(blockpos1, blokc);
        }
    }

    Messenger.m(source, "gi Filled " + affected + " blocks");

    return affected;
}