Skip to content

Commit

Permalink
fix(feature): fix feature compile & register configured features
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Dec 3, 2024
1 parent 79584d3 commit f076e83
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "hybrid-aquatic:deep_coral_claw",
"config": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "hybrid-aquatic:deep_coral_mushroom",
"config": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "hybrid-aquatic:deep_coral_tree",
"config": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ class ConfiguredFeatureProvider(output: FabricDataOutput, registriesFuture: Comp
)
)

// deep coral
entries.add(HybridAquaticConfiguredFeatures.DEEP_CORAL_TREE, ConfiguredFeature(HybridAquaticFeatures.DEEP_CORAL_TREE, DefaultFeatureConfig()))
entries.add(HybridAquaticConfiguredFeatures.DEEP_CORAL_CLAW, ConfiguredFeature(HybridAquaticFeatures.DEEP_CORAL_CLAW, DefaultFeatureConfig()))
entries.add(HybridAquaticConfiguredFeatures.DEEP_CORAL_MUSHROOM, ConfiguredFeature(HybridAquaticFeatures.DEEP_CORAL_MUSHROOM, DefaultFeatureConfig()))

// brine lake
entries.add(
HybridAquaticConfiguredFeatures.BRINE_LAKE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import net.minecraft.world.WorldAccess
import net.minecraft.world.gen.feature.DefaultFeatureConfig
import java.util.stream.Stream

class DeepCoralClawFeature(codec: Codec<DefaultFeatureConfig?>?) : DeepCoralFeature(codec) {
class DeepCoralClawFeature(codec: Codec<DefaultFeatureConfig>) : DeepCoralFeature(codec) {
override fun generateDeepCoral(world: WorldAccess, random: Random, pos: BlockPos, state: BlockState): Boolean {
if (!this.generateDeepCoralPiece(world, random, pos, state)) {
return false
Expand Down Expand Up @@ -69,4 +69,4 @@ class DeepCoralClawFeature(codec: Codec<DefaultFeatureConfig?>?) : DeepCoralFeat
return true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import net.minecraft.world.gen.feature.DefaultFeatureConfig
import net.minecraft.world.gen.feature.Feature
import net.minecraft.world.gen.feature.util.FeatureContext

abstract class DeepCoralFeature(codec: Codec<DefaultFeatureConfig?>?) :
Feature<DefaultFeatureConfig?>(codec) {
abstract class DeepCoralFeature(codec: Codec<DefaultFeatureConfig>) : Feature<DefaultFeatureConfig>(codec) {
override fun generate(context: FeatureContext<DefaultFeatureConfig?>): Boolean {
val random = context.random
val structureWorldAccess = context.world
Expand All @@ -47,51 +46,41 @@ abstract class DeepCoralFeature(codec: Codec<DefaultFeatureConfig?>?) :
): Boolean

protected fun generateDeepCoralPiece(world: WorldAccess, random: Random, pos: BlockPos, state: BlockState): Boolean {
val blockPos = pos.up()
val abovePos = pos.up()
val blockState = world.getBlockState(pos)
if ((blockState.isOf(Blocks.WATER) || blockState.isIn(HybridAquaticBlockTags.DEEP_CORALS)) && world.getBlockState(blockPos)
.isOf(Blocks.WATER)
) {
if ((blockState.isOf(Blocks.WATER) || blockState.isIn(HybridAquaticBlockTags.DEEP_CORALS)) && world.isWater(abovePos)) {
world.setBlockState(pos, state, 3)
if (random.nextFloat() < 0.25f) {
Registries.BLOCK.getEntryList(HybridAquaticBlockTags.DEEP_CORALS).flatMap { blocks: RegistryEntryList.Named<Block> ->
blocks.getRandom(
random
)
}.map { obj: RegistryEntry<Block> -> obj.value() }.ifPresent { block: Block ->
world.setBlockState(blockPos, block.defaultState, 2)
world.setBlockState(abovePos, block.defaultState, 2)
}
} else if (random.nextFloat() < 0.05f) {
world.setBlockState(
blockPos,
HybridAquaticBlocks.TUBE_WORM.defaultState.with(TubeWormBlock.WORMS, random.nextInt(4) + 1) as BlockState,
2
)
world.setBlockState(abovePos, HybridAquaticBlocks.TUBE_WORM.defaultState.with(TubeWormBlock.WORMS, random.nextInt(4) + 1), Block.NOTIFY_LISTENERS)
}

val var7: Iterator<*> = Direction.Type.HORIZONTAL.iterator()

while (var7.hasNext()) {
val direction = var7.next() as Direction
Direction.Type.HORIZONTAL.forEach { direction ->
if (random.nextFloat() < 0.2f) {
val blockPos2 = pos.offset(direction)
if (world.getBlockState(blockPos2).isOf(Blocks.WATER)) {
val wallPos = pos.offset(direction)
if (world.getBlockState(wallPos).isOf(Blocks.WATER)) {
Registries.BLOCK.getEntryList(HybridAquaticBlockTags.DEEP_WALL_CORALS)
.flatMap { blocks: RegistryEntryList.Named<Block> ->
blocks.getRandom(
random
)
}.map { obj: RegistryEntry<Block> -> obj.value() }
.ifPresent { block: Block ->
var blockState = block.defaultState
if (blockState.contains(DeadCoralWallFanBlock.FACING)) {
blockState =
blockState.with(
DeadCoralWallFanBlock.FACING,
direction
) as BlockState
.flatMap { blocks -> blocks.getRandom(random) }
.map(RegistryEntry<Block>::value)
.ifPresent { block ->
val defaultState = block.defaultState
val state = if (defaultState.contains(DeadCoralWallFanBlock.FACING)) {
defaultState.with(
DeadCoralWallFanBlock.FACING,
direction
)
} else {
defaultState
}
world.setBlockState(blockPos2, blockState, 2)

world.setBlockState(wallPos, state, Block.NOTIFY_LISTENERS)
}
}
}
Expand All @@ -102,4 +91,4 @@ abstract class DeepCoralFeature(codec: Codec<DefaultFeatureConfig?>?) :
return false
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import net.minecraft.util.math.random.Random
import net.minecraft.world.WorldAccess
import net.minecraft.world.gen.feature.DefaultFeatureConfig

class DeepCoralMushroomFeature(codec: Codec<DefaultFeatureConfig?>?) : DeepCoralFeature(codec) {
class DeepCoralMushroomFeature(codec: Codec<DefaultFeatureConfig>) : DeepCoralFeature(codec) {
override fun generateDeepCoral(world: WorldAccess, random: Random, pos: BlockPos, state: BlockState): Boolean {
val i = random.nextInt(3) + 3
val j = random.nextInt(3) + 3
Expand All @@ -35,4 +35,4 @@ class DeepCoralMushroomFeature(codec: Codec<DefaultFeatureConfig?>?) : DeepCoral

return true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import net.minecraft.util.math.random.Random
import net.minecraft.world.WorldAccess
import net.minecraft.world.gen.feature.DefaultFeatureConfig

class DeepCoralTreeFeature(codec: Codec<DefaultFeatureConfig?>?) : DeepCoralFeature(codec) {
class DeepCoralTreeFeature(codec: Codec<DefaultFeatureConfig>) : DeepCoralFeature(codec) {
override fun generateDeepCoral(world: WorldAccess, random: Random, pos: BlockPos, state: BlockState): Boolean {
val mutable = pos.mutableCopy()
val i = random.nextInt(3) + 1
Expand Down Expand Up @@ -48,4 +48,4 @@ class DeepCoralTreeFeature(codec: Codec<DefaultFeatureConfig?>?) : DeepCoralFeat

return true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import net.minecraft.world.gen.feature.FeatureConfig
object HybridAquaticFeatures {
val MESSAGE_IN_A_BOTTLE = register("message_in_a_bottle", MessageInABottleFeature(MessageInABottleFeatureConfig.CODEC))
val VENT_PATCH = register("vent_patch", VentPatchFeature(VentPatchFeatureConfig.CODEC))
val DEEP_CORAL_TREE = register("deep_coral_tree", DeepCoralFeature(DefaultFeatureConfig.CODEC))
val DEEP_CORAL_CLAW = register("deep_coral_claw", DeepCoralClawFeature(DeepCoralFeature.CODEC))
val DEEP_CORAL_MUSHROOM = register("deep_coral_mushroom", DeepCoralMushroomFeature(DeepCoralFeature.CODEC))
val DEEP_CORAL_TREE = register("deep_coral_tree", DeepCoralTreeFeature(DefaultFeatureConfig.CODEC))
val DEEP_CORAL_CLAW = register("deep_coral_claw", DeepCoralClawFeature(DefaultFeatureConfig.CODEC))
val DEEP_CORAL_MUSHROOM = register("deep_coral_mushroom", DeepCoralMushroomFeature(DefaultFeatureConfig.CODEC))

private fun <FC : FeatureConfig, F : Feature<FC>> register(id: String, feature: F): Feature<FC> {
return Registry.register(Registries.FEATURE, Identifier(HybridAquatic.MOD_ID, id), feature)
Expand Down

0 comments on commit f076e83

Please sign in to comment.