2017-02-23 13:29:43 +01:00
|
|
|
/*
|
|
|
|
* 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-06-09 12:24:15 +02:00
|
|
|
package techreborn.items;
|
|
|
|
|
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2016-03-29 09:30:05 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-06-09 12:24:15 +02:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-12-12 02:27:39 +01:00
|
|
|
import net.minecraft.util.NonNullList;
|
2016-03-29 11:17:48 +02:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2016-06-04 12:40:52 +02:00
|
|
|
import net.minecraft.util.text.translation.I18n;
|
2016-04-11 18:23:57 +02:00
|
|
|
import reborncore.common.recipes.RecipeCrafter;
|
2015-06-09 12:24:15 +02:00
|
|
|
import techreborn.client.TechRebornCreativeTabMisc;
|
|
|
|
import techreborn.init.ModItems;
|
2016-05-16 06:24:35 +02:00
|
|
|
import techreborn.utils.upgrade.IMachineUpgrade;
|
|
|
|
|
|
|
|
import java.security.InvalidParameterException;
|
|
|
|
import java.util.List;
|
2015-06-09 12:24:15 +02:00
|
|
|
|
2016-12-12 02:27:39 +01:00
|
|
|
public class ItemUpgrades extends ItemTRNoDestroy implements IMachineUpgrade {
|
2015-08-09 12:05:32 +02:00
|
|
|
|
2017-01-09 16:18:19 +01:00
|
|
|
public static final String[] types = new String[] { "overclock", "transformer", "energy_storage", "range" };
|
2015-08-09 12:05:32 +02:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public ItemUpgrades() {
|
2016-03-25 10:47:34 +01:00
|
|
|
setUnlocalizedName("techreborn.upgrade");
|
|
|
|
setHasSubtypes(true);
|
|
|
|
setCreativeTab(TechRebornCreativeTabMisc.instance);
|
|
|
|
}
|
2015-08-09 12:05:32 +02:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public static ItemStack getUpgradeByName(String name, int count) {
|
|
|
|
for (int i = 0; i < types.length; i++) {
|
|
|
|
if (types[i].equalsIgnoreCase(name)) {
|
2017-01-01 08:29:32 +01:00
|
|
|
return new ItemStack(ModItems.UPGRADES, count, i);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new InvalidParameterException("The upgrade " + name + " could not be found.");
|
|
|
|
}
|
2015-08-09 12:05:32 +02:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public static ItemStack getUpgradeByName(String name) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return getUpgradeByName(name, 1);
|
|
|
|
}
|
2015-08-09 12:05:32 +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;
|
|
|
|
}
|
2015-08-09 12:05:32 +02:00
|
|
|
|
2016-03-25 10:47:34 +01:00
|
|
|
return super.getUnlocalizedName() + "." + types[meta];
|
|
|
|
}
|
2015-08-09 12:05:32 +02:00
|
|
|
|
2016-03-25 10:47:34 +01:00
|
|
|
// Adds Dusts SubItems To Creative Tab
|
2016-12-12 02:27:39 +01:00
|
|
|
@Override
|
|
|
|
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) {
|
2016-03-25 10:47:34 +01:00
|
|
|
list.add(new ItemStack(item, 1, meta));
|
|
|
|
}
|
|
|
|
}
|
2015-08-09 12:05:32 +02:00
|
|
|
|
2016-03-25 10:47:34 +01:00
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public void processUpgrade(RecipeCrafter crafter, ItemStack stack) {
|
2016-03-25 10:47:34 +01:00
|
|
|
// Remember the max speed multiplier can only be 0.99!!
|
2015-08-09 12:05:32 +02:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
if (stack.getItemDamage() == 0) {// Check the meta data here
|
2016-03-25 10:47:34 +01:00
|
|
|
crafter.addSpeedMulti(0.2);// This will set the speed multiplier to
|
2016-10-08 21:46:16 +02:00
|
|
|
// 0.8
|
2016-03-25 10:47:34 +01:00
|
|
|
crafter.addPowerMulti(0.5);// This will use eu/tick x 1.5
|
|
|
|
// crafter.addPowerMulti(2); This will use twice the amount of
|
|
|
|
// power.
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (stack.getItemDamage() == 1) {
|
2016-03-25 10:47:34 +01:00
|
|
|
crafter.addPowerMulti(-0.2);// This will use eu/tick 0.8
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (stack.getItemDamage() == 2) {
|
2016-03-25 10:47:34 +01:00
|
|
|
crafter.addSpeedMulti(0.5);
|
|
|
|
crafter.addPowerMulti(1);
|
|
|
|
}
|
|
|
|
}
|
2016-03-29 09:30:05 +02:00
|
|
|
|
2016-03-29 11:17:48 +02:00
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
|
2016-06-04 12:40:52 +02:00
|
|
|
tooltip.add(TextFormatting.RED + I18n.translateToLocal("tooltip.wip"));
|
|
|
|
tooltip.add(TextFormatting.RED + I18n.translateToLocal("tooltip.upBroken"));
|
|
|
|
tooltip.add(TextFormatting.RED + I18n.translateToLocal("tooltip.ingredient"));
|
2016-03-29 11:17:48 +02:00
|
|
|
}
|
2015-06-09 12:24:15 +02:00
|
|
|
}
|