This commit is contained in:
Aleksey 2020-10-09 16:50:42 +03:00
commit 7584321c47
8 changed files with 184 additions and 31 deletions

View file

@ -9,10 +9,8 @@ import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.client.model.ModelProviderContext; import net.fabricmc.fabric.api.client.model.ModelProviderContext;
import net.fabricmc.fabric.api.client.model.ModelProviderException; import net.fabricmc.fabric.api.client.model.ModelProviderException;
import net.fabricmc.fabric.api.client.model.ModelResourceProvider; import net.fabricmc.fabric.api.client.model.ModelResourceProvider;
import net.minecraft.client.render.model.UnbakedModel; import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
public class EndModelProvider implements ModelResourceProvider { public class EndModelProvider implements ModelResourceProvider {

View file

@ -9,7 +9,6 @@ import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.mob.EndermanEntity; import net.minecraft.entity.mob.EndermanEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import ru.betterend.effects.EndEnchantments; import ru.betterend.effects.EndEnchantments;
import ru.betterend.effects.EndStatusEffects; import ru.betterend.effects.EndStatusEffects;

View file

@ -6,12 +6,14 @@ import net.minecraft.world.gen.GenerationStep.Feature;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.world.structures.EndStructureFeature; import ru.betterend.world.structures.EndStructureFeature;
import ru.betterend.world.structures.features.StructureGiantMossyGlowshroom; import ru.betterend.world.structures.features.StructureGiantMossyGlowshroom;
import ru.betterend.world.structures.piece.CavePiece;
import ru.betterend.world.structures.piece.MountainPiece; import ru.betterend.world.structures.piece.MountainPiece;
import ru.betterend.world.structures.piece.VoxelPiece; import ru.betterend.world.structures.piece.VoxelPiece;
public class StructureRegistry { public class StructureRegistry {
public static final StructurePieceType VOXEL_PIECE = register("voxel", VoxelPiece::new); public static final StructurePieceType VOXEL_PIECE = register("voxel", VoxelPiece::new);
public static final StructurePieceType MOUNTAIN_PIECE = register("mountain_piece", MountainPiece::new); public static final StructurePieceType MOUNTAIN_PIECE = register("mountain_piece", MountainPiece::new);
public static final StructurePieceType CAVE_PIECE = register("cave_piece", CavePiece::new);
public static final EndStructureFeature GIANT_MOSSY_GLOWSHROOM = new EndStructureFeature("giant_mossy_glowshroom", new StructureGiantMossyGlowshroom(), Feature.SURFACE_STRUCTURES, 16, 8); public static final EndStructureFeature GIANT_MOSSY_GLOWSHROOM = new EndStructureFeature("giant_mossy_glowshroom", new StructureGiantMossyGlowshroom(), Feature.SURFACE_STRUCTURES, 16, 8);

View file

@ -93,6 +93,10 @@ public class MHelper {
return (float) Math.sqrt(lengthSqr(x, y)); return (float) Math.sqrt(lengthSqr(x, y));
} }
public static double length(double x, double y) {
return Math.sqrt(lengthSqr(x, y));
}
public static float dot(float x1, float y1, float z1, float x2, float y2, float z2) { public static float dot(float x1, float y1, float z1, float x2, float y2, float z2) {
return x1 * x2 + y1 * y2 + z1 * z2; return x1 * x2 + y1 * y2 + z1 * z2;
} }

View file

@ -83,7 +83,6 @@ public class EndLakeFeature extends DefaultFeature {
} }
} }
for (int x = minX; x <= maxX; x++) { for (int x = minX; x <= maxX; x++) {
POS.setX(x); POS.setX(x);
int x2 = x - blockPos.getX(); int x2 = x - blockPos.getX();
@ -95,27 +94,37 @@ public class EndLakeFeature extends DefaultFeature {
z2 *= z2; z2 *= z2;
int mz = z - maskMinZ; int mz = z - maskMinZ;
if (!mask[mx][mz]) { if (!mask[mx][mz]) {
for (int y = blockPos.getY(); y <= blockPos.getY() + 10; y++) { double size = 1;
for (int y = blockPos.getY(); y <= blockPos.getY() + 20; y++) {
POS.setY(y); POS.setY(y);
int add = y - blockPos.getY(); double add = y - blockPos.getY();
double r = add * 1.8 + radius * (NOISE.eval(x * 0.2, y * 0.2, z * 0.2) * 0.25 + 0.75); if (add > 5) {
r *= r; size *= 0.8;
if (x2 + z2 <= r) { add = 5;
state = world.getBlockState(POS); }
if (state.isIn(BlockTagRegistry.END_GROUND)) { double r = (add * 1.8 + radius * (NOISE.eval(x * 0.2, y * 0.2, z * 0.2) * 0.25 + 0.75)) - 1.0 / size;
BlocksHelper.setWithoutUpdate(world, POS, AIR); if (r > 0) {
} r *= r;
pos = POS.down(); if (x2 + z2 <= r) {
if (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) { state = world.getBlockState(POS);
state = world.getBiome(pos).getGenerationSettings().getSurfaceConfig().getTopMaterial(); if (state.isIn(BlockTagRegistry.END_GROUND)) {
if (y > waterLevel + 1) BlocksHelper.setWithoutUpdate(world, POS, AIR);
BlocksHelper.setWithoutUpdate(world, pos, state); }
else if (y > waterLevel) pos = POS.down();
BlocksHelper.setWithoutUpdate(world, pos, random.nextBoolean() ? state : BlockRegistry.ENDSTONE_DUST.getDefaultState()); if (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) {
else state = world.getBiome(pos).getGenerationSettings().getSurfaceConfig().getTopMaterial();
BlocksHelper.setWithoutUpdate(world, pos, BlockRegistry.ENDSTONE_DUST.getDefaultState()); if (y > waterLevel + 1)
BlocksHelper.setWithoutUpdate(world, pos, state);
else if (y > waterLevel)
BlocksHelper.setWithoutUpdate(world, pos, random.nextBoolean() ? state : BlockRegistry.ENDSTONE_DUST.getDefaultState());
else
BlocksHelper.setWithoutUpdate(world, pos, BlockRegistry.ENDSTONE_DUST.getDefaultState());
}
} }
} }
else {
break;
}
} }
} }
} }

View file

@ -11,6 +11,7 @@ import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig; import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.StructureFeature; import net.minecraft.world.gen.feature.StructureFeature;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
import ru.betterend.world.structures.piece.CavePiece;
import ru.betterend.world.structures.piece.MountainPiece; import ru.betterend.world.structures.piece.MountainPiece;
public class StructureMountain extends StructureFeatureBase { public class StructureMountain extends StructureFeatureBase {
@ -32,7 +33,27 @@ public class StructureMountain extends StructureFeatureBase {
if (y > 5) { if (y > 5) {
float radius = MHelper.randRange(50, 100, random); float radius = MHelper.randRange(50, 100, random);
float height = radius * MHelper.randRange(0.8F, 1.2F, random); float height = radius * MHelper.randRange(0.8F, 1.2F, random);
this.children.add(new MountainPiece(new BlockPos(x, y, z), radius, height, random.nextInt())); MountainPiece piece = new MountainPiece(new BlockPos(x, y, z), radius, height, random.nextInt());
this.children.add(piece);
int count = (int) (radius / 15);
for (int i = 0; i < count; i++) {
double px = random.nextGaussian() * radius * 0.5 + x;
double pz = random.nextGaussian() * radius * 0.5 + z;
float rad = MHelper.randRange(10, 30, random);
int posX = MHelper.floor(px);
int posZ = MHelper.floor(pz);
int minY = chunkGenerator.getHeight(posX, posZ, Type.WORLD_SURFACE_WG);
if (minY > 56) {
int maxY = MHelper.floor(piece.getProtoHeight(posX, minY, posZ) - rad);
if (maxY > 20) {
int posY = MHelper.randRange(20, maxY, random);
this.children.add(new CavePiece(new BlockPos(posX, posY, posZ), rad, random.nextInt()));
}
}
}
} }
this.setBoundingBoxFromChildren(); this.setBoundingBoxFromChildren();
} }

View file

@ -0,0 +1,107 @@
package ru.betterend.world.structures.piece;
import java.util.Random;
import net.minecraft.block.Blocks;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.structure.StructureManager;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.BlockTagRegistry;
import ru.betterend.registry.StructureRegistry;
import ru.betterend.util.BlocksHelper;
import ru.betterend.util.MHelper;
public class CavePiece extends BasePiece {
private OpenSimplexNoise noise;
private BlockPos center;
private float radius;
public CavePiece(BlockPos center, float radius, int id) {
super(StructureRegistry.CAVE_PIECE, id);
this.center = center;
this.radius = radius;
this.noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ()));
makeBoundingBox();
}
public CavePiece(StructureManager manager, CompoundTag tag) {
super(StructureRegistry.CAVE_PIECE, tag);
makeBoundingBox();
}
@Override
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
int x1 = MHelper.max(this.boundingBox.minX, blockBox.minX);
int z1 = MHelper.max(this.boundingBox.minZ, blockBox.minZ);
int x2 = MHelper.min(this.boundingBox.maxX, blockBox.maxX);
int z2 = MHelper.min(this.boundingBox.maxZ, blockBox.maxZ);
int y1 = this.boundingBox.minY;
int y2 = this.boundingBox.maxY;
double hr = radius * 0.75;
double nr = radius * 0.25;
Mutable pos = new Mutable();
for (int x = x1; x <= x2; x++) {
int xsq = x - center.getX();
xsq *= xsq;
pos.setX(x);
for (int z = z1; z <= z2; z++) {
int zsq = z - center.getZ();
zsq *= zsq;
pos.setZ(z);
for (int y = y1; y <= y2; y++) {
int ysq = y - center.getY();
ysq *= 1.6;
ysq *= ysq;
pos.setY(y);
double r = noise.eval(x * 0.1, y * 0.1, z * 0.1) * nr + hr;
double r2 = r - 4.5;
double dist = xsq + ysq + zsq;
if (dist < r2 * r2) {
if (world.getBlockState(pos).isIn(BlockTagRegistry.END_GROUND)) {
BlocksHelper.setWithoutUpdate(world, pos, AIR);
}
}
else if (dist < r * r) {
if (world.getBlockState(pos).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, pos, Blocks.END_STONE);
}
}
}
}
}
return true;
}
@Override
protected void toNbt(CompoundTag tag) {
tag.put("center", NbtHelper.fromBlockPos(center));
tag.putFloat("radius", radius);
}
@Override
protected void fromNbt(CompoundTag tag) {
center = NbtHelper.toBlockPos(tag.getCompound("center"));
radius = tag.getFloat("radius");
noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ()));
}
private void makeBoundingBox() {
int minX = MHelper.floor(center.getX() - radius);
int minY = MHelper.floor(center.getY() - radius);
int minZ = MHelper.floor(center.getZ() - radius);
int maxX = MHelper.floor(center.getX() + radius + 1);
int maxY = MHelper.floor(center.getY() + radius + 1);
int maxZ = MHelper.floor(center.getZ() + radius + 1);
this.boundingBox = new BlockBox(minX, minY, minZ, maxX, maxY, maxZ);
}
}

