generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Dragonoidzero
committed
Apr 3, 2021
1 parent
e9602ae
commit 3fadaa0
Showing
8 changed files
with
312 additions
and
1 deletion.
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
34 changes: 34 additions & 0 deletions
34
src/main/java/azzy/fabric/incubus_core/worldgen/BiFeatureConfig.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,34 @@ | ||
package azzy.fabric.incubus_core.worldgen; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.world.gen.UniformIntDistribution; | ||
import net.minecraft.world.gen.feature.FeatureConfig; | ||
|
||
public class BiFeatureConfig implements FeatureConfig { | ||
@SuppressWarnings("CodeBlock2Expr") | ||
public static final Codec<BiFeatureConfig> CODEC = RecordCodecBuilder.create(biFeatureConfigInstance -> { | ||
return biFeatureConfigInstance.group(BlockState.CODEC.fieldOf("primState").forGetter((diskFeatureConfig) -> { | ||
return diskFeatureConfig.primaryState; | ||
}), BlockState.CODEC.fieldOf("secState").forGetter((diskFeatureConfig) -> { | ||
return diskFeatureConfig.secondaryState; | ||
}), Codec.floatRange(0, 1).fieldOf("chance").forGetter((diskFeatureConfig) -> { | ||
return diskFeatureConfig.chance; | ||
}), UniformIntDistribution.CODEC.fieldOf("scale").forGetter((diskFeatureConfig) -> { | ||
return diskFeatureConfig.scale; | ||
})).apply(biFeatureConfigInstance, BiFeatureConfig::new); | ||
}); | ||
|
||
public final BlockState primaryState; | ||
public final BlockState secondaryState; | ||
public final Float chance; | ||
public final UniformIntDistribution scale; | ||
|
||
public BiFeatureConfig(BlockState primaryState, BlockState secondaryState, float chance, UniformIntDistribution scale) { | ||
this.primaryState = primaryState; | ||
this.secondaryState = secondaryState; | ||
this.chance = chance; | ||
this.scale = scale; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/azzy/fabric/incubus_core/worldgen/CrustFeature.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,90 @@ | ||
package azzy.fabric.incubus_core.worldgen; | ||
|
||
import com.mojang.serialization.Codec; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.tag.FluidTags; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.StructureWorldAccess; | ||
import net.minecraft.world.gen.chunk.ChunkGenerator; | ||
import net.minecraft.world.gen.feature.Feature; | ||
|
||
import java.util.LinkedList; | ||
import java.util.Queue; | ||
import java.util.Random; | ||
|
||
public class CrustFeature extends Feature<BiFeatureConfig> { | ||
|
||
Queue<BlockPos> centers; | ||
|
||
public CrustFeature(Codec<BiFeatureConfig> configCodec) { | ||
super(configCodec); | ||
} | ||
|
||
@Override | ||
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos center, BiFeatureConfig config) { | ||
center = center.down(); | ||
|
||
int radius = config.scale.getValue(random); | ||
|
||
centers = generateCircleAndCenters(world, center, radius, random, config); | ||
|
||
radius = config.scale.getValue(random); | ||
|
||
Queue<BlockPos> holder = new LinkedList<>(); | ||
|
||
for (BlockPos blockPos : centers) { | ||
holder.addAll(generateCircleAndCenters(world, blockPos, radius, random, config)); | ||
} | ||
|
||
centers.clear(); | ||
centers.addAll(holder); | ||
|
||
radius = config.scale.getValue(random); | ||
|
||
for (BlockPos newCenter : centers) { | ||
generateCircleAndCenters(world, newCenter, radius, random, config); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private Queue<BlockPos> generateCircleAndCenters(StructureWorldAccess world, BlockPos center, int radius, Random random, BiFeatureConfig config) { | ||
Queue<BlockPos> centers = new LinkedList<>(); | ||
BlockPos.iterateOutwards(center, radius, 0, radius).forEach(pos -> { | ||
if(pos.getSquaredDistance(center) > Math.pow(radius, 2)) | ||
return; | ||
|
||
boolean add = false; | ||
|
||
if(pos.getManhattanDistance(center) == radius && random.nextFloat() < 0.1F) | ||
add = true; | ||
|
||
if(world.isAir(pos) || world.isWater(pos) || !world.isWater(pos.up()) || !world.isAir(pos.up())) { | ||
boolean fail = true; | ||
int tries = 5; | ||
|
||
while(tries >= -4) { | ||
tries--; | ||
pos = pos.offset(Direction.Axis.Y, tries); | ||
if(!world.isAir(pos) && !world.isWater(pos) && (world.isWater(pos.up()) || world.isAir(pos.up()))) { | ||
fail = false; | ||
break; | ||
} | ||
} | ||
|
||
if(fail) | ||
return; | ||
} | ||
|
||
if(add) | ||
centers.add(pos); | ||
|
||
BlockState state = random.nextFloat() <= config.chance ? config.secondaryState : config.primaryState; | ||
|
||
world.setBlockState(pos, state, 2); | ||
world.getBlockTickScheduler().schedule(pos, state.getBlock(), 0); | ||
}); | ||
return centers; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/main/java/azzy/fabric/incubus_core/worldgen/UnderwaterCrustFeature.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,93 @@ | ||
package azzy.fabric.incubus_core.worldgen; | ||
|
||
import com.mojang.serialization.Codec; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.tag.FluidTags; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.StructureWorldAccess; | ||
import net.minecraft.world.gen.chunk.ChunkGenerator; | ||
import net.minecraft.world.gen.feature.Feature; | ||
|
||
import java.util.LinkedList; | ||
import java.util.Queue; | ||
import java.util.Random; | ||
|
||
public class UnderwaterCrustFeature extends Feature<BiFeatureConfig> { | ||
|
||
Queue<BlockPos> centers; | ||
|
||
public UnderwaterCrustFeature(Codec<BiFeatureConfig> configCodec) { | ||
super(configCodec); | ||
} | ||
|
||
@Override | ||
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos center, BiFeatureConfig config) { | ||
if(!world.getFluidState(center).isIn(FluidTags.WATER)) | ||
return false; | ||
|
||
center = center.down(); | ||
|
||
int radius = config.scale.getValue(random); | ||
|
||
centers = generateCircleAndCenters(world, center, radius, random, config); | ||
|
||
radius = config.scale.getValue(random); | ||
|
||
Queue<BlockPos> holder = new LinkedList<>(); | ||
|
||
for (BlockPos blockPos : centers) { | ||
holder.addAll(generateCircleAndCenters(world, blockPos, radius, random, config)); | ||
} | ||
|
||
centers.clear(); | ||
centers.addAll(holder); | ||
|
||
radius = config.scale.getValue(random); | ||
|
||
for (BlockPos newCenter : centers) { | ||
generateCircleAndCenters(world, newCenter, radius, random, config); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private Queue<BlockPos> generateCircleAndCenters(StructureWorldAccess world, BlockPos center, int radius, Random random, BiFeatureConfig config) { | ||
Queue<BlockPos> centers = new LinkedList<>(); | ||
BlockPos.iterateOutwards(center, radius, 0, radius).forEach(pos -> { | ||
if(pos.getSquaredDistance(center) > Math.pow(radius, 2)) | ||
return; | ||
|
||
boolean add = false; | ||
|
||
if(pos.getManhattanDistance(center) == radius && random.nextFloat() < 0.1F) | ||
add = true; | ||
|
||
if(world.isWater(pos) || !world.isWater(pos.up())) { | ||
boolean fail = true; | ||
int tries = 5; | ||
|
||
while(tries >= -4) { | ||
tries--; | ||
pos = pos.offset(Direction.Axis.Y, tries); | ||
if(!world.isAir(pos) && !world.isWater(pos) && world.isWater(pos.up())) { | ||
fail = false; | ||
break; | ||
} | ||
} | ||
|
||
if(fail) | ||
return; | ||
} | ||
|
||
if(add) | ||
centers.add(pos); | ||
|
||
BlockState state = random.nextFloat() <= config.chance ? config.secondaryState : config.primaryState; | ||
|
||
world.setBlockState(pos, state, 2); | ||
world.getBlockTickScheduler().schedule(pos, state.getBlock(), 0); | ||
}); | ||
return centers; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/azzy/fabric/incubus_core/worldgen/UnderwaterPlantFeature.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 azzy.fabric.incubus_core.worldgen; | ||
|
||
import com.mojang.serialization.Codec; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.block.TallSeagrassBlock; | ||
import net.minecraft.block.enums.DoubleBlockHalf; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.Heightmap; | ||
import net.minecraft.world.StructureWorldAccess; | ||
import net.minecraft.world.gen.chunk.ChunkGenerator; | ||
import net.minecraft.world.gen.feature.Feature; | ||
|
||
import java.util.Random; | ||
|
||
public class UnderwaterPlantFeature extends Feature<BiFeatureConfig> { | ||
|
||
public UnderwaterPlantFeature(Codec<BiFeatureConfig> codec) { | ||
super(codec); | ||
} | ||
|
||
public boolean generate(StructureWorldAccess structureWorldAccess, ChunkGenerator chunkGenerator, Random random, BlockPos pos, BiFeatureConfig config) { | ||
boolean success = false; | ||
int i = random.nextInt(8) - random.nextInt(8); | ||
int j = random.nextInt(8) - random.nextInt(8); | ||
int k = structureWorldAccess.getTopY(Heightmap.Type.OCEAN_FLOOR, pos.getX() + i, pos.getZ() + j); | ||
BlockPos blockPos2 = new BlockPos(pos.getX() + i, k, pos.getZ() + j); | ||
if (structureWorldAccess.getBlockState(blockPos2).isOf(Blocks.WATER)) { | ||
boolean tall = random.nextDouble() < config.chance; | ||
BlockState blockState = tall ? config.secondaryState : config.primaryState; | ||
if (blockState.canPlaceAt(structureWorldAccess, blockPos2)) { | ||
if (tall && blockState.getBlock() instanceof TallSeagrassBlock) { | ||
BlockState blockState2 = blockState.with(TallSeagrassBlock.HALF, DoubleBlockHalf.UPPER); | ||
BlockPos blockPos3 = blockPos2.up(); | ||
if (structureWorldAccess.getBlockState(blockPos3).isOf(Blocks.WATER)) { | ||
structureWorldAccess.setBlockState(blockPos2, blockState, 2); | ||
structureWorldAccess.setBlockState(blockPos3, blockState2, 2); | ||
} | ||
} else { | ||
structureWorldAccess.setBlockState(blockPos2, blockState, 2); | ||
} | ||
|
||
success = true; | ||
} | ||
} | ||
|
||
return success; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/azzy/fabric/incubus_core/worldgen/UnderwaterStateFeature.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,33 @@ | ||
package azzy.fabric.incubus_core.worldgen; | ||
|
||
import com.mojang.serialization.Codec; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.StructureWorldAccess; | ||
import net.minecraft.world.TickPriority; | ||
import net.minecraft.world.gen.chunk.ChunkGenerator; | ||
import net.minecraft.world.gen.feature.Feature; | ||
import net.minecraft.world.gen.feature.SingleStateFeatureConfig; | ||
|
||
import java.util.Random; | ||
|
||
public class UnderwaterStateFeature extends Feature<SingleStateFeatureConfig> { | ||
|
||
public UnderwaterStateFeature(Codec<SingleStateFeatureConfig> configCodec) { | ||
super(configCodec); | ||
} | ||
|
||
@Override | ||
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, SingleStateFeatureConfig config) { | ||
if(!world.isWater(pos)) { | ||
return false; | ||
} | ||
|
||
if(!world.isWater(pos.down())) { | ||
world.setBlockState(pos.down(), config.state, 2); | ||
world.getBlockTickScheduler().schedule(pos.down(), config.state.getBlock(), 0, TickPriority.EXTREMELY_HIGH); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
"minecraft:ancient_debris" | ||
] | ||
} |
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,6 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
"minecraft:netherite_ingot" | ||
] | ||
} |