net.minecraft.client.MinecraftClient Java Examples

The following examples show how to use net.minecraft.client.MinecraftClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MixinPlayerEntity.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
@Inject(at = @At("RETURN"), method = "tick()V", cancellable = true)
public void tick(CallbackInfo info) {
	try {
		if (MinecraftClient.getInstance().player.age % 100 == 0) {
			BleachFileHelper.saveModules();
			BleachFileHelper.saveSettings();
			BleachFileHelper.saveBinds();
			BleachFileHelper.saveClickGui();
		}
		
		BleachQueue.nextQueue();
	} catch (Exception e) {}
	EventTick event = new EventTick();
	BleachHack.eventBus.post(event);
	if (event.isCancelled()) info.cancel();
}
 
Example #2
Source File: MineLittlePony.java    From MineLittlePony with MIT License 6 votes vote down vote up
private void onScreenInit(Screen screen, ScreenInitCallback.ButtonList buttons) {
    if (screen instanceof TitleScreen) {
        VisibilityMode mode = config.horseButton.get();
        boolean show = mode == VisibilityMode.ON || (mode == VisibilityMode.AUTO
            && !(hasHdSkins || hasModMenu
        ));

        if (show) {
            int y = hasHdSkins ? 75 : 50;
            Button button = buttons.add(new Button(screen.width - 50, screen.height - y, 20, 20))
                .onClick(sender -> MinecraftClient.getInstance().openScreen(new GuiPonySettings(screen)));
            button.getStyle()
                    .setIcon(new TextureSprite()
                            .setPosition(2, 2)
                            .setTexture(new Identifier("minelittlepony", "textures/gui/pony.png"))
                            .setTextureSize(16, 16)
                            .setSize(16, 16));
            button.y = screen.height - y; // ModMenu
        }
    }
}
 
Example #3
Source File: WTextField.java    From LibGui with MIT License 6 votes vote down vote up
/**
 * From an X offset past the left edge of a TextRenderer.draw, finds out what the closest caret
 * position (division between letters) is.
 * @param s
 * @param x
 * @return
 */
@Environment(EnvType.CLIENT)
public static int getCaretPos(String s, int x) {
	if (x<=0) return 0;
	
	TextRenderer font = MinecraftClient.getInstance().textRenderer;
	int lastAdvance = 0;
	for(int i=0; i<s.length()-1; i++) {
		int advance = font.getWidth(s.substring(0,i+1));
		int charAdvance = advance-lastAdvance;
		if (x<advance + (charAdvance/2)) return i+1;
		
		lastAdvance = advance;
	}
	
	return s.length();
}
 
Example #4
Source File: ScreenDrawing.java    From LibGui with MIT License 6 votes vote down vote up
/**
 * Draws a textured rectangle.
 *
 * @param x         the x coordinate of the box on-screen
 * @param y         the y coordinate of the box on-screen
 * @param width     the width of the box on-screen
 * @param height    the height of the box on-screen
 * @param texture   the Identifier for the texture
 * @param u1        the left edge of the texture
 * @param v1        the top edge of the texture
 * @param u2        the right edge of the texture
 * @param v2        the bottom edge of the texture
 * @param color     a color to tint the texture. This can be transparent! Use 0xFF_FFFFFF if you don't want a color tint
 * @param opacity   opacity of the drawn texture. (0f is fully opaque and 1f is fully visible)
 * @since 2.0.0
 */
public static void texturedRect(int x, int y, int width, int height, Identifier texture, float u1, float v1, float u2, float v2, int color, float opacity) {
	MinecraftClient.getInstance().getTextureManager().bindTexture(texture);

	//float scale = 0.00390625F;

	if (width <= 0) width = 1;
	if (height <= 0) height = 1;

	float r = (color >> 16 & 255) / 255.0F;
	float g = (color >> 8 & 255) / 255.0F;
	float b = (color & 255) / 255.0F;
	Tessellator tessellator = Tessellator.getInstance();
	BufferBuilder buffer = tessellator.getBuffer();
	RenderSystem.enableBlend();
	//GlStateManager.disableTexture2D();
	RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO);
	buffer.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE); //I thought GL_QUADS was deprecated but okay, sure.
	buffer.vertex(x,         y + height, 0).color(r, g, b, opacity).texture(u1, v2).next();
	buffer.vertex(x + width, y + height, 0).color(r, g, b, opacity).texture(u2, v2).next();
	buffer.vertex(x + width, y,          0).color(r, g, b, opacity).texture(u2, v1).next();
	buffer.vertex(x,         y,          0).color(r, g, b, opacity).texture(u1, v1).next();
	tessellator.draw();
	//GlStateManager.enableTexture2D();
	RenderSystem.disableBlend();
}
 
