BloodMagic/src/main/java/WayofTime/bloodmagic/item/ItemUpgradeTome.java

113 lines
4.2 KiB
Java
Raw Normal View History

package WayofTime.bloodmagic.item;
2017-08-15 21:30:48 -07:00
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.client.IVariantProvider;
import WayofTime.bloodmagic.item.armour.ItemLivingArmour;
import WayofTime.bloodmagic.livingArmour.LivingArmour;
2018-03-07 19:43:00 -08:00
import WayofTime.bloodmagic.livingArmour.LivingArmourHandler;
import WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade;
import WayofTime.bloodmagic.util.helper.ItemHelper.LivingUpgrades;
2017-08-15 21:30:48 -07:00
import WayofTime.bloodmagic.util.helper.TextHelper;
2018-03-07 19:43:00 -08:00
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
2017-08-15 20:21:54 -07:00
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
2016-03-18 16:50:33 -04:00
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
2016-03-18 16:50:33 -04:00
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumHand;
2017-01-01 22:26:42 -08:00
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2018-03-07 19:43:00 -08:00
import javax.annotation.Nonnull;
2017-08-15 21:30:48 -07:00
import java.util.List;
import java.util.Map.Entry;
2017-08-15 21:30:48 -07:00
public class ItemUpgradeTome extends Item implements IVariantProvider {
public ItemUpgradeTome() {
super();
setCreativeTab(BloodMagic.TAB_TOMES);
setUnlocalizedName(BloodMagic.MODID + ".upgradeTome");
setHasSubtypes(true);
setMaxStackSize(1);
}
@Override
2017-08-15 21:30:48 -07:00
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
2017-01-01 22:26:42 -08:00
ItemStack stack = player.getHeldItem(hand);
2017-08-15 21:30:48 -07:00
if (world.isRemote) {
2017-01-01 22:26:42 -08:00
return super.onItemRightClick(world, player, hand);
}
LivingArmourUpgrade upgrade = LivingUpgrades.getUpgrade(stack);
2017-08-15 21:30:48 -07:00
if (upgrade == null) {
2017-01-01 22:26:42 -08:00
return super.onItemRightClick(world, player, hand);
}
2016-03-18 16:50:33 -04:00
ItemStack chestStack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
2017-08-15 21:30:48 -07:00
if (chestStack.getItem() instanceof ItemLivingArmour) {
LivingArmour armour = ItemLivingArmour.getLivingArmourFromStack(chestStack);
2017-08-15 21:30:48 -07:00
if (armour == null) {
2017-01-01 22:26:42 -08:00
return super.onItemRightClick(world, player, hand);
}
2017-08-15 21:30:48 -07:00
if (armour.upgradeArmour(player, upgrade)) {
ItemLivingArmour.setLivingArmour(chestStack, armour);
// ((ItemLivingArmour) chestStack.getItem()).setLivingArmour(stack, armour, false);
2017-01-01 22:26:42 -08:00
stack.shrink(1);
}
}
2017-01-01 22:26:42 -08:00
return super.onItemRightClick(world, player, hand);
}
@Override
public String getUnlocalizedName(ItemStack stack) {
if (!stack.hasTagCompound())
return super.getUnlocalizedName(stack);
LivingArmourUpgrade upgrade = LivingUpgrades.getUpgrade(stack);
if (upgrade != null && upgrade.isDowngrade())
return "item." + BloodMagic.MODID + ".downgradeTome";
return super.getUnlocalizedName(stack);
}
@Override
@SideOnly(Side.CLIENT)
2017-08-15 21:30:48 -07:00
public void getSubItems(CreativeTabs creativeTab, NonNullList<ItemStack> list) {
2017-08-15 20:21:54 -07:00
if (!isInCreativeTab(creativeTab))
return;
2017-08-15 21:30:48 -07:00
for (Entry<String, Integer> entry : LivingArmourHandler.upgradeMaxLevelMap.entrySet()) {
String key = entry.getKey();
int maxLevel = entry.getValue();
2017-08-15 21:30:48 -07:00
for (int i = 0; i < maxLevel; i++) {
ItemStack stack = new ItemStack(this);
LivingUpgrades.setKey(stack, key);
LivingUpgrades.setLevel(stack, i);
list.add(stack);
}
}
}
2016-03-16 01:10:33 -07:00
@Override
2018-03-07 19:43:00 -08:00
public void gatherVariants(@Nonnull Int2ObjectMap<String> variants) {
variants.put(0, "type=upgradetome");
2016-03-16 01:10:33 -07:00
}
@Override
@SideOnly(Side.CLIENT)
2017-08-15 21:30:48 -07:00
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
if (!stack.hasTagCompound())
return;
LivingArmourUpgrade upgrade = LivingUpgrades.getUpgrade(stack);
2017-08-15 21:30:48 -07:00
if (upgrade != null) {
2017-01-02 01:18:29 -08:00
tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.livingArmour.upgrade.level", TextHelper.localize(upgrade.getUnlocalizedName()), upgrade.getUpgradeLevel() + 1));
}
}
}