Intersections, lakes, cleanup

This commit is contained in:
paulevsGitch 2020-10-03 01:24:33 +03:00
parent 8eb15c8d73
commit 81e62efcf6
13 changed files with 77 additions and 33 deletions

View file

@ -79,7 +79,9 @@ public abstract class BlockFeatureSapling extends BlockBaseNotFull implements Fe
@Override
public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) {
BlocksHelper.setWithoutUpdate(world, pos, Blocks.AIR.getDefaultState());
getFeature().generate(world, world.getChunkManager().getChunkGenerator(), random, pos, null);
if (!getFeature().generate(world, world.getChunkManager().getChunkGenerator(), random, pos, null)) {
BlocksHelper.setWithoutUpdate(world, pos, this.getDefaultState());
}
}
@Override

View file

@ -9,7 +9,6 @@ import org.jetbrains.annotations.NotNull;
import com.google.common.collect.Lists;
import it.unimi.dsi.fastutil.ints.IntList;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.EntryStack;
@ -18,7 +17,6 @@ import me.shedaniel.rei.api.widgets.Widgets;
import me.shedaniel.rei.gui.entries.RecipeEntry;
import me.shedaniel.rei.gui.entries.SimpleRecipeEntry;
import me.shedaniel.rei.gui.widget.Widget;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.TranslatableText;

View file

@ -10,7 +10,6 @@ import org.jetbrains.annotations.NotNull;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.TransferRecipeDisplay;
import me.shedaniel.rei.server.ContainerInfo;
import net.minecraft.item.Item;
import net.minecraft.recipe.BlastingRecipe;
import net.minecraft.recipe.Recipe;
@ -18,7 +17,6 @@ import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity;
import ru.betterend.recipe.AlloyingRecipe;

View file

@ -3,13 +3,10 @@ package ru.betterend.compat;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.api.RecipeHelper;
import me.shedaniel.rei.api.plugins.REIPluginV0;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.recipe.BlastingRecipe;
import net.minecraft.util.Identifier;
import ru.betterend.BetterEnd;
import ru.betterend.recipe.AlloyingRecipe;
import ru.betterend.registry.BlockRegistry;

View file

@ -3,11 +3,10 @@ package ru.betterend.item;
import java.util.UUID;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.ImmutableMultimap.Builder;
import com.google.common.collect.Multimap;
import io.netty.util.internal.ThreadLocalRandom;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;

View file

@ -5,7 +5,6 @@ import net.minecraft.block.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.util.registry.Registry;
import ru.betterend.registry.BlockRegistry;
import ru.betterend.registry.ItemRegistry;

View file

