From f076e834b433cafd09c630622e4eb147b4be474b Mon Sep 17 00:00:00 2001 From: Daniel Orr Date: Tue, 3 Dec 2024 22:16:38 +0000 Subject: [PATCH] fix(feature): fix feature compile & register configured features --- .../configured_feature/deep_coral_claw.json | 4 ++ .../deep_coral_mushroom.json | 4 ++ .../configured_feature/deep_coral_tree.json | 4 ++ .../data/server/ConfiguredFeatureProvider.kt | 5 ++ .../world/gen/feature/DeepCoralClawFeature.kt | 4 +- .../world/gen/feature/DeepCoralFeature.kt | 55 ++++++++----------- .../gen/feature/DeepCoralMushroomFeature.kt | 4 +- .../world/gen/feature/DeepCoralTreeFeature.kt | 4 +- .../gen/feature/HybridAquaticFeatures.kt | 6 +- 9 files changed, 48 insertions(+), 42 deletions(-) create mode 100644 src/generated/resources/data/hybrid-aquatic/worldgen/configured_feature/deep_coral_claw.json create mode 100644 src/generated/resources/data/hybrid-aquatic/worldgen/configured_feature/deep_coral_mushroom.json create mode 100644 src/generated/resources/data/hybrid-aquatic/worldgen/configured_feature/deep_coral_tree.json diff --git a/src/generated/resources/data/hybrid-aquatic/worldgen/configured_feature/deep_coral_claw.json b/src/generated/resources/data/hybrid-aquatic/worldgen/configured_feature/deep_coral_claw.json new file mode 100644 index 00000000..d08b874d --- /dev/null +++ b/src/generated/resources/data/hybrid-aquatic/worldgen/configured_feature/deep_coral_claw.json @@ -0,0 +1,4 @@ +{ + "type": "hybrid-aquatic:deep_coral_claw", + "config": {} +} \ No newline at end of file diff --git a/src/generated/resources/data/hybrid-aquatic/worldgen/configured_feature/deep_coral_mushroom.json b/src/generated/resources/data/hybrid-aquatic/worldgen/configured_feature/deep_coral_mushroom.json new file mode 100644 index 00000000..6f7560e0 --- /dev/null +++ b/src/generated/resources/data/hybrid-aquatic/worldgen/configured_feature/deep_coral_mushroom.json @@ -0,0 +1,4 @@ +{ + "type": "hybrid-aquatic:deep_coral_mushroom", + "config": {} +} \ No newline at end of file diff --git a/src/generated/resources/data/hybrid-aquatic/worldgen/configured_feature/deep_coral_tree.json b/src/generated/resources/data/hybrid-aquatic/worldgen/configured_feature/deep_coral_tree.json new file mode 100644 index 00000000..6e7b8465 --- /dev/null +++ b/src/generated/resources/data/hybrid-aquatic/worldgen/configured_feature/deep_coral_tree.json @@ -0,0 +1,4 @@ +{ + "type": "hybrid-aquatic:deep_coral_tree", + "config": {} +} \ No newline at end of file diff --git a/src/main/kotlin/dev/hybridlabs/aquatic/data/server/ConfiguredFeatureProvider.kt b/src/main/kotlin/dev/hybridlabs/aquatic/data/server/ConfiguredFeatureProvider.kt index 95e4964a..571e9289 100644 --- a/src/main/kotlin/dev/hybridlabs/aquatic/data/server/ConfiguredFeatureProvider.kt +++ b/src/main/kotlin/dev/hybridlabs/aquatic/data/server/ConfiguredFeatureProvider.kt @@ -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, diff --git a/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/DeepCoralClawFeature.kt b/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/DeepCoralClawFeature.kt index bfbf420f..4e93e358 100644 --- a/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/DeepCoralClawFeature.kt +++ b/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/DeepCoralClawFeature.kt @@ -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?) : DeepCoralFeature(codec) { +class DeepCoralClawFeature(codec: Codec) : DeepCoralFeature(codec) { override fun generateDeepCoral(world: WorldAccess, random: Random, pos: BlockPos, state: BlockState): Boolean { if (!this.generateDeepCoralPiece(world, random, pos, state)) { return false @@ -69,4 +69,4 @@ class DeepCoralClawFeature(codec: Codec?) : DeepCoralFeat return true } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/DeepCoralFeature.kt b/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/DeepCoralFeature.kt index 093ab323..1463d55e 100644 --- a/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/DeepCoralFeature.kt +++ b/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/DeepCoralFeature.kt @@ -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?) : - Feature(codec) { +abstract class DeepCoralFeature(codec: Codec) : Feature(codec) { override fun generate(context: FeatureContext): Boolean { val random = context.random val structureWorldAccess = context.world @@ -47,11 +46,9 @@ abstract class DeepCoralFeature(codec: Codec?) : ): 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 -> @@ -59,39 +56,31 @@ abstract class DeepCoralFeature(codec: Codec?) : random ) }.map { obj: RegistryEntry -> 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 -> - blocks.getRandom( - random - ) - }.map { obj: RegistryEntry -> 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::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) } } } @@ -102,4 +91,4 @@ abstract class DeepCoralFeature(codec: Codec?) : return false } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/DeepCoralMushroomFeature.kt b/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/DeepCoralMushroomFeature.kt index 5314a109..7590ebad 100644 --- a/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/DeepCoralMushroomFeature.kt +++ b/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/DeepCoralMushroomFeature.kt @@ -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?) : DeepCoralFeature(codec) { +class DeepCoralMushroomFeature(codec: Codec) : 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 @@ -35,4 +35,4 @@ class DeepCoralMushroomFeature(codec: Codec?) : DeepCoral return true } -} \ No newline at end of file +} diff --git a/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/DeepCoralTreeFeature.kt b/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/DeepCoralTreeFeature.kt index 1eb71945..d4014c82 100644 --- a/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/DeepCoralTreeFeature.kt +++ b/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/DeepCoralTreeFeature.kt @@ -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?) : DeepCoralFeature(codec) { +class DeepCoralTreeFeature(codec: Codec) : DeepCoralFeature(codec) { override fun generateDeepCoral(world: WorldAccess, random: Random, pos: BlockPos, state: BlockState): Boolean { val mutable = pos.mutableCopy() val i = random.nextInt(3) + 1 @@ -48,4 +48,4 @@ class DeepCoralTreeFeature(codec: Codec?) : DeepCoralFeat return true } -} \ No newline at end of file +} diff --git a/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/HybridAquaticFeatures.kt b/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/HybridAquaticFeatures.kt index 0d148844..d9aea172 100644 --- a/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/HybridAquaticFeatures.kt +++ b/src/main/kotlin/dev/hybridlabs/aquatic/world/gen/feature/HybridAquaticFeatures.kt @@ -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 > register(id: String, feature: F): Feature { return Registry.register(Registries.FEATURE, Identifier(HybridAquatic.MOD_ID, id), feature)