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

110 lines
3.6 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-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;
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;
2017-04-11 01:30:27 +02:00
import reborncore.api.tile.IUpgrade;
2017-04-11 20:26:46 +02:00
import reborncore.common.powerSystem.TilePowerAcceptor;
2016-04-11 18:23:57 +02:00
import reborncore.common.recipes.RecipeCrafter;
2017-04-11 01:30:27 +02:00
import reborncore.common.tile.TileLegacyMachineBase;
2015-06-09 12:24:15 +02:00
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.init.ModItems;
2017-04-11 01:30:27 +02:00
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.security.InvalidParameterException;
import java.util.List;
2015-06-09 12:24:15 +02:00
2017-04-11 01:30:27 +02:00
public class ItemUpgrades extends ItemTRNoDestroy implements IUpgrade {
2017-01-09 16:18:19 +01:00
public static final String[] types = new String[] { "overclock", "transformer", "energy_storage", "range" };
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);
}
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)) {
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.");
}
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);
}
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
@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));
}
}
2017-04-11 01:30:27 +02:00
@Override
public void process(
@Nonnull
TileLegacyMachineBase machineBase,
@Nullable
RecipeCrafter crafter,
@Nonnull
ItemStack stack) {
if(crafter != null){
if (stack.getItemDamage() == 0) {
crafter.addSpeedMulti(0.25);
2017-04-11 01:30:27 +02:00
crafter.addPowerMulti(0.5);
}
}
2017-04-11 20:26:46 +02:00
if(machineBase instanceof TilePowerAcceptor){
if (stack.getItemDamage() == 2) {
TilePowerAcceptor acceptor = (TilePowerAcceptor) machineBase;
acceptor.extraPowerStoage += acceptor.getBaseMaxPower();
}
}
2017-04-11 01:30:27 +02:00
}
2015-06-09 12:24:15 +02:00
}