View difference between Paste ID: CtnTSKZS and CnZRhMn5
SHOW: | | - or go back to the newest paste.
1
package com.example.examplemod;
2
3
import com.google.common.base.Throwables;
4
import com.google.common.collect.ObjectArrays;
5
import cpw.mods.fml.common.Mod;
6
import cpw.mods.fml.common.Mod.EventHandler;
7
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
8
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
9
import net.minecraft.world.biome.BiomeGenBase;
10
import net.minecraft.world.gen.layer.GenLayer;
11
import net.minecraft.world.gen.layer.GenLayerBiome;
12
import net.minecraft.world.gen.layer.GenLayerRiverMix;
13
import net.minecraft.world.gen.layer.MyModGenLayerAccessor;
14
import net.minecraftforge.common.MinecraftForge;
15
import net.minecraftforge.event.terraingen.WorldTypeEvent;
16
17
import java.lang.reflect.Field;
18
19
@Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)
20
public class ExampleMod
21
{
22
    public static final String MODID = "examplemod";
23
    public static final String VERSION = "1.0";
24
25
	public static BiomeGenBase myBiome;
26
27
	@EventHandler
28
	public void preInit(FMLPreInitializationEvent event) {
29
		MinecraftForge.TERRAIN_GEN_BUS.register(this);
30
31
		myBiome = new BiomeGenBase(245) {
32
33
		};
34
	}
35
36
	private static Field biomePatternGeneratorChainField;
37
	private static Field biomeArrayField;
38
39
	static {
40
		// TODO: SRG names for non-dev environment
41
		try {
42
			biomePatternGeneratorChainField = GenLayerRiverMix.class.getDeclaredField("biomePatternGeneratorChain");
43
			biomePatternGeneratorChainField.setAccessible(true);
44
45
			// this is just an example, there are 4 biome arrays in the class, i am not 100% what they do
46
			biomeArrayField = GenLayerBiome.class.getDeclaredField("field_151621_d");
47
			biomeArrayField.setAccessible(true);
48
		} catch (NoSuchFieldException e) {
49
			Throwables.propagate(e);
50
		}
51
	}
52
53
	@SubscribeEvent
54
	public void onGenLayerInit(WorldTypeEvent.InitBiomeGens event) throws IllegalAccessException {
55
		GenLayer biomeLayer = event.originalBiomeGens[1];
56
		do {
57
			if (biomeLayer instanceof GenLayerRiverMix) {
58
				biomeLayer = (GenLayer) biomePatternGeneratorChainField.get(biomeLayer);
59
			} else {
60
				biomeLayer = MyModGenLayerAccessor.getParent(biomeLayer);
61
			}
62
		} while (biomeLayer != null && !(biomeLayer instanceof GenLayerBiome));
63
64
		if (biomeLayer == null) {
65
			throw new IllegalStateException("couldn't locate GenLayerBiome!");
66
		}
67
68
		BiomeGenBase[] biomes = (BiomeGenBase[]) biomeArrayField.get(biomeLayer);
69
		biomes = ObjectArrays.concat(biomes, myBiome);
70
		biomeArrayField.set(biomeLayer, biomes);
71
	}
72
73
}
74
75
package net.minecraft.world.gen.layer;
76
77
/**
78
 * @author diesieben07
79
 */
80
public final class MyModGenLayerAccessor {
81
82
	public static GenLayer getParent(GenLayer genLayer) {
83
		return genLayer.parent;
84
	}
85
86
}