-
-
Save killerjdog51/f961a9cabbd3795d9e8dcdc0dfaff932 to your computer and use it in GitHub Desktop.
Oasis Biome data and Generation
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
public BiomeEnhancements() | |
{ | |
// Register blocks, Items, and Biome | |
RegistryHandler.init(); | |
// Register ourselves for server and other game events we are interested in | |
MinecraftForge.EVENT_BUS.register(this); | |
} | |
private void setup(final FMLCommonSetupEvent event) | |
{ | |
// Register Biome | |
WorldGeneration.registerBiome(RegistryHandler.OASIS_BIOME.get(), BiomeManager.BiomeType.DESERT, 1, Type.DRY, Type.OVERWORLD); | |
} |
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
public class OasisBiome { | |
// Create/build our biome | |
public static Biome makeOasisBiome(float depth, float scale) { | |
MobSpawnInfo.Builder mobspawninfo$builder = new MobSpawnInfo.Builder(); | |
withOasisMobs(mobspawninfo$builder); | |
BiomeGenerationSettings.Builder biomegenerationsettings$builder = (new BiomeGenerationSettings.Builder()).withSurfaceBuilder(ConfiguredSurfaceBuilders.field_244178_j); | |
DefaultBiomeFeatures.withStrongholdAndMineshaft(biomegenerationsettings$builder); | |
DefaultBiomeFeatures.withCavesAndCanyons(biomegenerationsettings$builder); | |
DefaultBiomeFeatures.withCommonOverworldBlocks(biomegenerationsettings$builder); | |
DefaultBiomeFeatures.withOverworldOres(biomegenerationsettings$builder); | |
DefaultBiomeFeatures.withDisks(biomegenerationsettings$builder); | |
withOasisVegetation(biomegenerationsettings$builder); | |
DefaultBiomeFeatures.withBadlandsGrass(biomegenerationsettings$builder); | |
DefaultBiomeFeatures.withDesertVegetation(biomegenerationsettings$builder); | |
DefaultBiomeFeatures.withLavaAndWaterSprings(biomegenerationsettings$builder); | |
DefaultBiomeFeatures.withDesertWells(biomegenerationsettings$builder); | |
return (new Biome.Builder()).precipitation(Biome.RainType.NONE).category(Biome.Category.DESERT).depth(depth).scale(scale).temperature(0.95F).downfall(0.9F).setEffects((new BiomeAmbience.Builder()).setWaterColor(4566514).setWaterFogColor(267827).setFogColor(12638463).withSkyColor(getSkyColorWithTemperatureModifier(2.0F)).setMoodSound(MoodSoundAmbience.DEFAULT_CAVE).build()).withMobSpawnSettings(mobspawninfo$builder.copy()).withGenerationSettings(biomegenerationsettings$builder.build()).build(); | |
} | |
// Mobs that spawn in the Oasis | |
public static void withOasisMobs(MobSpawnInfo.Builder builder) { | |
builder.withSpawner(EntityClassification.CREATURE, new MobSpawnInfo.Spawners(EntityType.RABBIT, 4, 2, 3)); | |
DefaultBiomeFeatures.withBats(builder); | |
builder.withSpawner(EntityClassification.CREATURE, new MobSpawnInfo.Spawners(EntityType.CHICKEN, 10, 4, 4)); | |
builder.withSpawner(EntityClassification.MONSTER, new MobSpawnInfo.Spawners(EntityType.SPIDER, 100, 4, 4)); | |
builder.withSpawner(EntityClassification.MONSTER, new MobSpawnInfo.Spawners(EntityType.ZOMBIE, 20, 4, 4)); | |
builder.withSpawner(EntityClassification.MONSTER, new MobSpawnInfo.Spawners(EntityType.ZOMBIE_VILLAGER, 2, 1, 1)); | |
builder.withSpawner(EntityClassification.MONSTER, new MobSpawnInfo.Spawners(EntityType.SKELETON, 20, 4, 4)); | |
} | |
// Generate our vegetation | |
public static void withOasisVegetation(BiomeGenerationSettings.Builder builder) { | |
builder.withFeature(GenerationStage.Decoration.VEGETAL_DECORATION, WorldFeatures.DESERT_CANDLE); | |
DefaultBiomeFeatures.withWarmFlowers(builder); | |
DefaultBiomeFeatures.withBadlandsGrass(builder); | |
DefaultBiomeFeatures.withSugarCaneAndPumpkins(builder); | |
builder.withFeature(GenerationStage.Decoration.VEGETAL_DECORATION, Features.PATCH_MELON); | |
builder.withFeature(GenerationStage.Decoration.VEGETAL_DECORATION, WorldFeatures.PALM_TREE); | |
} | |
private static int getSkyColorWithTemperatureModifier(float temperature) { | |
float lvt_1_1_ = temperature / 3.0F; | |
lvt_1_1_ = MathHelper.clamp(lvt_1_1_, -1.0F, 1.0F); | |
return MathHelper.hsvToRGB(0.62222224F - lvt_1_1_ * 0.05F, 0.5F + lvt_1_1_ * 0.1F, 1.0F); | |
} | |
} |
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
// Edit chunk biomeIds and BiomeContainer | |
private void EditBiome(IWorld worldIn, BlockPos pos) | |
{ | |
for(int x = -2; x <= 2; x++) | |
{ | |
for(int y = -2; y <= 2; y++) | |
{ | |
BlockPos blockpos = pos.add(x, 0, y); | |
// We want to change the chunk's biome to our custom oasis biome for that nice water/foliage color | |
try { | |
// Get the class we want access to | |
@SuppressWarnings("rawtypes") | |
Class BiomeContainerClass = BiomeContainer.class; | |
// Get the field we want access to | |
Field[] fields = BiomeContainerClass.getDeclaredFields(); | |
BiomeContainer BiomeContainerInstance = worldIn.getChunk(blockpos).getBiomes(); | |
Field field = null; | |
for(int i = 0; i < fields.length; i++) | |
{ | |
if (fields[i].getName().equals("biomes")) | |
{ | |
field = fields[i]; | |
} | |
} | |
field.setAccessible(true); | |
// Copy that field's data | |
Biome[] biomes = (Biome[]) field.get(BiomeContainerInstance); | |
// Overwrite with our data | |
Biome biome = RegistryHandler.OASIS_BIOME.get(); | |
int id = ((net.minecraftforge.registries.ForgeRegistry<Biome>)net.minecraftforge.registries.ForgeRegistries.BIOMES).getID(biome); | |
int place = (blockpos.getX() & 15) << 4 | (blockpos.getZ() & 15); | |
// Successfully inserts our biome data and biome id | |
for(int i = -2; i <= 2; i++) | |
{ | |
worldIn.getChunk(blockpos).getBiomes().getBiomeIds()[place + i] = id; | |
biomes[place + i] = biome; | |
} | |
// Edit the field's properties to replace it's data with our modified dataS | |
Field modifiersField = Field.class.getDeclaredField("modifiers"); | |
modifiersField.setAccessible(true); | |
modifiersField.setInt(field, field.getModifiers() & (~Modifier.PRIVATE & ~Modifier.FINAL)); | |
field.set(BiomeContainerInstance, biomes); | |
} catch (Exception e) { | |
System.out.println("failed to edit BiomeContainer or BiomeId"); | |
} | |
} | |
} | |
} |
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
public class RegistryHandler { | |
public static final DeferredRegister<Biome> BIOMES = DeferredRegister.create(ForgeRegistries.BIOMES, BiomeEnhancements.MOD_ID); | |
public static void init() | |
{ | |
BIOMES.register(FMLJavaModLoadingContext.get().getModEventBus()); | |
} | |
//Biomes | |
public static final RegistryObject<Biome> OASIS_BIOME = BIOMES.register("oasis", () -> WorldGeneration.OASIS); |
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
public class WorldGeneration { | |
// Register our biome to exist | |
public static final Biome OASIS = OasisBiome.makeOasisBiome(-0.1F, 0.0F); | |
public static void registerBiome(Biome biome, BiomeType biomeType, int weight, BiomeDictionary.Type...types) | |
{ | |
BiomeManager.addBiome(biomeType, new BiomeManager.BiomeEntry(key(biome), weight)); | |
BiomeDictionary.addTypes(key(biome), types); | |
} | |
private static RegistryKey<Biome> key(Biome biome) | |
{ | |
return RegistryKey.getOrCreateKey(ForgeRegistries.Keys.BIOMES, Objects.requireNonNull(ForgeRegistries.BIOMES.getKey(biome), "Biome registry name was null")); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment