Search in sources :

Example 61 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project meteor-client by MeteorDevelopment.

the class ContainerButtonWidget method renderButton.

@Override
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) {
    MinecraftClient minecraftClient = MinecraftClient.getInstance();
    TextRenderer textRenderer = minecraftClient.textRenderer;
    RenderSystem.setShader(GameRenderer::getPositionTexShader);
    RenderSystem.setShaderTexture(0, WIDGETS_TEXTURE);
    RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, alpha);
    RenderSystem.enableBlend();
    RenderSystem.defaultBlendFunc();
    RenderSystem.enableDepthTest();
    int halfWidth = width / 2;
    int halfHeight = height / 2;
    int texY = getYImage(isHovered()) * 20;
    drawTexture(matrices, x, y, 0, 46 + texY, halfWidth, halfHeight);
    drawTexture(matrices, x, y + halfHeight, 0, 46 + texY + 14, halfWidth, halfHeight);
    drawTexture(matrices, x + halfWidth, y, 200 - halfWidth, 46 + texY, halfWidth, halfHeight);
    drawTexture(matrices, x + halfWidth, y + halfHeight, 200 - halfWidth, 46 + texY + 14, halfWidth, halfHeight);
    drawCenteredText(matrices, textRenderer, getMessage(), x + width / 2, (y + height / 2) - 4, active ? 16777215 : 10526880 | MathHelper.ceil(alpha * 255.0F) << 24);
}
Also used : MinecraftClient(net.minecraft.client.MinecraftClient) GameRenderer(net.minecraft.client.render.GameRenderer) TextRenderer(net.minecraft.client.font.TextRenderer)

Example 62 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project FZMM-Mod by Zailer43.

the class EncodebookLogic method EncodeBook.

public static void EncodeBook(final int SEED, String message, final String AUTHOR, final String PADDING_CHARS, final int MAX_MESSAGE_LENGTH, String bookTitle) {
    /*
		{
			title:"&3Encode book (secret_mc_1)",
			author:"Zailer43",
			pages:[
				'{
					"translate":"secret_mc_1",
					"with":[
						"y","F","r","d","6","5","8","y","s","A",...,"e","s"
					]
				}',
				'{
					"hoverEvent":{
						"action":"show_text",
						"contents":{
							"text":"yFrd658ysA...es"
						}
					},
					"text":"&9Idea by: &0turkeybot69\\n
					&9Encode key: &0secret_mc_1\\n
					&9End-to-end encode: &0true\\n
					&9Encode message: &0Hover over here"
				}'
			]
		}

		 */
    MinecraftClient mc = MinecraftClient.getInstance();
    Character[] encodeMessage = new Character[MAX_MESSAGE_LENGTH];
    short[] encodedKey;
    Random random = new Random(new Date().getTime());
    StringBuilder messageBuilder, encodeMessageString = new StringBuilder();
    String[] paddingCharacters = PADDING_CHARS.split("");
    ItemStack book = Items.WRITTEN_BOOK.getDefaultStack();
    NbtCompound tag = new NbtCompound();
    NbtList pages = new NbtList();
    MutableText page1, page2;
    String translationKeyPrefix = Configs.Encodebook.TRANSLATION_KEY_PREFIX.getStringValue();
    assert mc.player != null;
    message += Configs.Encodebook.SEPARATOR_MESSAGE.getStringValue();
    message = message.replaceAll(" ", "_");
    messageBuilder = new StringBuilder(message);
    int messageLength = message.length();
    encodedKey = encodeKey(getKey(SEED), MAX_MESSAGE_LENGTH);
    if (bookTitle.contains("%s")) {
        bookTitle = String.format(bookTitle, translationKeyPrefix + SEED);
    }
    while (messageLength < MAX_MESSAGE_LENGTH) {
        messageBuilder.append(paddingCharacters[random.nextInt(paddingCharacters.length)]);
        messageLength++;
    }
    message = messageBuilder.toString();
    for (int i = 0; i < MAX_MESSAGE_LENGTH; i++) encodeMessage[encodedKey[i]] = message.charAt(i);
    for (int i = 0; i < MAX_MESSAGE_LENGTH; i++) {
        encodeMessageString.append(encodeMessage[i]);
    }
    tag.putString(WrittenBookItem.TITLE_KEY, bookTitle);
    tag.putString(WrittenBookItem.AUTHOR_KEY, AUTHOR);
    page1 = new TranslatableText(translationKeyPrefix + SEED, (Object[]) encodeMessage).setStyle(Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("You probably need the decoder to see this message"))));
    page2 = new LiteralText(Formatting.BLUE + "Idea by: " + Formatting.BLACK + "turkeybot69\n" + Formatting.BLUE + "Encode key: " + Formatting.BLACK + translationKeyPrefix + SEED + "\n" + Formatting.BLUE + "Asymmetric encode: " + Formatting.BLACK + (Configs.Encodebook.ASYMMETRIC_ENCODE_KEY.getIntegerValue() != 0) + "\n" + Formatting.BLUE + "Encode message: " + Formatting.BLACK + "Hover over here").setStyle(Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(encodeMessageString.toString()))));
    pages.add(FzmmUtils.textToNbtString(page1, false));
    pages.add(FzmmUtils.textToNbtString(page2, false));
    tag.put(WrittenBookItem.PAGES_KEY, pages);
    book.setNbt(tag);
    FzmmUtils.giveItem(book);
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) Date(java.util.Date) Random(java.util.Random) MinecraftClient(net.minecraft.client.MinecraftClient) NbtList(net.minecraft.nbt.NbtList) ItemStack(net.minecraft.item.ItemStack)

