Portal positioning fix

This commit is contained in:
paulevsGitch 2021-01-13 19:11:14 +03:00
parent 25efe551b2
commit a9a5d8f225
2 changed files with 86 additions and 78 deletions

View file

@ -8,7 +8,7 @@ import com.google.common.collect.Sets;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Material;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtHelper; import net.minecraft.nbt.NbtHelper;
import net.minecraft.particle.BlockStateParticleEffect; import net.minecraft.particle.BlockStateParticleEffect;
@ -25,6 +25,7 @@ import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey; import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.Heightmap; import net.minecraft.world.Heightmap;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.feature.ConfiguredFeatures; import net.minecraft.world.gen.feature.ConfiguredFeatures;
import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.BlockProperties;
@ -33,7 +34,6 @@ import ru.betterend.blocks.RunedFlavolite;
import ru.betterend.blocks.entities.EternalPedestalEntity; import ru.betterend.blocks.entities.EternalPedestalEntity;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndFeatures; import ru.betterend.registry.EndFeatures;
import ru.betterend.registry.EndTags;
public class EternalRitual { public class EternalRitual {
private final static Set<Point> STRUCTURE_MAP = Sets.newHashSet( private final static Set<Point> STRUCTURE_MAP = Sets.newHashSet(
@ -94,7 +94,8 @@ public class EternalRitual {
if (Direction.Axis.X == axis) { if (Direction.Axis.X == axis) {
moveX = Direction.EAST; moveX = Direction.EAST;
moveY = Direction.NORTH; moveY = Direction.NORTH;
} else { }
else {
moveX = Direction.SOUTH; moveX = Direction.SOUTH;
moveY = Direction.EAST; moveY = Direction.EAST;
} }
@ -134,10 +135,16 @@ public class EternalRitual {
this.doEffects((ServerWorld) world, center); this.doEffects((ServerWorld) world, center);
if (exit == null) { if (exit == null) {
this.exit = this.findPortalPos(); this.exit = this.findPortalPos();
} else { }
else {
World targetWorld = this.getTargetWorld(); World targetWorld = this.getTargetWorld();
if (targetWorld.getBlockState(exit.up()).isOf(EndBlocks.END_PORTAL_BLOCK)) {
this.exit = this.findPortalPos();
}
else {
this.activatePortal(targetWorld, exit); this.activatePortal(targetWorld, exit);
} }
}
this.active = true; this.active = true;
} }
@ -146,7 +153,8 @@ public class EternalRitual {
if (Direction.Axis.X == axis) { if (Direction.Axis.X == axis) {
moveX = Direction.EAST; moveX = Direction.EAST;
moveY = Direction.NORTH; moveY = Direction.NORTH;
} else { }
else {
moveX = Direction.SOUTH; moveX = Direction.SOUTH;
moveY = Direction.EAST; moveY = Direction.EAST;
} }
@ -237,32 +245,33 @@ public class EternalRitual {
Registry<DimensionType> registry = server.getRegistryManager().getDimensionTypes(); Registry<DimensionType> registry = server.getRegistryManager().getDimensionTypes();
double mult = registry.get(DimensionType.THE_END_ID).getCoordinateScale(); double mult = registry.get(DimensionType.THE_END_ID).getCoordinateScale();
BlockPos.Mutable basePos = center.mutableCopy().set(center.getX() / mult, center.getY(), center.getZ() / mult); BlockPos.Mutable basePos = center.mutableCopy().set(center.getX() / mult, center.getY(), center.getZ() / mult);
Direction.Axis portalAxis = Direction.Axis.X == axis ? Direction.Axis.Z : Direction.Axis.X; Direction.Axis portalAxis = (Direction.Axis.X == axis) ? Direction.Axis.Z : Direction.Axis.X;
if (checkIsAreaValid(targetWorld, basePos, portalAxis)) { if (checkIsAreaValid(targetWorld, basePos, portalAxis)) {
EternalRitual.generatePortal(targetWorld, basePos, portalAxis); EternalRitual.generatePortal(targetWorld, basePos, portalAxis);
if (portalAxis.equals(Direction.Axis.X)) { if (portalAxis.equals(Direction.Axis.X)) {
return basePos.toImmutable(); return basePos.toImmutable();
} else { }
else {
return basePos.toImmutable(); return basePos.toImmutable();
} }
} else { }
else {
Direction direction = Direction.EAST; Direction direction = Direction.EAST;
BlockPos.Mutable checkPos = basePos.mutableCopy(); BlockPos.Mutable checkPos = basePos.mutableCopy();
for (int step = 1; step < 64; step++) { for (int step = 1; step < 128; step++) {
for (int i = 0; i < step; i++) { for (int i = 0; i < (step >> 1); i++) {
checkPos.setY(5); Chunk chunk = world.getChunk(checkPos);
int ceil = targetWorld.getChunk(basePos).sampleHeightmap(Heightmap.Type.WORLD_SURFACE, checkPos.getX(), checkPos.getZ()) + 1; if (chunk != null) {
if (ceil < 5) continue; int ceil = chunk.sampleHeightmap(Heightmap.Type.WORLD_SURFACE, checkPos.getX() & 15, checkPos.getZ() & 15) + 1;
while(checkPos.getY() < ceil) { if (ceil < 2) continue;
checkPos.setY(ceil);
while (checkPos.getY() > 2) {
if(checkIsAreaValid(targetWorld, checkPos, portalAxis)) { if(checkIsAreaValid(targetWorld, checkPos, portalAxis)) {
EternalRitual.generatePortal(targetWorld, checkPos, portalAxis); EternalRitual.generatePortal(targetWorld, checkPos, portalAxis);
if (portalAxis.equals(Direction.Axis.X)) {
return checkPos.toImmutable();
} else {
return checkPos.toImmutable(); return checkPos.toImmutable();
} }
checkPos.move(Direction.DOWN);
} }
checkPos.move(Direction.UP);
} }
checkPos.move(direction); checkPos.move(direction);
} }
@ -271,16 +280,13 @@ public class EternalRitual {
} }
if (targetWorld.getRegistryKey() == World.END) { if (targetWorld.getRegistryKey() == World.END) {
ConfiguredFeatures.END_ISLAND.generate(targetWorld, targetWorld.getChunkManager().getChunkGenerator(), new Random(basePos.asLong()), basePos.down()); ConfiguredFeatures.END_ISLAND.generate(targetWorld, targetWorld.getChunkManager().getChunkGenerator(), new Random(basePos.asLong()), basePos.down());
} else { }
else {
basePos.setY(targetWorld.getChunk(basePos).sampleHeightmap(Heightmap.Type.WORLD_SURFACE, basePos.getX(), basePos.getZ()) + 1); basePos.setY(targetWorld.getChunk(basePos).sampleHeightmap(Heightmap.Type.WORLD_SURFACE, basePos.getX(), basePos.getZ()) + 1);
EndFeatures.OVERWORLD_ISLAND.getFeatureConfigured().generate(targetWorld, targetWorld.getChunkManager().getChunkGenerator(), new Random(basePos.asLong()), basePos.down()); EndFeatures.OVERWORLD_ISLAND.getFeatureConfigured().generate(targetWorld, targetWorld.getChunkManager().getChunkGenerator(), new Random(basePos.asLong()), basePos.down());
} }
EternalRitual.generatePortal(targetWorld, basePos, portalAxis); EternalRitual.generatePortal(targetWorld, basePos, portalAxis);
if (portalAxis.equals(Direction.Axis.X)) {
return basePos.toImmutable(); return basePos.toImmutable();
} else {
return basePos.toImmutable();
}
} }
private World getTargetWorld() { private World getTargetWorld() {
@ -302,7 +308,8 @@ public class EternalRitual {
BlockState state = world.getBlockState(checkPos); BlockState state = world.getBlockState(checkPos);
solid &= this.validBlock(world, checkPos, state); solid &= this.validBlock(world, checkPos, state);
} }
} else { }
else {
pos = pos.down().add(-3, 0, 0); pos = pos.down().add(-3, 0, 0);
for (int i = 0; i < 7; i++) { for (int i = 0; i < 7; i++) {
BlockPos checkPos = pos.add(i, 0, 0); BlockPos checkPos = pos.add(i, 0, 0);
@ -314,13 +321,7 @@ public class EternalRitual {
} }
private boolean validBlock(World world, BlockPos pos, BlockState state) { private boolean validBlock(World world, BlockPos pos, BlockState state) {
BlockState surfaceBlock = world.getBiome(pos).getGenerationSettings().getSurfaceConfig().getTopMaterial(); return state.isSolidBlock(world, pos) && state.isFullCube(world, pos);
return state.isSolidBlock(world, pos) &&
(EndTags.validGenBlock(state) ||
state.isOf(surfaceBlock.getBlock()) ||
state.isOf(Blocks.STONE) ||
state.isOf(Blocks.SAND) ||
state.isOf(Blocks.GRAVEL));
} }
public static void generatePortal(World world, BlockPos center, Direction.Axis axis) { public static void generatePortal(World world, BlockPos center, Direction.Axis axis) {
@ -363,9 +364,11 @@ public class EternalRitual {
for (BlockPos checkPos : BlockPos.iterate(center.offset(moveDir.rotateYClockwise()), center.offset(moveDir.rotateYCounterclockwise()))) { for (BlockPos checkPos : BlockPos.iterate(center.offset(moveDir.rotateYClockwise()), center.offset(moveDir.rotateYCounterclockwise()))) {
for (Point point : PORTAL_MAP) { for (Point point : PORTAL_MAP) {
BlockPos pos = checkPos.mutableCopy().move(moveDir, point.x).move(Direction.UP, point.y); BlockPos pos = checkPos.mutableCopy().move(moveDir, point.x).move(Direction.UP, point.y);
if (!world.getBlockState(pos).isAir()) return false; BlockState state = world.getBlockState(pos);
if (state.getFluidState().isEmpty() || (!state.getMaterial().isReplaceable() && !state.getMaterial().equals(Material.PLANT))) return false;
pos = checkPos.mutableCopy().move(moveDir, -point.x).move(Direction.UP, point.y); pos = checkPos.mutableCopy().move(moveDir, -point.x).move(Direction.UP, point.y);
if (!world.getBlockState(pos).isAir()) return false; state = world.getBlockState(pos);
if (state.getFluidState().isEmpty() || (!state.getMaterial().isReplaceable() && !state.getMaterial().equals(Material.PLANT))) return false;
} }
} }
return true; return true;
@ -403,7 +406,8 @@ public class EternalRitual {
if (this.hasPedestal(checkPos)) { if (this.hasPedestal(checkPos)) {
this.center = initial.north(5).east(4); this.center = initial.north(5).east(4);
return; return;
} else { }
else {
this.center = initial.north(5).west(4); this.center = initial.north(5).west(4);
return; return;
} }
@ -415,7 +419,8 @@ public class EternalRitual {
if (this.hasPedestal(checkPos)) { if (this.hasPedestal(checkPos)) {
this.center = initial.south(5).east(4); this.center = initial.south(5).east(4);
return; return;
} else { }
else {
this.center = initial.south(5).west(4); this.center = initial.south(5).west(4);
return; return;
} }
@ -427,7 +432,8 @@ public class EternalRitual {
if (this.hasPedestal(checkPos)) { if (this.hasPedestal(checkPos)) {
this.center = initial.east(5).south(4); this.center = initial.east(5).south(4);
return; return;
} else { }
else {
this.center = initial.east(5).north(4); this.center = initial.east(5).north(4);
return; return;
} }
@ -439,7 +445,8 @@ public class EternalRitual {
if (this.hasPedestal(checkPos)) { if (this.hasPedestal(checkPos)) {
this.center = initial.west(5).south(4); this.center = initial.west(5).south(4);
return; return;
} else { }
else {
this.center = initial.west(5).north(4); this.center = initial.west(5).north(4);
return; return;
} }

View file

@ -30,13 +30,14 @@ import ru.betterend.util.sdf.operator.SDFTranslate;
import ru.betterend.util.sdf.primitive.SDFHexPrism; import ru.betterend.util.sdf.primitive.SDFHexPrism;
import ru.betterend.util.sdf.primitive.SDFSphere; import ru.betterend.util.sdf.primitive.SDFSphere;
import ru.betterend.world.features.DefaultFeature; import ru.betterend.world.features.DefaultFeature;
import ru.betterend.world.generator.GeneratorOptions;
public class RoundCaveFeature extends DefaultFeature { public class RoundCaveFeature extends DefaultFeature {
private static final BlockState CAVE_AIR = Blocks.CAVE_AIR.getDefaultState(); private static final BlockState CAVE_AIR = Blocks.CAVE_AIR.getDefaultState();
@Override @Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) { public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
if (pos.getX() * pos.getX() + pos.getZ() * pos.getZ() <= 22500) { if (!(GeneratorOptions.useNewGenerator() && GeneratorOptions.noRingVoid()) || pos.getX() * pos.getX() + pos.getZ() * pos.getZ() <= 22500) {
return false; return false;
} }