Search in sources :

Example 1 with CommandSource

use of net.minecraft.command.CommandSource in project Bookshelf by Darkhax-Minecraft.

the class CommandHand method hand.

private int hand(CommandContext<CommandSource> context) throws CommandSyntaxException {
    final OutputType type = context.getArgument("type", OutputType.class);
    final ServerPlayerEntity player = context.getSource().getPlayerOrException();
    final String outputText = type.converter.apply(player.getMainHandItem());
    final ITextComponent component = TextComponentUtils.wrapInSquareBrackets(new StringTextComponent(outputText).withStyle((style) -> {
        return style.withColor(TextFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, outputText)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslationTextComponent("chat.copy.click"))).withInsertion(outputText);
    }));
    context.getSource().sendSuccess(component, false);
    return 0;
}
Also used : JsonObject(com.google.gson.JsonObject) VanillaIngredientSerializer(net.minecraftforge.common.crafting.VanillaIngredientSerializer) Serializers(net.darkhax.bookshelf.serialization.Serializers) ClickEvent(net.minecraft.util.text.event.ClickEvent) Function(java.util.function.Function) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) LazyOptional(net.minecraftforge.common.util.LazyOptional) ItemStack(net.minecraft.item.ItemStack) StringTextComponent(net.minecraft.util.text.StringTextComponent) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) CommandContext(com.mojang.brigadier.context.CommandContext) TextFormatting(net.minecraft.util.text.TextFormatting) NBTIngredient(net.minecraftforge.common.crafting.NBTIngredient) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) CommandSource(net.minecraft.command.CommandSource) TextComponentUtils(net.minecraft.util.text.TextComponentUtils) HoverEvent(net.minecraft.util.text.event.HoverEvent) StringJoiner(java.util.StringJoiner) ResourceLocation(net.minecraft.util.ResourceLocation) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) FluidStack(net.minecraftforge.fluids.FluidStack) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) Commands(net.minecraft.command.Commands) CraftingHelper(net.minecraftforge.common.crafting.CraftingHelper) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) HoverEvent(net.minecraft.util.text.event.HoverEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) StringTextComponent(net.minecraft.util.text.StringTextComponent)

Aggregations

JsonObject (com.google.gson.JsonObject)1 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)1 CommandContext (com.mojang.brigadier.context.CommandContext)1 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 StringJoiner (java.util.StringJoiner)1 Function (java.util.function.Function)1 Serializers (net.darkhax.bookshelf.serialization.Serializers)1 CommandSource (net.minecraft.command.CommandSource)1 Commands (net.minecraft.command.Commands)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 ItemStack (net.minecraft.item.ItemStack)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 StringTextComponent (net.minecraft.util.text.StringTextComponent)1 TextComponentUtils (net.minecraft.util.text.TextComponentUtils)1 TextFormatting (net.minecraft.util.text.TextFormatting)1 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)1 ClickEvent (net.minecraft.util.text.event.ClickEvent)1 HoverEvent (net.minecraft.util.text.event.HoverEvent)1 CraftingHelper (net.minecraftforge.common.crafting.CraftingHelper)1