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

119 lines
4.7 KiB
Java
Raw Normal View History

/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
2018-02-11 15:08:08 +01:00
* Copyright (c) 2018 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;
2016-12-13 00:44:16 +01:00
import com.google.common.base.CaseFormat;
2015-04-11 21:46:55 +02:00
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
2015-04-11 21:46:55 +02:00
import net.minecraft.item.ItemStack;
2016-11-25 14:23:42 +01:00
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import techreborn.Core;
import techreborn.client.EGui;
import techreborn.init.ModItems;
2018-07-20 23:02:46 +02:00
import techreborn.utils.TechRebornCreativeTab;
2015-04-15 17:23:12 +02:00
import java.security.InvalidParameterException;
2017-06-14 01:49:52 +02:00
public class ItemParts extends ItemTR {
2016-12-13 00:44:16 +01:00
public static final String[] types = new String[] { "energy_flow_circuit", "data_control_circuit", "data_storage_circuit",
2017-06-12 15:23:32 +02:00
"data_orb", "diamond_grinding_head", "diamond_saw_blade", "tungsten_grinding_head", "helium_coolant_simple",
"helium_coolant_triple", "helium_coolant_six", "nak_coolant_simple", "nak_coolant_triple", "nak_coolant_six",
"cupronickel_heating_coil", "nichrome_heating_coil", "kanthal_heating_coil", ModItems.META_PLACEHOLDER, "super_conductor",
"thorium_cell", "double_thorium_cell", "quad_thorium_cell", "plutonium_cell", "double_plutonium_cell",
"quad_plutonium_cell", "computer_monitor", "machine_parts", "neutron_reflector", "iridium_neutron_reflector",
"thick_neutron_reflector", "electronic_circuit", "advanced_circuit", "sap", "rubber", "scrap",
"carbon_mesh", "carbon_fiber", "coolant_simple", "coolant_triple", "coolant_six"};
2015-04-15 17:23:12 +02:00
2016-10-08 21:46:16 +02:00
public ItemParts() {
this.setCreativeTab(TechRebornCreativeTab.instance);
this.setHasSubtypes(true);
2018-07-20 23:31:20 +02:00
this.setTranslationKey("techreborn.part");
2016-03-25 10:47:34 +01:00
}
2015-04-15 17:23:12 +02:00
public static ItemStack getPartByName(String name, final int count) {
2016-12-13 00:44:16 +01:00
//TODO: Change all recipes n' shit to use proper snake_case names so I don't have to do this bullshit
if (name.equals("NaKCoolantSimple"))
name = "nak_coolant_simple";
if (name.equals("NaKCoolantTriple"))
name = "nak_coolant_triple";
if (name.equals("NaKCoolantSix"))
name = "nak_coolant_six";
if (name.equals("superconductor"))
name = "super_conductor";
if (name.equals("carbonfiber"))
name = "carbon_fiber";
if (name.equals("carbonmesh"))
name = "carbon_mesh";
if (name.equals("rubberSap"))
name = "sap";
name = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name);
for (int i = 0; i < ItemParts.types.length; i++) {
if (ItemParts.types[i].equalsIgnoreCase(name)) {
return new ItemStack(ModItems.PARTS, count, i);
2016-03-25 10:47:34 +01:00
}
}
throw new InvalidParameterException("The part " + name + " could not be found.");
}
2015-04-11 21:46:55 +02:00
public static ItemStack getPartByName(final String name) {
return ItemParts.getPartByName(name, 1);
2016-03-25 10:47:34 +01:00
}
2015-04-11 21:46:55 +02:00
2016-03-25 10:47:34 +01:00
@Override
// gets Unlocalized Name depending on meta data
2018-07-20 23:31:20 +02:00
public String getTranslationKey(final ItemStack itemStack) {
2016-03-25 10:47:34 +01:00
int meta = itemStack.getItemDamage();
if (meta < 0 || meta >= ItemParts.types.length) {
2016-03-25 10:47:34 +01:00
meta = 0;
}
2015-04-11 21:46:55 +02:00
2018-07-20 23:31:20 +02:00
return super.getTranslationKey() + "." + ItemParts.types[meta];
2016-03-25 10:47:34 +01:00
}
2016-03-25 10:47:34 +01:00
// Adds Dusts SubItems To Creative Tab
@Override
2017-09-14 16:55:28 +02:00
public void getSubItems(final CreativeTabs creativeTabs, final NonNullList<ItemStack> list) {
2017-06-28 21:54:12 +02:00
if (!isInCreativeTab(creativeTabs)) {
2017-06-12 18:30:21 +02:00
return;
}
for (int meta = 0; meta < ItemParts.types.length; ++meta) {
if (!ItemParts.types[meta].equals(ModItems.META_PLACEHOLDER)) {
2017-06-11 22:22:07 +02:00
list.add(new ItemStack(this, 1, meta));
2016-06-02 19:21:23 +02:00
}
2016-03-25 10:47:34 +01:00
}
}
public ItemStack onItemRightClick(final ItemStack itemStack, final World world, final EntityPlayer player) {
2016-10-08 21:46:16 +02:00
switch (itemStack.getItemDamage()) {
case 37: // Destructo pack
player.openGui(Core.INSTANCE, EGui.DESTRUCTOPACK.ordinal(), world, (int) player.posX, (int) player.posY,
2017-06-12 15:23:32 +02:00
(int) player.posY);
break;
2016-03-25 10:47:34 +01:00
}
return itemStack;
}
2015-04-11 21:46:55 +02:00
}