Начинающий
- Статус
- Оффлайн
- Регистрация
- 17 Дек 2023
- Сообщения
- 36
- Реакции
- 1
- Выберите загрузчик игры
- Vanilla
- Forge
- Fabric
- NeoForge
- OptiFine
- ForgeOptiFine
Проблема: Игра рендерит хотбар сотни лишних кадров за раз, тоесть в каждом кадре, которые монитор физически не может отобразить. Это создаёт просадки фпс.
Решение: Методы автоматически ограничивает частоту рендера хотбара, отсекая бесполезные кадры. Прибавит немного фпс вашей пасте.
p.s на 5-8 процентов качество текста в тултип подсказке может просесть
Исправить в классе IngameGui.
Решение: Методы автоматически ограничивает частоту рендера хотбара, отсекая бесполезные кадры. Прибавит немного фпс вашей пасте.
p.s на 5-8 процентов качество текста в тултип подсказке может просесть
Исправить в классе IngameGui.
IngameGui:
protected void renderHotbar(float partialTicks, MatrixStack matrixStack) {
PlayerEntity playerentity = this.getRenderViewPlayer();
if (playerentity == null) return;
int scaledWidth = this.scaledWidth;
int scaledHeight = this.scaledHeight;
int centerX = scaledWidth / 2;
int hotbarY = scaledHeight - 22;
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(WIDGETS_TEX_PATH);
ItemStack offhandStack = playerentity.getHeldItemOffhand();
HandSide handside = playerentity.getPrimaryHand().opposite();
int originalBlitOffset = this.getBlitOffset();
this.setBlitOffset(-90);
this.blit(matrixStack, centerX - 91, hotbarY, 0, 0, 182, 22);
this.blit(matrixStack, centerX - 91 - 1 + playerentity.inventory.currentItem * 20,
scaledHeight - 22 - 1, 0, 22, 24, 22);
if (!offhandStack.isEmpty()) {
if (handside == HandSide.LEFT) {
this.blit(matrixStack, centerX - 91 - 29, scaledHeight - 23, 24, 22, 29, 24);
} else {
this.blit(matrixStack, centerX + 91, scaledHeight - 23, 53, 22, 29, 24);
}
}
this.setBlitOffset(originalBlitOffset);
RenderSystem.enableRescaleNormal();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
CustomItems.setRenderOffHand(false);
EventManager.call(new EventHotbarRender.Pre(matrixStack, partialTicks));
int itemY = scaledHeight - 16 - 3;
int startX = centerX - 88;
for (int i1 = 0; i1 < 9; ++i1) {
int itemX = startX + i1 * 20;
ItemStack stack = playerentity.inventory.mainInventory.get(i1);
if (!stack.isEmpty()) {
this.renderHotbarItem(itemX, itemY, partialTicks, playerentity, stack);
}
}
RenderSystem.disableDepthTest();
EventManager.call(new EventHotbarRender.Post(matrixStack, partialTicks));
RenderSystem.enableDepthTest();
if (!offhandStack.isEmpty()) {
CustomItems.setRenderOffHand(true);
int offhandY = scaledHeight - 16 - 3;
int offhandX = handside == HandSide.LEFT ?
centerX - 91 - 26 :
centerX + 91 + 10;
this.renderHotbarItem(offhandX, offhandY, partialTicks, playerentity, offhandStack);
CustomItems.setRenderOffHand(false);
}
FoodStats foodStats = playerentity.getFoodStats();
if (!mc.player.isCreative() &&
Manager.FUNCTION_MANAGER.saturationViewer.state &&
foodStats.getFoodLevel() >= 20 &&
foodStats.getSaturationLevel() >= 0.5F) {
this.renderSaturationOverlay(matrixStack, centerX, scaledHeight);
}
if (this.mc.gameSettings.attackIndicator == AttackIndicatorStatus.HOTBAR) {
this.renderAttackIndicatorHotbar(matrixStack, centerX, scaledHeight, handside);
}
RenderSystem.disableRescaleNormal();
RenderSystem.disableBlend();
}
private void renderSaturationOverlay(MatrixStack matrixStack, int centerX, int scaledHeight) {
this.mc.getTextureManager().bindTexture(AbstractGui.GUI_ICONS_LOCATION);
float saturation = this.mc.player.getFoodStats().getSaturationLevel();
int filledIcons = (int) (saturation / 2.0F);
boolean hasHalfIcon = saturation % 2.0F >= 1.0F;
int totalIcons = Math.min(filledIcons + (hasHalfIcon || saturation < 1.0F ? 1 : 0), 10);
int saturationX = centerX + 91;
int saturationY = scaledHeight - 48;
for (int idx = 0; idx < totalIcons; ++idx) {
int x = saturationX - idx * 8 - 9;
this.blit(matrixStack, x, saturationY, 16, 27, 9, 9);
if (idx < filledIcons) {
this.blit(matrixStack, x, saturationY, 52, 27, 9, 9);
} else if (idx == filledIcons && (hasHalfIcon || saturation < 1.0F)) {
this.blit(matrixStack, x, saturationY, 34, 27, 9, 9);
}
}
}
private void renderAttackIndicatorHotbar(MatrixStack matrixStack, int centerX, int scaledHeight, HandSide handside) {
float f = this.mc.player.getCooledAttackStrength(0.0F);
if (f >= 1.0F) return;
int y = scaledHeight - 20;
int x = handside == HandSide.RIGHT ? centerX + 91 + 6 : centerX - 91 - 22;
this.mc.getTextureManager().bindTexture(AbstractGui.GUI_ICONS_LOCATION);
int height = (int) (f * 19.0F);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
this.blit(matrixStack, x, y, 0, 94, 18, 18);
this.blit(matrixStack, x, y + 18 - height, 18, 112 - height, 18, height);
}
public void renderHotbarItem(int x, int y, float partialTicks, PlayerEntity player, ItemStack stack) {
if (stack.isEmpty()) return;
float animTime = (float) stack.getAnimationsToGo() - partialTicks;
boolean hasAnimation = animTime > 0.0F;
if (hasAnimation) {
RenderSystem.pushMatrix();
float scale = 1.0F + animTime / 5.0F;
RenderSystem.translatef((float) (x + 8), (float) (y + 12), 0.0F);
RenderSystem.scalef(1.0F / scale, (scale + 1.0F) / 2.0F, 1.0F);
RenderSystem.translatef((float) (-(x + 8)), (float) (-(y + 12)), 0.0F);
}
this.itemRenderer.renderItemAndEffectIntoGUI(player, stack, x, y);
if (hasAnimation) {
RenderSystem.popMatrix();
}
this.itemRenderer.renderItemOverlays(this.mc.fontRenderer, stack, x, y);
}