Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/twilightforest/world/DefaultOrePlacer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package twilightforest.world;

import net.minecraft.block.Block;
import net.minecraft.world.World;

class DefaultOrePlacer implements OrePlacer {

@Override
public void placeOre(World world, int x, int y, int z, Block block) {
// Set the block without block updates.
// Taken from WorldGenerator::func_150515_a
world.setBlock(x, y, z, block, 0, 2);
}
}
13 changes: 13 additions & 0 deletions src/main/java/twilightforest/world/OrePlacer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package twilightforest.world;

import net.minecraft.block.Block;
import net.minecraft.world.World;

public interface OrePlacer {

/**
* Method which is expected to place a block in the given world at the given coordinates. The block can be
* overridden as the implementer chooses.
*/
void placeOre(World world, int x, int y, int z, Block block);
}
31 changes: 31 additions & 0 deletions src/main/java/twilightforest/world/StalactiteOreGen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package twilightforest.world;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Stream;

import net.minecraft.block.Block;

public class StalactiteOreGen {

private static final OrePlacer DEFAULT_ORE_PLACER = new DefaultOrePlacer();
private static final List<Function<Block, Optional<OrePlacer>>> orePlacerSources = new ArrayList<>();

/**
* Add an OrePlacer source that can determine which OrePlacer, if any, it wants to provide to a stalactite wanting
* to generate with a given Block.
*/
public static void addOrePlacerSource(Function<Block, Optional<OrePlacer>> orePlacerSource) {
orePlacerSources.add(orePlacerSource);
}

static OrePlacer getOrePlacer(Block block) {
// Given this only runs once per stalactite generated, I think we can afford the assumption there could
// eventually be several alternate sources of ore placers.
return orePlacerSources.stream().map(f -> f.apply(block))
.flatMap(o -> o.isPresent() ? Stream.of(o.get()) : Stream.empty()).findFirst()
.orElse(DEFAULT_ORE_PLACER);
}
}
4 changes: 2 additions & 2 deletions src/main/java/twilightforest/world/TFGenCaveStalactite.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public boolean generate(World world, Random random, int x, int y, int z) {
}

public boolean makeSpike(World world, Random random, int x, int y, int z, int maxLength) {

OrePlacer orePlacer = StalactiteOreGen.getOrePlacer(blockID);
int diameter = (int) (maxLength / 4.5); // diameter of the base

// let's see...
Expand Down Expand Up @@ -180,7 +180,7 @@ public boolean makeSpike(World world, Random random, int x, int y, int z, int ma
}

for (int dy = 0; dy != (spikeLength * dir); dy += dir) {
setBlock(world, x + dx, y + dy, z + dz, blockID);
orePlacer.placeOre(world, x + dx, y + dy, z + dz, blockID);
}
}
}
Expand Down