Skip to content

Commit

Permalink
限制冰雪工具只能在一定的范围内产生雪
Browse files Browse the repository at this point in the history
  • Loading branch information
SolidBlock-cn committed Jul 3, 2023
1 parent 02f870f commit 004e4bc
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/java/pers/solid/mishang/uc/item/IceSnowTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,27 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
public void applyIce(@NotNull ServerWorld world, @NotNull Vec3d pos, int strength) {
final float probability = getProbability(strength);
final int range = getRange(strength);
for (final BlockPos blockPos : BlockPos.iterateOutwards(BlockPos.ofFloored(pos), range, 0, range)) {
final BlockPos centerBlockPos = BlockPos.ofFloored(pos);
for (final BlockPos blockPos : BlockPos.iterateOutwards(centerBlockPos, range, 0, range)) {
if (world.random.nextFloat() > probability) {
continue;
}

final BlockPos topBlockPos = world.getTopPosition(Heightmap.Type.MOTION_BLOCKING, blockPos);

// 结冰
final boolean isInValidPos = pos.getY() >= world.getBottomY() && pos.getY() < world.getTopY();
final boolean isInsufficientBlockLight = isInValidPos && world.getLightLevel(LightType.BLOCK, topBlockPos) < 10;
final boolean isInsufficientBlockLight = world.getLightLevel(LightType.BLOCK, topBlockPos) < 10;
final BlockPos waterBlockPos = topBlockPos.down();
final boolean isWater = isInsufficientBlockLight && world.getBlockState(waterBlockPos).getBlock() instanceof FluidBlock && world.getFluidState(waterBlockPos).getFluid() == Fluids.WATER;
final boolean isWaterInRange = centerBlockPos.getY() - range <= waterBlockPos.getY() && blockPos.getY() <= centerBlockPos.getY() + range;
final boolean isWater = isWaterInRange && isInsufficientBlockLight && world.getBlockState(waterBlockPos).getBlock() instanceof FluidBlock && world.getFluidState(waterBlockPos).getFluid() == Fluids.WATER;
if (isWater) {
world.setBlockState(waterBlockPos, Blocks.ICE.getDefaultState());
}

// 模拟降雪
int snowAccumulationHeight = world.getGameRules().getInt(GameRules.SNOW_ACCUMULATION_HEIGHT);
if (snowAccumulationHeight > 0 && isInsufficientBlockLight && Blocks.SNOW.getDefaultState().canPlaceAt(world, topBlockPos)) {
final boolean isSnowInRange = centerBlockPos.getY() - range <= topBlockPos.getY() && topBlockPos.getY() <= centerBlockPos.getY() + range;
final int snowAccumulationHeight = world.getGameRules().getInt(GameRules.SNOW_ACCUMULATION_HEIGHT);
if (snowAccumulationHeight > 0 && isInsufficientBlockLight && isSnowInRange && Blocks.SNOW.getDefaultState().canPlaceAt(world, topBlockPos)) {
final BlockState blockState = world.getBlockState(topBlockPos);
if (blockState.isOf(Blocks.SNOW)) {
int layers = blockState.get(SnowBlock.LAYERS);
Expand Down

0 comments on commit 004e4bc

Please sign in to comment.