Rewrite ores

This commit is contained in:
modmuss50 2016-05-16 15:48:48 +01:00
parent 3fb1e4ceb8
commit 4c5cf82db4
5 changed files with 118 additions and 94 deletions

View file

@ -1,8 +1,8 @@
package techreborn.blocks; package techreborn.blocks;
import com.google.common.collect.Lists;
import me.modmuss50.jsonDestroyer.api.ITexturedBlock; import me.modmuss50.jsonDestroyer.api.ITexturedBlock;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
@ -18,8 +18,11 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import reborncore.common.BaseBlock; import reborncore.common.BaseBlock;
import reborncore.common.blocks.PropertyString;
import reborncore.common.util.ArrayUtils;
import reborncore.common.util.OreDrop; import reborncore.common.util.OreDrop;
import reborncore.common.util.OreDropSet; import reborncore.common.util.OreDropSet;
import reborncore.common.util.StringUtils;
import techreborn.client.TechRebornCreativeTabMisc; import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.config.ConfigTechReborn; import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks; import techreborn.init.ModBlocks;
@ -34,10 +37,11 @@ import java.util.Random;
public class BlockOre extends BaseBlock implements ITexturedBlock, IOreNameProvider public class BlockOre extends BaseBlock implements ITexturedBlock, IOreNameProvider
{ {
public static final String[] types = new String[] { "Galena", "Iridium", "Ruby", "Sapphire", "Bauxite", "Pyrite", public static final String[] ores = new String[] { "galena", "iridium", "ruby", "sapphire", "bauxite", "pyrite",
"Cinnabar", "Sphalerite", "Tungston", "Sheldonite", "Peridot", "Sodalite", "cinnabar", "sphalerite", "tungston", "sheldonite", "peridot", "sodalite",
"Lead", "Silver" }; "lead", "silver" };
public PropertyInteger METADATA; static List<String> oreNamesList = Lists.newArrayList(ArrayUtils.arrayToLowercase(ores));
public PropertyString VARIANTS = new PropertyString("type", oreNamesList);
public BlockOre(Material material) public BlockOre(Material material)
{ {
@ -46,14 +50,14 @@ public class BlockOre extends BaseBlock implements ITexturedBlock, IOreNameProvi
setCreativeTab(TechRebornCreativeTabMisc.instance); setCreativeTab(TechRebornCreativeTabMisc.instance);
setHardness(2.0f); setHardness(2.0f);
setHarvestLevel("pickaxe", 2); setHarvestLevel("pickaxe", 2);
this.setDefaultState(this.getDefaultState().withProperty(METADATA, 0)); this.setDefaultState(this.getStateFromMeta(0));
} }
public static ItemStack getOreByName(String name, int count) public static ItemStack getOreByName(String name, int count)
{ {
for (int i = 0; i < types.length; i++) for (int i = 0; i < ores.length; i++)
{ {
if (types[i].equalsIgnoreCase(name)) if (ores[i].equalsIgnoreCase(name))
{ {
return new ItemStack(ModBlocks.ore, count, i); return new ItemStack(ModBlocks.ore, count, i);
} }
@ -69,9 +73,9 @@ public class BlockOre extends BaseBlock implements ITexturedBlock, IOreNameProvi
public IBlockState getBlockStateFromName(String name) public IBlockState getBlockStateFromName(String name)
{ {
int index = -1; int index = -1;
for (int i = 0; i < types.length; i++) for (int i = 0; i < ores.length; i++)
{ {
if (types[i].equalsIgnoreCase(name)) if (ores[i].equalsIgnoreCase(name))
{ {
index = i; index = i;
break; break;
@ -87,10 +91,11 @@ public class BlockOre extends BaseBlock implements ITexturedBlock, IOreNameProvi
@Deprecated @Deprecated
public ArrayList<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) public ArrayList<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{ {
int metadata = getMetaFromState(state); String variant = state.getValue(VARIANTS);
int meta = getMetaFromState(state);
Random random = new Random(); Random random = new Random();
// Ruby // Ruby
if (metadata == 2) if (variant.equals("Ruby"))
{ {
OreDrop ruby = new OreDrop(ItemGems.getGemByName("ruby"), OreDrop ruby = new OreDrop(ItemGems.getGemByName("ruby"),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel); ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
@ -100,7 +105,7 @@ public class BlockOre extends BaseBlock implements ITexturedBlock, IOreNameProvi
} }
// Sapphire // Sapphire
if (metadata == 3) if (variant.equals("Sapphire"))
{ {
OreDrop sapphire = new OreDrop(ItemGems.getGemByName("sapphire"), OreDrop sapphire = new OreDrop(ItemGems.getGemByName("sapphire"),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel); ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
@ -110,7 +115,7 @@ public class BlockOre extends BaseBlock implements ITexturedBlock, IOreNameProvi
} }
// Pyrite // Pyrite
if (metadata == 5) if (variant.equals("Pyrite"))
{ {
OreDrop pyriteDust = new OreDrop(ItemDusts.getDustByName("pyrite"), OreDrop pyriteDust = new OreDrop(ItemDusts.getDustByName("pyrite"),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel); ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
@ -119,7 +124,7 @@ public class BlockOre extends BaseBlock implements ITexturedBlock, IOreNameProvi
} }
// Sodalite // Sodalite
if (metadata == 11) if (variant.equals("Sodalite"))
{ {
OreDrop sodalite = new OreDrop(ItemDusts.getDustByName("sodalite", 6), OreDrop sodalite = new OreDrop(ItemDusts.getDustByName("sodalite", 6),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel); ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
@ -129,7 +134,7 @@ public class BlockOre extends BaseBlock implements ITexturedBlock, IOreNameProvi
} }
// Cinnabar // Cinnabar
if (metadata == 6) if (variant.equals("Cinnabar"))
{ {
OreDrop cinnabar = new OreDrop(ItemDusts.getDustByName("cinnabar"), OreDrop cinnabar = new OreDrop(ItemDusts.getDustByName("cinnabar"),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel); ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
@ -139,7 +144,7 @@ public class BlockOre extends BaseBlock implements ITexturedBlock, IOreNameProvi
} }
// Sphalerite 1, 1/8 yellow garnet // Sphalerite 1, 1/8 yellow garnet
if (metadata == 7) if (variant.equals("Sphalerite"))
{ {
OreDrop sphalerite = new OreDrop(ItemDusts.getDustByName("sphalerite"), OreDrop sphalerite = new OreDrop(ItemDusts.getDustByName("sphalerite"),
ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel); ConfigTechReborn.FortuneSecondaryOreMultiplierPerLevel);
@ -149,7 +154,7 @@ public class BlockOre extends BaseBlock implements ITexturedBlock, IOreNameProvi
} }
ArrayList<ItemStack> block = new ArrayList<>(); ArrayList<ItemStack> block = new ArrayList<>();
block.add(new ItemStack(Item.getItemFromBlock(this), 1, metadata)); block.add(new ItemStack(Item.getItemFromBlock(this), 1, meta));
return block; return block;
} }
@ -163,7 +168,7 @@ public class BlockOre extends BaseBlock implements ITexturedBlock, IOreNameProvi
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list) public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list)
{ {
for (int meta = 0; meta < types.length; meta++) for (int meta = 0; meta < ores.length; meta++)
{ {
list.add(new ItemStack(item, 1, meta)); list.add(new ItemStack(item, 1, meta));
} }
@ -176,57 +181,59 @@ public class BlockOre extends BaseBlock implements ITexturedBlock, IOreNameProvi
return new ItemStack(this,1, getMetaFromState(state)); return new ItemStack(this,1, getMetaFromState(state));
} }
@Override // @Override
public int damageDropped(IBlockState state) // public int damageDropped(IBlockState state)
{ // {
int meta = getMetaFromState(state); // int meta = getMetaFromState(state);
if (meta == 2) // if (meta == 2)
{ // {
return 0; // return 0;
} else if (meta == 3) // } else if (meta == 3)
{ // {
return 1; // return 1;
} else if (meta == 5) // } else if (meta == 5)
{ // {
return 60; // return 60;
} // }
return meta; // return meta;
} // }
@Override @Override
public String getTextureNameFromState(IBlockState BlockStateContainer, EnumFacing facing) public String getTextureNameFromState(IBlockState BlockStateContainer, EnumFacing facing)
{ {
return "techreborn:blocks/ore/ore" + types[getMetaFromState(BlockStateContainer)]; return "techreborn:blocks/ore/ore" + StringUtils.toFirstCapital(ores[getMetaFromState(BlockStateContainer)]);
} }
@Override @Override
public int amountOfStates() public int amountOfStates()
{ {
return types.length; return ores.length;
} }
@Override @Override
public IBlockState getStateFromMeta(int meta) public int damageDropped(IBlockState state) {
{ return getMetaFromState(state);
return this.getDefaultState().withProperty(METADATA, meta);
} }
@Override @Override
public int getMetaFromState(IBlockState state) public IBlockState getStateFromMeta(int meta) {
{ return getBlockState().getBaseState().withProperty(VARIANTS, oreNamesList.get(meta));
return state.getValue(METADATA); }
@Override
public int getMetaFromState(IBlockState state) {
return oreNamesList.indexOf(state.getValue(VARIANTS));
} }
protected BlockStateContainer createBlockState() protected BlockStateContainer createBlockState()
{ {
VARIANTS = new PropertyString("type", oreNamesList);
METADATA = PropertyInteger.create("type", 0, types.length - 1); return new BlockStateContainer(this, VARIANTS);
return new BlockStateContainer(this, METADATA);
} }
@Override @Override
public String getUserLoclisedName(IBlockState state) public String getUserLoclisedName(IBlockState state)
{ {
return types[state.getValue(METADATA)]; return StringUtils.toFirstCapital(oreNamesList.get(getMetaFromState(state)));
} }
} }

View file

@ -3,6 +3,7 @@ package techreborn.blocks;
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
import java.util.List; import java.util.List;
import com.google.common.collect.Lists;
import me.modmuss50.jsonDestroyer.api.ITexturedBlock; import me.modmuss50.jsonDestroyer.api.ITexturedBlock;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.properties.PropertyInteger;
@ -19,6 +20,9 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import reborncore.common.BaseBlock; import reborncore.common.BaseBlock;
import reborncore.common.blocks.PropertyString;
import reborncore.common.util.ArrayUtils;
import reborncore.common.util.StringUtils;
import techreborn.client.TechRebornCreativeTabMisc; import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.init.ModBlocks; import techreborn.init.ModBlocks;
import techreborn.world.config.IOreNameProvider; import techreborn.world.config.IOreNameProvider;
@ -26,8 +30,9 @@ import techreborn.world.config.IOreNameProvider;
public class BlockOre2 extends BaseBlock implements ITexturedBlock, IOreNameProvider public class BlockOre2 extends BaseBlock implements ITexturedBlock, IOreNameProvider
{ {
public static final String[] types = new String[] { "Copper", "Tin" }; public static final String[] ores = new String[] { "copper", "tin"};
public PropertyInteger METADATA; static List<String> oreNamesList = Lists.newArrayList(ArrayUtils.arrayToLowercase(ores));
public PropertyString VARIANTS = new PropertyString("type", oreNamesList);
public BlockOre2(Material material) public BlockOre2(Material material)
{ {
@ -36,14 +41,14 @@ public class BlockOre2 extends BaseBlock implements ITexturedBlock, IOreNameProv
setCreativeTab(TechRebornCreativeTabMisc.instance); setCreativeTab(TechRebornCreativeTabMisc.instance);
setHardness(2.0f); setHardness(2.0f);
setHarvestLevel("pickaxe", 1); setHarvestLevel("pickaxe", 1);
this.setDefaultState(this.blockState.getBaseState().withProperty(METADATA, 0)); this.setDefaultState(this.getStateFromMeta(0));
} }
public static ItemStack getOreByName(String name, int count) public static ItemStack getOreByName(String name, int count)
{ {
for (int i = 0; i < types.length; i++) for (int i = 0; i < ores.length; i++)
{ {
if (types[i].equalsIgnoreCase(name)) if (ores[i].equalsIgnoreCase(name))
{ {
return new ItemStack(ModBlocks.ore2, count, i); return new ItemStack(ModBlocks.ore2, count, i);
} }
@ -59,9 +64,9 @@ public class BlockOre2 extends BaseBlock implements ITexturedBlock, IOreNameProv
public IBlockState getBlockStateFromName(String name) public IBlockState getBlockStateFromName(String name)
{ {
int index = -1; int index = -1;
for (int i = 0; i < types.length; i++) for (int i = 0; i < ores.length; i++)
{ {
if (types[i].equalsIgnoreCase(name)) if (ores[i].equalsIgnoreCase(name))
{ {
index = i; index = i;
break; break;
@ -69,7 +74,7 @@ public class BlockOre2 extends BaseBlock implements ITexturedBlock, IOreNameProv
} }
if (index == -1) if (index == -1)
{ {
throw new InvalidParameterException("The ore block " + name + " could not be found."); return ModBlocks.ore2.getBlockStateFromName(name);
} }
return getStateFromMeta(index); return getStateFromMeta(index);
} }
@ -84,7 +89,7 @@ public class BlockOre2 extends BaseBlock implements ITexturedBlock, IOreNameProv
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list) public void getSubBlocks(Item item, CreativeTabs creativeTabs, List list)
{ {
for (int meta = 0; meta < types.length; meta++) for (int meta = 0; meta < ores.length; meta++)
{ {
list.add(new ItemStack(item, 1, meta)); list.add(new ItemStack(item, 1, meta));
} }
@ -97,47 +102,59 @@ public class BlockOre2 extends BaseBlock implements ITexturedBlock, IOreNameProv
return new ItemStack(this,1, getMetaFromState(state)); return new ItemStack(this,1, getMetaFromState(state));
} }
@Override // @Override
public int damageDropped(IBlockState state) // public int damageDropped(IBlockState state)
{ // {
int meta = getMetaFromState(state); // int meta = getMetaFromState(state);
return meta; // if (meta == 2)
} // {
// return 0;
// } else if (meta == 3)
// {
// return 1;
// } else if (meta == 5)
// {
// return 60;
// }
// return meta;
// }
@Override @Override
public String getTextureNameFromState(IBlockState BlockStateContainer, EnumFacing facing) public String getTextureNameFromState(IBlockState BlockStateContainer, EnumFacing facing)
{ {
return "techreborn:blocks/ore/ore" + types[getMetaFromState(BlockStateContainer)]; return "techreborn:blocks/ore/ore" + StringUtils.toFirstCapital(ores[getMetaFromState(BlockStateContainer)]);
} }
@Override @Override
public int amountOfStates() public int amountOfStates()
{ {
return types.length; return ores.length;
} }
@Override @Override
public IBlockState getStateFromMeta(int meta) public int damageDropped(IBlockState state) {
{ return getMetaFromState(state);
return this.getDefaultState().withProperty(METADATA, meta);
} }
@Override @Override
public int getMetaFromState(IBlockState state) public IBlockState getStateFromMeta(int meta) {
{ return getBlockState().getBaseState().withProperty(VARIANTS, oreNamesList.get(meta));
return state.getValue(METADATA); }
@Override
public int getMetaFromState(IBlockState state) {
return oreNamesList.indexOf(state.getValue(VARIANTS));
} }
protected BlockStateContainer createBlockState() protected BlockStateContainer createBlockState()
{ {
VARIANTS = new PropertyString("type", oreNamesList);
METADATA = PropertyInteger.create("type", 0, types.length - 1); return new BlockStateContainer(this, VARIANTS);
return new BlockStateContainer(this, METADATA);
} }
@Override @Override
public String getUserLoclisedName(IBlockState state) public String getUserLoclisedName(IBlockState state)
{ {
return types[state.getValue(METADATA)]; return StringUtils.toFirstCapital(oreNamesList.get(getMetaFromState(state)));
} }
} }

View file

@ -10,7 +10,7 @@ public class ItemBlockOre extends ItemBlockBase
public ItemBlockOre(Block block) public ItemBlockOre(Block block)
{ {
super(ModBlocks.ore, ModBlocks.ore, BlockOre.types); super(ModBlocks.ore, ModBlocks.ore, BlockOre.ores);
} }
} }

View file

@ -10,7 +10,7 @@ public class ItemBlockOre2 extends ItemBlockBase
public ItemBlockOre2(Block block) public ItemBlockOre2(Block block)
{ {
super(ModBlocks.ore2, ModBlocks.ore2, BlockOre2.types); super(ModBlocks.ore2, ModBlocks.ore2, BlockOre2.ores);
} }
} }

View file

@ -63,8 +63,8 @@ tile.techreborn.electricfurnace.name=Electric Furnace
tile.techreborn.machineFrame.highlyAdvancedMachine.name=Highly Advanced Machine Block tile.techreborn.machineFrame.highlyAdvancedMachine.name=Highly Advanced Machine Block
tile.techreborn.machineFrame.advancedMachine.name=Advanced Machine Block tile.techreborn.machineFrame.advancedMachine.name=Advanced Machine Block
tile.techreborn.machineFrame.machine.name=Machine Block tile.techreborn.machineFrame.machine.name=Machine Block
tile.techreborn.ore2.Copper.name=Copper Ore tile.techreborn.ore2.copper.name=Copper Ore
tile.techreborn.ore2.Tin.name=Tin Ore tile.techreborn.ore2.tin.name=Tin Ore
tile.techreborn.storage2.copper.name=Copper Block tile.techreborn.storage2.copper.name=Copper Block
tile.techreborn.storage2.tin.name=Tin Block tile.techreborn.storage2.tin.name=Tin Block
tile.techreborn.solarpanel.name=Solar Panel tile.techreborn.solarpanel.name=Solar Panel
@ -92,22 +92,22 @@ tile.techreborn.rubbersapling.name=Rubber Sapling
tile.techreborn.ironfence.name=Iron Fence tile.techreborn.ironfence.name=Iron Fence
#Ores #Ores
tile.techreborn.ore.Galena.name=Galena Ore tile.techreborn.ore.galena.name=Galena Ore
tile.techreborn.ore.Iridium.name=Iridium Ore tile.techreborn.ore.iridium.name=Iridium Ore
tile.techreborn.ore.Ruby.name=Ruby Ore tile.techreborn.ore.ruby.name=Ruby Ore
tile.techreborn.ore.Sapphire.name=Sapphire Ore tile.techreborn.ore.sapphire.name=Sapphire Ore
tile.techreborn.ore.Bauxite.name=Bauxite Ore tile.techreborn.ore.bauxite.name=Bauxite Ore
tile.techreborn.ore.Pyrite.name=Pyrite Ore tile.techreborn.ore.pyrite.name=Pyrite Ore
tile.techreborn.ore.Cinnabar.name=Cinnabar Ore tile.techreborn.ore.cinnabar.name=Cinnabar Ore
tile.techreborn.ore.Sphalerite.name=Sphalerite Ore tile.techreborn.ore.sphalerite.name=Sphalerite Ore
tile.techreborn.ore.Tungston.name=Tungsten Ore tile.techreborn.ore.tungston.name=Tungsten Ore
tile.techreborn.ore.Sheldonite.name=Sheldonite Ore tile.techreborn.ore.sheldonite.name=Sheldonite Ore
tile.techreborn.ore.Peridot.name=Peridot Ore tile.techreborn.ore.peridot.name=Peridot Ore
tile.techreborn.ore.Sodalite.name=Sodalite Ore tile.techreborn.ore.sodalite.name=Sodalite Ore
tile.techreborn.ore.Tetrahedrite.name=Tetrahedrite Ore tile.techreborn.ore.tetrahedrite.name=Tetrahedrite Ore
tile.techreborn.ore.Cassiterite.name=Cassiterite Ore tile.techreborn.ore.cassiterite.name=Cassiterite Ore
tile.techreborn.ore.Lead.name=Lead Ore tile.techreborn.ore.lead.name=Lead Ore
tile.techreborn.ore.Silver.name=Silver Ore tile.techreborn.ore.silver.name=Silver Ore
#Storage #Storage
tile.techreborn.storage.silver.name=Block of Silver tile.techreborn.storage.silver.name=Block of Silver