Example #5
Source File: CottonInventoryScreen.java    From LibGui with MIT License 6 votes vote down vote up
@Override
public boolean keyPressed(int ch, int keyCode, int modifiers) {
	//System.out.println("Key " + Integer.toHexString(ch)+" "+Integer.toHexString(keyCode));
	if (ch==GLFW.GLFW_KEY_ESCAPE) {
		this.client.player.closeHandledScreen();
		return true;
	} else if (ch==GLFW.GLFW_KEY_TAB) {
		changeFocus(!hasShiftDown());
		return true;
	} else {
		//if (super.keyPressed(ch, keyCode, modifiers)) return true;
		if (description.getFocus()==null) {
			if (MinecraftClient.getInstance().options.keyInventory.matchesKey(ch, keyCode)) {
				this.client.player.closeHandledScreen();
				return true;
			}
			return false;
		} else {
			description.getFocus().onKeyPressed(ch, keyCode, modifiers);
			return true;
		}
	}
}
 
Example #6
Source File: TinyPumpkinRenderer.java    From the-hallow with MIT License 6 votes vote down vote up
@Override
public void render(TinyPumpkinBlockEntity pumpkin, float f, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j) {
	ItemRenderer renderer = MinecraftClient.getInstance().getItemRenderer();
	
	matrixStack.push();
	matrixStack.translate(0.5, 0.275, 0.5);
	matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(360 - pumpkin.getCachedState().get(HorizontalFacingBlock.FACING).asRotation()));
	matrixStack.multiply(NINETY_DEG_X);
	matrixStack.scale(0.75f, 0.75f, 0.75f);
	
	matrixStack.push();
	matrixStack.translate(0.25, 0, 0);
	matrixStack.multiply(MINUS_NINETY_DEG_Y);
	renderer.renderItem(pumpkin.getLeftItem(), ModelTransformation.Mode.FIXED, i, j, matrixStack, vertexConsumerProvider);
	matrixStack.pop();
	
	matrixStack.push();
	matrixStack.translate(-0.25, 0, 0);
	matrixStack.multiply(MINUS_NINETY_DEG_Y);
	renderer.renderItem(pumpkin.getRightItem(), ModelTransformation.Mode.FIXED, i, j, matrixStack, vertexConsumerProvider);
	matrixStack.pop();
	
	matrixStack.pop();
}
 
Example #7
Source File: DropDownWidget.java    From multiconnect with MIT License 6 votes vote down vote up
private void onExpandedMouseClicked(int mouseX, int mouseY) {
    if (hoveredSubcategory != -1) {
        setValue(categories.get(hoveredCategory).children.get(hoveredSubcategory));
        playDownSound(MinecraftClient.getInstance().getSoundManager());
        expanded = false;
        return;
    }

    if (hoveredCategory == -1 || !isMouseInMainMenuPart(mouseX, mouseY)) {
        expanded = false;
        if (isHovered()) {
            playDownSound(MinecraftClient.getInstance().getSoundManager());
        }
        return;
    }

    Category category = categories.get(hoveredCategory);
    if (!category.hasChildren()) {
        setValue(category.value);
        playDownSound(MinecraftClient.getInstance().getSoundManager());
        expanded = false;
    }
}
 
Example #8
Source File: AbstractProtocol.java    From multiconnect with MIT License 6 votes vote down vote up
public void setup(boolean resourceReload) {
    if (!resourceReload) {
        modifyPacketLists();
        DataTrackerManager.onConnectToServer();
    }
    DefaultRegistry.restoreAll();
    RegistryMutator mutator = new RegistryMutator();
    mutateRegistries(mutator);
    mutator.runMutations(DefaultRegistry.DEFAULT_REGISTRIES.keySet());
    DefaultRegistry.DEFAULT_REGISTRIES.keySet().forEach((this::postMutateRegistry));
    recomputeBlockStates();
    if (!resourceReload) {
        removeTrackedDataHandlers();
        OldLanguageManager.reloadLanguages();
    }
    ((MinecraftClientAccessor) MinecraftClient.getInstance()).callInitializeSearchableContainers();
    ((MinecraftClientAccessor) MinecraftClient.getInstance()).getSearchManager().apply(MinecraftClient.getInstance().getResourceManager());
}
 
