Jump to content

[1.10.2] Biome Tutorial


Egietje

Recommended Posts

package com.Egietje.degeweldigemod.init;

import com.Egietje.degeweldigemod.biome.BiomeCheese;

import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biome.BiomeProperties;
import net.minecraftforge.common.BiomeManager;
import net.minecraftforge.common.BiomeManager.BiomeEntry;
import net.minecraftforge.common.BiomeManager.BiomeType;

public class CheeseBiomes {

public static Biome CHEESE_BIOME;

public CheeseBiomes() {
	initBiome();
	registerBiome();
}

public static void initBiome() {
	CHEESE_BIOME = new BiomeCheese(137, new BiomeProperties("Cheese"));
}

public static void registerBiome() {
	BiomeManager.addBiome(BiomeType.WARM, new BiomeEntry(CHEESE_BIOME, 3));
}

}

package com.Egietje.degeweldigemod.biome;

import java.util.Random;

import com.Egietje.degeweldigemod.entities.cheesecow.EntityCheeseCow;
import com.Egietje.degeweldigemod.init.CheeseBlocks;

import net.minecraft.block.BlockDoublePlant;
import net.minecraft.block.BlockFlower;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.init.Biomes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.feature.WorldGenAbstractTree;

public class BiomeCheese extends Biome {

public BiomeCheese(int par1, Biome.BiomeProperties properties) {
	super(properties);
	this.spawnableCreatureList.add(new Biome.SpawnListEntry(EntityCheeseCow.class, 8, 4, 4));
	this.theBiomeDecorator.treesPerChunk = 0;
	this.theBiomeDecorator.field_189870_A = 0.05F;
	this.theBiomeDecorator.flowersPerChunk = 4;
	this.theBiomeDecorator.grassPerChunk = 10;
	this.topBlock = CheeseBlocks.CHEESE_BLOCK.getDefaultState();

}

public BlockFlower.EnumFlowerType pickRandomFlower(Random rand, BlockPos pos) {
	double d0 = GRASS_COLOR_NOISE.getValue((double) pos.getX() / 200.0D, (double) pos.getZ() / 200.0D);

	if (d0 < -0.8D) {
		int j = rand.nextInt(4);

		switch (j) {
		case 0:
			return BlockFlower.EnumFlowerType.ORANGE_TULIP;
		case 1:
			return BlockFlower.EnumFlowerType.RED_TULIP;
		case 2:
			return BlockFlower.EnumFlowerType.PINK_TULIP;
		case 3:
		default:
			return BlockFlower.EnumFlowerType.WHITE_TULIP;
		}
	} else if (rand.nextInt(3) > 0) {
		int i = rand.nextInt(3);
		return i == 0 ? BlockFlower.EnumFlowerType.POPPY
				: (i == 1 ? BlockFlower.EnumFlowerType.HOUSTONIA : BlockFlower.EnumFlowerType.OXEYE_DAISY);
	} else {
		return BlockFlower.EnumFlowerType.DANDELION;
	}
}

public void decorate(World worldIn, Random rand, BlockPos pos) {
	double d0 = GRASS_COLOR_NOISE.getValue((double) (pos.getX() +  / 200.0D, (double) (pos.getZ() +  / 200.0D);

	if (d0 < -0.8D) {
		this.theBiomeDecorator.flowersPerChunk = 15;
		this.theBiomeDecorator.grassPerChunk = 5;
	} else {
		this.theBiomeDecorator.flowersPerChunk = 4;
		this.theBiomeDecorator.grassPerChunk = 10;
		DOUBLE_PLANT_GENERATOR.setPlantType(BlockDoublePlant.EnumPlantType.GRASS);

		for (int i = 0; i < 7; ++i) {
			int j = rand.nextInt(16) + 8;
			int k = rand.nextInt(16) + 8;
			int l = rand.nextInt(worldIn.getHeight(pos.add(j, 0, k)).getY() + 32);
			DOUBLE_PLANT_GENERATOR.generate(worldIn, rand, pos.add(j, l, k));
		}
	}

	super.decorate(worldIn, rand, pos);
}

@Override
public void addDefaultFlowers() {
	BlockFlower red = net.minecraft.init.Blocks.RED_FLOWER;
	BlockFlower yel = net.minecraft.init.Blocks.YELLOW_FLOWER;
	addFlower(red.getDefaultState().withProperty(red.getTypeProperty(), BlockFlower.EnumFlowerType.ORANGE_TULIP),
			3);
	addFlower(red.getDefaultState().withProperty(red.getTypeProperty(), BlockFlower.EnumFlowerType.RED_TULIP), 3);
	addFlower(red.getDefaultState().withProperty(red.getTypeProperty(), BlockFlower.EnumFlowerType.PINK_TULIP), 3);
	addFlower(red.getDefaultState().withProperty(red.getTypeProperty(), BlockFlower.EnumFlowerType.WHITE_TULIP), 3);
	addFlower(red.getDefaultState().withProperty(red.getTypeProperty(), BlockFlower.EnumFlowerType.POPPY), 20);
	addFlower(red.getDefaultState().withProperty(red.getTypeProperty(), BlockFlower.EnumFlowerType.HOUSTONIA), 20);
	addFlower(red.getDefaultState().withProperty(red.getTypeProperty(), BlockFlower.EnumFlowerType.OXEYE_DAISY),
			20);
	addFlower(yel.getDefaultState().withProperty(yel.getTypeProperty(), BlockFlower.EnumFlowerType.DANDELION), 30);
}

public WorldGenAbstractTree genBigTreeChance(Random rand) {
	return (WorldGenAbstractTree) (rand.nextInt(3) == 0 ? BIG_TREE_FEATURE : TREE_FEATURE);
}
}

package com.Egietje.degeweldigemod;

import com.Egietje.degeweldigemod.biome.WorldTypeCheese;
import com.Egietje.degeweldigemod.entities.*;
import com.Egietje.degeweldigemod.handler.*;
import com.Egietje.degeweldigemod.init.*;
import com.Egietje.degeweldigemod.proxy.*;

import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntitySpawnPlacementRegistry;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.init.Biomes;
import net.minecraft.world.WorldType;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, acceptedMinecraftVersions = "[1.10.2]")
public class DeGeweldigeMod {
public static final CheeseTab tabCheeseStuff = new CheeseTab("tabCheeseStuff");

@SidedProxy(clientSide = Reference.CLIENTPROXY, serverSide = Reference.COMMONPROXY)
public static CommonProxy proxy;

@Instance(Reference.MODID)
public static DeGeweldigeMod DGMInstance;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
	new CheeseBlocks();
	new CheeseItems();
	new CheeseMobs();
	new CheeseAchievements();
	new CheeseSpawnPlacementRegistry();
	new CheeseBiomes();
	proxy.registerModels();
	proxy.renderEntities();
}

@EventHandler
public static void init(FMLInitializationEvent event) {
	new CheeseCraftingAndSmelting();

	proxy.registerEventHandler();
	NetworkRegistry.INSTANCE.registerGuiHandler(DGMInstance, new CheeseGuiHandler());

	GameRegistry.registerWorldGenerator(new CheeseGeneration(), 0);
}

@EventHandler
public static void postInit(FMLPostInitializationEvent event) {
	WorldType CHEESE = new WorldTypeCheese(4, "Cheese");
}
}

