TechReborn/src/main/java/techreborn/items/ItemIngots.java

90 lines
3.2 KiB
Java
Raw Normal View History

/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2017 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
2015-04-11 21:46:55 +02:00
package techreborn.items;
import com.google.common.base.CaseFormat;
2015-04-11 21:46:55 +02:00
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
2015-04-11 21:46:55 +02:00
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
2016-11-25 14:23:42 +01:00
import net.minecraft.util.NonNullList;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.init.ModItems;
2015-04-15 17:23:12 +02:00
import java.security.InvalidParameterException;
2016-12-10 09:15:39 +01:00
public class ItemIngots extends ItemTRNoDestroy {
public static final String[] types = new String[] { "aluminum", "brass", "bronze", "chrome", "copper", "electrum",
2016-10-08 21:46:16 +02:00
"invar", "iridium", "lead", "nickel", "platinum", "silver", "steel", "tin", "titanium", "tungsten",
2016-12-10 09:15:39 +01:00
"hot_tungstensteel", "tungstensteel", "zinc", "refined_iron", "advanced_alloy", "mixed_metal",
"iridium_alloy" };
2015-04-15 17:23:12 +02:00
2016-10-08 21:46:16 +02:00
public ItemIngots() {
2016-03-25 10:47:34 +01:00
setCreativeTab(TechRebornCreativeTabMisc.instance);
setHasSubtypes(true);
setUnlocalizedName("techreborn.ingot");
}
2015-04-15 17:23:12 +02:00
2016-10-08 21:46:16 +02:00
public static ItemStack getIngotByName(String name, int count) {
name = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name);
2016-10-08 21:46:16 +02:00
for (int i = 0; i < types.length; i++) {
if (types[i].equalsIgnoreCase(name)) {
return new ItemStack(ModItems.INGOTS, count, i);
2016-03-25 10:47:34 +01:00
}
}
if (name.equalsIgnoreCase("iron")) {
return new ItemStack(Items.IRON_INGOT);
}
if (name.equalsIgnoreCase("gold")) {
return new ItemStack(Items.GOLD_INGOT);
}
2016-03-25 10:47:34 +01:00
throw new InvalidParameterException("The ingot " + name + " could not be found.");
}
2015-04-11 21:46:55 +02:00
2016-10-08 21:46:16 +02:00
public static ItemStack getIngotByName(String name) {
2016-03-25 10:47:34 +01:00
return getIngotByName(name, 1);
}
2015-04-11 21:46:55 +02:00
2016-03-25 10:47:34 +01:00
@Override
// gets Unlocalized Name depending on meta data
2016-10-08 21:46:16 +02:00
public String getUnlocalizedName(ItemStack itemStack) {
2016-03-25 10:47:34 +01:00
int meta = itemStack.getItemDamage();
2016-10-08 21:46:16 +02:00
if (meta < 0 || meta >= types.length) {
2016-03-25 10:47:34 +01:00
meta = 0;
}
2016-03-25 10:47:34 +01:00
return super.getUnlocalizedName() + "." + types[meta];
}
2016-03-25 10:47:34 +01:00
// Adds Dusts SubItems To Creative Tab
2016-11-25 14:23:42 +01:00
public void getSubItems(Item item, CreativeTabs creativeTabs, NonNullList list) {
2016-10-08 21:46:16 +02:00
for (int meta = 0; meta < types.length; ++meta) {
if (!types[meta].equals(ModItems.META_PLACEHOLDER)) {
2016-05-30 14:18:43 +02:00
list.add(new ItemStack(item, 1, meta));
}
2016-03-25 10:47:34 +01:00
}
}
2015-04-11 21:46:55 +02:00
}