Implemented text interface
This commit is contained in:
+1
-1
Submodule common updated: 7eb705d802...48494cd857
@@ -1,57 +0,0 @@
|
|||||||
package org.saturnclient.impl;
|
|
||||||
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
|
||||||
import net.minecraft.text.Style;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
public class Fonts {
|
|
||||||
public static final Identifier INTER = Identifier.of("saturnclient", "inter");
|
|
||||||
public static final Identifier INTER_BOLD = Identifier.of("saturnclient", "inter_bold");
|
|
||||||
public static final Identifier DEFAULT = Identifier.ofVanilla("default");
|
|
||||||
|
|
||||||
public static Identifier getFont(int font) {
|
|
||||||
switch (font) {
|
|
||||||
case 0:
|
|
||||||
return DEFAULT;
|
|
||||||
case 1:
|
|
||||||
return INTER;
|
|
||||||
default:
|
|
||||||
return INTER_BOLD;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Text setFont(String text, Identifier font) {
|
|
||||||
return Text.literal(text).setStyle(
|
|
||||||
Style.EMPTY.withFont(font));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Text setFont(String text, int font) {
|
|
||||||
return Text.literal(text).setStyle(
|
|
||||||
Style.EMPTY.withFont(getFont(font)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getWidth(String text, int font) {
|
|
||||||
int w = 0;
|
|
||||||
for (String line : text.split("\n")) {
|
|
||||||
w = Math.max(w, getWidth(line, getFont(font)));
|
|
||||||
}
|
|
||||||
return w;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getWidth(String text, Identifier font) {
|
|
||||||
return SaturnClient.client.textRenderer.getWidth(setFont(text, font));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getHeight() {
|
|
||||||
return 18;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int centerX(int w, String text, int font) {
|
|
||||||
return (w - Fonts.getWidth(text, font)) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int centerY(int h) {
|
|
||||||
return (h - 18) / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package org.saturnclient.impl.mixins;
|
||||||
|
|
||||||
|
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||||
|
import org.saturnclient.common.ref.render.TextRef;
|
||||||
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
|
||||||
|
import net.minecraft.text.Style;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
@Mixin(Text.class)
|
||||||
|
public abstract class TextMixin implements TextRef {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TextRef withFont(IdentifierRef font) {
|
||||||
|
return (TextRef) (((Text) this).copy().setStyle(Style.EMPTY.withFont((Identifier) (Object) font)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWidth() {
|
||||||
|
return SaturnClient.client.textRenderer.getWidth((Text) this);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package org.saturnclient.impl;
|
package org.saturnclient.impl.provider;
|
||||||
|
|
||||||
import org.saturnclient.modules.Module;
|
import org.saturnclient.modules.Module;
|
||||||
import org.saturnclient.modules.ModManager.ModuleProvider;
|
import org.saturnclient.modules.ModManager.ModuleProvider;
|
||||||
@@ -2,7 +2,9 @@ package org.saturnclient.impl.provider;
|
|||||||
|
|
||||||
import org.saturnclient.common.provider.RefConstructorProvider;
|
import org.saturnclient.common.provider.RefConstructorProvider;
|
||||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||||
|
import org.saturnclient.common.ref.render.TextRef;
|
||||||
|
|
||||||
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class RefConstructorImpl implements RefConstructorProvider {
|
public class RefConstructorImpl implements RefConstructorProvider {
|
||||||
@@ -15,4 +17,9 @@ public class RefConstructorImpl implements RefConstructorProvider {
|
|||||||
public IdentifierRef identifier(String namespace, String path) {
|
public IdentifierRef identifier(String namespace, String path) {
|
||||||
return (IdentifierRef) (Object) Identifier.of(namespace, path);
|
return (IdentifierRef) (Object) Identifier.of(namespace, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TextRef text(String text) {
|
||||||
|
return (TextRef) Text.literal(text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import org.saturnclient.common.provider.SaturnProvider;
|
|||||||
import org.saturnclient.common.ref.asset.IdentifierRef;
|
import org.saturnclient.common.ref.asset.IdentifierRef;
|
||||||
import org.saturnclient.common.ref.game.MinecraftClientRef;
|
import org.saturnclient.common.ref.game.MinecraftClientRef;
|
||||||
import org.saturnclient.cosmetics.cloak.utils.IdentifierUtils;
|
import org.saturnclient.cosmetics.cloak.utils.IdentifierUtils;
|
||||||
import org.saturnclient.impl.Fonts;
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
@@ -24,11 +23,6 @@ public class SaturnProviderImpl implements SaturnProvider {
|
|||||||
&& SaturnClient.client.currentScreen == null;
|
&& SaturnClient.client.currentScreen == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidth(String text, int font) {
|
|
||||||
return Fonts.getWidth(text, font);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerBufferedImageTexture(IdentifierRef i, BufferedImage bi) {
|
public void registerBufferedImageTexture(IdentifierRef i, BufferedImage bi) {
|
||||||
IdentifierUtils.registerBufferedImageTextureFast((Identifier) (Object) i, bi);
|
IdentifierUtils.registerBufferedImageTextureFast((Identifier) (Object) i, bi);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import org.saturnclient.cosmetics.Hats;
|
|||||||
import org.saturnclient.cosmetics.cloak.Cloaks;
|
import org.saturnclient.cosmetics.cloak.Cloaks;
|
||||||
import org.saturnclient.common.bindings.SaturnClientBindings;
|
import org.saturnclient.common.bindings.SaturnClientBindings;
|
||||||
import org.saturnclient.common.provider.Providers;
|
import org.saturnclient.common.provider.Providers;
|
||||||
import org.saturnclient.impl.FabricModuleProvider;
|
import org.saturnclient.impl.provider.FabricModuleProvider;
|
||||||
import org.saturnclient.impl.provider.RefConstructorImpl;
|
import org.saturnclient.impl.provider.RefConstructorImpl;
|
||||||
import org.saturnclient.impl.provider.SaturnProviderImpl;
|
import org.saturnclient.impl.provider.SaturnProviderImpl;
|
||||||
import org.saturnclient.modules.ModManager;
|
import org.saturnclient.modules.ModManager;
|
||||||
|
|||||||
@@ -59,12 +59,13 @@ public class EntityDrawerImpl implements EntityDrawer {
|
|||||||
EntityRenderDispatcher entityRenderDispatcher = SaturnClient.client.getEntityRenderDispatcher();
|
EntityRenderDispatcher entityRenderDispatcher = SaturnClient.client.getEntityRenderDispatcher();
|
||||||
|
|
||||||
entityRenderDispatcher.setRenderShadows(false);
|
entityRenderDispatcher.setRenderShadows(false);
|
||||||
// TODO add the method draw with vertex consumers
|
if (renderScope instanceof RenderScopeImpl r) {
|
||||||
// renderScope.draw((vertexConsumers) -> {
|
r.draw((vertexConsumers) -> {
|
||||||
// entityRenderDispatcher.render(entity, 0.0, 0.0, 0.0, 1.0F,
|
entityRenderDispatcher.render(entity, 0.0, 0.0, 0.0, 1.0F,
|
||||||
// renderScope.getMatrixStack(), vertexConsumers,
|
r.matrices, vertexConsumers,
|
||||||
// 15728880);
|
15728880);
|
||||||
// });
|
});
|
||||||
|
}
|
||||||
renderScope.draw();
|
renderScope.draw();
|
||||||
entityRenderDispatcher.setRenderShadows(true);
|
entityRenderDispatcher.setRenderShadows(true);
|
||||||
renderScope.getMatrixStack().pop();
|
renderScope.getMatrixStack().pop();
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import net.minecraft.client.util.math.MatrixStack;
|
|||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.ModelTransformationMode;
|
import net.minecraft.item.ModelTransformationMode;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.crash.CrashException;
|
import net.minecraft.util.crash.CrashException;
|
||||||
import net.minecraft.util.crash.CrashReport;
|
import net.minecraft.util.crash.CrashReport;
|
||||||
@@ -130,7 +131,7 @@ public class RenderScopeImpl implements RenderScope {
|
|||||||
matrices.translate(x, y + (i * Fonts.getHeight()), 0);
|
matrices.translate(x, y + (i * Fonts.getHeight()), 0);
|
||||||
matrices.scale(scale, scale, 1.0f);
|
matrices.scale(scale, scale, 1.0f);
|
||||||
TextRenderer textRenderer = SaturnClient.client.textRenderer;
|
TextRenderer textRenderer = SaturnClient.client.textRenderer;
|
||||||
textRenderer.draw(org.saturnclient.impl.Fonts.setFont(line, font), 0,
|
textRenderer.draw((Text) Fonts.setFont(line, font), 0,
|
||||||
font == 0 ? 1 : 7, color, false,
|
font == 0 ? 1 : 7, color, false,
|
||||||
this.matrices.peek().getPositionMatrix(),
|
this.matrices.peek().getPositionMatrix(),
|
||||||
this.vertexConsumers, TextLayerType.NORMAL, 0, 15728880);
|
this.vertexConsumers, TextLayerType.NORMAL, 0, 15728880);
|
||||||
|
|||||||
Reference in New Issue
Block a user