Start migration

This commit is contained in:
Aleksey 2021-04-08 21:55:07 +03:00
parent 6630ce0cab
commit 47ed597358
491 changed files with 12045 additions and 11953 deletions

View file

@ -9,20 +9,20 @@ import java.util.Set;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FallingBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FallingBlock;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Property;
import net.minecraft.tag.BlockTags;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.level.block.Rotation;
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.LevelAccessor;
import ru.betterend.blocks.BlueVineBlock;
import ru.betterend.blocks.basis.DoublePlantBlock;
import ru.betterend.blocks.basis.FurBlock;
@ -34,7 +34,7 @@ import ru.betterend.registry.EndTags;
public class BlocksHelper {
public static final BooleanProperty ROOTS = BooleanProperty.of("roots");
private static final Map<Block, Integer> COLOR_BY_BLOCK = Maps.newHashMap();
public static final int FLAG_UPDATE_BLOCK = 1;
public static final int FLAG_SEND_CLIENT_CHANGES = 2;
public static final int FLAG_NO_RERENDER = 4;
@ -45,97 +45,92 @@ public class BlocksHelper {
public static final int SET_OBSERV = FLAG_UPDATE_BLOCK | FLAG_SEND_CLIENT_CHANGES;
public static final Direction[] HORIZONTAL = makeHorizontal();
public static final Direction[] DIRECTIONS = Direction.values();
private static final Mutable POS = new Mutable();
protected static final BlockState AIR = Blocks.AIR.getDefaultState();
protected static final BlockState WATER = Blocks.WATER.getDefaultState();
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),
private static final MutableBlockPos POS = new MutableBlockPos();
protected static final BlockState AIR = Blocks.AIR.defaultBlockState();
protected static final BlockState WATER = Blocks.WATER.defaultBlockState();
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),
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) };
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);
}
public static int getBlockColor(Block block) {
return COLOR_BY_BLOCK.getOrDefault(block, 0xFF000000);
}
public static void setWithoutUpdate(WorldAccess world, BlockPos pos, BlockState state) {
world.setBlockState(pos, state, SET_SILENT);
}
public static void setWithoutUpdate(WorldAccess world, BlockPos pos, Block block) {
world.setBlockState(pos, block.getDefaultState(), SET_SILENT);
}
public static void setWithUpdate(WorldAccess world, BlockPos pos, BlockState state) {
world.setBlockState(pos, state, SET_OBSERV);
}
public static void setWithUpdate(WorldAccess world, BlockPos pos, Block block) {
world.setBlockState(pos, block.getDefaultState(), SET_OBSERV);
public static void setWithoutUpdate(LevelAccessor world, BlockPos pos, BlockState state) {
world.setBlockAndUpdate(pos, state, SET_SILENT);
}
public static int upRay(WorldAccess world, BlockPos pos, int maxDist) {
public static void setWithoutUpdate(LevelAccessor world, BlockPos pos, Block block) {
world.setBlockAndUpdate(pos, block.defaultBlockState(), SET_SILENT);
}
public static void setWithUpdate(LevelAccessor world, BlockPos pos, BlockState state) {
world.setBlockAndUpdate(pos, state, SET_OBSERV);
}
public static void setWithUpdate(LevelAccessor world, BlockPos pos, Block block) {
world.setBlockAndUpdate(pos, block.defaultBlockState(), SET_OBSERV);
}
public static int upRay(LevelAccessor world, BlockPos pos, int maxDist) {
int length = 0;
for (int j = 1; j < maxDist && (world.isAir(pos.up(j))); j++)
length++;
return length;
}
public static int downRay(WorldAccess world, BlockPos pos, int maxDist) {
public static int downRay(LevelAccessor world, BlockPos pos, int maxDist) {
int length = 0;
for (int j = 1; j < maxDist && (world.isAir(pos.down(j))); j++)
length++;
return length;
}
public static int downRayRep(WorldAccess world, BlockPos pos, int maxDist) {
public static int downRayRep(LevelAccessor world, BlockPos pos, int maxDist) {
POS.set(pos);
for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++)
{
for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) {
POS.setY(POS.getY() - 1);
}
return pos.getY() - POS.getY();
}
public static int raycastSqr(WorldAccess world, BlockPos pos, int dx, int dy, int dz, int maxDist) {
public static int raycastSqr(LevelAccessor world, BlockPos pos, int dx, int dy, int dz, int maxDist) {
POS.set(pos);
for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++)
{
for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) {
POS.move(dx, dy, dz);
}
return (int) pos.getSquaredDistance(POS);
}
public static BlockState rotateHorizontal(BlockState state, BlockRotation rotation, Property<Direction> facing) {
return state.with(facing, rotation.rotate(state.get(facing)));
public static BlockState rotateHorizontal(BlockState state, Rotation rotation, Property<Direction> facing) {
return state.with(facing, rotation.rotate(state.getValue(facing)));
}
public static BlockState mirrorHorizontal(BlockState state, BlockMirror mirror, Property<Direction> facing) {
return state.rotate(mirror.getRotation(state.get(facing)));
return state.rotate(mirror.getRotation(state.getValue(facing)));
}
public static int getLengthDown(WorldAccess world, BlockPos pos, Block block) {
public static int getLengthDown(LevelAccessor world, BlockPos pos, Block block) {
int count = 1;
while (world.getBlockState(pos.down(count)).getBlock() == block)
count++;
return count;
}
public static void cover(WorldAccess world, BlockPos center, Block ground, BlockState cover, int radius, Random random) {
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) {
@ -147,7 +142,7 @@ public class BlocksHelper {
BlockPos pos = iterator.next();
for (Vec3i offset : OFFSETS) {
if (random.nextBoolean()) {
BlockPos pos2 = pos.add(offset);
BlockPos pos2 = pos.offset(offset);
if (random.nextBoolean() && world.getBlockState(pos2).getBlock() == ground
&& !points.contains(pos2))
points2.add(pos2);
@ -164,8 +159,8 @@ public class BlocksHelper {
}
}
}
public static void fixBlocks(WorldAccess world, BlockPos start, BlockPos end) {
public static void fixBlocks(LevelAccessor world, BlockPos start, BlockPos end) {
BlockState state;
Set<BlockPos> doubleCheck = Sets.newHashSet();
for (int x = start.getX(); x <= end.getX(); x++) {
@ -175,7 +170,7 @@ public class BlocksHelper {
for (int y = start.getY(); y <= end.getY(); y++) {
POS.setY(y);
state = world.getBlockState(POS);
if (state.getBlock() instanceof FurBlock) {
doubleCheck.add(POS.toImmutable());
}
@ -207,19 +202,17 @@ public class BlocksHelper {
break;
}
}
}
else if (state.isOf(EndBlocks.SMARAGDANT_CRYSTAL)) {
} else if (state.is(EndBlocks.SMARAGDANT_CRYSTAL)) {
POS.setY(POS.getY() - 1);
if (world.isAir(POS)) {
POS.setY(POS.getY() + 1);
while (state.isOf(EndBlocks.SMARAGDANT_CRYSTAL)) {
while (state.is(EndBlocks.SMARAGDANT_CRYSTAL)) {
setWithoutUpdate(world, POS, AIR);
POS.setY(POS.getY() + 1);
state = world.getBlockState(POS);
}
}
}
else if (state.getBlock() instanceof StalactiteBlock) {
} else if (state.getBlock() instanceof StalactiteBlock) {
if (!state.canPlaceAt(world, POS)) {
if (world.getBlockState(POS.up()).getBlock() instanceof StalactiteBlock) {
while (state.getBlock() instanceof StalactiteBlock) {
@ -227,8 +220,7 @@ public class BlocksHelper {
POS.setY(POS.getY() + 1);
state = world.getBlockState(POS);
}
}
else {
} else {
while (state.getBlock() instanceof StalactiteBlock) {
setWithoutUpdate(world, POS, AIR);
POS.setY(POS.getY() - 1);
@ -236,15 +228,13 @@ public class BlocksHelper {
}
}
}
}
else if (state.isOf(EndBlocks.CAVE_PUMPKIN)) {
if (!world.getBlockState(POS.up()).isOf(EndBlocks.CAVE_PUMPKIN_SEED)) {
} else if (state.is(EndBlocks.CAVE_PUMPKIN)) {
if (!world.getBlockState(POS.up()).is(EndBlocks.CAVE_PUMPKIN_SEED)) {
setWithoutUpdate(world, POS, AIR);
}
}
else if (!state.canPlaceAt(world, POS)) {
} else if (!state.canPlaceAt(world, POS)) {
// Chorus
if (state.isOf(Blocks.CHORUS_PLANT)) {
if (state.is(Blocks.CHORUS_PLANT)) {
Set<BlockPos> ends = Sets.newHashSet();
Set<BlockPos> add = Sets.newHashSet();
ends.add(POS.toImmutable());
@ -253,15 +243,17 @@ public class BlocksHelper {
ends.forEach((pos) -> {
setWithoutUpdate(world, pos, AIR);
for (Direction dir : HORIZONTAL) {
BlockPos p = pos.offset(dir);
BlockPos p = pos.relative(dir);
BlockState st = world.getBlockState(p);
if ((st.isOf(Blocks.CHORUS_PLANT) || st.isOf(Blocks.CHORUS_FLOWER)) && !st.canPlaceAt(world, p)) {
if ((st.is(Blocks.CHORUS_PLANT) || st.is(Blocks.CHORUS_FLOWER))
&& !st.canPlaceAt(world, p)) {
add.add(p);
}
}
BlockPos p = pos.up();
BlockState st = world.getBlockState(p);
if ((st.isOf(Blocks.CHORUS_PLANT) || st.isOf(Blocks.CHORUS_FLOWER)) && !st.canPlaceAt(world, p)) {
if ((st.is(Blocks.CHORUS_PLANT) || st.is(Blocks.CHORUS_FLOWER))
&& !st.canPlaceAt(world, p)) {
add.add(p);
}
});
@ -286,14 +278,13 @@ public class BlocksHelper {
int ray = downRayRep(world, POS.toImmutable(), 64);
if (ray > 32) {
BlocksHelper.setWithoutUpdate(world, POS, Blocks.END_STONE.getDefaultState());
BlocksHelper.setWithoutUpdate(world, POS, Blocks.END_STONE.defaultBlockState());
if (world.getRandom().nextBoolean()) {
POS.setY(POS.getY() - 1);
state = world.getBlockState(POS);
BlocksHelper.setWithoutUpdate(world, POS, Blocks.END_STONE.getDefaultState());
BlocksHelper.setWithoutUpdate(world, POS, Blocks.END_STONE.defaultBlockState());
}
}
else {
} else {
POS.setY(y);
BlockState replacement = AIR;
for (Direction dir : HORIZONTAL) {
@ -312,7 +303,8 @@ public class BlocksHelper {
else {
// Blue Vine
if (state.getBlock() instanceof BlueVineBlock) {
while (state.isOf(EndBlocks.BLUE_VINE) || state.isOf(EndBlocks.BLUE_VINE_LANTERN) || state.isOf(EndBlocks.BLUE_VINE_FUR)) {
while (state.is(EndBlocks.BLUE_VINE) || state.is(EndBlocks.BLUE_VINE_LANTERN)
|| state.is(EndBlocks.BLUE_VINE_FUR)) {
BlocksHelper.setWithoutUpdate(world, POS, AIR);
POS.setY(POS.getY() + 1);
state = world.getBlockState(POS);
@ -333,34 +325,34 @@ public class BlocksHelper {
}
}
}
doubleCheck.forEach((pos) -> {
if (!world.getBlockState(pos).canPlaceAt(world, pos)) {
BlocksHelper.setWithoutUpdate(world, pos, AIR);
}
});
}
private static BlockState getAirOrFluid(BlockState state) {
return state.getFluidState().isEmpty() ? AIR : state.getFluidState().getBlockState();
}
public static boolean isEndNylium(Block block) {
return block.isIn(BlockTags.NYLIUM) && block.isIn(EndTags.END_GROUND);
}
public static boolean isEndNylium(BlockState state) {
return isEndNylium(state.getBlock());
}
public static Direction[] makeHorizontal() {
return new Direction[] { Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST };
}
public static Direction randomHorizontal(Random random) {
return HORIZONTAL[random.nextInt(4)];
}
public static Direction randomDirection(Random random) {
return DIRECTIONS[random.nextInt(6)];
}