-
Notifications
You must be signed in to change notification settings - Fork 30
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
12 changed files
with
275 additions
and
6 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
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
2 changes: 1 addition & 1 deletion
2
...ch/init/world/OilSpringFeatureConfig.java → .../features/oil/OilSpringFeatureConfig.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
118 changes: 118 additions & 0 deletions
118
src/main/java/rearth/oritech/init/world/features/resourcenode/ResourceNodeFeature.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,118 @@ | ||
package rearth.oritech.init.world.features.resourcenode; | ||
|
||
import com.mojang.serialization.Codec; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.tag.BlockTags; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.util.math.random.Random; | ||
import net.minecraft.world.gen.feature.Feature; | ||
import net.minecraft.world.gen.feature.util.FeatureContext; | ||
|
||
import java.util.List; | ||
|
||
public class ResourceNodeFeature extends Feature<ResourceNodeFeatureConfig> { | ||
|
||
public ResourceNodeFeature(Codec<ResourceNodeFeatureConfig> configCodec) { | ||
super(configCodec); | ||
} | ||
|
||
@Override | ||
public boolean generate(FeatureContext<ResourceNodeFeatureConfig> context) { | ||
|
||
var world = context.getWorld(); | ||
var origin = context.getOrigin(); | ||
|
||
if (world.isClient()) return false; | ||
|
||
var bedrockFound = false; | ||
var testPos = new BlockPos(origin); | ||
var deepNodePos = testPos; | ||
for (int y = world.getBottomY(); y < world.getHeight(); y++) { | ||
testPos = testPos.up(); | ||
var testState = world.getBlockState(testPos); | ||
|
||
if (!testState.isOf(Blocks.BEDROCK) && !bedrockFound) { | ||
deepNodePos = testPos; | ||
bedrockFound = true; | ||
} else if (bedrockFound && testState.isOf(Blocks.BEDROCK)) { | ||
bedrockFound = false; | ||
// reset if another bedrock layer occurs | ||
} | ||
|
||
if (testState.isIn(BlockTags.DIRT) || testState.isIn(BlockTags.SAND)) { | ||
if (world.getBlockState(testPos.up()).isOf(Blocks.AIR)) { | ||
placeSurfaceBoulder(testPos, context); | ||
placeBedrockNode(deepNodePos, context); | ||
System.out.println("placing resource node at " + testPos + " with deep " + deepNodePos); | ||
return true; | ||
} | ||
} | ||
|
||
} | ||
|
||
return false; | ||
} | ||
|
||
private BlockState getRandomBlockFromList(List<Identifier> list, Random random) { | ||
return Registries.BLOCK.get(getRandomFromList(list, random)).getDefaultState(); | ||
} | ||
|
||
private Identifier getRandomFromList(List<Identifier> list, Random random) { | ||
return list.get(random.nextInt(list.size())); | ||
} | ||
|
||
private void placeBedrockNode(BlockPos startPos, FeatureContext<ResourceNodeFeatureConfig> context) { | ||
|
||
var world = context.getWorld(); | ||
var random = context.getRandom(); | ||
var ores = context.getConfig().nodeOres(); | ||
|
||
var radius = context.getConfig().nodeSize(); | ||
var overlayBlock = Registries.BLOCK.get(context.getConfig().overlayBlock()).getDefaultState(); | ||
|
||
for (int x = 0; x < radius; x++) { | ||
for (int y = 0; y < radius; y++) { | ||
var pos = startPos.add(x, 0, y); | ||
world.setBlockState(pos, getRandomBlockFromList(ores, random), 0x10); | ||
} | ||
} | ||
|
||
// overlay it with something | ||
for (int x = -1; x <= radius; x++) { | ||
for (int y = -1; y <= radius; y++) { | ||
var pos = startPos.add(x, 0, y); | ||
for (int i = 0; i < context.getConfig().overlayHeight(); i++) { | ||
world.setBlockState(pos.up(1 + i), overlayBlock, 0x10); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void placeSurfaceBoulder(BlockPos startPos, FeatureContext<ResourceNodeFeatureConfig> context) { | ||
|
||
var world = context.getWorld(); | ||
var random = context.getRandom(); | ||
var movedCenter = new Vec3d(startPos.getX() - random.nextFloat(), startPos.getY() - random.nextFloat(), startPos.getZ() - random.nextFloat()); | ||
var radius = context.getConfig().boulderRadius(); | ||
var ores = context.getConfig().boulderOres(); | ||
|
||
for (int x = -radius; x <= radius; x++) { | ||
for (int y = -radius; y <= radius; y++) { | ||
for (int z = -radius; z <= radius; z++) { | ||
var pos = startPos.add(x, y, z); | ||
var distance = movedCenter.distanceTo(pos.toCenterPos()); | ||
if (distance > radius) continue; | ||
world.setBlockState(pos, getRandomBlockFromList(ores, random), 0x10); | ||
} | ||
} | ||
} | ||
|
||
for (int i = 8; i < 20; i++) { | ||
world.setBlockState(startPos.up(i), Blocks.DIAMOND_BLOCK.getDefaultState(), 0x10); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/rearth/oritech/init/world/features/resourcenode/ResourceNodeFeatureConfig.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 rearth.oritech.init.world.features.resourcenode; | ||
|
||
import io.wispforest.owo.serialization.Endec; | ||
import io.wispforest.owo.serialization.endec.BuiltInEndecs; | ||
import io.wispforest.owo.serialization.endec.StructEndecBuilder; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.world.gen.feature.FeatureConfig; | ||
|
||
import java.util.List; | ||
|
||
public record ResourceNodeFeatureConfig(int nodeSize, int boulderRadius, List<Identifier> nodeOres, List<Identifier> boulderOres, Identifier overlayBlock, int overlayHeight) implements FeatureConfig { | ||
|
||
public static final Endec<ResourceNodeFeatureConfig> NODE_FEATURE_ENDEC = StructEndecBuilder.of( | ||
Endec.INT.fieldOf("nodeSize", ResourceNodeFeatureConfig::nodeSize), | ||
Endec.INT.fieldOf("boulderRadius", ResourceNodeFeatureConfig::boulderRadius), | ||
BuiltInEndecs.IDENTIFIER.listOf().fieldOf("nodeOres", ResourceNodeFeatureConfig::nodeOres), | ||
BuiltInEndecs.IDENTIFIER.listOf().fieldOf("boulderOres", ResourceNodeFeatureConfig::boulderOres), | ||
BuiltInEndecs.IDENTIFIER.fieldOf("overlayBlock", ResourceNodeFeatureConfig::overlayBlock), | ||
Endec.INT.fieldOf("overlayHeight", ResourceNodeFeatureConfig::overlayHeight), | ||
ResourceNodeFeatureConfig::new | ||
); | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/resources/data/oritech/worldgen/configured_feature/resource_node_common.json
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,26 @@ | ||
{ | ||
"type": "oritech:resource_node", | ||
"config": { | ||
"nodeSize": 5, | ||
"boulderRadius": 3, | ||
"nodeOres": [ | ||
"minecraft:deepslate_iron_ore", | ||
"minecraft:deepslate_iron_ore", | ||
"minecraft:deepslate_iron_ore", | ||
"minecraft:deepslate_copper_ore", | ||
"minecraft:deepslate_copper_ore", | ||
"minecraft:deepslate_coal_ore", | ||
"minecraft:deepslate_gold_ore", | ||
"minecraft:deepslate" | ||
], | ||
"boulderOres": [ | ||
"minecraft:deepslate_iron_ore", | ||
"minecraft:deepslate_copper_ore", | ||
"minecraft:deepslate_iron_ore", | ||
"minecraft:deepslate", | ||
"minecraft:deepslate" | ||
], | ||
"overlayBlock": "oritech:oil_fluid_block", | ||
"overlayHeight": 3 | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/resources/data/oritech/worldgen/configured_feature/resource_node_other.json
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,24 @@ | ||
{ | ||
"type": "oritech:resource_node", | ||
"config": { | ||
"nodeSize": 5, | ||
"boulderRadius": 3, | ||
"nodeOres": [ | ||
"minecraft:deepslate_gold_ore", | ||
"minecraft:deepslate_lapis_ore", | ||
"minecraft:deepslate_redstone_ore", | ||
"minecraft:deepslate_redstone_ore", | ||
"minecraft:deepslate", | ||
"minecraft:deepslate" | ||
], | ||
"boulderOres": [ | ||
"minecraft:deepslate_gold_ore", | ||
"minecraft:deepslate_lapis_ore", | ||
"minecraft:deepslate_redstone_ore", | ||
"minecraft:deepslate", | ||
"minecraft:deepslate" | ||
], | ||
"overlayBlock": "oritech:oil_fluid_block", | ||
"overlayHeight": 3 | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/resources/data/oritech/worldgen/configured_feature/resource_node_rare.json
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,25 @@ | ||
{ | ||
"type": "oritech:resource_node", | ||
"config": { | ||
"nodeSize": 5, | ||
"boulderRadius": 3, | ||
"nodeOres": [ | ||
"minecraft:deepslate_diamond_ore", | ||
"minecraft:deepslate_diamond_ore", | ||
"minecraft:deepslate_gold_ore", | ||
"minecraft:deepslate_gold_ore", | ||
"minecraft:deepslate_emerald_ore", | ||
"minecraft:deepslate", | ||
"minecraft:deepslate" | ||
], | ||
"boulderOres": [ | ||
"minecraft:deepslate_diamond_ore", | ||
"minecraft:deepslate_gold_ore", | ||
"minecraft:deepslate_emerald_ore", | ||
"minecraft:deepslate", | ||
"minecraft:deepslate" | ||
], | ||
"overlayBlock": "oritech:oil_fluid_block", | ||
"overlayHeight": 3 | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/main/resources/data/oritech/worldgen/placed_feature/resource_node_common.json
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,12 @@ | ||
{ | ||
"feature": "oritech:resource_node_common", | ||
"placement": [ | ||
{ | ||
"type": "minecraft:rarity_filter", | ||
"chance": 250 | ||
}, | ||
{ | ||
"type": "minecraft:in_square" | ||
} | ||
] | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/resources/data/oritech/worldgen/placed_feature/resource_node_other.json
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,12 @@ | ||
{ | ||
"feature": "oritech:resource_node_other", | ||
"placement": [ | ||
{ | ||
"type": "minecraft:rarity_filter", | ||
"chance": 300 | ||
}, | ||
{ | ||
"type": "minecraft:in_square" | ||
} | ||
] | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/resources/data/oritech/worldgen/placed_feature/resource_node_rare.json
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,12 @@ | ||
{ | ||
"feature": "oritech:resource_node_rare", | ||
"placement": [ | ||
{ | ||
"type": "minecraft:rarity_filter", | ||
"chance": 350 | ||
}, | ||
{ | ||
"type": "minecraft:in_square" | ||
} | ||
] | ||
} |