Example 63 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project FZMM-Mod by Zailer43.

the class GradientLogic method getGradient.

public static MutableText getGradient(String message, Color4f initialColor4f, Color4f finalColor4f, boolean obfuscated, boolean bold, boolean strikethrough, boolean underline, boolean italic) {
    MinecraftClient mc = MinecraftClient.getInstance();
    assert mc.player != null;
    Color initialColor = new Color(initialColor4f.intValue);
    Color finalColor = new Color(finalColor4f.intValue);
    byte red = (byte) (initialColor.getRed() + Byte.MIN_VALUE);
    byte green = (byte) (initialColor.getGreen() + Byte.MIN_VALUE);
    byte blue = (byte) (initialColor.getBlue() + Byte.MIN_VALUE);
    byte red2 = (byte) (finalColor.getRed() + Byte.MIN_VALUE);
    byte green2 = (byte) (finalColor.getGreen() + Byte.MIN_VALUE);
    byte blue2 = (byte) (finalColor.getBlue() + Byte.MIN_VALUE);
    Style style = Style.EMPTY;
    if (obfuscated)
        style = style.withObfuscated(true);
    if (bold)
        style = style.withBold(true);
    if (strikethrough)
        style = style.withStrikethrough(true);
    if (underline)
        style = style.withUnderline(true);
    if (italic)
        style = style.withItalic(true);
    else
        style = style.withItalic(false);
    return getGradient(message, red, green, blue, red2, green2, blue2, style);
}
Also used : MinecraftClient(net.minecraft.client.MinecraftClient) TextColor(net.minecraft.text.TextColor) Style(net.minecraft.text.Style)

Example 64 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project FZMM-Mod by Zailer43.

the class GenericCallback method changeGuiScale.

private boolean changeGuiScale(boolean increment) {
    MinecraftClient mc = MinecraftClient.getInstance();
    int guiScale = mc.options.guiScale;
    if (increment)
        guiScale++;
    else
        guiScale--;
    guiScale = MathHelper.clamp(guiScale, 1, 4);
    mc.options.guiScale = guiScale;
    mc.onResolutionChanged();
    return true;
}
Also used : MinecraftClient(net.minecraft.client.MinecraftClient)

Example 65 with MinecraftClient

use of net.minecraft.client.MinecraftClient in project BlockMeter by ModProg.

the class BlockMeterClient method renderOverlay.

