mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-27 23:33:08 +00:00
78 lines
2.6 KiB
Java
78 lines
2.6 KiB
Java
package mekanism.common.item;
|
|
|
|
import java.util.List;
|
|
import javax.annotation.Nonnull;
|
|
import mekanism.api.EnumColor;
|
|
import mekanism.common.Upgrade;
|
|
import mekanism.common.base.IUpgradeItem;
|
|
import mekanism.common.base.IUpgradeTile;
|
|
import mekanism.common.tile.component.TileComponentUpgrade;
|
|
import mekanism.common.util.LangUtils;
|
|
import mekanism.common.util.MekanismUtils;
|
|
import net.minecraft.client.util.ITooltipFlag;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.util.EnumActionResult;
|
|
import net.minecraft.util.EnumFacing;
|
|
import net.minecraft.util.EnumHand;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
import org.lwjgl.input.Keyboard;
|
|
|
|
public class ItemUpgrade extends ItemMekanism implements IUpgradeItem {
|
|
|
|
private Upgrade upgrade;
|
|
|
|
public ItemUpgrade(Upgrade type) {
|
|
super();
|
|
upgrade = type;
|
|
setMaxStackSize(type.getMax());
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public void addInformation(ItemStack itemstack, World world, List<String> list, ITooltipFlag flag) {
|
|
if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
|
list.add(
|
|
LangUtils.localize("tooltip.hold") + " " + EnumColor.AQUA + "shift" + EnumColor.GREY + " " + LangUtils
|
|
.localize("tooltip.forDetails"));
|
|
} else {
|
|
list.addAll(MekanismUtils.splitTooltip(getUpgradeType(itemstack).getDescription(), itemstack));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Upgrade getUpgradeType(ItemStack stack) {
|
|
return upgrade;
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX,
|
|
float hitY, float hitZ, EnumHand hand) {
|
|
if (player.isSneaking()) {
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
ItemStack stack = player.getHeldItem(hand);
|
|
Upgrade type = getUpgradeType(stack);
|
|
|
|
if (tile instanceof IUpgradeTile) {
|
|
TileComponentUpgrade component = ((IUpgradeTile) tile).getComponent();
|
|
|
|
if (component.supports(type)) {
|
|
if (!world.isRemote && component.getUpgrades(type) < type.getMax()) {
|
|
component.addUpgrade(type);
|
|
stack.shrink(1);
|
|
}
|
|
}
|
|
|
|
return EnumActionResult.SUCCESS;
|
|
}
|
|
}
|
|
|
|
return EnumActionResult.PASS;
|
|
}
|
|
}
|