Search in sources :

Example 11 with HoverEvent

use of net.minecraft.util.text.event.HoverEvent in project RecurrentComplex by Ivorforce.

the class OperationRegistry method queueOperation.

public static void queueOperation(Operation operation, ICommandSender commandSender) throws PlayerNotFoundException {
    boolean instant = true;
    if (commandSender instanceof EntityPlayer) {
        EntityPlayer player = CommandBase.getCommandSenderAsPlayer(commandSender);
        RCEntityInfo info = RCEntityInfo.get(player, null);
        if (info != null) {
            if (info.getPreviewType() != Operation.PreviewType.NONE) {
                info.queueOperation(operation, player);
                instant = false;
                ITextComponent confirmComponent = new TextComponentString("/" + RCCommands.confirm.getName());
                confirmComponent.getStyle().setColor(TextFormatting.GREEN);
                confirmComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + RCCommands.confirm.getName()));
                confirmComponent.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, ServerTranslations.get("commands.rcconfirm.run")));
                ITextComponent cancelComponent = new TextComponentString("/" + RCCommands.cancel.getName());
                cancelComponent.getStyle().setColor(TextFormatting.RED);
                cancelComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + RCCommands.cancel.getName()));
                cancelComponent.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, ServerTranslations.get("commands.rccancel.run")));
                commandSender.sendMessage(ServerTranslations.format("commands.rc.queuedOp", confirmComponent, cancelComponent));
            }
        }
    }
    if (instant)
        operation.perform((WorldServer) commandSender.getEntityWorld());
}
Also used : HoverEvent(net.minecraft.util.text.event.HoverEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldServer(net.minecraft.world.WorldServer) RCEntityInfo(ivorius.reccomplex.capability.RCEntityInfo) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 12 with HoverEvent

use of net.minecraft.util.text.event.HoverEvent in project AgriCraft by AgriCraft.

the class DebugModeIGrowable method debugActionBlockClicked.

@Override
public void debugActionBlockClicked(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return;
    }
    // Start with the position of the block that was clicked on. '7' is gray. Btw, the chat font is not fixed width. :(
    StringBuilder outputRaw = new StringBuilder(String.format("`7%1$4d,%2$4d,%3$4d`r ", pos.getX(), pos.getY(), pos.getZ()));
    // Check if the clicked on block has the IGrowable interface.
    final IGrowable crop = WorldHelper.getBlock(world, pos, IGrowable.class).orElse(null);
    if (crop == null) {
        // If it does not, add a nicely formatted report, then skip onward.
        outputRaw.append(chatNotIG);
    } else {
        // Otherwise run the tests and record the results.
        IBlockState state = world.getBlockState(pos);
        // canGrow
        outputRaw.append(crop.canGrow(world, pos, state, false) ? chatTrue : chatFalse);
        // canUseBonemeal
        outputRaw.append(crop.canUseBonemeal(world, world.rand, pos, state) ? chatTrue : chatFalse);
        // grow
        crop.grow(world, world.rand, pos, state);
        // It's also helpful to also make clear what block was being tested.
        // '3' is dark aqua.
        outputRaw.append("`3");
        outputRaw.append(crop.toString().replaceFirst("Block", ""));
        outputRaw.append("`r");
    }
    // Ellipsis are added as a clue that there's more text.
    // '8' is dark gray.
    outputRaw.append(" `8[...]`r");
    // Create a hover box with explanatory information.
    TextComponentString hoverComponent = new TextComponentString(MessageUtil.colorize(chatInfo));
    HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent);
    // Turn the output String into a chat message.
    TextComponentString outputComponent = new TextComponentString(MessageUtil.colorize(outputRaw.toString()));
    // Add the hover box to the chat message.
    outputComponent.getStyle().setHoverEvent(hoverEvent);
    // Now send the completed chat message.
    player.sendMessage(outputComponent);
}
Also used : HoverEvent(net.minecraft.util.text.event.HoverEvent) IBlockState(net.minecraft.block.state.IBlockState) IGrowable(net.minecraft.block.IGrowable) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 13 with HoverEvent

use of net.minecraft.util.text.event.HoverEvent in project RecurrentComplex by Ivorforce.

the class RCTextStyle method path.

@Nonnull
public static ITextComponent path(ResourceDirectory directory, String... path) {
    ITextComponent pathComponent = new TextComponentString(String.format("%s%s%s", directory, path.length > 0 ? "/" : "", Strings.join(path, "/")));
    pathComponent.getStyle().setColor(TextFormatting.GOLD);
    pathComponent.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Visit File")));
    pathComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, directory.toFile().getAbsolutePath()));
    return pathComponent;
}
Also used : HoverEvent(net.minecraft.util.text.event.HoverEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) Nonnull(javax.annotation.Nonnull)

Example 14 with HoverEvent

use of net.minecraft.util.text.event.HoverEvent in project RecurrentComplex by Ivorforce.

the class RCTextStyle method copy.

public static ITextComponent copy(String text) {
    ITextComponent comp = new TextComponentString(text);
    comp.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, ServerTranslations.get("commands.rccopy.suggest")));
    comp.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, text));
    return comp;
}
Also used : HoverEvent(net.minecraft.util.text.event.HoverEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent)

Example 15 with HoverEvent

use of net.minecraft.util.text.event.HoverEvent in project RecurrentComplex by Ivorforce.

the class RCTextStyle method biome.

@Nonnull
public static ITextComponent biome(Biome biome) {
    ITextComponent component = new TextComponentString(biome.getBiomeName());
    Style style = component.getStyle();
    style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/%s types %s", RCCommands.biomeDict.getName(), biome.getRegistryName())));
    style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, ServerTranslations.format("commands.biomedict.list.number", BiomeDictionary.getTypes(biome).size())));
    style.setColor(TextFormatting.AQUA);
    return component;
}
Also used : HoverEvent(net.minecraft.util.text.event.HoverEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) Nonnull(javax.annotation.Nonnull)

Aggregations

HoverEvent (net.minecraft.util.text.event.HoverEvent)18 ClickEvent (net.minecraft.util.text.event.ClickEvent)16 Nonnull (javax.annotation.Nonnull)7 TextComponentString (net.minecraft.util.text.TextComponentString)5 ITextComponent (net.minecraft.util.text.ITextComponent)4 RCEntityInfo (ivorius.reccomplex.capability.RCEntityInfo)1 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)1 WorldRandomData (ivorius.reccomplex.world.gen.feature.WorldRandomData)1 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)1 Metadata (ivorius.reccomplex.world.gen.feature.structure.generic.Metadata)1 IGrowable (net.minecraft.block.IGrowable)1 IBlockState (net.minecraft.block.state.IBlockState)1 Minecraft (net.minecraft.client.Minecraft)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 WorldServer (net.minecraft.world.WorldServer)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1