diff --git a/src/main/java/twilightforest/world/DefaultOrePlacer.java b/src/main/java/twilightforest/world/DefaultOrePlacer.java new file mode 100644 index 0000000000..02899fde43 --- /dev/null +++ b/src/main/java/twilightforest/world/DefaultOrePlacer.java @@ -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); + } +} diff --git a/src/main/java/twilightforest/world/OrePlacer.java b/src/main/java/twilightforest/world/OrePlacer.java new file mode 100644 index 0000000000..a10e2dbd5f --- /dev/null +++ b/src/main/java/twilightforest/world/OrePlacer.java @@ -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); +} diff --git a/src/main/java/twilightforest/world/StalactiteOreGen.java b/src/main/java/twilightforest/world/StalactiteOreGen.java new file mode 100644 index 0000000000..828351c708 --- /dev/null +++ b/src/main/java/twilightforest/world/StalactiteOreGen.java @@ -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>> 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> 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); + } +} diff --git a/src/main/java/twilightforest/world/TFGenCaveStalactite.java b/src/main/java/twilightforest/world/TFGenCaveStalactite.java index 673845f35d..95f58590a8 100644 --- a/src/main/java/twilightforest/world/TFGenCaveStalactite.java +++ b/src/main/java/twilightforest/world/TFGenCaveStalactite.java @@ -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... @@ -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); } } }