Code cleanup

This commit is contained in:
LemADEC 2015-12-06 19:57:36 +01:00
parent a532b3acd7
commit 603a904dfd

View file

@ -6,22 +6,19 @@ import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
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.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraftforge.oredict.ShapedOreRecipe;
import cpw.mods.fml.common.registry.GameRegistry;
import cr0s.warpdrive.WarpDrive;
public class BlockDecorative extends Block {
public static enum decorativeTypes {
Plain, Energized, Network
};
private ItemStack[] isCache = new ItemStack[decorativeTypes.values().length];
private IIcon[] iconBuffer = new IIcon[decorativeTypes.values().length];
private static ItemStack[] isCache = new ItemStack[decorativeTypes.values().length];
private static IIcon[] iconBuffer = new IIcon[decorativeTypes.values().length];
public BlockDecorative() {
super(Material.iron);
setHardness(0.5f);
@ -29,59 +26,54 @@ public class BlockDecorative extends Block {
setCreativeTab(WarpDrive.creativeTabWarpDrive);
setBlockName("warpdrive.passive.Plain");
}
private boolean isValidDamage(final int damage) {
private static boolean isValidDamage(final int damage) {
return damage >= 0 && damage < decorativeTypes.values().length;
}
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
for (decorativeTypes val : decorativeTypes.values())
for (decorativeTypes val : decorativeTypes.values()) {
par3List.add(new ItemStack(par1, 1, val.ordinal()));
}
}
@Override
public void registerBlockIcons(IIconRegister ir) {
for (decorativeTypes val : decorativeTypes.values())
for (decorativeTypes val : decorativeTypes.values()) {
iconBuffer[val.ordinal()] = ir.registerIcon("warpdrive:passive/decorative" + val.toString());
}
}
@Override
public IIcon getIcon(int side, int damage) {
if (isValidDamage(damage))
if (isValidDamage(damage)) {
return iconBuffer[damage];
}
return iconBuffer[0];
}
@Override
public int damageDropped(int damage) {
return damage;
}
public ItemStack getItemStack(int damage) {
if (!isValidDamage(damage))
public static ItemStack getItemStack(int damage) {
if (!isValidDamage(damage)) {
return null;
if (isCache[damage] == null)
isCache[damage] = getItemStackNoCache(damage);
}
if (isCache[damage] == null) {
isCache[damage] = getItemStackNoCache(damage, 1);
}
return isCache[damage];
}
public ItemStack getItemStackNoCache(int damage, int amount) {
if (!isValidDamage(damage))
public static ItemStack getItemStackNoCache(int damage, int amount) {
if (!isValidDamage(damage)) {
return null;
}
return new ItemStack(WarpDrive.blockDecorative, amount, damage);
}
public ItemStack getItemStackNoCache(int damage) {
return getItemStackNoCache(damage, 1);
}
public void initRecipes() {
GameRegistry.addRecipe(new ShapedOreRecipe(getItemStackNoCache(0, 8), false, "sss", "scs", "sss", 's', Blocks.stone, 'c', WarpDrive.itemComponent.getItemStack(0)));
GameRegistry.addRecipe(new ShapedOreRecipe(getItemStackNoCache(2, 8), false, "sss", "scs", "sss", 's', getItemStack(0), 'c', WarpDrive.itemComponent.getItemStack(5)));
}
}