Mosses, fixes

This commit is contained in:
paulevsGitch 2020-10-01 01:39:06 +03:00
parent 4eb7105e33
commit 72b173a9e3
28 changed files with 354 additions and 53 deletions

View file

@ -13,6 +13,8 @@ public class BiomeFoggyMushroomland extends EndBiome {
.setSurface(BlockRegistry.END_MOSS, BlockRegistry.END_MYCELIUM)
.addFeature(FeatureRegistry.ENDER_ORE)
.addFeature(FeatureRegistry.END_LAKE)
.addFeature(FeatureRegistry.MOSSY_GLOWSHROOM));
.addFeature(FeatureRegistry.MOSSY_GLOWSHROOM)
.addFeature(FeatureRegistry.UMBRELLA_MOSS)
.addFeature(FeatureRegistry.CREEPING_MOSS));
}
}

View file

@ -16,7 +16,7 @@ public abstract class DefaultFeature extends Feature<DefaultFeatureConfig> {
super(DefaultFeatureConfig.CODEC);
}
protected BlockPos getTopPos(StructureWorldAccess world, BlockPos pos) {
protected BlockPos getPosOnSurface(StructureWorldAccess world, BlockPos pos) {
return world.getTopPosition(Type.WORLD_SURFACE, pos);
}
}

View file

@ -0,0 +1,72 @@
package ru.betterend.world.features;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import ru.betterend.blocks.basis.BlockDoublePlant;
import ru.betterend.registry.BlockTagRegistry;
import ru.betterend.util.BlocksHelper;
import ru.betterend.util.MHelper;
public class DoublePlantFeature extends DefaultFeature {
private static final Mutable POS = new Mutable();
private final Block smallPlant;
private final Block largePlant;
private final int radius;
public DoublePlantFeature(Block smallPlant, Block largePlant, int radius) {
this.smallPlant = smallPlant;
this.largePlant = largePlant;
this.radius = radius;
}
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, DefaultFeatureConfig featureConfig) {
blockPos = getPosOnSurface(world, blockPos);
if (blockPos.getY() < 5) {
return false;
}
if (!world.getBlockState(blockPos.down()).isIn(BlockTagRegistry.END_GROUND)) {
return false;
}
float r = MHelper.randRange(radius * 0.5F, radius, random);
int count = MHelper.floor(r * r * MHelper.randRange(1.5F, 3F, random));
Block block;
for (int i = 0; i < count; i++) {
float pr = r * (float) Math.sqrt(random.nextFloat());
float theta = random.nextFloat() * MHelper.PI2;
float x = pr * (float) Math.cos(theta);
float z = pr * (float) Math.sin(theta);
POS.set(blockPos.getX() + x, blockPos.getY() + 5, blockPos.getZ() + z);
int down = BlocksHelper.downRay(world, POS, 16);
if (down > 10) continue;
POS.setY(POS.getY() - down);
float d = MHelper.length(x, z) / r * 0.6F + random.nextFloat() * 0.4F;
block = d < 0.5F ? largePlant : smallPlant;
if (block.canPlaceAt(block.getDefaultState(), world, POS)) {
if (block instanceof BlockDoublePlant) {
int rot = random.nextInt(4);
BlockState state = block.getDefaultState().with(BlockDoublePlant.ROTATION, rot);
BlocksHelper.setWithoutUpdate(world, POS, state);
BlocksHelper.setWithoutUpdate(world, POS.up(), state.with(BlockDoublePlant.TOP, true));
}
else {
BlocksHelper.setWithoutUpdate(world, POS, block);
}
}
}
return true;
}
}

View file

@ -27,24 +27,24 @@ public class EndLakeFeature extends DefaultFeature {
int dist = MHelper.floor(radius);
int dist2 = MHelper.floor(radius * 1.5);
int bott = MHelper.floor(depth);
blockPos = getTopPos(world, blockPos);
blockPos = getPosOnSurface(world, blockPos);
if (blockPos.getY() < 10) return false;
int waterLevel = blockPos.getY();
BlockPos pos = getTopPos(world, blockPos.north(dist));
BlockPos pos = getPosOnSurface(world, blockPos.north(dist));
if (pos.getY() < 10) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getTopPos(world, blockPos.south(dist));
pos = getPosOnSurface(world, blockPos.south(dist));
if (pos.getY() < 10) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getTopPos(world, blockPos.east(dist));
pos = getPosOnSurface(world, blockPos.east(dist));
if (pos.getY() < 10) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getTopPos(world, blockPos.west(dist));
pos = getPosOnSurface(world, blockPos.west(dist));
if (pos.getY() < 10) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);

View file

@ -51,7 +51,7 @@ public class MossyGlowshroomFeature extends DefaultFeature {
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, DefaultFeatureConfig featureConfig) {
blockPos = getTopPos(world, blockPos);
blockPos = getPosOnSurface(world, blockPos);
if (blockPos.getY() < 5) {
return false;
}

View file

@ -0,0 +1,66 @@
package ru.betterend.world.features;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import ru.betterend.blocks.basis.BlockDoublePlant;
import ru.betterend.registry.BlockTagRegistry;
import ru.betterend.util.BlocksHelper;
import ru.betterend.util.MHelper;
public class SinglePlantFeature extends DefaultFeature {
private static final Mutable POS = new Mutable();
private final Block plant;
private final int radius;
public SinglePlantFeature(Block plant, int radius) {
this.plant = plant;
this.radius = radius;
}
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, DefaultFeatureConfig featureConfig) {
blockPos = getPosOnSurface(world, blockPos);
if (blockPos.getY() < 5) {
return false;
}
if (!world.getBlockState(blockPos.down()).isIn(BlockTagRegistry.END_GROUND)) {
return false;
}
float r = MHelper.randRange(radius * 0.5F, radius, random);
int count = MHelper.floor(r * r * MHelper.randRange(1.5F, 3F, random));
for (int i = 0; i < count; i++) {
float pr = r * (float) Math.sqrt(random.nextFloat());
float theta = random.nextFloat() * MHelper.PI2;
float x = pr * (float) Math.cos(theta);
float z = pr * (float) Math.sin(theta);
POS.set(blockPos.getX() + x, blockPos.getY() + 5, blockPos.getZ() + z);
int down = BlocksHelper.downRay(world, POS, 16);
if (down > 10) continue;
POS.setY(POS.getY() - down);
if (plant.canPlaceAt(plant.getDefaultState(), world, POS)) {
if (plant instanceof BlockDoublePlant) {
int rot = random.nextInt(4);
BlockState state = plant.getDefaultState().with(BlockDoublePlant.ROTATION, rot);
BlocksHelper.setWithoutUpdate(world, POS, state);
BlocksHelper.setWithoutUpdate(world, POS.up(), state.with(BlockDoublePlant.TOP, true));
}
else {
BlocksHelper.setWithoutUpdate(world, POS, plant);
}
}
}
return true;
}
}

View file

@ -10,7 +10,6 @@ import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.surfacebuilder.SurfaceBuilder;
import net.minecraft.world.gen.surfacebuilder.TernarySurfaceConfig;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.util.MHelper;