Created
February 19, 2019 15:05
-
-
Save alcatrazEscapee/bea8ac45201c01ca2cc2301848d95df5 to your computer and use it in GitHub Desktop.
An example of using an enum to control flower generation for TFC
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
import java.util.*; | |
import java.util.function.Supplier; | |
import java.util.stream.Collector; | |
import java.util.stream.Collectors; | |
import net.minecraft.world.World; | |
import net.minecraft.world.chunk.IChunkProvider; | |
import net.minecraft.world.gen.IChunkGenerator; | |
import net.minecraftforge.fml.common.IWorldGenerator; | |
import net.minecraftforge.registries.IForgeRegistry; | |
import net.minecraftforge.registries.IForgeRegistryEntry; | |
public class ExampleFlowers | |
{ | |
/** | |
* This is the flower registry object | |
* It is built with some spawn conditions, maybe multiple | |
*/ | |
public static class Flower extends IForgeRegistryEntry.Impl<Flower> | |
{ | |
private FlowerSpawnConditions[] conditions; | |
public Flower(FlowerSpawnConditions... conditions) | |
{ | |
this.conditions = conditions; | |
} | |
public boolean hasSpawnCondition(FlowerSpawnConditions condition) | |
{ | |
for (FlowerSpawnConditions c : conditions) | |
{ | |
if (c == condition) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} | |
} | |
/** | |
* These are possible flower spawn conditions | |
* For now it should be an enum, but in future this could be dynamic, to allow addons to add to this. | |
* (Or they could add to this as an enum with forge's enum manipulation tools (I think)) | |
*/ | |
public enum FlowerSpawnConditions | |
{ | |
NORMAL, | |
CLAY_INDICATOR | |
} | |
/** | |
* A sample world generator that uses the CLAY_INDICATOR flower spawn condition | |
*/ | |
public static class WorldGenClay implements IWorldGenerator | |
{ | |
@Override | |
public void generate(Random random, int i, int i1, World world, IChunkGenerator iChunkGenerator, IChunkProvider iChunkProvider) | |
{ | |
// Generate clay | |
// If clay generation happened: | |
List<Flower> validFlowers = TFCRegistries.FLOWERS | |
.getValuesCollection() | |
.stream() | |
.filter(x -> x.hasSpawnCondition(FlowerSpawnConditions.CLAY_INDICATOR)) | |
// Also filter on rain / temperature here | |
.collect(Collectors.toList()); | |
Flower pickedFlower = validFlowers.get(new Random().nextInt(validFlowers.size())); | |
// Generate the pickedFlower | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment