use of mekanism.common.tile.component.TileComponentUpgrade in project Mekanism by mekanism.
the class ItemUpgrade method useOn.
@Nonnull
@Override
public ActionResultType useOn(ItemUseContext context) {
PlayerEntity player = context.getPlayer();
if (player != null && player.isShiftKeyDown()) {
World world = context.getLevel();
TileEntity tile = WorldUtils.getTileEntity(world, context.getClickedPos());
if (tile instanceof IUpgradeTile) {
IUpgradeTile upgradeTile = (IUpgradeTile) tile;
if (upgradeTile.supportsUpgrades()) {
TileComponentUpgrade component = upgradeTile.getComponent();
ItemStack stack = context.getItemInHand();
Upgrade type = getUpgradeType(stack);
if (component.supports(type)) {
if (!world.isClientSide) {
int added = component.addUpgrades(type, stack.getCount());
if (added > 0) {
stack.shrink(added);
}
}
return ActionResultType.SUCCESS;
}
}
}
}
return ActionResultType.PASS;
}
Aggregations