generated from natanfudge/fabric-example-mod-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
74 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/github/hotm/mod/world/gen/decorator/HotMPlacementModifiers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.github.hotm.mod.world.gen.decorator | ||
|
||
import com.github.hotm.mod.Constants.id | ||
import net.minecraft.registry.Registries | ||
import net.minecraft.registry.Registry | ||
import net.minecraft.world.gen.decorator.PlacementModifierType | ||
|
||
object HotMPlacementModifiers { | ||
val RANDOM_SURFACE_IN_RANGE by lazy { PlacementModifierType { RandomSurfaceInRangePlacementModifier.MODIFIER_CODEC } } | ||
|
||
fun init() { | ||
Registry.register(Registries.PLACEMENT_MODIFIER_TYPE, id("random_surface_in_range"), RANDOM_SURFACE_IN_RANGE) | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...n/kotlin/com/github/hotm/mod/world/gen/decorator/RandomSurfaceInRangePlacementModifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.github.hotm.mod.world.gen.decorator | ||
|
||
import java.util.stream.Stream | ||
import it.unimi.dsi.fastutil.ints.IntArrayList | ||
import com.mojang.serialization.Codec | ||
import com.mojang.serialization.codecs.RecordCodecBuilder | ||
import net.minecraft.util.math.BlockPos | ||
import net.minecraft.util.random.RandomGenerator | ||
import net.minecraft.world.gen.YOffset | ||
import net.minecraft.world.gen.decorator.DecoratorContext | ||
import net.minecraft.world.gen.decorator.PlacementModifierType | ||
import net.minecraft.world.gen.feature.PlacementModifier | ||
|
||
class RandomSurfaceInRangePlacementModifier(val minInclusive: YOffset, val maxInclusive: YOffset) : | ||
PlacementModifier() { | ||
companion object { | ||
val MODIFIER_CODEC: Codec<RandomSurfaceInRangePlacementModifier> = RecordCodecBuilder.create { instance -> | ||
instance.group( | ||
YOffset.OFFSET_CODEC.fieldOf("min_inclusive").forGetter { it.minInclusive }, | ||
YOffset.OFFSET_CODEC.fieldOf("max_inclusive").forGetter { it.maxInclusive } | ||
).apply(instance, ::RandomSurfaceInRangePlacementModifier) | ||
} | ||
|
||
private val levels: ThreadLocal<IntArrayList> = ThreadLocal.withInitial { IntArrayList() } | ||
} | ||
|
||
override fun getPositions(context: DecoratorContext, random: RandomGenerator, pos: BlockPos): Stream<BlockPos> { | ||
val minHeight = minInclusive.getY(context) | ||
val maxHeight = maxInclusive.getY(context) | ||
|
||
val mutable = pos.mutableCopy() | ||
val ls = levels.get() | ||
ls.clear() | ||
for (y in minHeight..maxHeight) { | ||
mutable.y = y | ||
if (context.getBlockState(mutable).isAir && !context.getBlockState(mutable.down()).isAir) { | ||
ls.add(y) | ||
} | ||
} | ||
|
||
if (ls.isEmpty) { | ||
return Stream.empty() | ||
} else { | ||
return Stream.of(BlockPos(pos.x, ls.getInt(random.nextInt(ls.size)), pos.z)) | ||
} | ||
} | ||
|
||
override fun getType(): PlacementModifierType<*> = HotMPlacementModifiers.RANDOM_SURFACE_IN_RANGE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters