Search in sources :

Example 16 with StringTextComponent

use of net.minecraft.util.text.StringTextComponent in project BluePower by Qmunity.

the class BlockBPMicroblock method getCloneItemStack.

@Override
public ItemStack getCloneItemStack(IBlockReader world, BlockPos pos, BlockState state) {
    TileEntity tileentity = world.getBlockEntity(pos);
    ItemStack stack = ItemStack.EMPTY;
    if (tileentity instanceof TileBPMultipart) {
        tileentity = ((TileBPMultipart) tileentity).getTileForState(state);
    }
    if (tileentity instanceof TileBPMicroblock) {
        CompoundNBT nbt = new CompoundNBT();
        nbt.putString("block", ((TileBPMicroblock) tileentity).getBlock().getRegistryName().toString());
        stack = new ItemStack(this);
        stack.setTag(nbt);
        stack.setHoverName(new TranslationTextComponent(((TileBPMicroblock) tileentity).getBlock().getDescriptionId()).append(new StringTextComponent(" ")).append(new TranslationTextComponent(this.getDescriptionId())));
    }
    return stack;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileBPMicroblock(com.bluepowermod.tile.TileBPMicroblock) CompoundNBT(net.minecraft.nbt.CompoundNBT) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) ItemStack(net.minecraft.item.ItemStack)

Example 17 with StringTextComponent

use of net.minecraft.util.text.StringTextComponent 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)

Example 18 with StringTextComponent

use of net.minecraft.util.text.StringTextComponent in project BluePower by Qmunity.

the class JEIPlugin method getMicroblockRecipes.

private static List<IRecipe<?>> getMicroblockRecipes() {
    List<IRecipe<?>> recipes = new ArrayList<>();
    for (Block block : ForgeRegistries.BLOCKS.getValues().stream().filter(b -> !b.hasTileEntity(b.defaultBlockState())).collect(Collectors.toList())) {
        VoxelShape shape = null;
        try {
            shape = block.defaultBlockState().getShape(null, null);
        } catch (NullPointerException ignored) {
        // Shulker Boxes try to query the Tile Entity
        }
        if (block.getRegistryName() != null && shape == VoxelShapes.block()) {
            ItemStack output = ItemStack.EMPTY;
            for (Block mb : BPBlocks.microblocks) {
                NonNullList<Ingredient> input = NonNullList.create();
                input.add(Ingredient.of(ItemTags.createOptional(new ResourceLocation("bluepower:saw"))));
                if (mb == BPBlocks.half_block) {
                    input.add(Ingredient.of(new ItemStack(block)));
                } else {
                    input.add(Ingredient.of(output));
                }
                CompoundNBT nbt = new CompoundNBT();
                nbt.putString("block", block.getRegistryName().toString());
                ItemStack stack = new ItemStack(mb);
                stack.setTag(nbt);
                stack.setHoverName(new TranslationTextComponent(block.getDescriptionId()).append(new StringTextComponent(" ")).append(new TranslationTextComponent(mb.getDescriptionId())));
                output = stack;
                recipes.add(new ShapelessRecipe(new ResourceLocation("bluepower:" + mb.getDescriptionId() + block.getDescriptionId()), "", output, input));
            }
        }
    }
    return recipes;
}
Also used : Refs(com.bluepowermod.reference.Refs) java.util(java.util) ContainerBlulectricAlloyFurnace(com.bluepowermod.container.ContainerBlulectricAlloyFurnace) GuiBlulectricAlloyFurnace(com.bluepowermod.client.gui.GuiBlulectricAlloyFurnace) Item(net.minecraft.item.Item) BPBlocks(com.bluepowermod.init.BPBlocks) CompoundNBT(net.minecraft.nbt.CompoundNBT) AlloyFurnaceRegistry(com.bluepowermod.recipe.AlloyFurnaceRegistry) net.minecraft.item.crafting(net.minecraft.item.crafting) IGuiHelper(mezz.jei.api.helpers.IGuiHelper) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ContainerBlulectricFurnace(com.bluepowermod.container.ContainerBlulectricFurnace) ItemStack(net.minecraft.item.ItemStack) IAlloyFurnaceRecipe(com.bluepowermod.api.recipe.IAlloyFurnaceRecipe) Block(net.minecraft.block.Block) Minecraft(net.minecraft.client.Minecraft) IRecipeCategory(mezz.jei.api.recipe.category.IRecipeCategory) mezz.jei.api(mezz.jei.api) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) StringTextComponent(net.minecraft.util.text.StringTextComponent) NonNullList(net.minecraft.util.NonNullList) VanillaRecipeCategoryUid(mezz.jei.api.constants.VanillaRecipeCategoryUid) ContainerAlloyFurnace(com.bluepowermod.container.ContainerAlloyFurnace) ItemTags(net.minecraft.tags.ItemTags) ContainerProjectTable(com.bluepowermod.container.ContainerProjectTable) ItemStackUtils(com.bluepowermod.util.ItemStackUtils) mezz.jei.api.registration(mezz.jei.api.registration) Collectors(java.util.stream.Collectors) IJeiHelpers(mezz.jei.api.helpers.IJeiHelpers) GuiBlulectricFurnace(com.bluepowermod.client.gui.GuiBlulectricFurnace) ResourceLocation(net.minecraft.util.ResourceLocation) VoxelShapes(net.minecraft.util.math.shapes.VoxelShapes) BluePower(com.bluepowermod.BluePower) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) GuiAlloyFurnace(com.bluepowermod.client.gui.GuiAlloyFurnace) CompoundNBT(net.minecraft.nbt.CompoundNBT) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack)

Example 19 with StringTextComponent

use of net.minecraft.util.text.StringTextComponent in project BluePower by Qmunity.

the class BlockBPMicroblock method getDrops.

@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
    TileEntity tileentity = builder.getParameter(LootParameters.BLOCK_ENTITY);
    List<ItemStack> itemStacks = new ArrayList<>();
    if (tileentity instanceof TileBPMultipart) {
        tileentity = ((TileBPMultipart) tileentity).getTileForState(state);
    }
    if (tileentity instanceof TileBPMicroblock) {
        CompoundNBT nbt = new CompoundNBT();
        nbt.putString("block", ((TileBPMicroblock) tileentity).getBlock().getRegistryName().toString());
        ItemStack stack = new ItemStack(this);
        stack.setTag(nbt);
        stack.setHoverName(new TranslationTextComponent(((TileBPMicroblock) tileentity).getBlock().getDescriptionId()).append(new StringTextComponent(" ")).append(new TranslationTextComponent(this.getDescriptionId())));
        itemStacks.add(stack);
    }
    return itemStacks;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileBPMicroblock(com.bluepowermod.tile.TileBPMicroblock) CompoundNBT(net.minecraft.nbt.CompoundNBT) ArrayList(java.util.ArrayList) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) ItemStack(net.minecraft.item.ItemStack)

Example 20 with StringTextComponent

use of net.minecraft.util.text.StringTextComponent in project BluePower by Qmunity.

the class ItemMultimeter method useOn.

@Override
public ActionResultType useOn(ItemUseContext context) {
    TileEntity tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
    if (tileEntity != null && tileEntity.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY).isPresent()) {
        if (!context.getLevel().isClientSide) {
            double volts = tileEntity.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY).orElse(null).getVoltage();
            double amps = tileEntity.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY).orElse(null).getCurrent();
            String voltage = String.format("%.2f", volts);
            String ampere = String.format("%.2f", amps);
            String watts = String.format("%.2f", volts * amps);
            if (context.getPlayer() != null)
                context.getPlayer().sendMessage(new StringTextComponent("Reading " + voltage + "V " + ampere + "A (" + watts + "W)"), Util.NIL_UUID);
        }
        return ActionResultType.SUCCESS;
    }
    return super.useOn(context);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) StringTextComponent(net.minecraft.util.text.StringTextComponent)

Aggregations

StringTextComponent (net.minecraft.util.text.StringTextComponent)31 ItemStack (net.minecraft.item.ItemStack)17 CompoundNBT (net.minecraft.nbt.CompoundNBT)7 TileEntity (net.minecraft.tileentity.TileEntity)5 Nonnull (javax.annotation.Nonnull)4 BlockPos (net.minecraft.util.math.BlockPos)4 ITextComponent (net.minecraft.util.text.ITextComponent)4 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)4 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)4 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)4 IGenericDataStorage (com.cjm721.overloaded.storage.IGenericDataStorage)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 IEnergyStorage (net.minecraftforge.energy.IEnergyStorage)3 TileBPMicroblock (com.bluepowermod.tile.TileBPMicroblock)2 TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)2 ItemSeedBag (com.infinityraider.agricraft.content.tools.ItemSeedBag)2 BlockState (net.minecraft.block.BlockState)2 Minecraft (net.minecraft.client.Minecraft)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 Vector3d (net.minecraft.util.math.vector.Vector3d)2