View file

@ -87,18 +87,10 @@ public class MountainPiece extends BasePiece {
if (maxY > 0) { if (maxY > 0) {
maxY *= (float) noise.eval(px * 0.05, pz * 0.05) * 0.3F + 0.7F; maxY *= (float) noise.eval(px * 0.05, pz * 0.05) * 0.3F + 0.7F;
maxY *= (float) noise.eval(px * 0.1, pz * 0.1) * 0.1F + 0.8F; maxY *= (float) noise.eval(px * 0.1, pz * 0.1) * 0.1F + 0.8F;
//float rigid = Math.abs(1F - (float) noise.eval(px * 0.1, pz * 0.1)) * maxY / 20F - 0.5F;
maxY += minY; maxY += minY;
//float surf = maxY - 3;
for (int y = minY; y < maxY; y++) { for (int y = minY; y < maxY; y++) {
pos.setY(y); pos.setY(y);
chunk.setBlockState(pos, Blocks.END_STONE.getDefaultState(), false); chunk.setBlockState(pos, Blocks.END_STONE.getDefaultState(), false);
/*if (y > surf && rigid > 0.5) {
chunk.setBlockState(pos, BlockRegistry.AURORA_CRYSTAL.getDefaultState(), false);
}
else {
chunk.setBlockState(pos, Blocks.END_STONE.getDefaultState(), false);
}*/
} }
} }
} }
@ -147,6 +139,27 @@ public class MountainPiece extends BasePiece {
return true; return true;
} }
public int getProtoHeight(int px, int py, int pz) {
int px2 = px - center.getX();
px2 *= px2;
int pz2 = pz - center.getZ();
pz2 *= pz2;
float dist = px2 + pz2;
dist = 1 - (float) Math.pow(dist / r2, 0.3);
if (py > 56) {
float maxY = dist * height;
if (maxY > 0) {
maxY *= (float) noise.eval(px * 0.05, pz * 0.05) * 0.3F + 0.7F;
maxY *= (float) noise.eval(px * 0.1, pz * 0.1) * 0.1F + 0.8F;
return MHelper.floor(maxY + py * ((float) MathHelper.clamp((py - 57) / 7F, 0, 1)));
}
}
return py;
}
private int getHeight(StructureWorldAccess world, BlockPos pos) { private int getHeight(StructureWorldAccess world, BlockPos pos) {
if (BiomeRegistry.getFromBiome(world.getBiome(pos)) != BiomeRegistry.END_HIGHLANDS) { if (BiomeRegistry.getFromBiome(world.getBiome(pos)) != BiomeRegistry.END_HIGHLANDS) {
return -4; return -4;