forked from mirrors/cobblemon
Merge branch 'cobblemon-structure' into '1.8.0'
Slippy can Cook now! See merge request cable-mc/cobblemon!2144
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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<Registry<Feature<*>>, ResourceKey<Re
|
||||
val MINT_FEATURE = create("mint", MintBlockFeature())
|
||||
@JvmField
|
||||
val BERRY_GROVE_FEATURE = CobblemonFeatures.create("berry_grove", BerryGroveFeature())
|
||||
|
||||
@JvmField
|
||||
val COBBLEMON_FEATURE = create("structure", CobblemonFeature())
|
||||
}
|
||||
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.Vec3i
|
||||
import net.minecraft.util.RandomSource
|
||||
import net.minecraft.world.level.WorldGenLevel
|
||||
import net.minecraft.world.level.block.Mirror
|
||||
import net.minecraft.world.level.block.Rotation
|
||||
import net.minecraft.world.level.levelgen.feature.Feature
|
||||
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorList
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager
|
||||
|
||||
class CobblemonFeature : Feature<CobblemonFeatureConfiguration>(CobblemonFeatureConfiguration.CODEC) {
|
||||
override fun place(context: FeaturePlaceContext<CobblemonFeatureConfiguration>): 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
|
||||
)
|
||||
}
|
||||
}
|
||||
+37
@@ -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<ResourceLocation>,
|
||||
val cobblemonProcessors: Holder<StructureProcessorList>,
|
||||
) : FeatureConfiguration {
|
||||
init {
|
||||
if (cobblemonStructures.isEmpty()) {
|
||||
throw IllegalArgumentException("Cobblemon structure lists need at least one entry")
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val CODEC: Codec<CobblemonFeatureConfiguration> = 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user