Example #9
Source File: HeldItemFeature.java    From MineLittlePony with MIT License 6 votes vote down vote up
private void renderHeldItem(T entity, ItemStack drop, ModelTransformation.Mode transform, Arm arm, MatrixStack stack, VertexConsumerProvider renderContext, int lightUv) {
    if (!drop.isEmpty()) {
        stack.push();
        renderArm(arm, stack);

        if (getContextModel().getAttributes().isCrouching) {
            stack.translate(0, 0.2F, 0);
        }

        float left = arm == Arm.LEFT ? 1 : -1;

        if (entity.hasVehicle()) {
            stack.translate(left / 10, -0.2F, -0.5F);
        }

        stack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(-90));
        stack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(left * 180));
        stack.translate(left * -0.2F, 0, 0);

        preItemRender(entity, drop, transform, arm, stack);
        MinecraftClient.getInstance().getItemRenderer().renderItem(entity, drop, transform, arm == Arm.LEFT, stack, renderContext, entity.world, lightUv, OverlayTexture.DEFAULT_UV);
        postItemRender(entity, drop, transform, arm, stack, renderContext);

        stack.pop();
    }
}
 
Example #10
Source File: Window.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public void render(int mX, int mY) {
	TextRenderer textRend = MinecraftClient.getInstance().textRenderer;
	
	if (dragging) {
		x2 = (x2 - x1) + mX - dragOffX;
		y2 = (y2 - y1) + mY - dragOffY;
		x1 = mX - dragOffX;
		y1 = mY - dragOffY;
	}
	
	drawBar(mX, mY, textRend);
	
	for (WindowButton w: buttons) {
		int bx1 = x1 + w.x1;
		int by1 = y1 + w.y1;
		int bx2 = x1 + w.x2;
		int by2 = y1 + w.y2;
		
		Screen.fill(bx1, by1, bx2 - 1, by2 - 1, 0xffb0b0b0);
		Screen.fill(bx1 + 1, by1 + 1, bx2, by2, 0xff000000);
		Screen.fill(bx1 + 1, by1 + 1, bx2 - 1, by2 - 1,
				selected && mX >= bx1 && mX <= bx2 && mY >= by1 && mY <= by2 ? 0xff959595 : 0xff858585);
		textRend.drawWithShadow(w.text, bx1 + (bx2 - bx1) / 2 - textRend.getStringWidth(w.text) / 2, by1 + (by2 - by1) / 2 - 4, -1);
	}
	
	/* window icon */
	if (icon != null && selected) {
		GL11.glPushMatrix();
		GL11.glScaled(0.55, 0.55, 1);
		GuiLighting.enable();
		MinecraftClient.getInstance().getItemRenderer().renderGuiItem(icon, (int)((x1 + 3) * 1/0.55), (int)((y1 + 3) * 1/0.55));
		GL11.glPopMatrix();
	}
	
	/* window title */
	textRend.drawWithShadow(title, x1 + (icon == null  || !selected ? 4 : 15), y1 + 3, -1);
}
 
Example #11
Source File: MixinClientPlayNetworkHandler.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true)
private void onOnCustomPayload(CustomPayloadS2CPacket packet, CallbackInfo ci) {
    NetworkThreadUtils.forceMainThread(packet, (ClientPlayNetworkHandler) (Object) this, MinecraftClient.getInstance());
    if (packet.getChannel().equals(CustomPayloadHandler.DROP_ID)) {
        ci.cancel();
    } else if (ConnectionInfo.protocolVersion != SharedConstants.getGameVersion().getProtocolVersion()
            && !CustomPayloadHandler.VANILLA_CHANNELS.contains(packet.getChannel())) {
        CustomPayloadHandler.handleCustomPayload(packet);
        ci.cancel();
    }
}
 
