Generate cherry trees

This commit is contained in:
Matthias Schiffer 2014-05-26 06:27:57 +02:00
parent c179a1cb76
commit 414d63fd3e
2 changed files with 243 additions and 1 deletions

View file

@ -3,10 +3,14 @@ package net.universe_factory.minecraft.test;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.terraingen.BiomeEvent.CreateDecorator;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.common.registry.LanguageRegistry;
import net.universe_factory.minecraft.test.blocks.*; import net.universe_factory.minecraft.test.blocks.*;
@ -33,7 +37,16 @@ public class Test {
public static Test instance; public static Test instance;
@EventHandler @EventHandler
public void init(FMLInitializationEvent event) { public void preInit(FMLInitializationEvent event) {
MinecraftForge.TERRAIN_GEN_BUS.register(new TerrainGenHandler());
cherry.register(); cherry.register();
} }
public class TerrainGenHandler {
@SubscribeEvent
public void handleCreateDecorator(CreateDecorator event) {
event.newBiomeDecorator = new TestBiomeDecorator(cherry);
}
}
} }

View file

@ -0,0 +1,229 @@
package net.universe_factory.minecraft.test;
import static net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.BIG_SHROOM;
import static net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.CACTUS;
import static net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.CLAY;
import static net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.DEAD_BUSH;
import static net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.FLOWERS;
import static net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.GRASS;
import static net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.LAKE;
import static net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.LILYPAD;
import static net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.PUMPKIN;
import static net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.REED;
import static net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.SAND;
import static net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.SAND_PASS2;
import static net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.SHROOM;
import static net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.TREE;
import net.minecraft.block.BlockFlower;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.world.biome.BiomeDecorator;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.gen.feature.WorldGenAbstractTree;
import net.minecraft.world.gen.feature.WorldGenDeadBush;
import net.minecraft.world.gen.feature.WorldGenLiquids;
import net.minecraft.world.gen.feature.WorldGenPumpkin;
import net.minecraft.world.gen.feature.WorldGenTrees;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.terraingen.DecorateBiomeEvent;
import net.minecraftforge.event.terraingen.TerrainGen;
import net.universe_factory.minecraft.test.generic.GenericWood;
import net.universe_factory.minecraft.test.generic.WorldGenGenericTrees;
public class TestBiomeDecorator extends BiomeDecorator {
protected WorldGenGenericTrees worldGenGenericTrees;
public TestBiomeDecorator(GenericWood genericWood) {
worldGenGenericTrees = new WorldGenGenericTrees(false, genericWood);
}
protected void genDecorations(BiomeGenBase biome) {
MinecraftForge.EVENT_BUS.post(new DecorateBiomeEvent.Pre(currentWorld, randomGenerator, chunk_X, chunk_Z));
this.generateOres();
int i;
int j;
int k;
boolean doGen = TerrainGen.decorate(currentWorld, randomGenerator, chunk_X, chunk_Z, SAND);
for (i = 0; doGen && i < this.sandPerChunk2; ++i) {
j = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
k = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
this.sandGen.generate(this.currentWorld, this.randomGenerator, j, this.currentWorld.getTopSolidOrLiquidBlock(j, k), k);
}
doGen = TerrainGen.decorate(currentWorld, randomGenerator, chunk_X, chunk_Z, CLAY);
for (i = 0; doGen && i < this.clayPerChunk; ++i) {
j = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
k = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
this.clayGen.generate(this.currentWorld, this.randomGenerator, j, this.currentWorld.getTopSolidOrLiquidBlock(j, k), k);
}
doGen = TerrainGen.decorate(currentWorld, randomGenerator, chunk_X, chunk_Z, SAND_PASS2);
for (i = 0; doGen && i < this.sandPerChunk; ++i) {
j = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
k = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
this.gravelAsSandGen.generate(this.currentWorld, this.randomGenerator, j, this.currentWorld.getTopSolidOrLiquidBlock(j, k), k);
}
i = this.treesPerChunk;
if (this.randomGenerator.nextInt(10) == 0) {
++i;
}
int l;
int i1;
doGen = TerrainGen.decorate(currentWorld, randomGenerator, chunk_X, chunk_Z, TREE);
for (j = 0; doGen && j < i; ++j) {
k = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
l = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
i1 = this.currentWorld.getHeightValue(k, l);
WorldGenAbstractTree worldgenabstracttree = biome.func_150567_a(this.randomGenerator);
if (worldgenabstracttree instanceof WorldGenTrees && biome.getTempCategory() == BiomeGenBase.TempCategory.MEDIUM
&& this.randomGenerator.nextDouble() < 0.5f) {
worldgenabstracttree = this.worldGenGenericTrees;
}
worldgenabstracttree.setScale(1.0D, 1.0D, 1.0D);
if (worldgenabstracttree.generate(this.currentWorld, this.randomGenerator, k, i1, l)) {
worldgenabstracttree.func_150524_b(this.currentWorld, this.randomGenerator, k, i1, l);
}
}
doGen = TerrainGen.decorate(currentWorld, randomGenerator, chunk_X, chunk_Z, BIG_SHROOM);
for (j = 0; doGen && j < this.bigMushroomsPerChunk; ++j) {
k = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
l = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
this.bigMushroomGen.generate(this.currentWorld, this.randomGenerator, k, this.currentWorld.getHeightValue(k, l), l);
}
doGen = TerrainGen.decorate(currentWorld, randomGenerator, chunk_X, chunk_Z, FLOWERS);
for (j = 0; doGen && j < this.flowersPerChunk; ++j) {
k = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
l = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
i1 = this.randomGenerator.nextInt(this.currentWorld.getHeightValue(k, l) + 32);
String s = biome.func_150572_a(this.randomGenerator, k, i1, l);
BlockFlower blockflower = BlockFlower.func_149857_e(s);
if (blockflower.getMaterial() != Material.air) {
this.yellowFlowerGen.func_150550_a(blockflower, BlockFlower.func_149856_f(s));
this.yellowFlowerGen.generate(this.currentWorld, this.randomGenerator, k, i1, l);
}
}
doGen = TerrainGen.decorate(currentWorld, randomGenerator, chunk_X, chunk_Z, GRASS);
for (j = 0; doGen && j < this.grassPerChunk; ++j) {
k = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
l = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
i1 = this.randomGenerator.nextInt(this.currentWorld.getHeightValue(k, l) * 2);
WorldGenerator worldgenerator = biome.getRandomWorldGenForGrass(this.randomGenerator);
worldgenerator.generate(this.currentWorld, this.randomGenerator, k, i1, l);
}
doGen = TerrainGen.decorate(currentWorld, randomGenerator, chunk_X, chunk_Z, DEAD_BUSH);
for (j = 0; doGen && j < this.deadBushPerChunk; ++j) {
k = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
l = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
i1 = this.randomGenerator.nextInt(this.currentWorld.getHeightValue(k, l) * 2);
(new WorldGenDeadBush(Blocks.deadbush)).generate(this.currentWorld, this.randomGenerator, k, i1, l);
}
doGen = TerrainGen.decorate(currentWorld, randomGenerator, chunk_X, chunk_Z, LILYPAD);
for (j = 0; doGen && j < this.waterlilyPerChunk; ++j) {
k = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
l = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
for (i1 = this.randomGenerator.nextInt(this.currentWorld.getHeightValue(k, l) * 2); i1 > 0
&& this.currentWorld.isAirBlock(k, i1 - 1, l); --i1) {
;
}
this.waterlilyGen.generate(this.currentWorld, this.randomGenerator, k, i1, l);
}
doGen = TerrainGen.decorate(currentWorld, randomGenerator, chunk_X, chunk_Z, SHROOM);
for (j = 0; doGen && j < this.mushroomsPerChunk; ++j) {
if (this.randomGenerator.nextInt(4) == 0) {
k = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
l = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
i1 = this.currentWorld.getHeightValue(k, l);
this.mushroomBrownGen.generate(this.currentWorld, this.randomGenerator, k, i1, l);
}
if (this.randomGenerator.nextInt(8) == 0) {
k = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
l = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
i1 = this.randomGenerator.nextInt(this.currentWorld.getHeightValue(k, l) * 2);
this.mushroomRedGen.generate(this.currentWorld, this.randomGenerator, k, i1, l);
}
}
if (doGen && this.randomGenerator.nextInt(4) == 0) {
j = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
k = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
l = this.randomGenerator.nextInt(this.currentWorld.getHeightValue(j, k) * 2);
this.mushroomBrownGen.generate(this.currentWorld, this.randomGenerator, j, l, k);
}
if (doGen && this.randomGenerator.nextInt(8) == 0) {
j = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
k = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
l = this.randomGenerator.nextInt(this.currentWorld.getHeightValue(j, k) * 2);
this.mushroomRedGen.generate(this.currentWorld, this.randomGenerator, j, l, k);
}
doGen = TerrainGen.decorate(currentWorld, randomGenerator, chunk_X, chunk_Z, REED);
for (j = 0; doGen && j < this.reedsPerChunk; ++j) {
k = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
l = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
i1 = this.randomGenerator.nextInt(this.currentWorld.getHeightValue(k, l) * 2);
this.reedGen.generate(this.currentWorld, this.randomGenerator, k, i1, l);
}
for (j = 0; doGen && j < 10; ++j) {
k = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
l = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
i1 = this.randomGenerator.nextInt(this.currentWorld.getHeightValue(k, l) * 2);
this.reedGen.generate(this.currentWorld, this.randomGenerator, k, i1, l);
}
doGen = TerrainGen.decorate(currentWorld, randomGenerator, chunk_X, chunk_Z, PUMPKIN);
if (doGen && this.randomGenerator.nextInt(32) == 0) {
j = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
k = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
l = this.randomGenerator.nextInt(this.currentWorld.getHeightValue(j, k) * 2);
(new WorldGenPumpkin()).generate(this.currentWorld, this.randomGenerator, j, l, k);
}
doGen = TerrainGen.decorate(currentWorld, randomGenerator, chunk_X, chunk_Z, CACTUS);
for (j = 0; doGen && j < this.cactiPerChunk; ++j) {
k = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
l = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
i1 = this.randomGenerator.nextInt(this.currentWorld.getHeightValue(k, l) * 2);
this.cactusGen.generate(this.currentWorld, this.randomGenerator, k, i1, l);
}
doGen = TerrainGen.decorate(currentWorld, randomGenerator, chunk_X, chunk_Z, LAKE);
if (doGen && this.generateLakes) {
for (j = 0; j < 50; ++j) {
k = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
l = this.randomGenerator.nextInt(this.randomGenerator.nextInt(248) + 8);
i1 = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
(new WorldGenLiquids(Blocks.flowing_water)).generate(this.currentWorld, this.randomGenerator, k, l, i1);
}
for (j = 0; j < 20; ++j) {
k = this.chunk_X + this.randomGenerator.nextInt(16) + 8;
l = this.randomGenerator.nextInt(this.randomGenerator.nextInt(this.randomGenerator.nextInt(240) + 8) + 8);
i1 = this.chunk_Z + this.randomGenerator.nextInt(16) + 8;
(new WorldGenLiquids(Blocks.flowing_lava)).generate(this.currentWorld, this.randomGenerator, k, l, i1);
}
}
MinecraftForge.EVENT_BUS.post(new DecorateBiomeEvent.Post(currentWorld, randomGenerator, chunk_X, chunk_Z));
}
}