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
5 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/com/terraforged/feature/fast/FastDecorator.java
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.terraforged.feature.fast; | ||
|
||
import com.mojang.datafixers.Dynamic; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.IWorld; | ||
import net.minecraft.world.gen.ChunkGenerator; | ||
import net.minecraft.world.gen.feature.ConfiguredFeature; | ||
import net.minecraft.world.gen.feature.Feature; | ||
import net.minecraft.world.gen.feature.IFeatureConfig; | ||
import net.minecraft.world.gen.placement.IPlacementConfig; | ||
import net.minecraft.world.gen.placement.Placement; | ||
|
||
import java.util.Random; | ||
import java.util.function.Function; | ||
import java.util.stream.Stream; | ||
|
||
public abstract class FastDecorator<C extends IPlacementConfig> extends Placement<C> { | ||
|
||
public FastDecorator(Function<Dynamic<?>, ? extends C> factory) { | ||
super(factory); | ||
} | ||
|
||
public FastDecorator<C> name(String name) { | ||
setRegistryName(name); | ||
return this; | ||
} | ||
|
||
@Override | ||
public final Stream<BlockPos> getPositions(IWorld world, ChunkGenerator<?> generator, Random random, C config, BlockPos pos) { | ||
return Stream.empty(); | ||
} | ||
|
||
@Override | ||
public final <FC extends IFeatureConfig, F extends Feature<FC>> boolean place(IWorld world, ChunkGenerator<?> generator, Random random, BlockPos pos, C config, ConfiguredFeature<FC, F> feature) { | ||
boolean result = false; | ||
int count = getCount(config); | ||
BlockPos.Mutable mutable = new BlockPos.Mutable(); | ||
for (int i = 0; i < count; i++) { | ||
if (next(world, generator, random, config, pos, mutable)) { | ||
result |= feature.place(world, generator, random, mutable); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
protected abstract int getCount(C config); | ||
|
||
protected abstract boolean next(IWorld world, ChunkGenerator<?> generator, Random random, C config, BlockPos pos, BlockPos.Mutable mutable); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/terraforged/feature/fast/FastFrequencyDecorator.java
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,15 @@ | ||
package com.terraforged.feature.fast; | ||
|
||
import net.minecraft.world.gen.placement.FrequencyConfig; | ||
|
||
public abstract class FastFrequencyDecorator extends FastDecorator<FrequencyConfig> { | ||
|
||
public FastFrequencyDecorator() { | ||
super(FrequencyConfig::deserialize); | ||
} | ||
|
||
@Override | ||
protected int getCount(FrequencyConfig config) { | ||
return config.count; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/terraforged/feature/fast/impl/FastAtSurface.java
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,22 @@ | ||
package com.terraforged.feature.fast.impl; | ||
|
||
import com.terraforged.feature.fast.FastFrequencyDecorator; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.IWorld; | ||
import net.minecraft.world.gen.ChunkGenerator; | ||
import net.minecraft.world.gen.GenerationSettings; | ||
import net.minecraft.world.gen.Heightmap; | ||
import net.minecraft.world.gen.placement.FrequencyConfig; | ||
|
||
import java.util.Random; | ||
|
||
public class FastAtSurface extends FastFrequencyDecorator { | ||
@Override | ||
protected boolean next(IWorld world, ChunkGenerator<? extends GenerationSettings> generator, Random random, FrequencyConfig config, BlockPos pos, BlockPos.Mutable mutable) { | ||
int x = random.nextInt(16) + pos.getX(); | ||
int z = random.nextInt(16) + pos.getZ(); | ||
int y = world.getHeight(Heightmap.Type.MOTION_BLOCKING, x, z); | ||
mutable.setPos(x, y, z); | ||
return true; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/terraforged/feature/fast/impl/FastCountRange.java
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,30 @@ | ||
package com.terraforged.feature.fast.impl; | ||
|
||
import com.terraforged.feature.fast.FastDecorator; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.IWorld; | ||
import net.minecraft.world.gen.ChunkGenerator; | ||
import net.minecraft.world.gen.placement.CountRangeConfig; | ||
|
||
import java.util.Random; | ||
|
||
public class FastCountRange extends FastDecorator<CountRangeConfig> { | ||
|
||
public FastCountRange() { | ||
super(CountRangeConfig::deserialize); | ||
} | ||
|
||
@Override | ||
protected int getCount(CountRangeConfig config) { | ||
return config.count; | ||
} | ||
|
||
@Override | ||
protected boolean next(IWorld world, ChunkGenerator<?> generator, Random random, CountRangeConfig config, BlockPos pos, BlockPos.Mutable mutable) { | ||
int x = random.nextInt(16) + pos.getX(); | ||
int z = random.nextInt(16) + pos.getZ(); | ||
int y = random.nextInt(config.maximum - config.topOffset) + config.bottomOffset; | ||
mutable.setPos(x, y, z); | ||
return true; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/terraforged/feature/fast/impl/FastTopSolid.java
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,22 @@ | ||
package com.terraforged.feature.fast.impl; | ||
|
||
import com.terraforged.feature.fast.FastFrequencyDecorator; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.IWorld; | ||
import net.minecraft.world.gen.ChunkGenerator; | ||
import net.minecraft.world.gen.GenerationSettings; | ||
import net.minecraft.world.gen.Heightmap; | ||
import net.minecraft.world.gen.placement.FrequencyConfig; | ||
|
||
import java.util.Random; | ||
|
||
public class FastTopSolid extends FastFrequencyDecorator { | ||
@Override | ||
protected boolean next(IWorld world, ChunkGenerator<? extends GenerationSettings> generator, Random random, FrequencyConfig config, BlockPos pos, BlockPos.Mutable mutable) { | ||
int i = random.nextInt(16) + pos.getX(); | ||
int j = random.nextInt(16) + pos.getZ(); | ||
int k = world.getHeight(Heightmap.Type.OCEAN_FLOOR_WG, i, j); | ||
mutable.setPos(i, k, j); | ||
return true; | ||
} | ||
} |