Example #12
Source File: WorldUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isBoxEmpty(Box box) {
	for (int x = (int) Math.floor(box.minX); x < Math.ceil(box.maxX); x++) {
		for (int y = (int) Math.floor(box.minY); y < Math.ceil(box.maxY); y++) {
			for (int z = (int) Math.floor(box.minZ); z < Math.ceil(box.maxZ); z++) {
				if (!NONSOLID_BLOCKS.contains(MinecraftClient.getInstance().world.getBlockState(new BlockPos(x, y, z)).getBlock())) {
					return false;
				}
			}
		}
	}
	return true;
}
 
Example #13
Source File: WText.java    From LibGui with MIT License 5 votes vote down vote up
/**
 * Gets the text style at the specific widget-space coordinates.
 *
 * @param x the X coordinate in widget space
 * @param y the Y coordinate in widget space
 * @return the text style at the position, or null if not found
 */
@Environment(EnvType.CLIENT)
@Nullable
public Style getTextStyleAt(int x, int y) {
	TextRenderer font = MinecraftClient.getInstance().textRenderer;
	int lineIndex = y / font.fontHeight;

	if (lineIndex >= 0 && lineIndex < wrappedLines.size()) {
		StringRenderable line = wrappedLines.get(lineIndex);
		return font.getTextHandler().trimToWidth(line, x);
	}

	return null;
}
 
Example #14
Source File: ItemContentUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public static List<List<String>> getTextInBook(ItemStack item) {
	List<String> pages = new ArrayList<>();
	CompoundTag nbt = item.getTag();
	
	if (nbt != null && nbt.contains("pages")) {
		ListTag nbt2 = nbt.getList("pages", 8);
		for (int i = 0; i < nbt2.size(); i++) pages.add(nbt2.getString(i));
	}
	
	List<List<String>> finalPages = new ArrayList<>();
	
	for (String s: pages) {
		String buffer = "";
		List<String> pageBuffer = new ArrayList<>();
		
		for (char c: s.toCharArray()) {
			if (MinecraftClient.getInstance().textRenderer.getWidth(buffer) > 114 || buffer.endsWith("\n")) {
				pageBuffer.add(buffer.replace("\n", ""));
				buffer = "";
			}
			
			buffer += c;
		}
		pageBuffer.add(buffer);
		finalPages.add(pageBuffer);
	}
	
	return finalPages;
}
 
Example #15
Source File: MixinTitleScreen.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(at = @At("HEAD"), method = "init()V")
private void init(CallbackInfo info) {
	if (BleachMainMenu.customTitleScreen) {
		MinecraftClient.getInstance().openScreen(new BleachMainMenu());
	} else {
		addButton(new ButtonWidget(width / 2 - 124, height / 4 + 96, 20, 20, new LiteralText("BH"), button -> {
			BleachMainMenu.customTitleScreen = !BleachMainMenu.customTitleScreen;
			client.openScreen(new TitleScreen(false));
		}));
	}
}
 
Example #16
Source File: VRPlatform.java    From ViaFabric with MIT License 5 votes vote down vote up
@Environment(EnvType.CLIENT)
private void sendMessageClient(String s) {
    ClientPlayNetworkHandler handler = MinecraftClient.getInstance().getNetworkHandler();
    if (handler != null) {
        try {
            handler.onGameMessage(new GameMessageS2CPacket(
                    Text.Serializer.fromJson(ChatRewriter.legacyTextToJson(s)), MessageType.SYSTEM, Util.NIL_UUID
            ));
        } catch (OffThreadException ignored) {
        }
    }
}
 
Example #17
Source File: ClientPonyConfig.java    From MineLittlePony with MIT License 5 votes vote down vote up
@Override
public void save() {
    super.save();
    PlayerEntity player = MinecraftClient.getInstance().player;
    if (player != null) {
        player.calculateDimensions();
    }
}
 
Example #18
Source File: HorseCam.java    From MineLittlePony with MIT License 5 votes vote down vote up
/**
 * Transforms the client pony's pitch to the corresponding angle for a human character.
 */
public static float transformCameraAngle(float pitch) {

    if (!MineLittlePony.getInstance().getConfig().fillycam.get()) {
        return pitch;
    }

    PlayerEntity player = MinecraftClient.getInstance().player;
    IPony pony = MineLittlePony.getInstance().getManager().getPony(player);

    if (!pony.getRace(false).isHuman()) {
        float factor = pony.getMetadata().getSize().getEyeHeightFactor();
        return rescaleCameraPitch(player.getStandingEyeHeight() / factor, pitch);
    }

    return pitch;
}
 
