Tags, surface builders, biome API (WIP), processors, features
This commit is contained in:
parent
6b0bf593ad
commit
979e2ab92a
15 changed files with 1513 additions and 51 deletions
|
@ -1,14 +1,15 @@
|
|||
package ru.bclib.util;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.ClipContext.Fluid;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
@ -37,20 +38,6 @@ public class BlocksHelper {
|
|||
protected static final BlockState AIR = Blocks.AIR.defaultBlockState();
|
||||
protected static final BlockState WATER = Blocks.WATER.defaultBlockState();
|
||||
|
||||
private static final Vec3i[] OFFSETS = new Vec3i[] {
|
||||
new Vec3i(-1, -1, -1), new Vec3i(-1, -1, 0), new Vec3i(-1, -1, 1),
|
||||
new Vec3i(-1, 0, -1), new Vec3i(-1, 0, 0), new Vec3i(-1, 0, 1),
|
||||
new Vec3i(-1, 1, -1), new Vec3i(-1, 1, 0), new Vec3i(-1, 1, 1),
|
||||
|
||||
new Vec3i(0, -1, -1), new Vec3i(0, -1, 0), new Vec3i(0, -1, 1),
|
||||
new Vec3i(0, 0, -1), new Vec3i(0, 0, 0), new Vec3i(0, 0, 1),
|
||||
new Vec3i(0, 1, -1), new Vec3i(0, 1, 0), new Vec3i(0, 1, 1),
|
||||
|
||||
new Vec3i(1, -1, -1), new Vec3i(1, -1, 0), new Vec3i(1, -1, 1),
|
||||
new Vec3i(1, 0, -1), new Vec3i(1, 0, 0), new Vec3i(1, 0, 1),
|
||||
new Vec3i(1, 1, -1), new Vec3i(1, 1, 0), new Vec3i(1, 1, 1)
|
||||
};
|
||||
|
||||
public static void addBlockColor(Block block, int color) {
|
||||
COLOR_BY_BLOCK.put(block, color);
|
||||
}
|
||||
|
@ -107,14 +94,35 @@ public class BlocksHelper {
|
|||
return (int) pos.distSqr(POS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates {@link BlockState} horizontally. Used in block classes with {@link Direction} {@link Property} in rotate function.
|
||||
* @param state - {@link BlockState} to mirror;
|
||||
* @param rotation - {@link Rotation};
|
||||
* @param facing - Block {@link Direction} {@link Property}.
|
||||
* @return Rotated {@link BlockState}.
|
||||
*/
|
||||
public static BlockState rotateHorizontal(BlockState state, Rotation rotation, Property<Direction> facing) {
|
||||
return state.setValue(facing, rotation.rotate(state.getValue(facing)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirrors {@link BlockState} horizontally. Used in block classes with {@link Direction} {@link Property} in mirror function.
|
||||
* @param state - {@link BlockState} to mirror;
|
||||
* @param mirror - {@link Mirror};
|
||||
* @param facing - Block {@link Direction} {@link Property}.
|
||||
* @return Mirrored {@link BlockState}.
|
||||
*/
|
||||
public static BlockState mirrorHorizontal(BlockState state, Mirror mirror, Property<Direction> facing) {
|
||||
return state.rotate(mirror.getRotation(state.getValue(facing)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the amount of same block down.
|
||||
* @param world - {@link LevelAccessor} world;
|
||||
* @param pos - {@link BlockPos} start position;
|
||||
* @param block - {@link Block} to count.
|
||||
* @return Integer amount of blocks.
|
||||
*/
|
||||
public static int getLengthDown(LevelAccessor world, BlockPos pos, Block block) {
|
||||
int count = 1;
|
||||
while (world.getBlockState(pos.below(count)).getBlock() == block) {
|
||||
|
@ -123,49 +131,59 @@ public class BlocksHelper {
|
|||
return count;
|
||||
}
|
||||
|
||||
public static void cover(LevelAccessor world, BlockPos center, Block ground, BlockState cover, int radius, Random random) {
|
||||
HashSet<BlockPos> points = new HashSet<BlockPos>();
|
||||
HashSet<BlockPos> points2 = new HashSet<BlockPos>();
|
||||
if (world.getBlockState(center).getBlock() == ground) {
|
||||
points.add(center);
|
||||
points2.add(center);
|
||||
for (int i = 0; i < radius; i++) {
|
||||
Iterator<BlockPos> iterator = points.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
BlockPos pos = iterator.next();
|
||||
for (Vec3i offset : OFFSETS) {
|
||||
if (random.nextBoolean()) {
|
||||
BlockPos pos2 = pos.offset(offset);
|
||||
if (random.nextBoolean() && world.getBlockState(pos2).getBlock() == ground
|
||||
&& !points.contains(pos2))
|
||||
points2.add(pos2);
|
||||
}
|
||||
}
|
||||
}
|
||||
points.addAll(points2);
|
||||
points2.clear();
|
||||
}
|
||||
Iterator<BlockPos> iterator = points.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
BlockPos pos = iterator.next();
|
||||
BlocksHelper.setWithoutUpdate(world, pos, cover);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Direction} array with clockwise order:
|
||||
* NORTH -> EAST -> SOUTH -> WEST
|
||||
* @return Array of {@link Direction}.
|
||||
*/
|
||||
public static Direction[] makeHorizontal() {
|
||||
return new Direction[] { Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST };
|
||||
}
|
||||
|
||||
/**
|
||||
* Get any random horizontal {@link Direction}.
|
||||
* @param random - {@link Random}.
|
||||
* @return {@link Direction}.
|
||||
*/
|
||||
public static Direction randomHorizontal(Random random) {
|
||||
return HORIZONTAL[random.nextInt(4)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get any random {@link Direction} including vertical and horizontal.
|
||||
* @param random - {@link Random}.
|
||||
* @return {@link Direction}.
|
||||
*/
|
||||
public static Direction randomDirection(Random random) {
|
||||
return DIRECTIONS[random.nextInt(6)];
|
||||
}
|
||||
|
||||
public static boolean isFluid(BlockState blockState) {
|
||||
return !blockState.getFluidState().isEmpty();
|
||||
/**
|
||||
* Check if block is {@link Fluid} or not.
|
||||
* @param state - {@link BlockState} to check.
|
||||
* @return {@code true} if block is fluid and {@code false} if not.
|
||||
*/
|
||||
public static boolean isFluid(BlockState state) {
|
||||
return !state.getFluidState().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if block is "invulnerable" like Bedrock.
|
||||
* @param state - {@link BlockState} to check;
|
||||
* @param world - {@link BlockGetter} world where BlockState exist;
|
||||
* @param pos - {@link BlockPos} where BlockState is.
|
||||
* @return {@code true} if block is "invulnerable" and {@code false} if not.
|
||||
*/
|
||||
public static boolean isInvulnerable(BlockState state, BlockGetter world, BlockPos pos) {
|
||||
return state.getDestroySpeed(world, pos) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if block is "invulnerable" like Bedrock. Unlike safe function will pass world and position parameters as {@code null}.
|
||||
* @param state - {@link BlockState} to check.
|
||||
* @return {@code true} if block is "invulnerable" and {@code false} if not.
|
||||
*/
|
||||
public static boolean isInvulnerableUnsafe(BlockState state) {
|
||||
return isInvulnerable(state, null, null);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue