Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/MC_1.17-Structures' into MC_1.17…
Browse files Browse the repository at this point in the history
…_Jar
  • Loading branch information
CorgiTaco committed Jun 15, 2021
2 parents 0e951a1 + b82341a commit 5e8e430
Show file tree
Hide file tree
Showing 27 changed files with 625 additions and 168 deletions.
2 changes: 1 addition & 1 deletion config/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<!-- TODO: DebugVulkan doesn't work yet anyway, and this requires some refactoring -->
<suppress checks="CyclomaticComplexity" files="DebugVulkan.java"/>
<!-- Mixins don't count for now until ASM is done -->
<suppress checks="CyclomaticComplexity" files=".*Mixin.*\.java"/>
<suppress checks="CyclomaticComplexity" files=".*Mixin.*\.java|VerticalSettingsReloadListener.java"/>
<!-- we are not fixing setBlockState -->
<suppress checks="CyclomaticComplexity" files="BigCube.java|CubePrimer.java"/>
<!-- TODO: These probably need refactoring -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.github.opencubicchunks.cubicchunks.meta.EarlyConfig;
import io.github.opencubicchunks.cubicchunks.network.PacketDispatcher;
import io.github.opencubicchunks.cubicchunks.server.CubicLevelHeightAccessor;
import io.github.opencubicchunks.cubicchunks.server.VerticalSettingsReloadListener;
import io.github.opencubicchunks.cubicchunks.world.biome.StripedBiomeSource;
import io.github.opencubicchunks.cubicchunks.world.gen.feature.CCFeatures;
import io.github.opencubicchunks.cubicchunks.world.gen.placement.CCPlacement;
Expand Down Expand Up @@ -73,7 +74,6 @@ public CubicChunks() {
if (System.getProperty("cubicchunks.debug", "false").equalsIgnoreCase("true")) {
try {
Class.forName("io.github.opencubicchunks.cubicchunks.debug.DebugVisualization").getMethod("enable").invoke(null);
SharedConstants.IS_RUNNING_IN_IDE = true;
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassNotFoundException e) {
LOGGER.catching(e);
}
Expand Down Expand Up @@ -153,5 +153,7 @@ public void onInitialize() {

Registry.register(Registry.BIOME_SOURCE, new ResourceLocation(MODID, "stripes"), StripedBiomeSource.CODEC);
// Registry.register(Registry.CHUNK_GENERATOR, new ResourceLocation(MODID, "generator"), CCNoiseBasedChunkGenerator.CODEC);

VerticalSettingsReloadListener.registerVerticalSettingsReloadListener();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import io.github.opencubicchunks.cubicchunks.chunk.cube.CubePrimer;
import io.github.opencubicchunks.cubicchunks.world.CubeWorldGenRegion;
import net.minecraft.server.level.WorldGenRegion;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.SectionPos;
import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.biome.BiomeManager;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;

public interface ICubeGenerator {
default void decorate(CubeWorldGenRegion region, StructureFeatureManager structureManager, CubePrimer chunkAccess) {
Expand All @@ -15,4 +19,9 @@ default void decorate(CubeWorldGenRegion region, StructureFeatureManager structu
void buildSurfaceAndBedrockCC(WorldGenRegion region, ChunkAccess chunk);

void applyCubicCarvers(long seed, BiomeManager access, ChunkAccess chunkAccess, GenerationStep.Carving carver);

default void createStructures(RegistryAccess registryAccess, StructureFeatureManager structureFeatureManager, ChunkAccess chunkAccess, SectionPos section,
StructureManager structureManager, long worldSeed) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public SectionPos asSectionPos() {
return SectionPos.of(cubeToSection(this.getX(), 0), cubeToSection(this.getY(), 0), cubeToSection(this.getZ(), 0));
}

public SectionPos asSectionPos(int dx, int dy, int dz) {
return SectionPos.of(cubeToSection(this.getX(), dx), cubeToSection(this.getY(), dy), cubeToSection(this.getZ(), dz));
}

public BlockPos asBlockPos() {
return new BlockPos(minCubeX(), minCubeY(), minCubeZ());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import io.github.opencubicchunks.cubicchunks.utils.Coords;
import io.github.opencubicchunks.cubicchunks.world.CubeWorldGenRandom;
import io.github.opencubicchunks.cubicchunks.world.CubeWorldGenRegion;
import io.github.opencubicchunks.cubicchunks.world.ICubicStructureStart;
import io.github.opencubicchunks.cubicchunks.world.biome.BiomeGetter;
import io.github.opencubicchunks.cubicchunks.world.biome.StripedBiomeSource;
import io.github.opencubicchunks.cubicchunks.world.gen.structure.ICubicConfiguredStructureFeature;
import io.github.opencubicchunks.cubicchunks.world.surfacebuilder.ChunkGeneratorSurfaceBuilderContextObtainer;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.MappingResolver;
Expand Down Expand Up @@ -112,52 +114,31 @@ private void switchBiomeSource(BiomeSource biomeSourceIn, BiomeSource biomeSourc
this.surfaceNoise = new PerlinNoise(new NonAtomicWorldgenRandom(), IntStream.rangeClosed(-3, 0));
}

@Override
public void createStructures(RegistryAccess registryAccess, StructureFeatureManager structureFeatureManager, ChunkAccess chunkAccess, SectionPos section,
StructureManager structureManager, long worldSeed) {
Biome biome = this.biomeSource.getPrimaryBiome(chunkAccess.getPos());
this.createCcStructure(StructureFeatures.STRONGHOLD, registryAccess, structureFeatureManager, chunkAccess, section, structureManager, worldSeed, biome);

// TODO: check which one is which
@Inject(method = "createStructures", at = @At("HEAD"), cancellable = true)
public void onGenerateStructures(RegistryAccess registry, StructureFeatureManager featureManager, ChunkAccess chunkAccess, StructureManager manager, long seed, CallbackInfo ci) {
if (((CubicLevelHeightAccessor) chunkAccess).generates2DChunks()) {
return;
}
if (!(chunkAccess instanceof IBigCube)) {
return;
}
ci.cancel();


//TODO: Patch entity game crashes in order to spawn villages(village pieces spawn villagers)
//TODO: Setup a 2D and 3D placement.

IBigCube cube = (IBigCube) chunkAccess;

CubePos cubePos = cube.getCubePos();

Biome biome = this.biomeSource.getPrimaryBiome(cube.getCubePos().asChunkPos());
this.createCCStructure(StructureFeatures.STRONGHOLD, registry, featureManager, cube, manager, seed, cubePos, biome);

for (Supplier<ConfiguredStructureFeature<?, ?>> configuredStructureFeatureSupplier : biome.getGenerationSettings().structures()) {
this.createCCStructure(configuredStructureFeatureSupplier.get(), registry, featureManager, cube, manager, seed, cubePos, biome);
for (Supplier<ConfiguredStructureFeature<?, ?>> supplier : biome.getGenerationSettings().structures()) {
this.createCcStructure(supplier.get(), registryAccess, structureFeatureManager, chunkAccess, section, structureManager, worldSeed, biome);
}
}


private void createCCStructure(ConfiguredStructureFeature<?, ?> configuredStructureFeature, RegistryAccess registryAccess, StructureFeatureManager structureFeatureManager, IBigCube cube,
StructureManager structureManager, long seed, CubePos cubePos, Biome biome) {
StructureStart<?> structureStart = structureFeatureManager
.getStartForFeature(/*SectionPos.of(cube.getPos(), 0) We return null as a sectionPos Arg is not used in the method*/null, configuredStructureFeature.feature, cube);
int i = structureStart != null ? structureStart.getReferences() : 0;
StructureFeatureConfiguration structureFeatureConfiguration = this.settings.getConfig(configuredStructureFeature.feature);
if (structureFeatureConfiguration != null) {
StructureStart<?> structureStart2 = configuredStructureFeature
.generate(registryAccess, ((ChunkGenerator) (Object) this), this.biomeSource, structureManager, seed, cubePos.asChunkPos(), biome, i, structureFeatureConfiguration, cube);
structureFeatureManager
.setStartForFeature(/* SectionPos.of(cube.getPos(), 0) We return null as a sectionPos Arg is not used in the method*/null, configuredStructureFeature.feature,
structureStart2, cube);
public void createCcStructure(ConfiguredStructureFeature<?, ?> structure, RegistryAccess registryAccess, StructureFeatureManager structureFeatureManager,
ChunkAccess chunk, SectionPos pos, StructureManager structureManager, long worldSeed, Biome biome) {
StructureStart<?> previousStart = structureFeatureManager.getStartForFeature(pos, structure.feature, chunk);
// TODO: is this right?
int referenceCount = previousStart != null ? previousStart.getReferences() : 0;
StructureFeatureConfiguration config = this.settings.getConfig(structure.feature);

if (config != null) {
StructureStart<?> newStart = ((ICubicConfiguredStructureFeature) structure).generate(registryAccess, ((ChunkGenerator) (Object) this), this.biomeSource, structureManager,
worldSeed, pos, biome, referenceCount, config, chunk);
structureFeatureManager.setStartForFeature(pos, structure.feature, newStart, chunk);
}

}


@Inject(method = "createReferences", at = @At("HEAD"), cancellable = true)
public void createReferences(WorldGenLevel worldGenLevel, StructureFeatureManager featureManager, ChunkAccess chunkAccess, CallbackInfo ci) {
if (((CubicLevelHeightAccessor) chunkAccess).generates2DChunks()) {
Expand Down Expand Up @@ -188,6 +169,11 @@ public void createReferences(WorldGenLevel worldGenLevel, StructureFeatureManage
long cubePosAsLong = CubePos.asLong(x, y, z);

for (StructureStart<?> structureStart : world.getCube(CubePos.of(x, y, z)).getAllCubeStructureStarts().values()) {

if (!((ICubicStructureStart) structureStart).has3DPlacement() && y != cubeY) {
continue;
}

try {
if (structureStart != StructureStart.INVALID_START && structureStart.getBoundingBox().intersects(
//We use a new Bounding Box and check if it intersects a given cube.
Expand Down Expand Up @@ -290,7 +276,8 @@ public void decorate(CubeWorldGenRegion region, StructureFeatureManager structur


BoundingBox boundingBox =
new BoundingBox(minSectionX, minSectionY, minSectionZ, minSectionX + 15, minSectionY + IBigCube.DIAMETER_IN_BLOCKS - 1, minSectionZ + 15);
new BoundingBox(minSectionX, Coords.cubeToMinBlock(region.getMinCubeY()) + 1, minSectionZ, minSectionX + 15, Coords.cubeToMaxBlock(region.getMaxCubeY()) - 1,
minSectionZ + 15);
try {
((BiomeGetter) (Object) biome).generate(structureManager, ((ChunkGenerator) (Object) this), region, seed, worldgenRandom, columnMinPos, generateFeatures, boundingBox);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private static void noopLoadingWorker(
+ "Ljava/util/concurrent/CompletableFuture;",
at = @At("HEAD"), cancellable = true
)
private static void generateStructureStatus(
private static void generateStructureStarts(
ChunkStatus status, Executor executor, ServerLevel world, ChunkGenerator generator,
StructureManager templateManager, ThreadedLevelLightEngine lightManager,
Function<ChunkAccess, CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>>> func,
Expand Down Expand Up @@ -128,10 +128,17 @@ private static void generateStructureStatus(
//cc
if (!((IBigCube) chunk).getCubeStatus().isOrAfter(status)) {
if (world.getServer().getWorldData().worldGenSettings().generateFeatures()) { // check if structures are enabled
// structureFeatureManager == getStructureManager?
generator.createStructures(world.registryAccess(), world.structureFeatureManager(), chunk, templateManager, world.getSeed());
for (int dx = 0; dx < IBigCube.DIAMETER_IN_SECTIONS; dx++) {
for (int dy = 0; dy < IBigCube.DIAMETER_IN_SECTIONS; dy++) {
for (int dz = 0; dz < IBigCube.DIAMETER_IN_SECTIONS; dz++) {
// structureFeatureManager == getStructureManager?
((ICubeGenerator) generator).createStructures(world.registryAccess(), world.structureFeatureManager(), chunk,
((IBigCube) chunk).getCubePos().asSectionPos(dx, dy, dz),
templateManager, world.getSeed());
}
}
}
}

if (chunk instanceof CubePrimer) {
((CubePrimer) chunk).setCubeStatus(status);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import io.github.opencubicchunks.cubicchunks.server.CubicLevelHeightAccessor;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.WorldGenRegion;
import net.minecraft.server.level.WorldGenRegion;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -57,9 +55,6 @@ public abstract class MixinNoiseBasedChunkGenerator {
@Shadow public abstract int getSeaLevel();

@Shadow @Final private BaseStoneSource baseStoneSource;
@Shadow @Final protected BlockState defaultFluid;

@Shadow public abstract int getSeaLevel();

@Shadow @Final private SurfaceNoise surfaceNoise;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import io.github.opencubicchunks.cubicchunks.server.CubicLevelHeightAccessor;
import io.github.opencubicchunks.cubicchunks.world.CubeWorldGenRandom;
import io.github.opencubicchunks.cubicchunks.world.CubeWorldGenRegion;
import io.github.opencubicchunks.cubicchunks.world.SetupCubeStructureStart;
import io.github.opencubicchunks.cubicchunks.world.biome.BiomeGetter;
import io.github.opencubicchunks.cubicchunks.world.gen.feature.CCFeatures;
import net.minecraft.CrashReport;
Expand All @@ -25,6 +24,7 @@
import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeGenerationSettings;
Expand Down Expand Up @@ -84,9 +84,10 @@ public void generate(StructureFeatureManager structureManager, ChunkGenerator ch
random.setDecorationSeed(seed, k, genStepIDX);

try {
region.usesRegionHeightMap();
structureManager.startsForFeature(SectionPos.of(blockPos), structure).forEach((structureStart) -> {
((SetupCubeStructureStart) structureStart).placeInCube(region, structureManager, chunkGenerator, random,
structureBoundingBox, blockPos);
structureStart.placeInChunk(region, structureManager, chunkGenerator, random,
structureBoundingBox, new ChunkPos(blockPos));
});
} catch (Exception e) {
CrashReport crashReport = CrashReport.forThrowable(e, "Structure Feature placement");
Expand Down Expand Up @@ -117,6 +118,7 @@ public void generate(StructureFeatureManager structureManager, ChunkGenerator ch

if (!featureBlacklist.contains(key)) {
try {
region.usesCubeHeightMap();
configuredFeature.place(region, chunkGenerator, random, blockPos);
} catch (Exception e) {
CrashReport crashReport2 = CrashReport.forThrowable(e, "Feature placement");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.github.opencubicchunks.cubicchunks.mixin.core.common.world.structure;

import io.github.opencubicchunks.cubicchunks.world.CubeWorldGenRandom;
import io.github.opencubicchunks.cubicchunks.world.gen.structure.ICubicConfiguredStructureFeature;
import io.github.opencubicchunks.cubicchunks.world.gen.structure.ICubicStructureFeature;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.SectionPos;
import net.minecraft.world.level.LevelHeightAccessor;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.StructureFeatureConfiguration;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(ConfiguredStructureFeature.class)
public class MixinConfiguredStructureFeature<FC extends FeatureConfiguration, F extends StructureFeature<FC>> implements ICubicConfiguredStructureFeature {
@Shadow @Final public F feature;

@Shadow @Final public FC config;

@SuppressWarnings("unchecked") @Override public StructureStart<?> generate(RegistryAccess registryManager, ChunkGenerator chunkGenerator, BiomeSource biomeSource,
StructureManager structureManager, long worldSeed, SectionPos chunkPos, Biome biome, int referenceCount,
StructureFeatureConfiguration structureConfig, LevelHeightAccessor levelHeightAccessor) {
return ((ICubicStructureFeature<FC>) this.feature).generateCC(registryManager, chunkGenerator, biomeSource, structureManager, worldSeed, chunkPos,
biome, referenceCount, new CubeWorldGenRandom(), structureConfig, this.config, levelHeightAccessor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.opencubicchunks.cubicchunks.mixin.core.common.world.structure;

import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Style;
import net.minecraft.server.commands.LocateCommand;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(LocateCommand.class)
public class MixinLocateCommand {

@ModifyConstant(method = "showLocateResult", constant = @Constant(stringValue = "~"))
private static String show3DLocateResultInBrackets(String arg0, CommandSourceStack source, String structure, BlockPos sourcePos, BlockPos structurePos, String successMessage) {
return String.valueOf(structurePos.getY());
}

// @SuppressWarnings("UnresolvedMixinReference")
// @ModifyConstant(method = "lambda$showLocateResult$2(Lnet/minecraft/core/BlockPos;Lnet/minecraft/network/chat/Style;)Lnet/minecraft/network/chat/Style;",
// constant = @Constant(stringValue = " ~ "))
// private static String show3DLocateResultForTPSuggestion(String arg0, BlockPos structurePos, Style style) {
// return " " + structurePos.getY() + " ";
// }
}
Loading

0 comments on commit 5e8e430

Please sign in to comment.