@ -8,14 +8,14 @@ import ru.betterend.world.features.SinglePlantFeature;
public class FeatureRegistry {
// Trees //
public static final EndFeature MOSSY_GLOWSHROOM = new EndFeature("mossy_glowshroom", new MossyGlowshroomFeature(), 2);
public static final EndFeature MOSSY_GLOWSHROOM = new EndFeature("mossy_glowshroom", new MossyGlowshroomFeature(), 3);
// Plants //
public static final EndFeature UMBRELLA_MOSS = new EndFeature("umbrella_moss", new DoublePlantFeature(BlockRegistry.UMBRELLA_MOSS, BlockRegistry.UMBRELLA_MOSS_TALL, 5), 5);
public static final EndFeature CREEPING_MOSS = new EndFeature("creeping_moss", new SinglePlantFeature(BlockRegistry.CREEPING_MOSS, 5), 5);
// Features //
public static final EndFeature END_LAKE = EndFeature.makeLakeFeature("end_lake", new EndLakeFeature(), 100);
public static final EndFeature END_LAKE = EndFeature.makeLakeFeature("end_lake", new EndLakeFeature(), 4);
// Ores //
public static final EndFeature ENDER_ORE = EndFeature.makeOreFeature("ender_ore", BlockRegistry.ENDER_ORE, 6, 3, 0, 4, 96);

View file

@ -16,7 +16,6 @@ import net.minecraft.item.ToolItem;
import net.minecraft.item.ToolMaterials;
import net.minecraft.tag.Tag;
import net.minecraft.util.registry.Registry;
import ru.betterend.BetterEnd;
import ru.betterend.item.EndArmorMaterial;
import ru.betterend.item.EndAxe;

View file

@ -7,6 +7,7 @@ import net.minecraft.world.Heightmap.Type;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import ru.betterend.util.BlocksHelper;
public abstract class DefaultFeature extends Feature<DefaultFeatureConfig> {
protected static final BlockState AIR = Blocks.AIR.getDefaultState();
@ -19,4 +20,14 @@ public abstract class DefaultFeature extends Feature<DefaultFeatureConfig> {
protected BlockPos getPosOnSurface(StructureWorldAccess world, BlockPos pos) {
return world.getTopPosition(Type.WORLD_SURFACE, pos);
}
protected BlockPos getPosOnSurfaceRaycast(StructureWorldAccess world, BlockPos pos) {
int h = BlocksHelper.downRay(world, pos, 256);
return pos.down(h);
}
protected BlockPos getPosOnSurfaceRaycast(StructureWorldAccess world, BlockPos pos, int dist) {
int h = BlocksHelper.downRay(world, pos, dist);
return pos.down(h);
}
}

View file

@ -48,12 +48,12 @@ public class EndFeature {
}
public static EndFeature makeRawGenFeature(String name, Feature<DefaultFeatureConfig> feature, int chance) {
ConfiguredFeature<?, ?> configured = feature.configure(FeatureConfig.DEFAULT).decorate(Decorator.CHANCE.configure(new ChanceDecoratorConfig(100)));
ConfiguredFeature<?, ?> configured = feature.configure(FeatureConfig.DEFAULT).decorate(Decorator.CHANCE.configure(new ChanceDecoratorConfig(chance)));
return new EndFeature(name, feature, GenerationStep.Feature.RAW_GENERATION, configured);
}
public static EndFeature makeLakeFeature(String name, Feature<DefaultFeatureConfig> feature, int chance) {
ConfiguredFeature<?, ?> configured = feature.configure(FeatureConfig.DEFAULT).decorate(Decorator.CHANCE.configure(new ChanceDecoratorConfig(100)));
ConfiguredFeature<?, ?> configured = feature.configure(FeatureConfig.DEFAULT).decorate(Decorator.WATER_LAKE.configure(new ChanceDecoratorConfig(chance)));
return new EndFeature(name, feature, GenerationStep.Feature.LAKES, configured);
}

View file

@ -4,6 +4,7 @@ import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.world.StructureWorldAccess;
@ -32,21 +33,22 @@ public class EndLakeFeature extends DefaultFeature {
int waterLevel = blockPos.getY();
BlockPos pos = getPosOnSurface(world, blockPos.north(dist));
if (pos.getY() < 10) return false;
BlockPos pos = getPosOnSurfaceRaycast(world, blockPos.north(dist).up(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getPosOnSurface(world, blockPos.south(dist));
if (pos.getY() < 10) return false;
pos = getPosOnSurfaceRaycast(world, blockPos.south(dist).up(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getPosOnSurface(world, blockPos.east(dist));
if (pos.getY() < 10) return false;
pos = getPosOnSurfaceRaycast(world, blockPos.east(dist).up(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getPosOnSurface(world, blockPos.west(dist));
if (pos.getY() < 10) return false;
pos = getPosOnSurfaceRaycast(world, blockPos.west(dist).up(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
BlockState state;
for (int y = blockPos.getY(); y <= blockPos.getY() + 10; y++) {
POS.setY(y);
@ -62,13 +64,14 @@ public class EndLakeFeature extends DefaultFeature {
double r = add * 1.8 + radius * (NOISE.eval(x * 0.2, y * 0.2, z * 0.2) * 0.25 + 0.75);
r *= r;
if (x2 + z2 <= r) {
if (world.getBlockState(POS).isIn(BlockTagRegistry.END_GROUND)) {
state = world.getBlockState(POS);
if (state.isIn(BlockTagRegistry.END_GROUND) || !state.canPlaceAt(world, POS) || state.getBlock() == BlockRegistry.ENDSTONE_DUST) {
BlocksHelper.setWithoutUpdate(world, POS, AIR);
}
pos = POS.down();
if (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND))
{
BlockState state = world.getBiome(pos).getGenerationSettings().getSurfaceConfig().getTopMaterial();
state = world.getBiome(pos).getGenerationSettings().getSurfaceConfig().getTopMaterial();
if (y > waterLevel + 1)
BlocksHelper.setWithoutUpdate(world, pos, state);
else if (y > waterLevel)
@ -106,13 +109,16 @@ public class EndLakeFeature extends DefaultFeature {
r *= r;
rb *= rb;
if (y2 + x2 + z2 <= r) {
state = world.getBlockState(POS);
if (state.isIn(BlockTagRegistry.END_GROUND) || state.getMaterial().equals(Material.PLANT) || state.getBlock() == BlockRegistry.ENDSTONE_DUST) {
BlocksHelper.setWithoutUpdate(world, POS, y < waterLevel ? WATER : AIR);
}
pos = POS.down();
if (world.getBlockState(pos).getBlock().isIn(BlockTagRegistry.END_GROUND))
BlocksHelper.setWithoutUpdate(world, POS.down(), BlockRegistry.ENDSTONE_DUST.getDefaultState());
pos = POS.up();
if (!world.getBlockState(pos).isAir()) {
while (!world.getBlockState(pos).isAir()) {
if (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) {
while (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) {
BlocksHelper.setWithoutUpdate(world, pos, pos.getY() < waterLevel ? WATER : AIR);
pos = pos.up();
}
@ -121,7 +127,7 @@ public class EndLakeFeature extends DefaultFeature {
else if (y <= waterLevel && y2 + x2 + z2 <= rb) {
if (world.getBlockState(POS).getMaterial().isReplaceable()) {
if (world.isAir(POS.up())) {
BlockState state = world.getBiome(POS).getGenerationSettings().getSurfaceConfig().getTopMaterial();
state = world.getBiome(POS).getGenerationSettings().getSurfaceConfig().getTopMaterial();
BlocksHelper.setWithoutUpdate(world, POS, random.nextBoolean() ? state : BlockRegistry.ENDSTONE_DUST.getDefaultState());
BlocksHelper.setWithoutUpdate(world, POS.down(), END_STONE);
}

View file

@ -10,7 +10,9 @@ import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -50,6 +52,8 @@ public class MossyGlowshroomFeature extends DefaultFeature {
private static final SDFPrimitive CONE_GLOW;
private static final SDFPrimitive ROOTS;
private static final Mutable POS = new Mutable();
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, DefaultFeatureConfig featureConfig) {
blockPos = getPosOnSurface(world, blockPos);
@ -77,8 +81,39 @@ public class MossyGlowshroomFeature extends DefaultFeature {
HEAD_POS.setTranslate(pos.getX(), pos.getY(), pos.getZ());
ROOTS_ROT.setAngle(random.nextFloat() * MHelper.PI2);
FUNCTION.setSourceA(sdf);
float scale = MHelper.randRange(0.75F, 1.1F, random);
Vector3f vec = spline.get(0);
float x1 = blockPos.getX() + vec.getX() * scale;
float y1 = blockPos.getY() + vec.getY() * scale;
float z1 = blockPos.getZ() + vec.getZ() * scale;
for (int i = 1; i < count; i++) {
vec = spline.get(i);
float x2 = blockPos.getX() + vec.getX() * scale;
float y2 = blockPos.getY() + vec.getY() * scale;
float z2 = blockPos.getZ() + vec.getZ() * scale;
for (float py = y1; py < y2; py += 3) {
if (py - blockPos.getY() < 10) continue;
float lerp = (py - y1) / (y2 - y1);
float x = MathHelper.lerp(lerp, x1, x2);
float z = MathHelper.lerp(lerp, z1, z2);
POS.set(x, py, z);
BlockState state = world.getBlockState(POS);
boolean generate = state.getMaterial().isReplaceable() || state.getMaterial().equals(Material.PLANT);
if (!generate) {
return false;
}
}
x1 = x2;
y1 = y2;
z1 = z2;
}
BlocksHelper.setWithoutUpdate(world, blockPos, AIR);
Set<BlockPos> blocks = new SDFScale()
.setScale(MHelper.randRange(0.75F, 1.1F, random))
.setScale(scale)
.setSource(FUNCTION)
.setReplaceFunction(REPLACE)
.setPostProcess(POST_PROCESS)

View file

@ -35,8 +35,8 @@ public class BetterEndBiomeSource extends BiomeSource {
public BetterEndBiomeSource(Registry<Biome> biomeRegistry, long seed) {
super(Collections.emptyList());
this.mapLand = new BiomeMap(seed, 50, BiomeRegistry.LAND_BIOMES);
this.mapVoid = new BiomeMap(seed, 50, BiomeRegistry.VOID_BIOMES);
this.mapLand = new BiomeMap(seed, 150, BiomeRegistry.LAND_BIOMES);
this.mapVoid = new BiomeMap(seed, 150, BiomeRegistry.VOID_BIOMES);
this.centerBiome = biomeRegistry.getOrThrow(BiomeKeys.THE_END);
this.biomeRegistry = biomeRegistry;
this.seed = seed;