aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/bop/blocks/base/LeavesBase.java
blob: 5c86c45591035513420ad9d6dce466fb340691e6 (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
package gtPlusPlus.xmod.bop.blocks.base;

import java.util.List;
import java.util.Random;

import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.block.BlockLeaves;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;

import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.creative.AddToCreativeTab;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.minecraft.ItemUtils;

public class LeavesBase extends BlockLeaves {

	protected IIcon[][] leafTextures = new IIcon[2][];
	protected String[][] leafType = new String[][] {{}, {}};
	protected String[] treeType = new String[] {};
	protected ItemStack[] bonusDrops;

	@SuppressWarnings("deprecation")
	public LeavesBase(String blockNameLocalized, String blockNameUnlocalized, ItemStack[] bonusDrops){
		this.bonusDrops = bonusDrops;
		String blockName = "block"+Utils.sanitizeString(blockNameLocalized)+"Leaves";
		GameRegistry.registerBlock(this, ItemBlock.class, blockName);
		this.setBlockName(blockName);
		ItemUtils.addItemToOreDictionary(ItemUtils.getSimpleStack(this), "treeLeaves", true);
		this.setCreativeTab(AddToCreativeTab.tabBOP);
		LanguageRegistry.addName(this, blockNameLocalized+" Leaves");
		Blocks.fire.setFireInfo(this, 80, 150);
	}

	private final void setVanillaVariable(Object toSet, Object value){
		toSet = value;
	}

	@Override
	public int quantityDropped(Random p_149745_1_){
		return p_149745_1_.nextInt(20) == 0 ? 1 : 0;
	}


	@Override//Drops when Leaf is broken
	protected void func_150124_c(World world, int x, int y, int z, int meta, int randomChance){
		Logger.INFO("Dropping Bonus Drops");
		for (int i = 0; i < this.bonusDrops.length; ++i){
			if (this.bonusDrops[i] != null && world.rand.nextInt(randomChance) == 0){
				this.dropBlockAsItem(world, x, y, z, ItemUtils.getSimpleStack(this.bonusDrops[i], 1));
			}
		}
	}

	/**
	 * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
	 */
	@SuppressWarnings("unchecked")
	@Override
	@SideOnly(Side.CLIENT)
	public void getSubBlocks(Item item, CreativeTabs tab, @SuppressWarnings("rawtypes") List metaList){
		for (int i = 0; i < this.treeType.length; ++i){
			metaList.add(new ItemStack(item, 1, i));
		}
	}

	/**
	 * Gets the block's texture. Args: side, meta
	 */
	@Override
	@SideOnly(Side.CLIENT)
	public IIcon getIcon(int p_149691_1_, int metaID){    	
		return (metaID & 3) == 1 ? this.leafTextures[this.field_150127_b][1] : this.leafTextures[this.field_150127_b][0];
	}

	@Override
	public boolean isOpaqueCube() {
		return false;
	}

	@Override
	@SideOnly(Side.CLIENT)
	public void registerBlockIcons(IIconRegister iIcon){
		for (int i = 0; i < leafType.length; ++i){
			this.leafTextures[i] = new IIcon[leafType[i].length];
			for (int j = 0; j < leafType[i].length; ++j){
				this.leafTextures[i][j] = iIcon.registerIcon(CORE.MODID + ":" + "trees/" + "leaves/" + "leaves_" + leafType[i][j]);
			}
		}
		setVanillaVariable(this.field_150129_M, this.leafTextures);
	}

	@Override
	public String[] func_150125_e()
	{
		return treeType;
	}
}