Portal pos finding optimisation, Overworld island feature for portals

This commit is contained in:
Aleksey 2020-12-24 22:47:22 +03:00
parent 2c2757ba8e
commit f42af8bd67
5 changed files with 30 additions and 6 deletions

View file

@ -17,6 +17,7 @@ import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.Heightmap;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.dimension.DimensionType;
@ -100,7 +101,9 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
for (int step = 1; step < 64; step++) {
for (int i = 0; i < step; i++) {
checkPos.setY(5);
while(checkPos.getY() < world.getHeight()) {
int ceil = world.getChunk(basePos).sampleHeightmap(Heightmap.Type.WORLD_SURFACE, checkPos.getX(), checkPos.getZ()) + 1;
if (ceil < 5) continue;
while(checkPos.getY() < ceil) {
BlockState state = world.getBlockState(checkPos);
if(state.isOf(this)) {
int offStep;

View file

@ -23,6 +23,7 @@ import ru.betterend.world.features.GlowPillarFeature;
import ru.betterend.world.features.HydraluxFeature;
import ru.betterend.world.features.LanceleafFeature;
import ru.betterend.world.features.MengerSpongeFeature;
import ru.betterend.world.features.OverworldIslandFeature;
import ru.betterend.world.features.SinglePlantFeature;
import ru.betterend.world.features.UnderwaterPlantFeature;
import ru.betterend.world.features.VineFeature;
@ -116,6 +117,7 @@ public class EndFeatures {
public static final EndFeature CHARNIA_GREEN = new EndFeature("charnia_green", new CharniaFeature(EndBlocks.CHARNIA_GREEN), 10);
public static final EndFeature MENGER_SPONGE = new EndFeature("menger_sponge", new MengerSpongeFeature(5), 1);
public static final EndFeature CHARNIA_RED_RARE = new EndFeature("charnia_red_rare", new CharniaFeature(EndBlocks.CHARNIA_RED), 2);
public static final EndFeature OVERWORLD_ISLAND = EndFeature.makeOverworldIsland("overworld_island", new OverworldIslandFeature());
// Terrain //
public static final EndFeature END_LAKE = EndFeature.makeLakeFeature("end_lake", new EndLakeFeature(), 4);

View file

@ -32,6 +32,7 @@ import ru.betterend.blocks.EndPortalBlock;
import ru.betterend.blocks.RunedFlavolite;
import ru.betterend.blocks.entities.EternalPedestalEntity;
import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndFeatures;
import ru.betterend.registry.EndTags;
public class EternalRitual {
@ -250,7 +251,9 @@ public class EternalRitual {
for (int step = 1; step < 64; step++) {
for (int i = 0; i < step; i++) {
checkPos.setY(5);
while(checkPos.getY() < world.getHeight()) {
int ceil = targetWorld.getChunk(basePos).sampleHeightmap(Heightmap.Type.WORLD_SURFACE, checkPos.getX(), checkPos.getZ()) + 1;
if (ceil < 5) continue;
while(checkPos.getY() < ceil) {
if(checkIsAreaValid(targetWorld, checkPos, portalAxis)) {
EternalRitual.generatePortal(targetWorld, checkPos, portalAxis);
if (portalAxis.equals(Direction.Axis.X)) {
@ -270,6 +273,7 @@ public class EternalRitual {
ConfiguredFeatures.END_ISLAND.generate(targetWorld, targetWorld.getChunkManager().getChunkGenerator(), new Random(basePos.asLong()), basePos.down());
} else {
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());
}
EternalRitual.generatePortal(targetWorld, basePos, portalAxis);
if (portalAxis.equals(Direction.Axis.X)) {

View file

@ -114,6 +114,11 @@ public class EndFeature {
return new EndFeature(name, feature, GenerationStep.Feature.RAW_GENERATION, configured);
}
public static EndFeature makeOverworldIsland(String name, Feature<DefaultFeatureConfig> feature) {
ConfiguredFeature<?, ?> configured = feature.configure(FeatureConfig.DEFAULT);
return new EndFeature(name, feature, GenerationStep.Feature.RAW_GENERATION, configured);
}
public Feature<?> getFeature() {
return feature;
}

View file

@ -17,21 +17,31 @@ import ru.betterend.util.sdf.primitive.SDFCapedCone;
public class OverworldIslandFeature extends DefaultFeature {
private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(412);
private static final Mutable CENTER = new Mutable();
private static final SDF FUNCTION;
private static final SDF ISLAND;
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
CENTER.set(pos);
FUNCTION.fillRecursive(world, pos.down());
ISLAND.fillRecursive(world, pos.down());
return true;
}
static {
SDF cone = new SDFCapedCone().setRadius1(0).setRadius2(4).setHeight(4).setBlock(Blocks.STONE);
SDF cone = new SDFCapedCone().setRadius1(0).setRadius2(6).setHeight(4).setBlock((pos) -> {
if (pos.getY() == CENTER.getY()) return Blocks.GRASS_BLOCK.getDefaultState();
if (pos.getY() == CENTER.getY() - 1) {
return Blocks.DIRT.getDefaultState();
} else if (pos.getY() == CENTER.getY() - Math.round(2.0 * Math.random())) {
return Blocks.DIRT.getDefaultState();
}
return Blocks.STONE.getDefaultState();
});
cone = new SDFTranslate().setTranslate(0, -3, 0).setSource(cone);
cone = new SDFDisplacement().setFunction((pos) -> {
return (float) NOISE.eval(CENTER.getX() + pos.getX(), CENTER.getY() + pos.getY(), CENTER.getZ() + pos.getZ());
}).setSource(cone).setReplaceFunction(state -> {
return state.isOf(Blocks.WATER) || state.getMaterial().isReplaceable();
});
FUNCTION = cone;
ISLAND = cone;
}
}