Item Stages

Item Stages

20M Downloads

No option to keep tooltip of restricted item untouched

QuentinPortet opened this issue ยท 0 comments

commented

Hello!
For our specific needs, we would need Item Stages to still prevent players from using a restricted item, but without completely hiding its stats, name, or anything else.

I went to check the source code and I made a version of the onItemTooltip() method that would allow us to do that.
However, I did this in a "dirty" way, there should be a boolean variable in the description class that allows to switch on and off tooltip modifications.

private void onItemTooltip (ItemTooltipEvent event) {
        if (event.getPlayer() != null) {
            final PlayerEntity player = event.getPlayer();
            final IStageData data = GameStageSaveHandler.getClientData();
            final ItemStack stack = event.getItemStack();
            final Restriction restriction = RestrictionManager.INSTANCE.getRestriction(player, data, stack);

            if (restriction != null) {
                // Debug tooltip shows which stages the player doesn't have.
                if (event.getFlags().isAdvanced()) {
                    final List<ITextComponent> stages = new ArrayList<>();
                    final ITextComponent sep = new StringTextComponent(", ").withStyle(TextFormatting.GRAY);
                    
                    for (final String stage : restriction.getStages()) {
                        stages.add(new StringTextComponent(stage).withStyle(data.hasStage(stage) ? TextFormatting.GREEN : TextFormatting.RED));
                    }
                    
                    final ITextComponent desc = new TranslationTextComponent("tooltip.itemstages.item.description", TextUtils.join(sep, stages)).withStyle(TextFormatting.GRAY);
                    event.getToolTip().add(desc);
                    
                    if (restriction.shouldPreventUsing()) { // I removed some if statements
                        event.getToolTip().add(new TranslationTextComponent("tooltip.itemstages.debug.use").withStyle(TextFormatting.RED));
                    }
                }
            }
        }
    }

The main issue for me was actually the "event.getToolTip().clear();", which, I suppose, deletes all the previous tooltip info.
The "hidden name" part is also a little issue, but I should be able to make it null to prevent the name from being modified.
The rest isn't too much of a problem for me.