Skip to content

Commit

Permalink
Added mc tweak f3TextScale
Browse files Browse the repository at this point in the history
resolved #75
  • Loading branch information
Fallen-Breath committed Sep 4, 2024
1 parent c6ff6de commit 9761f6f
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/document-en_us.md
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,17 @@ Use coordinate "~ ~1 ~" instead of "~ ~ ~" in option f3IUseRelatedCoordinate
- Default value: `true`


### f3TextScale

Scale the texts in the F3 debug hud with given factor

- Category: MC Tweaks
- Type: double (Generic)
- Default value: `1.0`
- Minimum value: `0.01`
- Maximum value: `4.0`


### fakeNightVision

Always use night vision for game rendering, regardless of whether the player actually has night vision
Expand Down
11 changes: 11 additions & 0 deletions docs/document-zh_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,17 @@ schematicBlockPlacement的严格模式
- 默认值: `true`


### F3字体大小缩放 (f3TextScale)

将F3界面的文本按照给定参数进行缩放

- 分类: MC修改
- 类型: 实数 (通用)
- 默认值: `1.0`
- 最小值: `0.01`
- 最大值: `4.0`


### 伪夜视 (fakeNightVision)

总是运用夜视效果下的游戏渲染,无论玩家是否确实拥有夜视效果
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ public class TweakerMoreConfigs
@Config(type = Config.Type.GENERIC, category = Config.Category.MC_TWEAKS)
public static final TweakerMoreConfigBoolean F3_I_USE_RELATED_COORDINATE_SHIFT_1 = newConfigBoolean("f3IUseRelatedCoordinateShift1", true);

@Config(type = Config.Type.GENERIC, category = Config.Category.MC_TWEAKS)
public static final TweakerMoreConfigDouble F3_TEXT_SCALE = newConfigDouble("f3TextScale", 1, 0.01, 4);

@Config(type = Config.Type.TWEAK, category = Config.Category.MC_TWEAKS)
public static final TweakerMoreConfigBooleanHotkeyed FAKE_NIGHT_VISION = newConfigBooleanHotkeyed("fakeNightVision");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* This file is part of the TweakerMore project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* TweakerMore is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TweakerMore is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with TweakerMore. If not, see <https://www.gnu.org/licenses/>.
*/

package me.fallenbreath.tweakermore.mixins.tweaks.mc_tweaks.f3TextScale;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs;
import me.fallenbreath.tweakermore.util.render.RenderUtil;
import me.fallenbreath.tweakermore.util.render.context.RenderContext;
import net.minecraft.client.gui.hud.DebugHud;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

//#if MC >= 12000
//$$ import net.minecraft.client.gui.DrawContext;
//#elseif MC >= 11600
//$$ import net.minecraft.client.util.math.MatrixStack;
//#endif

//#if MC >= 11600
//$$ import com.llamalad7.mixinextras.sugar.Local;
//#endif

@Mixin(DebugHud.class)
public abstract class DebugHudMixin
{
@Inject(
//#if MC >= 12000
//$$ method = "drawText",
//#else
method = {"renderLeftText", "renderRightText"},
//#endif
at = @At("HEAD")
)
private void f3TextScale_renderLeftRightText_scalingApply(
CallbackInfo ci,
//#if MC >= 12000
//$$ @Local(argsOnly = true) DrawContext matrixStackOrDrawContext,
//#elseif MC >= 11600
//$$ @Local(argsOnly = true) MatrixStack matrixStackOrDrawContext,
//#endif
@Share("scaler") LocalRef<RenderUtil.Scaler> scaler
)
{
if (TweakerMoreConfigs.F3_TEXT_SCALE.isModified())
{
scaler.set(RenderUtil.createScaler(0, 0, TweakerMoreConfigs.F3_TEXT_SCALE.getDoubleValue()));
scaler.get().apply(RenderContext.of(
//#if MC >= 11600
//$$ matrixStackOrDrawContext
//#endif
));
}
}

@ModifyExpressionValue(
//#if MC >= 12000
//$$ method = "drawText",
//#else
method = "renderRightText",
//#endif
at = @At(
value = "INVOKE",
//#if MC >= 12000
//$$ target = "Lnet/minecraft/client/gui/DrawContext;getScaledWindowWidth()I"
//#else
target = "Lnet/minecraft/client/util/Window;getScaledWidth()I"
//#endif
)
)
private int f3TextScale_renderRightText_fixWindowScaledWidth(int width, @Share("scaler") LocalRef<RenderUtil.Scaler> scaler)
{
if (scaler.get() != null)
{
width = (int)(width / scaler.get().getScaleFactor());
}
return width;
}

@Inject(
//#if MC >= 12000
//$$ method = "drawText",
//#else
method = {"renderLeftText", "renderRightText"},
//#endif
at = @At("TAIL")
)
private void f3TextScale_renderLeftRightText_scalingRestore(CallbackInfo ci, @Share("scaler") LocalRef<RenderUtil.Scaler> scaler)
{
if (scaler.get() != null)
{
scaler.get().restore();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ private Scaler(double anchorX, double anchorY, double factor)
this.factor = factor;
}

public double getScaleFactor()
{
return this.factor;
}

public void apply(RenderContext renderContext)
{
this.renderContext = renderContext;
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/tweakermore/lang/en_us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,9 @@ tweakermore:
.: f3IUseRelatedCoordinateShift1
comment: |-
Use coordinate "~ ~1 ~" instead of "~ ~ ~" in option @option#f3IUseRelatedCoordinate@
f3TextScale:
.: f3TextScale
comment: Scale the texts in the F3 debug hud with given factor
fakeNightVision:
.: fakeNightVision
comment: Always use night vision for game rendering, regardless of whether the player actually has night vision
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/tweakermore/lang/zh_cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,9 @@ tweakermore:
.: F3+I使用相对坐标-上移1m
comment: |-
在选项@option#f3IUseRelatedCoordinate@中,使用坐标 ~ ~1 ~ 代替 ~ ~ ~
f3TextScale:
.: F3字体大小缩放
comment: 将F3界面的文本按照给定参数进行缩放
fakeNightVision:
.: 伪夜视
comment: 总是运用夜视效果下的游戏渲染,无论玩家是否确实拥有夜视效果
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/tweakermore.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
"util.render.TextHandlerAccessor"
],
"client": [
"tweaks.mc_tweaks.f3TextScale.DebugHudMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 9761f6f

Please sign in to comment.