public void renderOverlay(float partialTicks, MatrixStack stack) {
    final MinecraftClient client = MinecraftClient.getInstance();
    final Camera camera = client.gameRenderer.getCamera();
    final Identifier currentDimension = client.player.world.getRegistryKey().getValue();
    final ModConfig cfg = AutoConfig.getConfigHolder(ModConfig.class).getConfig();
    // MEH! but this seems to be needed to get the first background
    // rectangle
    client.textRenderer.draw(stack, "XXX", -100, -100, 0);
    if (this.active || cfg.showBoxesWhenDisabled)
        if (cfg.showOtherUsersBoxes) {
            if (otherUsersBoxes != null && otherUsersBoxes.size() > 0) {
                this.otherUsersBoxes.forEach((playerText, boxList) -> {
                    boxList.forEach(box -> box.render(camera, stack, currentDimension, playerText));
                });
                this.boxes.forEach(box -> {
                    if (!box.isFinished())
                        box.render(camera, stack, currentDimension);
                });
            }
            if (!cfg.sendBoxes)
                this.boxes.forEach(box -> {
                    if (box.isFinished())
                        box.render(camera, stack, currentDimension, client.player.getDisplayName());
                    else
                        box.render(camera, stack, currentDimension);
                });
        } else
            this.boxes.forEach(box -> box.render(camera, stack, currentDimension));
}
Also used : PacketSender(net.fabricmc.fabric.api.networking.v1.PacketSender) Item(net.minecraft.item.Item) OptionsGui(win.baruna.blockmeter.gui.OptionsGui) ConfigManager(me.shedaniel.autoconfig.ConfigManager) TranslatableText(net.minecraft.text.TranslatableText) PacketByteBuf(net.minecraft.network.PacketByteBuf) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Unpooled(io.netty.buffer.Unpooled) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) UseBlockCallback(net.fabricmc.fabric.api.event.player.UseBlockCallback) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler) ClientModInitializer(net.fabricmc.api.ClientModInitializer) ClientPlayNetworking(net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking) PlayerEntity(net.minecraft.entity.player.PlayerEntity) KeyBindingHelper(net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper) InputUtil(net.minecraft.client.util.InputUtil) MatrixStack(net.minecraft.client.util.math.MatrixStack) BlockHitResult(net.minecraft.util.hit.BlockHitResult) BlockPos(net.minecraft.util.math.BlockPos) KeyBinding(net.minecraft.client.option.KeyBinding) GLFW(org.lwjgl.glfw.GLFW) Toml4jConfigSerializer(me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer) ActionResult(net.minecraft.util.ActionResult) HitResult(net.minecraft.util.hit.HitResult) List(java.util.List) Screen(net.minecraft.client.gui.screen.Screen) DyeColor(net.minecraft.util.DyeColor) SelectBoxGui(win.baruna.blockmeter.gui.SelectBoxGui) AutoConfig(me.shedaniel.autoconfig.AutoConfig) Identifier(net.minecraft.util.Identifier) ClientTickEvents(net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents) MinecraftClient(net.minecraft.client.MinecraftClient) Text(net.minecraft.text.Text) ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) Camera(net.minecraft.client.render.Camera) Identifier(net.minecraft.util.Identifier) MinecraftClient(net.minecraft.client.MinecraftClient) Camera(net.minecraft.client.render.Camera)

Aggregations

MinecraftClient (net.minecraft.client.MinecraftClient)84 ItemStack (net.minecraft.item.ItemStack)12 Text (net.minecraft.text.Text)7 Identifier (net.minecraft.util.Identifier)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 BlockPos (net.minecraft.util.math.BlockPos)6 BlockEntity (net.minecraft.block.entity.BlockEntity)5 TextRenderer (net.minecraft.client.font.TextRenderer)5 ClientPlayNetworkHandler (net.minecraft.client.network.ClientPlayNetworkHandler)5 BlockHitResult (net.minecraft.util.hit.BlockHitResult)5 List (java.util.List)4 BlockState (net.minecraft.block.BlockState)4 MatrixStack (net.minecraft.client.util.math.MatrixStack)4 Entity (net.minecraft.entity.Entity)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 NbtCompound (net.minecraft.nbt.NbtCompound)4 AreaIsometricRenderScreen (com.glisco.isometricrenders.client.gui.AreaIsometricRenderScreen)3 IsometricRenderScreen (com.glisco.isometricrenders.client.gui.IsometricRenderScreen)3 GameRenderer (net.minecraft.client.render.GameRenderer)3 VertexConsumerProvider (net.minecraft.client.render.VertexConsumerProvider)3