summaryrefslogtreecommitdiff
path: root/src/main/java/ihl/worldgen/ores/BlockOre.java
blob: 00a8bcc73a5839723d844799302c6734ecc7172c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package ihl.worldgen.ores;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ihl.IHLCreativeTab;
import ihl.IHLModInfo;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;

public class BlockOre extends Block
{
	private Type type;
	private static List<BlockOre> instances = new ArrayList<BlockOre>();
	private static Map<Type, IIcon> iconMap = new HashMap<Type, IIcon>();

	public BlockOre(Type type1) 
	{
		super(Material.rock);
		this.type=type1;
		this.setCreativeTab(IHLCreativeTab.tab);
		this.setBlockName(type.unLocalizedName);
		instances.add(this);
		this.setHardness(2.0F).setResistance(4.0F);
	}
	
	public static void init()
	{
		Type[] var1 = Type.values();
		for(int i=0;i<var1.length;i++)
		{
			new BlockOre(var1[i]);
		}
		Iterator<BlockOre> ii = instances.iterator();
		while(ii.hasNext())
		{
			BlockOre instance = ii.next();
			GameRegistry.registerBlock(instance,instance.type.unLocalizedName);
			OreDictionary.registerOre(instance.type.unLocalizedName, instance);
		}
	}
	
	@Override
	public void	dropBlockAsItemWithChance(World world, int x, int y, int z, int meta, float chance, int flag)
	{
		super.dropBlockAsItemWithChance(world, x, y, z, meta, chance, flag);
		if(this.type.fortuneAffectsDrops)
		{
			this.dropXpOnBlockBreak(world, x, y, z, MathHelper.getRandomIntegerInRange(world.rand, 1, 4));
		}
	}

	@Override
	public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
		ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
		int fortmod = world.rand.nextInt(fortune + 2) - 1;
		if (fortmod < 0 || !type.fortuneAffectsDrops)fortmod = 0;
		ItemStack drop = null;
		int amount = 1;
		amount = (type.amountFrom + (type.amountTo>0?world.rand.nextInt(type.amountTo):0)) * (fortmod + 1);
		drop = OreDictionary.getOres(type.oreDrop).get(0);
		if (drop != null && amount > 0)
		{
			drop.stackSize=amount;
			drops.add(drop);
		}
		return drops;
	}


	public enum Type
	{
		Bischofite("oreBischofite", "dustBischofite",1,2),
		Datolite("oreDatolite", "dustDatolite",1,2),
		Stibnite("oreStibnite"),
		Chromite("oreChromite"),
		Muscovite("oreMica"),
		Bauxite("oreBauxite"),
		Cinnabar("oreCinnabar"),
		RockSalt("oreRockSalt", "dustRockSalt",1,2),
		Limestone("oreLimestone", "dustCalcite",1,2),
		Gypsum("oreGypsum"),
		Gyubnera("oreGyubnera"),//(Mn,Fe)WO4 Mn:Fe 5/1
		OreTrona("oreTrona", "dustTrona",1,2),
		PotassiumFeldspar("orePotassiumFeldspar"),
		Apatite("oreApatite", "gemApatite",2,5),
		Saltpeter("oreSaltpeter", "dustSaltpeter",1,2);
		Type(String unlocalizedName1, String oreDrop1, int amountFrom1, int amountTo1 )
		{
			unLocalizedName=unlocalizedName1;
			oreDrop=oreDrop1;
			amountFrom=amountFrom1;
			amountTo=amountTo1;
		}
		Type(String unlocalizedName1)
		{
			unLocalizedName=unlocalizedName1;
			oreDrop=unlocalizedName1;
			amountFrom=1;
			amountTo=0;
			fortuneAffectsDrops=false;
		}
		String unLocalizedName;
		String oreDrop;
		int amountFrom;
		int amountTo;
		boolean fortuneAffectsDrops=true;
	}
	

	@Override
	@SideOnly(Side.CLIENT)
	public void registerBlockIcons(IIconRegister register) 
	{
		iconMap.put(this.type, register.registerIcon(IHLModInfo.MODID + ":"+this.type.unLocalizedName));
	}

	@Override
	@SideOnly(Side.CLIENT)
	public IIcon getIcon(int i, int j) 
	{
		return iconMap.get(type);
	}
}