Start migration
This commit is contained in:
parent
6630ce0cab
commit
47ed597358
491 changed files with 12045 additions and 11953 deletions
|
@ -3,7 +3,7 @@ package ru.betterend.world.structures;
|
|||
import java.util.Random;
|
||||
|
||||
import net.fabricmc.fabric.api.structure.v1.FabricStructureBuilder;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.world.gen.GenerationStep;
|
||||
import net.minecraft.world.gen.feature.ConfiguredStructureFeature;
|
||||
|
@ -16,18 +16,17 @@ public class EndStructureFeature {
|
|||
private final StructureFeature<DefaultFeatureConfig> structure;
|
||||
private final ConfiguredStructureFeature<?, ?> featureConfigured;
|
||||
private final GenerationStep.Feature featureStep;
|
||||
|
||||
public EndStructureFeature(String name, StructureFeature<DefaultFeatureConfig> structure, GenerationStep.Feature step, int spacing, int separation) {
|
||||
Identifier id = BetterEnd.makeID(name);
|
||||
|
||||
|
||||
public EndStructureFeature(String name, StructureFeature<DefaultFeatureConfig> structure,
|
||||
GenerationStep.Feature step, int spacing, int separation) {
|
||||
ResourceLocation id = BetterEnd.makeID(name);
|
||||
|
||||
this.featureStep = step;
|
||||
this.structure = FabricStructureBuilder.create(id, structure)
|
||||
.step(step)
|
||||
.defaultConfig(spacing, separation, RANDOM.nextInt(8192))
|
||||
.register();
|
||||
this.structure = FabricStructureBuilder.create(id, structure).step(step)
|
||||
.defaultConfig(spacing, separation, RANDOM.nextInt(8192)).register();
|
||||
|
||||
this.featureConfigured = this.structure.configure(DefaultFeatureConfig.DEFAULT);
|
||||
|
||||
|
||||
BuiltinRegistries.add(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, id, this.featureConfigured);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,13 +4,13 @@ import java.util.Map;
|
|||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtHelper;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
@ -25,9 +25,10 @@ public class StructureWorld {
|
|||
private int maxX = Integer.MIN_VALUE;
|
||||
private int maxY = Integer.MIN_VALUE;
|
||||
private int maxZ = Integer.MIN_VALUE;
|
||||
|
||||
public StructureWorld() {}
|
||||
|
||||
|
||||
public StructureWorld() {
|
||||
}
|
||||
|
||||
public StructureWorld(CompoundTag tag) {
|
||||
minX = tag.getInt("minX");
|
||||
maxX = tag.getInt("maxX");
|
||||
|
@ -35,7 +36,7 @@ public class StructureWorld {
|
|||
maxY = tag.getInt("maxY");
|
||||
minZ = tag.getInt("minZ");
|
||||
maxZ = tag.getInt("maxZ");
|
||||
|
||||
|
||||
ListTag map = tag.getList("parts", 10);
|
||||
map.forEach((element) -> {
|
||||
CompoundTag compound = (CompoundTag) element;
|
||||
|
@ -45,33 +46,39 @@ public class StructureWorld {
|
|||
parts.put(new ChunkPos(x, z), part);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void setBlock(BlockPos pos, BlockState state) {
|
||||
ChunkPos cPos = new ChunkPos(pos);
|
||||
|
||||
|
||||
if (cPos.equals(lastPos)) {
|
||||
lastPart.addBlock(pos, state);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Part part = parts.get(cPos);
|
||||
if (part == null) {
|
||||
part = new Part();
|
||||
parts.put(cPos, part);
|
||||
|
||||
if (cPos.x < minX) minX = cPos.x;
|
||||
if (cPos.x > maxX) maxX = cPos.x;
|
||||
if (cPos.z < minZ) minZ = cPos.z;
|
||||
if (cPos.z > maxZ) maxZ = cPos.z;
|
||||
|
||||
if (cPos.x < minX)
|
||||
minX = cPos.x;
|
||||
if (cPos.x > maxX)
|
||||
maxX = cPos.x;
|
||||
if (cPos.z < minZ)
|
||||
minZ = cPos.z;
|
||||
if (cPos.z > maxZ)
|
||||
maxZ = cPos.z;
|
||||
}
|
||||
if (pos.getY() < minY) minY = pos.getY();
|
||||
if (pos.getY() > maxY) maxY = pos.getY();
|
||||
if (pos.getY() < minY)
|
||||
minY = pos.getY();
|
||||
if (pos.getY() > maxY)
|
||||
maxY = pos.getY();
|
||||
part.addBlock(pos, state);
|
||||
|
||||
|
||||
lastPos = cPos;
|
||||
lastPart = part;
|
||||
}
|
||||
|
||||
|
||||
public boolean placeChunk(StructureWorldAccess world, ChunkPos chunkPos) {
|
||||
Part part = parts.get(chunkPos);
|
||||
if (part != null) {
|
||||
|
@ -81,7 +88,7 @@ public class StructureWorld {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public CompoundTag toBNT() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putInt("minX", minX);
|
||||
|
@ -97,19 +104,21 @@ public class StructureWorld {
|
|||
});
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
public BlockBox getBounds() {
|
||||
if (minX == Integer.MAX_VALUE || maxX == Integer.MIN_VALUE || minZ == Integer.MAX_VALUE || maxZ == Integer.MIN_VALUE) {
|
||||
if (minX == Integer.MAX_VALUE || maxX == Integer.MIN_VALUE || minZ == Integer.MAX_VALUE
|
||||
|| maxZ == Integer.MIN_VALUE) {
|
||||
return BlockBox.empty();
|
||||
}
|
||||
return new BlockBox(minX << 4, minY, minZ << 4, (maxX << 4) | 15, maxY, (maxZ << 4) | 15);
|
||||
}
|
||||
|
||||
|
||||
private static final class Part {
|
||||
Map<BlockPos, BlockState> blocks = Maps.newHashMap();
|
||||
|
||||
public Part() {}
|
||||
|
||||
|
||||
public Part() {
|
||||
}
|
||||
|
||||
public Part(CompoundTag tag) {
|
||||
ListTag map = tag.getList("blocks", 10);
|
||||
ListTag map2 = tag.getList("states", 10);
|
||||
|
@ -117,7 +126,7 @@ public class StructureWorld {
|
|||
for (int i = 0; i < states.length; i++) {
|
||||
states[i] = NbtHelper.toBlockState((CompoundTag) map2.get(i));
|
||||
}
|
||||
|
||||
|
||||
map.forEach((element) -> {
|
||||
CompoundTag block = (CompoundTag) element;
|
||||
BlockPos pos = NbtHelper.toBlockPos(block.getCompound("pos"));
|
||||
|
@ -126,18 +135,18 @@ public class StructureWorld {
|
|||
blocks.put(pos, state);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void addBlock(BlockPos pos, BlockState state) {
|
||||
BlockPos inner = new BlockPos(pos.getX() & 15, pos.getY(), pos.getZ() & 15);
|
||||
blocks.put(inner, state);
|
||||
}
|
||||
|
||||
|
||||
void placeChunk(Chunk chunk) {
|
||||
blocks.forEach((pos, state) -> {
|
||||
chunk.setBlockState(pos, state, false);
|
||||
chunk.setBlockAndUpdate(pos, state, false);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
CompoundTag toNBT(int x, int z) {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putInt("x", x);
|
||||
|
@ -146,24 +155,24 @@ public class StructureWorld {
|
|||
tag.put("blocks", map);
|
||||
ListTag stateMap = new ListTag();
|
||||
tag.put("states", stateMap);
|
||||
|
||||
|
||||
int[] id = new int[1];
|
||||
Map<BlockState, Integer> states = Maps.newHashMap();
|
||||
|
||||
|
||||
blocks.forEach((pos, state) -> {
|
||||
int stateID = states.getOrDefault(states, -1);
|
||||
if (stateID < 0) {
|
||||
stateID = id[0] ++;
|
||||
stateID = id[0]++;
|
||||
states.put(state, stateID);
|
||||
stateMap.add(NbtHelper.fromBlockState(state));
|
||||
}
|
||||
|
||||
|
||||
CompoundTag block = new CompoundTag();
|
||||
block.put("pos", NbtHelper.fromBlockPos(pos));
|
||||
block.putInt("state", stateID);
|
||||
map.add(block);
|
||||
});
|
||||
|
||||
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@ package ru.betterend.world.structures.features;
|
|||
import net.minecraft.structure.Structure;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.structure.StructureStart;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.world.Heightmap;
|
||||
|
@ -22,11 +22,13 @@ import ru.betterend.util.StructureHelper;
|
|||
import ru.betterend.world.structures.piece.NBTPiece;
|
||||
|
||||
public class EternalPortalStructure extends FeatureBaseStructure {
|
||||
private static final Identifier STRUCTURE_ID = BetterEnd.makeID("portal/eternal_portal");
|
||||
private static final ResourceLocation STRUCTURE_ID = BetterEnd.makeID("portal/eternal_portal");
|
||||
private static final Structure STRUCTURE = StructureHelper.readStructure(STRUCTURE_ID);
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean shouldStartAt(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long worldSeed, ChunkRandom chunkRandom, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos, DefaultFeatureConfig featureConfig) {
|
||||
protected boolean shouldStartAt(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long worldSeed,
|
||||
ChunkRandom chunkRandom, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos,
|
||||
DefaultFeatureConfig featureConfig) {
|
||||
long x = chunkPos.x;
|
||||
long z = chunkPos.z;
|
||||
if (x * x + z * z < 10000) {
|
||||
|
@ -35,26 +37,30 @@ public class EternalPortalStructure extends FeatureBaseStructure {
|
|||
if (chunkGenerator.getHeight((chunkX << 4) | 8, (chunkZ << 4) | 8, Heightmap.Type.WORLD_SURFACE_WG) < 10) {
|
||||
return false;
|
||||
}
|
||||
return super.shouldStartAt(chunkGenerator, biomeSource, worldSeed, chunkRandom, chunkX, chunkZ, biome, chunkPos, featureConfig);
|
||||
return super.shouldStartAt(chunkGenerator, biomeSource, worldSeed, chunkRandom, chunkX, chunkZ, biome, chunkPos,
|
||||
featureConfig);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public StructureFeature.StructureStartFactory<DefaultFeatureConfig> getStructureStartFactory() {
|
||||
return SDFStructureStart::new;
|
||||
}
|
||||
|
||||
|
||||
public static class SDFStructureStart extends StructureStart<DefaultFeatureConfig> {
|
||||
public SDFStructureStart(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box, int references, long seed) {
|
||||
public SDFStructureStart(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box,
|
||||
int references, long seed) {
|
||||
super(feature, chunkX, chunkZ, box, references, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, DefaultFeatureConfig config) {
|
||||
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator,
|
||||
StructureManager manager, int chunkX, int chunkZ, Biome biome, DefaultFeatureConfig config) {
|
||||
int x = (chunkX << 4) | MHelper.randRange(4, 12, random);
|
||||
int z = (chunkZ << 4) | MHelper.randRange(4, 12, random);
|
||||
int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG);
|
||||
if (y > 4) {
|
||||
this.children.add(new NBTPiece(STRUCTURE_ID, STRUCTURE, new BlockPos(x, y - 4, z), random.nextInt(5), true, random));
|
||||
this.children.add(new NBTPiece(STRUCTURE_ID, STRUCTURE, new BlockPos(x, y - 4, z), random.nextInt(5),
|
||||
true, random));
|
||||
}
|
||||
this.setBoundingBoxFromChildren();
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package ru.betterend.world.structures.features;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.util.BlockRotation;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
@ -15,27 +15,29 @@ import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
|||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
|
||||
public abstract class FeatureBaseStructure extends StructureFeature<DefaultFeatureConfig> {
|
||||
protected static final BlockState AIR = Blocks.AIR.getDefaultState();
|
||||
|
||||
protected static final BlockState AIR = Blocks.AIR.defaultBlockState();
|
||||
|
||||
public FeatureBaseStructure() {
|
||||
super(DefaultFeatureConfig.CODEC);
|
||||
}
|
||||
|
||||
protected boolean shouldStartAt(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long worldSeed, ChunkRandom chunkRandom, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos, DefaultFeatureConfig featureConfig) {
|
||||
|
||||
protected boolean shouldStartAt(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long worldSeed,
|
||||
ChunkRandom chunkRandom, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos,
|
||||
DefaultFeatureConfig featureConfig) {
|
||||
return getGenerationHeight(chunkX, chunkZ, chunkGenerator) >= 20;
|
||||
}
|
||||
|
||||
private static int getGenerationHeight(int chunkX, int chunkZ, ChunkGenerator chunkGenerator) {
|
||||
Random random = new Random((long) (chunkX + chunkZ * 10387313));
|
||||
BlockRotation blockRotation = BlockRotation.random(random);
|
||||
Rotation blockRotation = Rotation.random(random);
|
||||
int i = 5;
|
||||
int j = 5;
|
||||
if (blockRotation == BlockRotation.CLOCKWISE_90) {
|
||||
if (blockRotation == Rotation.CLOCKWISE_90) {
|
||||
i = -5;
|
||||
} else if (blockRotation == BlockRotation.CLOCKWISE_180) {
|
||||
} else if (blockRotation == Rotation.CLOCKWISE_180) {
|
||||
i = -5;
|
||||
j = -5;
|
||||
} else if (blockRotation == BlockRotation.COUNTERCLOCKWISE_90) {
|
||||
} else if (blockRotation == Rotation.COUNTERCLOCKWISE_90) {
|
||||
j = -5;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,12 +4,12 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.structure.StructureStart;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
|
@ -29,59 +29,58 @@ public class GiantIceStarStructure extends SDFStructureFeature {
|
|||
private final float maxSize = 35;
|
||||
private final int minCount = 25;
|
||||
private final int maxCount = 40;
|
||||
|
||||
|
||||
@Override
|
||||
protected SDF getSDF(BlockPos pos, Random random) {
|
||||
float size = MHelper.randRange(minSize, maxSize, random);
|
||||
int count = MHelper.randRange(minCount, maxCount, random);
|
||||
List<Vector3f> points = getFibonacciPoints(count);
|
||||
SDF sdf = null;
|
||||
SDF spike = new SDFCappedCone().setRadius1(3 + (size - 5) * 0.2F).setRadius2(0).setHeight(size).setBlock(EndBlocks.DENSE_SNOW);
|
||||
SDF spike = new SDFCappedCone().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);
|
||||
for (Vector3f point: points) {
|
||||
for (Vector3f point : points) {
|
||||
SDF rotated = spike;
|
||||
point = MHelper.normalize(point);
|
||||
float angle = MHelper.angle(Vector3f.POSITIVE_Y, point);
|
||||
if (angle > 0.01F && angle < 3.14F) {
|
||||
Vector3f axis = MHelper.normalize(MHelper.cross(Vector3f.POSITIVE_Y, point));
|
||||
rotated = new SDFRotation().setRotation(axis, angle).setSource(spike);
|
||||
}
|
||||
else if (angle > 1) {
|
||||
} else if (angle > 1) {
|
||||
rotated = new SDFRotation().setRotation(Vector3f.POSITIVE_Y, (float) Math.PI).setSource(spike);
|
||||
}
|
||||
sdf = (sdf == null) ? rotated : new SDFUnion().setSourceA(sdf).setSourceB(rotated);
|
||||
}
|
||||
|
||||
|
||||
final float ancientRadius = size * 0.7F;
|
||||
final float denseRadius = size * 0.9F;
|
||||
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 BlockState ice = EndBlocks.EMERALD_ICE.defaultBlockState();
|
||||
final BlockState dense = EndBlocks.DENSE_EMERALD_ICE.defaultBlockState();
|
||||
final BlockState ancient = EndBlocks.ANCIENT_EMERALD_ICE.defaultBlockState();
|
||||
final SDF sdfCopy = sdf;
|
||||
|
||||
|
||||
return sdf.addPostProcess((info) -> {
|
||||
BlockPos bpos = info.getPos();
|
||||
float px = bpos.getX() - center.getX();
|
||||
float py = bpos.getY() - center.getY();
|
||||
float pz = bpos.getZ() - center.getZ();
|
||||
float distance = MHelper.length(px, py, pz) + sdfCopy.getDistance(px, py, pz) * 0.4F + random.nextFloat() * randScale;
|
||||
float distance = MHelper.length(px, py, pz) + sdfCopy.getDistance(px, py, pz) * 0.4F
|
||||
+ random.nextFloat() * randScale;
|
||||
if (distance < ancientRadius) {
|
||||
return ancient;
|
||||
}
|
||||
else if (distance < denseRadius) {
|
||||
} else if (distance < denseRadius) {
|
||||
return dense;
|
||||
}
|
||||
else if (distance < iceRadius) {
|
||||
} else if (distance < iceRadius) {
|
||||
return ice;
|
||||
}
|
||||
return info.getState();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private List<Vector3f> getFibonacciPoints(int count) {
|
||||
float max = count - 1;
|
||||
List<Vector3f> result = new ArrayList<Vector3f>(count);
|
||||
|
@ -95,23 +94,27 @@ public class GiantIceStarStructure extends SDFStructureFeature {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public StructureFeature.StructureStartFactory<DefaultFeatureConfig> getStructureStartFactory() {
|
||||
return StarStructureStart::new;
|
||||
}
|
||||
|
||||
|
||||
public static class StarStructureStart extends StructureStart<DefaultFeatureConfig> {
|
||||
public StarStructureStart(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box, int references, long seed) {
|
||||
public StarStructureStart(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box,
|
||||
int references, long seed) {
|
||||
super(feature, chunkX, chunkZ, box, references, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, DefaultFeatureConfig config) {
|
||||
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator,
|
||||
StructureManager manager, int chunkX, int chunkZ, Biome biome, DefaultFeatureConfig config) {
|
||||
int x = (chunkX << 4) | MHelper.randRange(4, 12, random);
|
||||
int z = (chunkZ << 4) | MHelper.randRange(4, 12, random);
|
||||
BlockPos start = new BlockPos(x, MHelper.randRange(32, 128, random), z);
|
||||
VoxelPiece piece = new VoxelPiece((world) -> { ((SDFStructureFeature) this.getFeature()).getSDF(start, this.random).fillRecursive(world, start); }, random.nextInt());
|
||||
VoxelPiece piece = new VoxelPiece((world) -> {
|
||||
((SDFStructureFeature) this.getFeature()).getSDF(start, this.random).fillRecursive(world, start);
|
||||
}, random.nextInt());
|
||||
this.children.add(piece);
|
||||
this.setBoundingBoxFromChildren();
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ import java.util.List;
|
|||
import java.util.Random;
|
||||
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import ru.betterend.blocks.MossyGlowshroomCapBlock;
|
||||
import ru.betterend.blocks.basis.FurBlock;
|
||||
import ru.betterend.noise.OpenSimplexNoise;
|
||||
|
@ -34,89 +34,95 @@ public class GiantMossyGlowshroomStructure extends SDFStructureFeature {
|
|||
SDFCappedCone cone1 = new SDFCappedCone().setHeight(2.5F).setRadius1(1.5F).setRadius2(2.5F);
|
||||
SDFCappedCone cone2 = new SDFCappedCone().setHeight(3F).setRadius1(2.5F).setRadius2(13F);
|
||||
SDF posedCone2 = new SDFTranslate().setTranslate(0, 5, 0).setSource(cone2);
|
||||
SDF posedCone3 = new SDFTranslate().setTranslate(0, 12F, 0).setSource(new SDFScale().setScale(2).setSource(cone2));
|
||||
SDF posedCone3 = new SDFTranslate().setTranslate(0, 12F, 0)
|
||||
.setSource(new SDFScale().setScale(2).setSource(cone2));
|
||||
SDF upCone = new SDFSubtraction().setSourceA(posedCone2).setSourceB(posedCone3);
|
||||
SDF wave = new SDFFlatWave().setRaysCount(12).setIntensity(1.3F).setSource(upCone);
|
||||
SDF cones = new SDFSmoothUnion().setRadius(3).setSourceA(cone1).setSourceB(wave);
|
||||
|
||||
|
||||
SDF innerCone = new SDFTranslate().setTranslate(0, 1.25F, 0).setSource(upCone);
|
||||
innerCone = new SDFScale3D().setScale(1.2F, 1F, 1.2F).setSource(innerCone);
|
||||
cones = new SDFUnion().setSourceA(cones).setSourceB(innerCone);
|
||||
|
||||
|
||||
SDF glowCone = new SDFCappedCone().setHeight(3F).setRadius1(2F).setRadius2(12.5F);
|
||||
SDFPrimitive priGlowCone = (SDFPrimitive) glowCone;
|
||||
glowCone = new SDFTranslate().setTranslate(0, 4.25F, 0).setSource(glowCone);
|
||||
glowCone = new SDFSubtraction().setSourceA(glowCone).setSourceB(posedCone3);
|
||||
|
||||
|
||||
cones = new SDFUnion().setSourceA(cones).setSourceB(glowCone);
|
||||
|
||||
|
||||
OpenSimplexNoise noise = new OpenSimplexNoise(1234);
|
||||
cones = new SDFCoordModify().setFunction((pos) -> {
|
||||
float dist = MHelper.length(pos.getX(), pos.getZ());
|
||||
float y = pos.getY() + (float) noise.eval(pos.getX() * 0.1 + center.getX(), pos.getZ() * 0.1 + center.getZ()) * dist * 0.3F - dist * 0.15F;
|
||||
float y = pos.getY()
|
||||
+ (float) noise.eval(pos.getX() * 0.1 + center.getX(), pos.getZ() * 0.1 + center.getZ()) * dist
|
||||
* 0.3F
|
||||
- dist * 0.15F;
|
||||
pos.set(pos.getX(), y, pos.getZ());
|
||||
}).setSource(cones);
|
||||
|
||||
SDFTranslate HEAD_POS = (SDFTranslate) new SDFTranslate().setSource(new SDFTranslate().setTranslate(0, 2.5F, 0).setSource(cones));
|
||||
|
||||
|
||||
SDFTranslate HEAD_POS = (SDFTranslate) new SDFTranslate()
|
||||
.setSource(new SDFTranslate().setTranslate(0, 2.5F, 0).setSource(cones));
|
||||
|
||||
SDF roots = new SDFSphere().setRadius(4F);
|
||||
SDFPrimitive primRoots = (SDFPrimitive) roots;
|
||||
roots = new SDFScale3D().setScale(1, 0.7F, 1).setSource(roots);
|
||||
SDFFlatWave rotRoots = (SDFFlatWave) new SDFFlatWave().setRaysCount(5).setIntensity(1.5F).setSource(roots);
|
||||
|
||||
SDFBinary function = new SDFSmoothUnion().setRadius(4).setSourceB(new SDFUnion().setSourceA(HEAD_POS).setSourceB(rotRoots));
|
||||
|
||||
|
||||
SDFBinary function = new SDFSmoothUnion().setRadius(4)
|
||||
.setSourceB(new SDFUnion().setSourceA(HEAD_POS).setSourceB(rotRoots));
|
||||
|
||||
cone1.setBlock(EndBlocks.MOSSY_GLOWSHROOM_CAP);
|
||||
cone2.setBlock(EndBlocks.MOSSY_GLOWSHROOM_CAP);
|
||||
priGlowCone.setBlock(EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE);
|
||||
primRoots.setBlock(EndBlocks.MOSSY_GLOWSHROOM.bark);
|
||||
|
||||
|
||||
float height = MHelper.randRange(10F, 25F, random);
|
||||
int count = MHelper.floor(height / 4);
|
||||
List<Vector3f> spline = SplineHelper.makeSpline(0, 0, 0, 0, height, 0, count);
|
||||
SplineHelper.offsetParts(spline, random, 1F, 0, 1F);
|
||||
SDF sdf = SplineHelper.buildSDF(spline, 2.1F, 1.5F, (pos) -> {
|
||||
return EndBlocks.MOSSY_GLOWSHROOM.log.getDefaultState();
|
||||
return EndBlocks.MOSSY_GLOWSHROOM.log.defaultBlockState();
|
||||
});
|
||||
Vector3f pos = spline.get(spline.size() - 1);
|
||||
float scale = MHelper.randRange(2F, 3.5F, random);
|
||||
|
||||
|
||||
HEAD_POS.setTranslate(pos.getX(), pos.getY(), pos.getZ());
|
||||
rotRoots.setAngle(random.nextFloat() * MHelper.PI2);
|
||||
function.setSourceA(sdf);
|
||||
|
||||
return new SDFRound().setRadius(1.5F).setSource(new SDFScale()
|
||||
.setScale(scale)
|
||||
.setSource(function))
|
||||
|
||||
return new SDFRound().setRadius(1.5F).setSource(new SDFScale().setScale(scale).setSource(function))
|
||||
.addPostProcess((info) -> {
|
||||
if (EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getState())) {
|
||||
if (random.nextBoolean() && info.getStateUp().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_CAP) {
|
||||
info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.getDefaultState().with(MossyGlowshroomCapBlock.TRANSITION, true));
|
||||
info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState()
|
||||
.with(MossyGlowshroomCapBlock.TRANSITION, true));
|
||||
return info.getState();
|
||||
} else if (!EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateUp())
|
||||
|| !EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) {
|
||||
info.setState(EndBlocks.MOSSY_GLOWSHROOM.bark.defaultBlockState());
|
||||
return info.getState();
|
||||
}
|
||||
else if (!EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateUp()) || !EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) {
|
||||
info.setState(EndBlocks.MOSSY_GLOWSHROOM.bark.getDefaultState());
|
||||
return info.getState();
|
||||
}
|
||||
}
|
||||
else if (info.getState().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_CAP) {
|
||||
} else if (info.getState().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_CAP) {
|
||||
if (EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown().getBlock())) {
|
||||
info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.getDefaultState().with(MossyGlowshroomCapBlock.TRANSITION, true));
|
||||
info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState()
|
||||
.with(MossyGlowshroomCapBlock.TRANSITION, true));
|
||||
return info.getState();
|
||||
}
|
||||
|
||||
info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.getDefaultState());
|
||||
|
||||
info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState());
|
||||
return info.getState();
|
||||
}
|
||||
else if (info.getState().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE) {
|
||||
for (Direction dir: BlocksHelper.HORIZONTAL) {
|
||||
} else if (info.getState().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE) {
|
||||
for (Direction dir : BlocksHelper.HORIZONTAL) {
|
||||
if (info.getState(dir) == AIR) {
|
||||
info.setBlockPos(info.getPos().offset(dir), EndBlocks.MOSSY_GLOWSHROOM_FUR.getDefaultState().with(FurBlock.FACING, dir));
|
||||
info.setBlockPos(info.getPos().offset(dir),
|
||||
EndBlocks.MOSSY_GLOWSHROOM_FUR.defaultBlockState().with(FurBlock.FACING, dir));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (info.getStateDown().getBlock() != EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE) {
|
||||
info.setBlockPos(info.getPos().down(), EndBlocks.MOSSY_GLOWSHROOM_FUR.getDefaultState().with(FurBlock.FACING, Direction.DOWN));
|
||||
info.setBlockPos(info.getPos().below(), EndBlocks.MOSSY_GLOWSHROOM_FUR.defaultBlockState()
|
||||
.with(FurBlock.FACING, Direction.DOWN));
|
||||
}
|
||||
}
|
||||
return info.getState();
|
||||
|
|
|
@ -3,7 +3,7 @@ package ru.betterend.world.structures.features;
|
|||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.structure.StructureStart;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
@ -18,14 +18,16 @@ public class MegaLakeSmallStructure extends FeatureBaseStructure {
|
|||
public StructureFeature.StructureStartFactory<DefaultFeatureConfig> getStructureStartFactory() {
|
||||
return SDFStructureStart::new;
|
||||
}
|
||||
|
||||
|
||||
public static class SDFStructureStart extends StructureStart<DefaultFeatureConfig> {
|
||||
public SDFStructureStart(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box, int references, long seed) {
|
||||
public SDFStructureStart(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box,
|
||||
int references, long seed) {
|
||||
super(feature, chunkX, chunkZ, box, references, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, DefaultFeatureConfig config) {
|
||||
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator,
|
||||
StructureManager manager, int chunkX, int chunkZ, Biome biome, DefaultFeatureConfig config) {
|
||||
int x = (chunkX << 4) | MHelper.randRange(4, 12, random);
|
||||
int z = (chunkZ << 4) | MHelper.randRange(4, 12, random);
|
||||
int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG);
|
||||
|
|
|
@ -3,7 +3,7 @@ package ru.betterend.world.structures.features;
|
|||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.structure.StructureStart;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
@ -18,14 +18,16 @@ public class MegaLakeStructure extends FeatureBaseStructure {
|
|||
public StructureFeature.StructureStartFactory<DefaultFeatureConfig> getStructureStartFactory() {
|
||||
return SDFStructureStart::new;
|
||||
}
|
||||
|
||||
|
||||
public static class SDFStructureStart extends StructureStart<DefaultFeatureConfig> {
|
||||
public SDFStructureStart(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box, int references, long seed) {
|
||||
public SDFStructureStart(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box,
|
||||
int references, long seed) {
|
||||
super(feature, chunkX, chunkZ, box, references, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, DefaultFeatureConfig config) {
|
||||
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator,
|
||||
StructureManager manager, int chunkX, int chunkZ, Biome biome, DefaultFeatureConfig config) {
|
||||
int x = (chunkX << 4) | MHelper.randRange(4, 12, random);
|
||||
int z = (chunkZ << 4) | MHelper.randRange(4, 12, random);
|
||||
int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG);
|
||||
|
|
|
@ -3,7 +3,7 @@ package ru.betterend.world.structures.features;
|
|||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.structure.StructureStart;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
@ -18,21 +18,24 @@ public class MountainStructure extends FeatureBaseStructure {
|
|||
public StructureFeature.StructureStartFactory<DefaultFeatureConfig> getStructureStartFactory() {
|
||||
return SDFStructureStart::new;
|
||||
}
|
||||
|
||||
|
||||
public static class SDFStructureStart extends StructureStart<DefaultFeatureConfig> {
|
||||
public SDFStructureStart(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box, int references, long seed) {
|
||||
public SDFStructureStart(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box,
|
||||
int references, long seed) {
|
||||
super(feature, chunkX, chunkZ, box, references, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, DefaultFeatureConfig config) {
|
||||
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator,
|
||||
StructureManager manager, int chunkX, int chunkZ, Biome biome, DefaultFeatureConfig config) {
|
||||
int x = (chunkX << 4) | MHelper.randRange(4, 12, random);
|
||||
int z = (chunkZ << 4) | MHelper.randRange(4, 12, random);
|
||||
int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG);
|
||||
if (y > 5) {
|
||||
float radius = MHelper.randRange(50, 100, random);
|
||||
float height = radius * MHelper.randRange(0.8F, 1.2F, random);
|
||||
CrystalMountainPiece piece = new CrystalMountainPiece(new BlockPos(x, y, z), radius, height, random, biome);
|
||||
CrystalMountainPiece piece = new CrystalMountainPiece(new BlockPos(x, y, z), radius, height, random,
|
||||
biome);
|
||||
this.children.add(piece);
|
||||
}
|
||||
this.setBoundingBoxFromChildren();
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package ru.betterend.world.structures.features;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.structure.StructureStart;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
@ -18,19 +18,21 @@ import ru.betterend.world.structures.piece.PaintedMountainPiece;
|
|||
|
||||
public class PaintedMountainStructure extends FeatureBaseStructure {
|
||||
private static final BlockState[] VARIANTS;
|
||||
|
||||
|
||||
@Override
|
||||
public StructureFeature.StructureStartFactory<DefaultFeatureConfig> getStructureStartFactory() {
|
||||
return SDFStructureStart::new;
|
||||
}
|
||||
|
||||
|
||||
public static class SDFStructureStart extends StructureStart<DefaultFeatureConfig> {
|
||||
public SDFStructureStart(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box, int references, long seed) {
|
||||
public SDFStructureStart(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box,
|
||||
int references, long seed) {
|
||||
super(feature, chunkX, chunkZ, box, references, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, DefaultFeatureConfig config) {
|
||||
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator,
|
||||
StructureManager manager, int chunkX, int chunkZ, Biome biome, DefaultFeatureConfig config) {
|
||||
int x = (chunkX << 4) | MHelper.randRange(4, 12, random);
|
||||
int z = (chunkZ << 4) | MHelper.randRange(4, 12, random);
|
||||
int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG);
|
||||
|
@ -42,17 +44,15 @@ public class PaintedMountainStructure extends FeatureBaseStructure {
|
|||
for (int i = 0; i < count; i++) {
|
||||
slises[i] = VARIANTS[random.nextInt(VARIANTS.length)];
|
||||
}
|
||||
this.children.add(new PaintedMountainPiece(new BlockPos(x, y, z), radius, height, random, biome, slises ));
|
||||
this.children
|
||||
.add(new PaintedMountainPiece(new BlockPos(x, y, z), radius, height, random, biome, slises));
|
||||
}
|
||||
this.setBoundingBoxFromChildren();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static {
|
||||
VARIANTS = new BlockState[] {
|
||||
Blocks.END_STONE.getDefaultState(),
|
||||
EndBlocks.FLAVOLITE.stone.getDefaultState(),
|
||||
EndBlocks.VIOLECITE.stone.getDefaultState(),
|
||||
};
|
||||
VARIANTS = new BlockState[] { Blocks.END_STONE.defaultBlockState(),
|
||||
EndBlocks.FLAVOLITE.stone.defaultBlockState(), EndBlocks.VIOLECITE.stone.defaultBlockState(), };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.util.Random;
|
|||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.structure.StructureStart;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
@ -17,27 +17,31 @@ import ru.betterend.util.sdf.SDF;
|
|||
import ru.betterend.world.structures.piece.VoxelPiece;
|
||||
|
||||
public abstract class SDFStructureFeature extends FeatureBaseStructure {
|
||||
|
||||
|
||||
protected abstract SDF getSDF(BlockPos pos, Random random);
|
||||
|
||||
|
||||
@Override
|
||||
public StructureFeature.StructureStartFactory<DefaultFeatureConfig> getStructureStartFactory() {
|
||||
return SDFStructureStart::new;
|
||||
}
|
||||
|
||||
|
||||
public static class SDFStructureStart extends StructureStart<DefaultFeatureConfig> {
|
||||
public SDFStructureStart(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box, int references, long seed) {
|
||||
public SDFStructureStart(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box,
|
||||
int references, long seed) {
|
||||
super(feature, chunkX, chunkZ, box, references, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, DefaultFeatureConfig config) {
|
||||
public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator,
|
||||
StructureManager manager, int chunkX, int chunkZ, Biome biome, DefaultFeatureConfig config) {
|
||||
int x = (chunkX << 4) | MHelper.randRange(4, 12, random);
|
||||
int z = (chunkZ << 4) | MHelper.randRange(4, 12, random);
|
||||
int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG);
|
||||
if (y > 5) {
|
||||
BlockPos start = new BlockPos(x, y, z);
|
||||
VoxelPiece piece = new VoxelPiece((world) -> { ((SDFStructureFeature) this.getFeature()).getSDF(start, this.random).fillRecursive(world, start); }, random.nextInt());
|
||||
VoxelPiece piece = new VoxelPiece((world) -> {
|
||||
((SDFStructureFeature) this.getFeature()).getSDF(start, this.random).fillRecursive(world, start);
|
||||
}, random.nextInt());
|
||||
this.children.add(piece);
|
||||
}
|
||||
this.setBoundingBoxFromChildren();
|
||||
|
|
|
@ -2,13 +2,13 @@ package ru.betterend.world.structures.piece;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.world.level.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.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
|
@ -23,7 +23,7 @@ public class CavePiece extends BasePiece {
|
|||
private OpenSimplexNoise noise;
|
||||
private BlockPos center;
|
||||
private float radius;
|
||||
|
||||
|
||||
public CavePiece(BlockPos center, float radius, int id) {
|
||||
super(EndStructures.CAVE_PIECE, id);
|
||||
this.center = center;
|
||||
|
@ -36,19 +36,20 @@ public class CavePiece extends BasePiece {
|
|||
super(EndStructures.CAVE_PIECE, tag);
|
||||
makeBoundingBox();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
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();
|
||||
MutableBlockPos pos = new MutableBlockPos();
|
||||
for (int x = x1; x <= x2; x++) {
|
||||
int xsq = x - center.getX();
|
||||
xsq *= xsq;
|
||||
|
@ -69,8 +70,7 @@ public class CavePiece extends BasePiece {
|
|||
if (world.getBlockState(pos).isIn(EndTags.END_GROUND)) {
|
||||
BlocksHelper.setWithoutUpdate(world, pos, AIR);
|
||||
}
|
||||
}
|
||||
else if (dist < r * r) {
|
||||
} else if (dist < r * r) {
|
||||
if (world.getBlockState(pos).getMaterial().isReplaceable()) {
|
||||
BlocksHelper.setWithoutUpdate(world, pos, Blocks.END_STONE);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public class CavePiece extends BasePiece {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ public class CavePiece extends BasePiece {
|
|||
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);
|
||||
|
|
|
@ -2,15 +2,15 @@ package ru.betterend.world.structures.piece;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
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.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
|
@ -26,7 +26,7 @@ import ru.betterend.util.MHelper;
|
|||
|
||||
public class CrystalMountainPiece extends MountainPiece {
|
||||
private BlockState top;
|
||||
|
||||
|
||||
public CrystalMountainPiece(BlockPos center, float radius, float height, Random random, Biome biome) {
|
||||
super(EndStructures.MOUNTAIN_PIECE, center, radius, height, random, biome);
|
||||
top = biome.getGenerationSettings().getSurfaceConfig().getTopMaterial();
|
||||
|
@ -43,10 +43,11 @@ public class CrystalMountainPiece extends MountainPiece {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator,
|
||||
Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
int sx = chunkPos.getStartX();
|
||||
int sz = chunkPos.getStartZ();
|
||||
Mutable pos = new Mutable();
|
||||
MutableBlockPos pos = new MutableBlockPos();
|
||||
Chunk chunk = world.getChunk(chunkPos.x, chunkPos.z);
|
||||
Heightmap map = chunk.getHeightmap(Type.WORLD_SURFACE);
|
||||
Heightmap map2 = chunk.getHeightmap(Type.WORLD_SURFACE_WG);
|
||||
|
@ -68,7 +69,8 @@ public class CrystalMountainPiece extends MountainPiece {
|
|||
continue;
|
||||
}
|
||||
pos.setY(minY);
|
||||
while (!chunk.getBlockState(pos).isIn(EndTags.GEN_TERRAIN) && pos.getY() > 56 && !chunk.getBlockState(pos.down()).isOf(Blocks.CAVE_AIR)) {
|
||||
while (!chunk.getBlockState(pos).isIn(EndTags.GEN_TERRAIN) && pos.getY() > 56
|
||||
&& !chunk.getBlockState(pos.below()).is(Blocks.CAVE_AIR)) {
|
||||
pos.setY(pos.getY() - 1);
|
||||
}
|
||||
minY = pos.getY();
|
||||
|
@ -81,22 +83,24 @@ public class CrystalMountainPiece extends MountainPiece {
|
|||
maxY += center.getY();
|
||||
int maxYI = (int) (maxY);
|
||||
int cover = maxYI - 1;
|
||||
boolean needCover = (noise1.eval(px * 0.1, pz * 0.1) + MHelper.randRange(-0.4, 0.4, random) - (center.getY() + 14) * 0.1) > 0;
|
||||
boolean needCover = (noise1.eval(px * 0.1, pz * 0.1) + MHelper.randRange(-0.4, 0.4, random)
|
||||
- (center.getY() + 14) * 0.1) > 0;
|
||||
for (int y = minY - 1; y < maxYI; y++) {
|
||||
pos.setY(y);
|
||||
chunk.setBlockState(pos, needCover && y == cover ? top : Blocks.END_STONE.getDefaultState(), false);
|
||||
chunk.setBlockAndUpdate(pos,
|
||||
needCover && y == cover ? top : Blocks.END_STONE.defaultBlockState(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
map = chunk.getHeightmap(Type.WORLD_SURFACE);
|
||||
|
||||
|
||||
// Big crystals
|
||||
int count = (map.get(8, 8) - (center.getY() + 24)) / 7;
|
||||
count = MathHelper.clamp(count, 0, 8);
|
||||
count = Mth.clamp(count, 0, 8);
|
||||
for (int i = 0; i < count; i++) {
|
||||
int radius = MHelper.randRange(2, 3, random);
|
||||
float fill = MHelper.randRange(0F, 1F, random);
|
||||
|
@ -105,16 +109,16 @@ public class CrystalMountainPiece extends MountainPiece {
|
|||
int y = map.get(x, z);
|
||||
if (y > 80) {
|
||||
pos.set(x, y, z);
|
||||
if (chunk.getBlockState(pos.down()).isOf(Blocks.END_STONE)) {
|
||||
if (chunk.getBlockState(pos.below()).is(Blocks.END_STONE)) {
|
||||
int height = MHelper.floor(radius * MHelper.randRange(1.5F, 3F, random) + (y - 80) * 0.3F);
|
||||
crystal(chunk, pos, radius, height, fill, random);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Small crystals
|
||||
count = (map.get(8, 8) - (center.getY() + 24)) / 2;
|
||||
count = MathHelper.clamp(count, 4, 8);
|
||||
count = Mth.clamp(count, 4, 8);
|
||||
for (int i = 0; i < count; i++) {
|
||||
int radius = MHelper.randRange(1, 2, random);
|
||||
float fill = random.nextBoolean() ? 0 : 1;
|
||||
|
@ -123,18 +127,18 @@ public class CrystalMountainPiece extends MountainPiece {
|
|||
int y = map.get(x, z);
|
||||
if (y > 80) {
|
||||
pos.set(x, y, z);
|
||||
if (chunk.getBlockState(pos.down()).getBlock() == Blocks.END_STONE) {
|
||||
if (chunk.getBlockState(pos.below()).getBlock() == Blocks.END_STONE) {
|
||||
int height = MHelper.floor(radius * MHelper.randRange(1.5F, 3F, random) + (y - 80) * 0.3F);
|
||||
crystal(chunk, pos, radius, height, fill, random);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void crystal(Chunk chunk, BlockPos pos, int radius, int height, float fill, Random random) {
|
||||
Mutable mut = new Mutable();
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
int max = MHelper.floor(fill * radius + radius + 0.5F);
|
||||
height += pos.getY();
|
||||
Heightmap map = chunk.getHeightmap(Type.WORLD_SURFACE);
|
||||
|
@ -156,7 +160,7 @@ public class CrystalMountainPiece extends MountainPiece {
|
|||
int h = coefX * x + coefZ * z + height;
|
||||
for (int y = minY; y < h; y++) {
|
||||
mut.setY(y);
|
||||
chunk.setBlockState(mut, EndBlocks.AURORA_CRYSTAL.getDefaultState(), false);
|
||||
chunk.setBlockAndUpdate(mut, EndBlocks.AURORA_CRYSTAL.defaultBlockState(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,19 +5,19 @@ import java.util.Random;
|
|||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtHelper;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.Mutable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
@ -33,8 +33,8 @@ import ru.betterend.util.BlocksHelper;
|
|||
import ru.betterend.util.MHelper;
|
||||
|
||||
public class LakePiece extends BasePiece {
|
||||
private static final BlockState ENDSTONE = Blocks.END_STONE.getDefaultState();
|
||||
private static final BlockState WATER = Blocks.WATER.getDefaultState();
|
||||
private static final BlockState ENDSTONE = Blocks.END_STONE.defaultBlockState();
|
||||
private static final BlockState WATER = Blocks.WATER.defaultBlockState();
|
||||
private Map<Integer, Byte> heightmap = Maps.newHashMap();
|
||||
private OpenSimplexNoise noise;
|
||||
private BlockPos center;
|
||||
|
@ -42,9 +42,9 @@ public class LakePiece extends BasePiece {
|
|||
private float aspect;
|
||||
private float depth;
|
||||
private int seed;
|
||||
|
||||
private Identifier biomeID;
|
||||
|
||||
|
||||
private ResourceLocation biomeID;
|
||||
|
||||
public LakePiece(BlockPos center, float radius, float depth, Random random, Biome biome) {
|
||||
super(EndStructures.LAKE_PIECE, random.nextInt());
|
||||
this.center = center;
|
||||
|
@ -79,16 +79,17 @@ public class LakePiece extends BasePiece {
|
|||
seed = tag.getInt("seed");
|
||||
noise = new OpenSimplexNoise(seed);
|
||||
aspect = radius / depth;
|
||||
biomeID = new Identifier(tag.getString("biome"));
|
||||
biomeID = new ResourceLocation(tag.getString("biome"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator,
|
||||
Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
int minY = this.boundingBox.minY;
|
||||
int maxY = this.boundingBox.maxY;
|
||||
int sx = chunkPos.x << 4;
|
||||
int sz = chunkPos.z << 4;
|
||||
Mutable mut = new Mutable();
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
Chunk chunk = world.getChunk(chunkPos.x, chunkPos.z);
|
||||
for (int x = 0; x < 16; x++) {
|
||||
mut.setX(x);
|
||||
|
@ -101,12 +102,13 @@ public class LakePiece extends BasePiece {
|
|||
double nz = wz * 0.1;
|
||||
int z2 = wz - center.getZ();
|
||||
float clamp = getHeightClamp(world, 8, wx, wz);
|
||||
if (clamp < 0.01) continue;
|
||||
|
||||
if (clamp < 0.01)
|
||||
continue;
|
||||
|
||||
double n = noise.eval(nx, nz) * 1.5 + 1.5;
|
||||
double x3 = MHelper.pow2(x2 + noise.eval(nx, nz, 100) * 10);
|
||||
double z3 = MHelper.pow2(z2 + noise.eval(nx, nz, -100) * 10);
|
||||
|
||||
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
mut.setY((int) (y + n));
|
||||
double y2 = MHelper.pow2((y - center.getY()) * aspect);
|
||||
|
@ -119,21 +121,22 @@ public class LakePiece extends BasePiece {
|
|||
BlockState state = chunk.getBlockState(mut);
|
||||
if (state.isIn(EndTags.GEN_TERRAIN) || state.isAir()) {
|
||||
state = mut.getY() < center.getY() ? WATER : AIR;
|
||||
chunk.setBlockState(mut, state, false);
|
||||
chunk.setBlockAndUpdate(mut, state, false);
|
||||
}
|
||||
}
|
||||
else if (dist <= r3 && mut.getY() < center.getY()) {
|
||||
} else if (dist <= r3 && mut.getY() < center.getY()) {
|
||||
BlockState state = chunk.getBlockState(mut);
|
||||
BlockPos worldPos = mut.add(sx, 0, sz);
|
||||
if (!state.isFullCube(world, worldPos) && !state.isSolidBlock(world, worldPos)) {
|
||||
state = chunk.getBlockState(mut.up());
|
||||
if (state.isAir()) {
|
||||
state = random.nextBoolean() ? ENDSTONE : world.getBiome(worldPos).getGenerationSettings().getSurfaceConfig().getTopMaterial();
|
||||
state = random.nextBoolean() ? ENDSTONE
|
||||
: world.getBiome(worldPos).getGenerationSettings().getSurfaceConfig()
|
||||
.getTopMaterial();
|
||||
} else {
|
||||
state = state.getFluidState().isEmpty() ? ENDSTONE
|
||||
: EndBlocks.ENDSTONE_DUST.defaultBlockState();
|
||||
}
|
||||
else {
|
||||
state = state.getFluidState().isEmpty() ? ENDSTONE : EndBlocks.ENDSTONE_DUST.getDefaultState();
|
||||
}
|
||||
chunk.setBlockState(mut, state, false);
|
||||
chunk.setBlockAndUpdate(mut, state, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,8 +145,8 @@ public class LakePiece extends BasePiece {
|
|||
fixWater(world, chunk, mut, random, sx, sz);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void fixWater(StructureWorldAccess world, Chunk chunk, Mutable mut, Random random, int sx, int sz) {
|
||||
|
||||
private void fixWater(StructureWorldAccess world, Chunk chunk, MutableBlockPos mut, Random random, int sx, int sz) {
|
||||
int minY = this.boundingBox.minY;
|
||||
int maxY = this.boundingBox.maxY;
|
||||
for (int x = 0; x < 16; x++) {
|
||||
|
@ -157,39 +160,41 @@ public class LakePiece extends BasePiece {
|
|||
mut.setY(y - 1);
|
||||
if (chunk.getBlockState(mut).isAir()) {
|
||||
mut.setY(y + 1);
|
||||
|
||||
|
||||
BlockState bState = chunk.getBlockState(mut);
|
||||
if (bState.isAir()) {
|
||||
bState = random.nextBoolean() ? ENDSTONE : world.getBiome(mut.add(sx, 0, sz)).getGenerationSettings().getSurfaceConfig().getTopMaterial();
|
||||
bState = random.nextBoolean() ? ENDSTONE
|
||||
: world.getBiome(mut.add(sx, 0, sz)).getGenerationSettings().getSurfaceConfig()
|
||||
.getTopMaterial();
|
||||
} else {
|
||||
bState = bState.getFluidState().isEmpty() ? ENDSTONE
|
||||
: EndBlocks.ENDSTONE_DUST.defaultBlockState();
|
||||
}
|
||||
else {
|
||||
bState = bState.getFluidState().isEmpty() ? ENDSTONE : EndBlocks.ENDSTONE_DUST.getDefaultState();
|
||||
}
|
||||
|
||||
|
||||
mut.setY(y);
|
||||
|
||||
|
||||
makeEndstonePillar(chunk, mut, bState);
|
||||
}
|
||||
else if (x > 1 && x < 15 && z > 1 && z < 15) {
|
||||
} else if (x > 1 && x < 15 && z > 1 && z < 15) {
|
||||
mut.setY(y);
|
||||
for (Direction dir: BlocksHelper.HORIZONTAL) {
|
||||
for (Direction dir : BlocksHelper.HORIZONTAL) {
|
||||
BlockPos wPos = mut.add(dir.getOffsetX(), 0, dir.getOffsetZ());
|
||||
if (chunk.getBlockState(wPos).isAir()) {
|
||||
mut.setY(y + 1);
|
||||
BlockState bState = chunk.getBlockState(mut);
|
||||
if (bState.isAir()) {
|
||||
bState = random.nextBoolean() ? ENDSTONE : world.getBiome(mut.add(sx, 0, sz)).getGenerationSettings().getSurfaceConfig().getTopMaterial();
|
||||
}
|
||||
else {
|
||||
bState = bState.getFluidState().isEmpty() ? ENDSTONE : EndBlocks.ENDSTONE_DUST.getDefaultState();
|
||||
bState = random.nextBoolean() ? ENDSTONE
|
||||
: world.getBiome(mut.add(sx, 0, sz)).getGenerationSettings()
|
||||
.getSurfaceConfig().getTopMaterial();
|
||||
} else {
|
||||
bState = bState.getFluidState().isEmpty() ? ENDSTONE
|
||||
: EndBlocks.ENDSTONE_DUST.defaultBlockState();
|
||||
}
|
||||
mut.setY(y);
|
||||
makeEndstonePillar(chunk, mut, bState);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (chunk.getBlockState(mut.move(Direction.UP)).isAir()) {
|
||||
} else if (chunk.getBlockState(mut.move(Direction.UP)).isAir()) {
|
||||
chunk.getFluidTickScheduler().schedule(mut.move(Direction.DOWN), state.getFluid(), 0);
|
||||
}
|
||||
}
|
||||
|
@ -197,38 +202,38 @@ public class LakePiece extends BasePiece {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void makeEndstonePillar(Chunk chunk, Mutable mut, BlockState terrain) {
|
||||
chunk.setBlockState(mut, terrain, false);
|
||||
|
||||
private void makeEndstonePillar(Chunk chunk, MutableBlockPos mut, BlockState terrain) {
|
||||
chunk.setBlockAndUpdate(mut, terrain, false);
|
||||
mut.setY(mut.getY() - 1);
|
||||
while (!chunk.getFluidState(mut).isEmpty()) {
|
||||
chunk.setBlockState(mut, ENDSTONE, false);
|
||||
chunk.setBlockAndUpdate(mut, ENDSTONE, false);
|
||||
mut.setY(mut.getY() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int getHeight(StructureWorldAccess world, BlockPos pos) {
|
||||
int p = ((pos.getX() & 2047) << 11) | (pos.getZ() & 2047);
|
||||
int h = heightmap.getOrDefault(p, Byte.MIN_VALUE);
|
||||
if (h > Byte.MIN_VALUE) {
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
if (!EndBiomes.getBiomeID(world.getBiome(pos)).equals(biomeID)) {
|
||||
heightmap.put(p, (byte) 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
h = world.getTopY(Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
|
||||
h = MathHelper.abs(h - center.getY());
|
||||
h = Mth.abs(h - center.getY());
|
||||
h = h < 8 ? 1 : 0;
|
||||
|
||||
|
||||
heightmap.put(p, (byte) h);
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
private float getHeightClamp(StructureWorldAccess world, int radius, int posX, int posZ) {
|
||||
Mutable mut = new Mutable();
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
int r2 = radius * radius;
|
||||
float height = 0;
|
||||
float max = 0;
|
||||
|
@ -246,9 +251,9 @@ public class LakePiece extends BasePiece {
|
|||
}
|
||||
}
|
||||
height /= max;
|
||||
return MathHelper.clamp(height, 0, 1);
|
||||
return Mth.clamp(height, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
private void makeBoundingBox() {
|
||||
int minX = MHelper.floor(center.getX() - radius - 8);
|
||||
int minY = MHelper.floor(center.getY() - depth - 8);
|
||||
|
|
|
@ -9,11 +9,11 @@ import net.minecraft.nbt.CompoundTag;
|
|||
import net.minecraft.nbt.NbtHelper;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.structure.StructurePieceType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.Mutable;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
@ -29,11 +29,12 @@ public abstract class MountainPiece extends BasePiece {
|
|||
protected float radius;
|
||||
protected float height;
|
||||
protected float r2;
|
||||
protected Identifier biomeID;
|
||||
protected ResourceLocation biomeID;
|
||||
protected int seed1;
|
||||
protected int seed2;
|
||||
|
||||
public MountainPiece(StructurePieceType type, BlockPos center, float radius, float height, Random random, Biome biome) {
|
||||
|
||||
public MountainPiece(StructurePieceType type, BlockPos center, float radius, float height, Random random,
|
||||
Biome biome) {
|
||||
super(type, random.nextInt());
|
||||
this.center = center;
|
||||
this.radius = radius;
|
||||
|
@ -67,47 +68,48 @@ public abstract class MountainPiece extends BasePiece {
|
|||
center = NbtHelper.toBlockPos(tag.getCompound("center"));
|
||||
radius = tag.getFloat("radius");
|
||||
height = tag.getFloat("height");
|
||||
biomeID = new Identifier(tag.getString("biome"));
|
||||
biomeID = new ResourceLocation(tag.getString("biome"));
|
||||
r2 = radius * radius;
|
||||
seed1 = tag.getInt("seed1");
|
||||
seed2 = tag.getInt("seed2");
|
||||
noise1 = new OpenSimplexNoise(seed1);
|
||||
noise2 = new OpenSimplexNoise(seed2);
|
||||
}
|
||||
|
||||
|
||||
private int getHeight(StructureWorldAccess world, BlockPos pos) {
|
||||
int p = ((pos.getX() & 2047) << 11) | (pos.getZ() & 2047);
|
||||
int h = heightmap.getOrDefault(p, Integer.MIN_VALUE);
|
||||
if (h > Integer.MIN_VALUE) {
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
if (!EndBiomes.getBiomeID(world.getBiome(pos)).equals(biomeID)) {
|
||||
heightmap.put(p, -10);
|
||||
return -10;
|
||||
}
|
||||
h = world.getTopY(Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
|
||||
h = MathHelper.abs(h - center.getY());
|
||||
h = Mth.abs(h - center.getY());
|
||||
if (h > 4) {
|
||||
h = 4 - h;
|
||||
heightmap.put(p, h);
|
||||
return h;
|
||||
}
|
||||
|
||||
h = MHelper.floor(noise2.eval(pos.getX() * 0.01, pos.getZ() * 0.01) * noise2.eval(pos.getX() * 0.002, pos.getZ() * 0.002) * 8 + 8);
|
||||
|
||||
|
||||
h = MHelper.floor(noise2.eval(pos.getX() * 0.01, pos.getZ() * 0.01)
|
||||
* noise2.eval(pos.getX() * 0.002, pos.getZ() * 0.002) * 8 + 8);
|
||||
|
||||
if (h < 0) {
|
||||
heightmap.put(p, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
heightmap.put(p, h);
|
||||
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
protected float getHeightClamp(StructureWorldAccess world, int radius, int posX, int posZ) {
|
||||
Mutable mut = new Mutable();
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
float height = 0;
|
||||
float max = 0;
|
||||
for (int x = -radius; x <= radius; x++) {
|
||||
|
@ -124,9 +126,9 @@ public abstract class MountainPiece extends BasePiece {
|
|||
}
|
||||
}
|
||||
height /= max;
|
||||
return MathHelper.clamp(height / radius, 0, 1);
|
||||
return Mth.clamp(height / radius, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
private void makeBoundingBox() {
|
||||
int minX = MHelper.floor(center.getX() - radius);
|
||||
int minZ = MHelper.floor(center.getZ() - radius);
|
||||
|
|
|
@ -8,10 +8,10 @@ import net.minecraft.structure.Structure;
|
|||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.structure.StructurePlacementData;
|
||||
import net.minecraft.util.BlockMirror;
|
||||
import net.minecraft.util.BlockRotation;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
|
@ -21,19 +21,20 @@ import ru.betterend.util.MHelper;
|
|||
import ru.betterend.util.StructureHelper;
|
||||
|
||||
public class NBTPiece extends BasePiece {
|
||||
private Identifier structureID;
|
||||
private BlockRotation rotation;
|
||||
private ResourceLocation structureID;
|
||||
private Rotation rotation;
|
||||
private BlockMirror mirror;
|
||||
private Structure structure;
|
||||
private BlockPos pos;
|
||||
private int erosion;
|
||||
private boolean cover;
|
||||
|
||||
public NBTPiece(Identifier structureID, Structure structure, BlockPos pos, int erosion, boolean cover, Random random) {
|
||||
|
||||
public NBTPiece(ResourceLocation structureID, Structure structure, BlockPos pos, int erosion, boolean cover,
|
||||
Random random) {
|
||||
super(EndStructures.NBT_PIECE, random.nextInt());
|
||||
this.structureID = structureID;
|
||||
this.structure = structure;
|
||||
this.rotation = BlockRotation.random(random);
|
||||
this.rotation = Rotation.random(random);
|
||||
this.mirror = BlockMirror.values()[random.nextInt(3)];
|
||||
this.pos = StructureHelper.offsetPos(pos, structure, rotation, mirror);
|
||||
this.erosion = erosion;
|
||||
|
@ -58,8 +59,8 @@ public class NBTPiece extends BasePiece {
|
|||
|
||||
@Override
|
||||
protected void fromNbt(CompoundTag tag) {
|
||||
structureID = new Identifier(tag.getString("id"));
|
||||
rotation = BlockRotation.values()[tag.getInt("rotation")];
|
||||
structureID = new ResourceLocation(tag.getString("id"));
|
||||
rotation = Rotation.values()[tag.getInt("rotation")];
|
||||
mirror = BlockMirror.values()[tag.getInt("mirror")];
|
||||
erosion = tag.getInt("erosion");
|
||||
pos = NbtHelper.toBlockPos(tag.getCompound("pos"));
|
||||
|
@ -68,11 +69,13 @@ public class NBTPiece extends BasePiece {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator,
|
||||
Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
BlockBox bounds = new BlockBox(blockBox);
|
||||
bounds.maxY = this.boundingBox.maxY;
|
||||
bounds.minY = this.boundingBox.minY;
|
||||
StructurePlacementData placementData = new StructurePlacementData().setRotation(rotation).setMirror(mirror).setBoundingBox(bounds);
|
||||
StructurePlacementData placementData = new StructurePlacementData().setRotation(rotation).setMirror(mirror)
|
||||
.setBoundingBox(bounds);
|
||||
structure.place(world, pos, placementData, random);
|
||||
if (erosion > 0) {
|
||||
bounds.maxX = MHelper.min(bounds.maxX, boundingBox.maxX);
|
||||
|
@ -86,7 +89,7 @@ public class NBTPiece extends BasePiece {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void makeBoundingBox() {
|
||||
this.boundingBox = StructureHelper.getStructureBounds(pos, structure, rotation, mirror);
|
||||
}
|
||||
|
|
|
@ -2,14 +2,14 @@ package ru.betterend.world.structures.piece;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
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.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
|
@ -23,7 +23,9 @@ import ru.betterend.util.MHelper;
|
|||
|
||||
public class PaintedMountainPiece extends MountainPiece {
|
||||
private BlockState[] slises;
|
||||
public PaintedMountainPiece(BlockPos center, float radius, float height, Random random, Biome biome, BlockState[] slises) {
|
||||
|
||||
public PaintedMountainPiece(BlockPos center, float radius, float height, Random random, Biome biome,
|
||||
BlockState[] slises) {
|
||||
super(EndStructures.PAINTED_MOUNTAIN_PIECE, center, radius, height, random, biome);
|
||||
this.slises = slises;
|
||||
}
|
||||
|
@ -36,7 +38,7 @@ public class PaintedMountainPiece extends MountainPiece {
|
|||
protected void toNbt(CompoundTag tag) {
|
||||
super.toNbt(tag);
|
||||
ListTag slise = new ListTag();
|
||||
for (BlockState state: slises) {
|
||||
for (BlockState state : slises) {
|
||||
slise.add(NbtHelper.fromBlockState(state));
|
||||
}
|
||||
tag.put("slises", slise);
|
||||
|
@ -53,10 +55,11 @@ public class PaintedMountainPiece extends MountainPiece {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator,
|
||||
Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
int sx = chunkPos.getStartX();
|
||||
int sz = chunkPos.getStartZ();
|
||||
Mutable pos = new Mutable();
|
||||
MutableBlockPos pos = new MutableBlockPos();
|
||||
Chunk chunk = world.getChunk(chunkPos.x, chunkPos.z);
|
||||
Heightmap map = chunk.getHeightmap(Type.WORLD_SURFACE);
|
||||
Heightmap map2 = chunk.getHeightmap(Type.WORLD_SURFACE_WG);
|
||||
|
@ -76,7 +79,7 @@ public class PaintedMountainPiece extends MountainPiece {
|
|||
int minY = map.get(x, z);
|
||||
pos.setY(minY - 1);
|
||||
while (chunk.getBlockState(pos).isAir() && pos.getY() > 50) {
|
||||
pos.setY(minY --);
|
||||
pos.setY(minY--);
|
||||
}
|
||||
minY = pos.getY();
|
||||
minY = Math.max(minY, map2.get(x, z));
|
||||
|
@ -86,18 +89,19 @@ public class PaintedMountainPiece extends MountainPiece {
|
|||
maxY *= (float) noise1.eval(px * 0.05, pz * 0.05) * 0.3F + 0.7F;
|
||||
maxY *= (float) noise1.eval(px * 0.1, pz * 0.1) * 0.1F + 0.9F;
|
||||
maxY += center.getY();
|
||||
float offset = (float) (noise1.eval(px * 0.07, pz * 0.07) * 5 + noise1.eval(px * 0.2, pz * 0.2) * 2 + 7);
|
||||
float offset = (float) (noise1.eval(px * 0.07, pz * 0.07) * 5
|
||||
+ noise1.eval(px * 0.2, pz * 0.2) * 2 + 7);
|
||||
for (int y = minY - 1; y < maxY; y++) {
|
||||
pos.setY(y);
|
||||
int index = MHelper.floor((y + offset) * 0.65F) % slises.length;
|
||||
chunk.setBlockState(pos, slises[index], false);
|
||||
chunk.setBlockAndUpdate(pos, slises[index], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.function.Consumer;
|
|||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
|
@ -16,7 +16,7 @@ import ru.betterend.world.structures.StructureWorld;
|
|||
|
||||
public class VoxelPiece extends BasePiece {
|
||||
private StructureWorld world;
|
||||
|
||||
|
||||
public VoxelPiece(Consumer<StructureWorld> function, int id) {
|
||||
super(EndStructures.VOXEL_PIECE, id);
|
||||
world = new StructureWorld();
|
||||
|
@ -40,7 +40,8 @@ public class VoxelPiece extends BasePiece {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
public boolean generate(StructureWorldAccess world, StructureAccessor arg, ChunkGenerator chunkGenerator,
|
||||
Random random, BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) {
|
||||
this.world.placeChunk(world, chunkPos);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue