From ac695b10923a6b1ae31717c0b2216c0be595a7cd Mon Sep 17 00:00:00 2001 From: Aram Date: Fri, 30 Jan 2026 10:45:31 +0100 Subject: [PATCH] Slippy can Cook now! --- CHANGELOG-1.8.md | 1 + .../common/world/feature/CobblemonFeatures.kt | 4 ++ .../feature/structure/CobblemonFeature.kt | 63 +++++++++++++++++++ .../CobblemonFeatureConfiguration.kt | 37 +++++++++++ 4 files changed, 105 insertions(+) create mode 100644 common/src/main/kotlin/com/cobblemon/mod/common/world/feature/structure/CobblemonFeature.kt create mode 100644 common/src/main/kotlin/com/cobblemon/mod/common/world/feature/structure/CobblemonFeatureConfiguration.kt diff --git a/CHANGELOG-1.8.md b/CHANGELOG-1.8.md index bfeaa94ec9..8733e6ea7c 100644 --- a/CHANGELOG-1.8.md +++ b/CHANGELOG-1.8.md @@ -2,6 +2,7 @@ ## [1.8.0 (MONTH Xth, 2026)](#1-8-0) ### Additions +- Added a new `cobblemon:structure`, which is a feature without any restrictions allowing the Builders to place certain structures in much more specific manner. ### Changes diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/world/feature/CobblemonFeatures.kt b/common/src/main/kotlin/com/cobblemon/mod/common/world/feature/CobblemonFeatures.kt index d03317a86c..8445be1e87 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/world/feature/CobblemonFeatures.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/world/feature/CobblemonFeatures.kt @@ -9,6 +9,7 @@ package com.cobblemon.mod.common.world.feature import com.cobblemon.mod.common.platform.PlatformRegistry +import com.cobblemon.mod.common.world.feature.structure.CobblemonFeature import net.minecraft.core.Registry import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.core.registries.Registries @@ -28,4 +29,7 @@ object CobblemonFeatures : PlatformRegistry>, ResourceKey(CobblemonFeatureConfiguration.CODEC) { + override fun place(context: FeaturePlaceContext): Boolean { + val randomSource: RandomSource = context.random() + val worldGenLevel: WorldGenLevel = context.level() + val blockPos: BlockPos = context.origin() + val rotation: Rotation = Rotation.getRandom(randomSource) + val cobblemonFeatureConfiguration = context.config() + + val i = randomSource.nextInt(cobblemonFeatureConfiguration.cobblemonStructures.size) + val structureTemplateManager: StructureTemplateManager = worldGenLevel.level.server.structureManager + val structureTemplate: StructureTemplate = + structureTemplateManager.getOrCreate(cobblemonFeatureConfiguration.cobblemonStructures[i]) + + val structurePlaceSettings = StructurePlaceSettings() + .setRotation(rotation) + .setRandom(randomSource) + + val vec3i: Vec3i = structureTemplate.getSize(rotation) + + if (vec3i.x == 0 && vec3i.y == 0 && vec3i.z == 0) { + return false + } + + val blockPos2: BlockPos = blockPos.offset(-vec3i.x / 2, 0, -vec3i.z / 2) + val blockPos3 = structureTemplate.getZeroPositionWithTransform(blockPos2, Mirror.NONE, rotation) + + structurePlaceSettings.clearProcessors() + val processors = (cobblemonFeatureConfiguration.cobblemonProcessors.value() as StructureProcessorList).list() + processors.forEach { structurePlaceSettings.addProcessor(it) } + + return structureTemplate.placeInWorld( + worldGenLevel, + blockPos3, + blockPos3, + structurePlaceSettings, + randomSource, + 2 + ) + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/world/feature/structure/CobblemonFeatureConfiguration.kt b/common/src/main/kotlin/com/cobblemon/mod/common/world/feature/structure/CobblemonFeatureConfiguration.kt new file mode 100644 index 0000000000..d95e95c6f6 --- /dev/null +++ b/common/src/main/kotlin/com/cobblemon/mod/common/world/feature/structure/CobblemonFeatureConfiguration.kt @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2023 Cobblemon Contributors + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package com.cobblemon.mod.common.world.feature.structure + +import com.mojang.serialization.Codec +import com.mojang.serialization.codecs.RecordCodecBuilder +import net.minecraft.core.Holder +import net.minecraft.resources.ResourceLocation +import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorList +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorType + +class CobblemonFeatureConfiguration( + val cobblemonStructures: List, + val cobblemonProcessors: Holder, +) : FeatureConfiguration { + init { + if (cobblemonStructures.isEmpty()) { + throw IllegalArgumentException("Cobblemon structure lists need at least one entry") + } + } + + companion object { + val CODEC: Codec = RecordCodecBuilder.create { instance -> + instance.group( + ResourceLocation.CODEC.listOf().fieldOf("cobblemon_structures").forGetter { it.cobblemonStructures }, + StructureProcessorType.LIST_CODEC.fieldOf("cobblemon_processors").forGetter { it.cobblemonProcessors }, + ).apply(instance, ::CobblemonFeatureConfiguration) + } + } +} \ No newline at end of file