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

107 lines
3.7 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-05-04 22:52:08 +02:00
package techreborn.items;
2016-12-10 09:15:39 +01:00
import com.google.common.base.CaseFormat;
2015-05-04 22:52:08 +02:00
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
2016-11-25 14:23:42 +01:00
import net.minecraft.util.NonNullList;
import net.minecraftforge.oredict.OreDictionary;
2015-05-04 22:52:08 +02:00
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.events.TRRecipeHandler;
import techreborn.init.ModItems;
2015-05-04 22:52:08 +02:00
import java.security.InvalidParameterException;
2017-06-14 01:49:52 +02:00
public class ItemPlates extends ItemTR {
2016-03-25 10:47:34 +01:00
//Vanilla plates or plates not from ingots or gems
public static String[] types = new String[] {
"iron", "gold", "carbon", "wood", "redstone", "diamond", "emerald", ModItems.META_PLACEHOLDER, "coal", "obsidian", "lazurite"
};
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
public ItemPlates() {
2016-03-25 10:47:34 +01:00
setUnlocalizedName("techreborn.plate");
setHasSubtypes(true);
setCreativeTab(TechRebornCreativeTabMisc.instance);
TRRecipeHandler.hideEntry(this);
2016-03-25 10:47:34 +01:00
}
2016-10-08 21:46:16 +02:00
public static ItemStack getPlateByName(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)) {
if (types[i].equals(ModItems.META_PLACEHOLDER)) {
throw new InvalidParameterException("The dust " + name + " could not be found.");
}
return new ItemStack(ModItems.PLATES, count, i);
2016-03-25 10:47:34 +01:00
}
}
throw new InvalidParameterException("The plate " + name + " could not be found.");
}
2016-10-08 21:46:16 +02:00
public static ItemStack getPlateByName(String name) {
2016-03-25 10:47:34 +01:00
return getPlateByName(name, 1);
}
public static void registerType(String plateType) {
for (String type : types) {
2016-10-08 21:46:16 +02:00
if (type.equals(plateType))
return;
}
int plateIndex = types.length;
String[] newTypes = new String[plateIndex + 1];
System.arraycopy(types, 0, newTypes, 0, types.length);
types = newTypes;
newTypes[plateIndex] = plateType;
2016-12-10 09:15:39 +01:00
String oreName = "plate" + CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, plateType);
OreDictionary.registerOre(oreName, new ItemStack(ModItems.PLATES, 1, plateIndex));
}
2016-10-08 21:46:16 +02:00
@Override
2016-12-10 09:15:39 +01:00
// gets Unlocalized Name depending on meta data
public String getUnlocalizedName(ItemStack itemStack) {
int meta = itemStack.getItemDamage();
if (meta < 0 || meta >= types.length) {
meta = 0;
}
2016-03-25 10:47:34 +01:00
2016-12-10 09:15:39 +01:00
return super.getUnlocalizedName() + "." + types[meta];
2016-03-25 10:47:34 +01:00
}
2015-11-24 23:58:18 +01:00
2016-12-10 09:15:39 +01:00
// Adds Dusts SubItems To Creative Tab
2017-06-12 18:30:21 +02:00
@Override
public void getSubItems(CreativeTabs creativeTabs, NonNullList list) {
2017-06-28 21:54:12 +02:00
if (!isInCreativeTab(creativeTabs)) {
2017-06-12 18:30:21 +02:00
return;
}
2016-12-10 09:15:39 +01:00
for (int meta = 0; meta < types.length; ++meta) {
if (!types[meta].equals(ModItems.META_PLACEHOLDER)) {
2017-06-12 18:30:21 +02:00
list.add(new ItemStack(this, 1, meta));
}
2016-12-10 09:15:39 +01:00
}
}
2015-05-04 22:52:08 +02:00
}