Link to comment
Share on other sites

package com.Egietje.degeweldigemod.biome;

import com.Egietje.degeweldigemod.init.CheeseBiomes;

import net.minecraft.init.Biomes;
import net.minecraft.world.WorldType;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.ChunkProviderSettings;
import net.minecraft.world.gen.layer.GenLayer;
import net.minecraft.world.gen.layer.IntCache;

public class CheeseGenLayerBiome extends GenLayer {
@SuppressWarnings("unchecked")
private java.util.List<net.minecraftforge.common.BiomeManager.BiomeEntry>[] biomes = new java.util.ArrayList[net.minecraftforge.common.BiomeManager.BiomeType
		.values().length];
private final ChunkProviderSettings settings;

public CheeseGenLayerBiome(long p_i45560_1_, GenLayer p_i45560_3_, WorldType p_i45560_4_, String p_i45560_5_) {
	super(p_i45560_1_);
	this.parent = p_i45560_3_;

	for (net.minecraftforge.common.BiomeManager.BiomeType type : net.minecraftforge.common.BiomeManager.BiomeType
			.values()) {
		com.google.common.collect.ImmutableList<net.minecraftforge.common.BiomeManager.BiomeEntry> biomesToAdd = net.minecraftforge.common.BiomeManager
				.getBiomes(type);
		int idx = type.ordinal();

		if (biomes[idx] == null)
			biomes[idx] = new java.util.ArrayList<net.minecraftforge.common.BiomeManager.BiomeEntry>();
		if (biomesToAdd != null)
			biomes[idx].addAll(biomesToAdd);
	}

	int desertIdx = net.minecraftforge.common.BiomeManager.BiomeType.DESERT.ordinal();

	biomes[desertIdx].add(new net.minecraftforge.common.BiomeManager.BiomeEntry(Biomes.DESERT, 30));
	biomes[desertIdx].add(new net.minecraftforge.common.BiomeManager.BiomeEntry(Biomes.SAVANNA, 20));
	biomes[desertIdx].add(new net.minecraftforge.common.BiomeManager.BiomeEntry(Biomes.PLAINS, 10));
	biomes[desertIdx].add(new net.minecraftforge.common.BiomeManager.BiomeEntry(CheeseBiomes.CHEESE_BIOME, 40));

	if (p_i45560_4_ == WorldType.DEFAULT_1_1) {
		biomes[desertIdx].clear();
		biomes[desertIdx].add(new net.minecraftforge.common.BiomeManager.BiomeEntry(Biomes.DESERT, 10));
		biomes[desertIdx].add(new net.minecraftforge.common.BiomeManager.BiomeEntry(Biomes.FOREST, 10));
		biomes[desertIdx].add(new net.minecraftforge.common.BiomeManager.BiomeEntry(Biomes.EXTREME_HILLS, 10));
		biomes[desertIdx].add(new net.minecraftforge.common.BiomeManager.BiomeEntry(Biomes.SWAMPLAND, 10));
		biomes[desertIdx].add(new net.minecraftforge.common.BiomeManager.BiomeEntry(Biomes.PLAINS, 10));
		biomes[desertIdx].add(new net.minecraftforge.common.BiomeManager.BiomeEntry(Biomes.TAIGA, 10));
		biomes[desertIdx].add(new net.minecraftforge.common.BiomeManager.BiomeEntry(CheeseBiomes.CHEESE_BIOME, 15));
		this.settings = null;
	} else if (p_i45560_4_ == WorldType.CUSTOMIZED) {
		this.settings = ChunkProviderSettings.Factory.jsonToFactory(p_i45560_5_).build();
	} else {
		this.settings = null;
	}
}

/**
 * Returns a list of integer values generated by this layer. These may be
 * interpreted as temperatures, rainfall amounts, or biomeList[] indices
 * based on the particular GenLayer subclass.
 */
public int[] getInts(int areaX, int areaY, int areaWidth, int areaHeight) {
	int[] aint = this.parent.getInts(areaX, areaY, areaWidth, areaHeight);
	int[] aint1 = IntCache.getIntCache(areaWidth * areaHeight);

	for (int i = 0; i < areaHeight; ++i) {
		for (int j = 0; j < areaWidth; ++j) {
			this.initChunkSeed((long) (j + areaX), (long) (i + areaY));
			int k = aint[j + i * areaWidth];
			int l = (k & 3840) >> 8;
			k = k & -3841;

			if (this.settings != null && this.settings.fixedBiome >= 0) {
				aint1[j + i * areaWidth] = this.settings.fixedBiome;
			} else if (isBiomeOceanic(k)) {
				aint1[j + i * areaWidth] = k;
			} else if (k == Biome.getIdForBiome(Biomes.MUSHROOM_ISLAND)) {
				aint1[j + i * areaWidth] = k;
			} else if (k == 1) {
				if (l > 0) {
					if (this.nextInt(3) == 0) {
						aint1[j + i * areaWidth] = Biome.getIdForBiome(Biomes.MESA_CLEAR_ROCK);
					} else {
						aint1[j + i * areaWidth] = Biome.getIdForBiome(Biomes.MESA_ROCK);
					}
				} else {
					aint1[j + i * areaWidth] = Biome.getIdForBiome(
							getWeightedBiomeEntry(net.minecraftforge.common.BiomeManager.BiomeType.DESERT).biome);
				}
			} else if (k == 2) {
				if (l > 0) {
					aint1[j + i * areaWidth] = Biome.getIdForBiome(Biomes.JUNGLE);
				} else {
					aint1[j + i * areaWidth] = Biome.getIdForBiome(
							getWeightedBiomeEntry(net.minecraftforge.common.BiomeManager.BiomeType.WARM).biome);
				}
			} else if (k == 3) {
				if (l > 0) {
					aint1[j + i * areaWidth] = Biome.getIdForBiome(Biomes.REDWOOD_TAIGA);
				} else {
					aint1[j + i * areaWidth] = Biome.getIdForBiome(
							getWeightedBiomeEntry(net.minecraftforge.common.BiomeManager.BiomeType.COOL).biome);
				}
			} else if (k == 4) {
				aint1[j + i * areaWidth] = Biome.getIdForBiome(
						getWeightedBiomeEntry(net.minecraftforge.common.BiomeManager.BiomeType.ICY).biome);
			} else {
				aint1[j + i * areaWidth] = Biome.getIdForBiome(Biomes.MUSHROOM_ISLAND);
			}
		}
	}

	return aint1;
}

protected net.minecraftforge.common.BiomeManager.BiomeEntry getWeightedBiomeEntry(
		net.minecraftforge.common.BiomeManager.BiomeType type) {
	java.util.List<net.minecraftforge.common.BiomeManager.BiomeEntry> biomeList = biomes[type.ordinal()];
	int totalWeight = net.minecraft.util.WeightedRandom.getTotalWeight(biomeList);
	int weight = net.minecraftforge.common.BiomeManager.isTypeListModded(type) ? nextInt(totalWeight)
			: nextInt(totalWeight / 10) * 10;
	return (net.minecraftforge.common.BiomeManager.BiomeEntry) net.minecraft.util.WeightedRandom
			.getRandomItem(biomeList, weight);
}
}

package com.Egietje.degeweldigemod.biome;

import net.minecraft.world.WorldType;
import net.minecraft.world.gen.layer.GenLayer;
import net.minecraft.world.gen.layer.GenLayerBiome;
import net.minecraft.world.gen.layer.GenLayerBiomeEdge;
import net.minecraft.world.gen.layer.GenLayerZoom;

public class WorldTypeCheese extends WorldType {

public WorldTypeCheese(int par1, String name) {
	super(name);
}

public GenLayer getBiomeLayer(long worldSeed, GenLayer parentLayer, String chunkProviderSettingsJson)
    {
        GenLayer ret = new CheeseGenLayerBiome(200L, parentLayer, this, chunkProviderSettingsJson);
        ret = GenLayerZoom.magnify(1000L, ret, 2);
        ret = new GenLayerBiomeEdge(1000L, ret);
        return ret;
    }

}

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.