Example #19
Source File: MixinDownloadingTerrainScreen.java    From multiconnect with MIT License 5 votes vote down vote up
@Override
public void tick() {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_12_1) {
        tickCounter++;

        if (tickCounter % 20 == 0) {
            //noinspection ConstantConditions
            MinecraftClient.getInstance().getNetworkHandler().sendPacket(new KeepAliveC2SPacket());
        }
    }
}
 
Example #20
Source File: MixinClientChunkManager.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "tick", at = @At("HEAD"))
private void onTick(BooleanSupplier fallingBehind, CallbackInfo ci) {
    if (MinecraftClient.getInstance().getCameraEntity() != null
            && MinecraftClient.getInstance().getCameraEntity() != MinecraftClient.getInstance().player
            && MinecraftClient.getInstance().getCameraEntity().isAlive()) {
        Protocol_1_13_2.updateCameraPosition();
    }
}
 
Example #21
Source File: UseBedS2CPacket.java    From multiconnect with MIT License 5 votes vote down vote up
@Override
public void apply(ClientPlayNetworkHandler handler) {
    NetworkThreadUtils.forceMainThread(this, handler, MinecraftClient.getInstance());
    Entity entity = MinecraftClient.getInstance().world.getEntityById(playerId);
    if (entity instanceof PlayerEntity) {
        ((PlayerEntity) entity).trySleep(bedPos);
    }
}
 
Example #22
Source File: EntitySpawnGlobalS2CPacket_1_15_2.java    From multiconnect with MIT License 5 votes vote down vote up
@Override
public void apply(ClientPlayPacketListener listener) {
    NetworkThreadUtils.forceMainThread(this, listener, MinecraftClient.getInstance());
    if (entityTypeId == 1) {
        LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(MinecraftClient.getInstance().world);
        if (lightning == null) {
            return;
        }
        lightning.setPos(x, y, z);
        listener.onEntitySpawn(new EntitySpawnS2CPacket(lightning));
    }
}
 
Example #23
Source File: WLabel.java    From LibGui with MIT License 5 votes vote down vote up
@Environment(EnvType.CLIENT)
@Override
public void onClick(int x, int y, int button) {
	Style hoveredTextStyle = getTextStyleAt(x, y);
	if (hoveredTextStyle != null) {
		Screen screen = MinecraftClient.getInstance().currentScreen;
		if (screen != null) {
			screen.handleTextClick(hoveredTextStyle);
		}
	}
}
 
Example #24
Source File: ShapesRenderer.java    From fabric-carpet with MIT License 5 votes vote down vote up
protected RenderedShape(MinecraftClient client, T shape)
{
    this.shape = shape;
    expiryTick = client.world.getTime()+shape.getExpiry();
    renderEpsilon = (3+((double)shape.key())/Long.MAX_VALUE)/1000;
    this.client = client;
}
 
Example #25
Source File: PonyRenderDispatcher.java    From MineLittlePony with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Nullable
public <T extends LivingEntity, M extends EntityModel<T> & IPonyModel<T>> IPonyRenderContext<T, M> getPonyRenderer(@Nullable T entity) {
    if (entity == null) {
        return null;
    }

    EntityRenderer<?> renderer = MinecraftClient.getInstance().getEntityRenderManager().getRenderer(entity);

    if (renderer instanceof IPonyRenderContext) {
        return (IPonyRenderContext<T, M>) renderer;
    }

    return null;
}
 
Example #26
Source File: ButtonWidgetMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void renderBg(MatrixStack matrixStack, MinecraftClient client,
	int mouseX, int mouseY)
{
	int i = getYImage(isHovered());
	drawTexture(matrixStack, x, y, 0, 46 + i * 20, width / 2, height / 2);
	drawTexture(matrixStack, x + width / 2, y, 200 - width / 2, 46 + i * 20,
		width / 2, height / 2);
	drawTexture(matrixStack, x, y + height / 2, 0,
		46 + i * 20 + 20 - height / 2, width / 2, height / 2);
	drawTexture(matrixStack, x + width / 2, y + height / 2, 200 - width / 2,
		46 + i * 20 + 20 - height / 2, width / 2, height / 2);
}
 
Example #27
Source File: WLabel.java    From LibGui with MIT License 5 votes vote down vote up
/**
 * Gets the text style at the specific widget-space coordinates.
 *
 * @param x the X coordinate in widget space
 * @param y the Y coordinate in widget space
 * @return the text style at the position, or null if not found
 */
@Environment(EnvType.CLIENT)
@Nullable
public Style getTextStyleAt(int x, int y) {
	if (isWithinBounds(x, y)) {
		return MinecraftClient.getInstance().textRenderer.getTextHandler().trimToWidth(text, x);
	}
	return null;
}
 
Example #28
Source File: InGameOverlayRendererMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(at = {@At("HEAD")},
	method = {
		"renderUnderwaterOverlay(Lnet/minecraft/client/MinecraftClient;Lnet/minecraft/client/util/math/MatrixStack;)V"},
	cancellable = true)
private static void onRenderUnderwaterOverlay(
	MinecraftClient minecraftClient, MatrixStack matrixStack,
	CallbackInfo ci)
{
	if(WurstClient.INSTANCE.getHax().noOverlayHack.isEnabled())
		ci.cancel();
}
 
Example #29
Source File: Window.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public void render(int mX, int mY) {
	TextRenderer textRend = MinecraftClient.getInstance().textRenderer;
	
	if (dragging) {
		x2 = (x2 - x1) + mX - dragOffX;
		y2 = (y2 - y1) + mY - dragOffY;
		x1 = mX - dragOffX;
		y1 = mY - dragOffY;
	}
	
	drawBar(mX, mY, textRend);
	
	for (WindowButton w: buttons) {
		int bx1 = x1 + w.x1;
		int by1 = y1 + w.y1;
		int bx2 = x1 + w.x2;
		int by2 = y1 + w.y2;
		
		Screen.fill(bx1, by1, bx2 - 1, by2 - 1, 0xffb0b0b0);
		Screen.fill(bx1 + 1, by1 + 1, bx2, by2, 0xff000000);
		Screen.fill(bx1 + 1, by1 + 1, bx2 - 1, by2 - 1,
				selected && mX >= bx1 && mX <= bx2 && mY >= by1 && mY <= by2 ? 0xff959595 : 0xff858585);
		textRend.drawWithShadow(w.text, bx1 + (bx2 - bx1) / 2 - textRend.getStringWidth(w.text) / 2, by1 + (by2 - by1) / 2 - 4, -1);
	}
	
	/* window icon */
	if (icon != null && selected) {
		GL11.glPushMatrix();
		GL11.glScaled(0.55, 0.55, 1);
		DiffuseLighting.enableGuiDepthLighting();
		MinecraftClient.getInstance().getItemRenderer().renderGuiItem(icon, (int)((x1 + 3) * 1/0.55), (int)((y1 + 3) * 1/0.55));
		GL11.glPopMatrix();
	}
	
	/* window title */
	textRend.drawWithShadow(title, x1 + (icon == null || !selected || icon.getItem() == Items.AIR ? 4 : 15), y1 + 3, -1);
}
 
Example #30
Source File: WLabel.java    From LibGui with MIT License 5 votes vote down vote up
@Override
public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) {
	MinecraftClient mc = MinecraftClient.getInstance();
	TextRenderer renderer = mc.textRenderer;
	int yOffset;

	switch (verticalAlignment) {
		case CENTER:
			yOffset = height / 2 - renderer.fontHeight / 2;
			break;
		case BOTTOM:
			yOffset = height - renderer.fontHeight;
			break;
		case TOP:
		default:
			yOffset = 0;
			break;
	}

	ScreenDrawing.drawString(matrices, text, horizontalAlignment, x, y + yOffset, this.getWidth(), LibGuiClient.config.darkMode ? darkmodeColor : color);

	Style hoveredTextStyle = getTextStyleAt(mouseX, mouseY);
	if (hoveredTextStyle != null) {
		Screen screen = MinecraftClient.getInstance().currentScreen;
		if (screen instanceof TextHoverRendererScreen) {
			((TextHoverRendererScreen) screen).renderTextHover(matrices, hoveredTextStyle, x + mouseX, y + mouseY);
		}
	}
}