Skip to content

Commit

Permalink
1.21 porting done, and optimized pistorder rendering
Browse files Browse the repository at this point in the history
another mojank time
  • Loading branch information
Fallen-Breath committed Jun 19, 2024
1 parent 9603c0e commit 1af0afd
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void renderStatusEffectIcon(Vec3d pos, StatusEffect statusEffect, int am

// ref: net.minecraft.client.gui.hud.InGameHud.renderStatusEffectOverlay

renderContext.scale(-FONT_SCALE, -FONT_SCALE, FONT_SCALE);
renderContext.scale(FONT_SCALE * RenderUtil.getSizeScalingXSign(), -FONT_SCALE, FONT_SCALE);
renderContext.translate(deltaX, 0, 0);

// scale 2: make the rendered texture height == expected height (line height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,47 @@

package me.fallenbreath.tweakermore.impl.features.pistorder.pushlimit.handlers;

import net.fabricmc.loader.api.FabricLoader;

import java.lang.reflect.Field;

public abstract class BasicStaticFieldRulePushLimitHandler implements PushLimitHandler
{
private final String className;
private final String fieldName;
private final boolean modLoaded;
private Field ruleField;

public BasicStaticFieldRulePushLimitHandler(String className, String fieldName)
{
this.className = className;
this.fieldName = fieldName;
this.modLoaded = FabricLoader.getInstance().isModLoaded(this.getModId());
this.ruleField = null;
}

private Field getRuleField() throws ClassNotFoundException, NoSuchFieldException
{
Class<?> clazz = Class.forName(className);
Field field = clazz.getField(fieldName);
if (this.ruleField != null)
{
return this.ruleField;
}

Class<?> clazz = Class.forName(this.className);
Field field = clazz.getField(this.fieldName);
field.setAccessible(true);

this.ruleField = field;
return field;
}

@Override
public void setPushLimit(int pushLimit) throws PushLimitOperateException
{
if (!this.modLoaded)
{
throw new PushLimitOperateException();
}
try
{
this.getRuleField().setInt(null, pushLimit);
Expand All @@ -57,6 +74,10 @@ public void setPushLimit(int pushLimit) throws PushLimitOperateException
@Override
public int getPushLimit() throws PushLimitOperateException
{
if (!this.modLoaded)
{
throw new PushLimitOperateException();
}
try
{
return this.getRuleField().getInt(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ public PushLimitOperateException(Exception cause)
{
super(cause);
}

public PushLimitOperateException()
{
super();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ public static int getRenderWidth(String text)
return TEXT_RENDERER.getStringWidth(text);
}

public static int getSizeScalingXSign()
{
// stupid change in 24w21a
//#if MC >= 12100
//$$ return 1;
//#else
return -1;
//#endif
}

//#if MC >= 11600
//$$ public static int getRenderWidth(OrderedText text)
//$$ {
Expand All @@ -66,7 +76,7 @@ public static int getRenderWidth(String text)
public static VertexConsumerProvider.Immediate getVertexConsumer()
{
//#if MC >= 12100
//$$ return VertexConsumerProvider.immediate(new BufferAllocator(RenderLayer.DEFAULT_BUFFER_SIZE));
//$$ return MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
//#else
return VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
//#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void render()
InWorldPositionTransformer positionTransformer = new InWorldPositionTransformer(this.pos);
positionTransformer.apply(renderContext);
{
renderContext.scale(-this.fontScale, -this.fontScale, this.fontScale);
renderContext.scale(this.fontScale * RenderUtil.getSizeScalingXSign(), -this.fontScale, this.fontScale);

//#if MC < 11700
RenderGlobals.disableLighting();
Expand Down Expand Up @@ -183,8 +183,8 @@ public void render()
int backgroundColor = this.backgroundColor;
while (true)
{
VertexConsumerProvider.Immediate immediate = RenderUtil.getVertexConsumer();
Matrix4f matrix4f = Rotation3.identity().getMatrix();
VertexConsumerProvider.Immediate immediate = RenderUtil.getVertexConsumer();
mc.textRenderer.draw(
holder.text, textX, textY, this.color, this.shadow, matrix4f, immediate,
//#if MC >= 11904
Expand All @@ -206,6 +206,7 @@ public void render()
backgroundColor = 0;
}
}

//#else
//$$ if (this.shadow)
//$$ {
Expand Down

0 comments on commit 1af0afd

Please sign in to comment.