Ice stars update
This commit is contained in:
parent
0ddc5e44eb
commit
a6b778b9d7
2 changed files with 38 additions and 32 deletions
|
@ -5,7 +5,6 @@ import java.util.Random;
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.particle.ParticleEffect;
|
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
|
@ -13,6 +12,7 @@ import ru.betterend.blocks.basis.BlockBase;
|
||||||
import ru.betterend.registry.EndBlocks;
|
import ru.betterend.registry.EndBlocks;
|
||||||
import ru.betterend.registry.EndParticles;
|
import ru.betterend.registry.EndParticles;
|
||||||
import ru.betterend.util.BlocksHelper;
|
import ru.betterend.util.BlocksHelper;
|
||||||
|
import ru.betterend.util.MHelper;
|
||||||
|
|
||||||
public class BlockAncientEmeraldIce extends BlockBase {
|
public class BlockAncientEmeraldIce extends BlockBase {
|
||||||
public BlockAncientEmeraldIce() {
|
public BlockAncientEmeraldIce() {
|
||||||
|
@ -22,6 +22,18 @@ public class BlockAncientEmeraldIce extends BlockBase {
|
||||||
@Override
|
@Override
|
||||||
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
|
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
|
||||||
Direction dir = BlocksHelper.randomDirection(random);
|
Direction dir = BlocksHelper.randomDirection(random);
|
||||||
|
|
||||||
|
if (random.nextBoolean()) {
|
||||||
|
int x = MHelper.randRange(-2, 2, random);
|
||||||
|
int y = MHelper.randRange(-2, 2, random);
|
||||||
|
int z = MHelper.randRange(-2, 2, random);
|
||||||
|
BlockPos p = pos.add(x, y, z);
|
||||||
|
if (world.getBlockState(p).isOf(Blocks.WATER)) {
|
||||||
|
world.setBlockState(p, EndBlocks.EMERALD_ICE.getDefaultState());
|
||||||
|
makeParticles(world, p, random);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pos = pos.offset(dir);
|
pos = pos.offset(dir);
|
||||||
state = world.getBlockState(pos);
|
state = world.getBlockState(pos);
|
||||||
if (state.isOf(Blocks.WATER)) {
|
if (state.isOf(Blocks.WATER)) {
|
||||||
|
@ -35,12 +47,6 @@ public class BlockAncientEmeraldIce extends BlockBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeParticles(ServerWorld world, BlockPos pos, Random random) {
|
private void makeParticles(ServerWorld world, BlockPos pos, Random random) {
|
||||||
for (int i = 0; i < 20; i++) {
|
world.spawnParticles(EndParticles.SNOWFLAKE, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 20, 0.5, 0.5, 0.5, 0);
|
||||||
int side = random.nextInt(3);
|
|
||||||
double x = (side == 0 ? random.nextDouble() : random.nextBoolean() ? 0 : 1) + pos.getX();
|
|
||||||
double y = (side == 1 ? random.nextDouble() : random.nextBoolean() ? 0 : 1) + pos.getY();
|
|
||||||
double z = (side == 2 ? random.nextDouble() : random.nextBoolean() ? 0 : 1) + pos.getZ();
|
|
||||||
world.addParticle(EndParticles.SNOWFLAKE, x, y, z, 0, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,12 @@ import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
import net.minecraft.client.util.math.Vector3f;
|
import net.minecraft.client.util.math.Vector3f;
|
||||||
import net.minecraft.state.property.Properties;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.StructureWorldAccess;
|
import net.minecraft.world.StructureWorldAccess;
|
||||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||||
import ru.betterend.noise.OpenSimplexNoise;
|
import ru.betterend.registry.EndBlocks;
|
||||||
import ru.betterend.util.MHelper;
|
import ru.betterend.util.MHelper;
|
||||||
import ru.betterend.util.sdf.SDF;
|
import ru.betterend.util.sdf.SDF;
|
||||||
import ru.betterend.util.sdf.operator.SDFRotation;
|
import ru.betterend.util.sdf.operator.SDFRotation;
|
||||||
|
@ -40,7 +38,7 @@ public class IceStarFeature extends DefaultFeature {
|
||||||
int count = MHelper.randRange(minCount, maxCount, random);
|
int count = MHelper.randRange(minCount, maxCount, random);
|
||||||
List<Vector3f> points = getFibonacciPoints(count);
|
List<Vector3f> points = getFibonacciPoints(count);
|
||||||
SDF sdf = null;
|
SDF sdf = null;
|
||||||
SDF spike = new SDFCapedCone().setRadius1(3 + (size - 5) * 0.2F).setRadius2(0).setHeight(size).setBlock(Blocks.ICE);
|
SDF spike = new SDFCapedCone().setRadius1(3 + (size - 5) * 0.2F).setRadius2(0).setHeight(size).setBlock(EndBlocks.DENSE_SNOW);
|
||||||
spike = new SDFTranslate().setTranslate(0, size - 0.5F, 0).setSource(spike);
|
spike = new SDFTranslate().setTranslate(0, size - 0.5F, 0).setSource(spike);
|
||||||
for (Vector3f point: points) {
|
for (Vector3f point: points) {
|
||||||
SDF rotated = spike;
|
SDF rotated = spike;
|
||||||
|
@ -60,29 +58,31 @@ public class IceStarFeature extends DefaultFeature {
|
||||||
int z1 = (pos.getZ() >> 4) << 4;
|
int z1 = (pos.getZ() >> 4) << 4;
|
||||||
pos = new BlockPos(x1 + random.nextInt(16), MHelper.randRange(32, 128, random), z1 + random.nextInt(16));
|
pos = new BlockPos(x1 + random.nextInt(16), MHelper.randRange(32, 128, random), z1 + random.nextInt(16));
|
||||||
|
|
||||||
OpenSimplexNoise noise1 = new OpenSimplexNoise(random.nextLong());
|
final float ancientRadius = size * 0.45F;
|
||||||
OpenSimplexNoise noise2 = new OpenSimplexNoise(random.nextLong());
|
final float denseRadius = size * 0.8F;
|
||||||
|
final float iceRadius = size < 7 ? size * 5 : size * 1.3F;
|
||||||
|
final float randScale = size * 0.3F;
|
||||||
|
|
||||||
|
final BlockPos center = pos;
|
||||||
|
final BlockState ice = EndBlocks.EMERALD_ICE.getDefaultState();
|
||||||
|
final BlockState dense = EndBlocks.DENSE_EMERALD_ICE.getDefaultState();
|
||||||
|
final BlockState ancient = EndBlocks.ANCIENT_EMERALD_ICE.getDefaultState();
|
||||||
|
final SDF sdfCopy = sdf;
|
||||||
|
|
||||||
final boolean hasSnow = random.nextBoolean();
|
|
||||||
BlockState layer = Blocks.SNOW.getDefaultState();
|
|
||||||
BlockState snow = Blocks.SNOW_BLOCK.getDefaultState();
|
|
||||||
BlockState blue = Blocks.BLUE_ICE.getDefaultState();
|
|
||||||
BlockState packed = Blocks.PACKED_ICE.getDefaultState();
|
|
||||||
sdf.setPostProcess((info) -> {
|
sdf.setPostProcess((info) -> {
|
||||||
BlockPos bpos = info.getPos();
|
BlockPos bpos = info.getPos();
|
||||||
|
float px = bpos.getX() - center.getX();
|
||||||
if (!info.getState().isOf(Blocks.SNOW)) {
|
float py = bpos.getY() - center.getY();
|
||||||
if (hasSnow && info.getStateUp().isAir()) {
|
float pz = bpos.getZ() - center.getZ();
|
||||||
info.setBlockPos(bpos.up(), layer.with(Properties.LAYERS, MHelper.randRange(1, 3, random)));
|
float distance = MHelper.length(px, py, pz) + sdfCopy.getDistance(px, py, pz) * 0.1F + random.nextFloat() * randScale;
|
||||||
return snow;
|
if (distance < ancientRadius) {
|
||||||
|
return ancient;
|
||||||
}
|
}
|
||||||
|
else if (distance < denseRadius) {
|
||||||
if (noise1.eval(bpos.getX() * 0.1, bpos.getY() * 0.1, bpos.getZ() * 0.1) > 0.3) {
|
return dense;
|
||||||
return packed;
|
|
||||||
}
|
|
||||||
else if (noise2.eval(bpos.getX() * 0.1, bpos.getY() * 0.1, bpos.getZ() * 0.1) > 0.3) {
|
|
||||||
return blue;
|
|
||||||
}
|
}
|
||||||
|
else if (distance < iceRadius) {
|
||||||
|
return ice;
|
||||||
}
|
}
|
||||||
return info.getState();
|
return info.getState();
|
||||||
}).fillRecursive(world, pos);
|
}).fillRecursive(world, pos);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue