Skip to content

Commit

Permalink
[#515] Shadow support for text renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
SirEndii committed Aug 6, 2024
1 parent 7f4e9e7 commit c81e843
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ public void renderBatch(List<RenderableObject> objects, ForgeGui gui, PoseStack
for (RenderableObject object : objects) {
Text text = (Text) object;
poseStack.scale(text.fontSize, text.fontSize, 1);
minecraft.font.draw(poseStack, text.content, text.x / text.fontSize, text.y / text.fontSize, text.color);
if (text.shadow) {
minecraft.font.drawShadow(poseStack, text.content, text.x / text.fontSize, text.y / text.fontSize, text.color);
} else {
minecraft.font.draw(poseStack, text.content, text.x / text.fontSize, text.y / text.fontSize, text.color);
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import de.srendi.advancedperipherals.client.smartglasses.objects.IObjectRenderer;
import de.srendi.advancedperipherals.client.smartglasses.objects.TextRenderer;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.OverlayModule;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertytypes.BooleanProperty;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertytypes.FloatingNumberProperty;
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertytypes.StringProperty;
import net.minecraft.network.FriendlyByteBuf;
Expand All @@ -24,6 +25,9 @@ public class Text extends RenderableObject {
@FloatingNumberProperty(min = 0, max = 128)
public float fontSize = 1;

@BooleanProperty
public boolean shadow = false;

public Text(OverlayModule module, IArguments arguments) throws LuaException {
super(module, arguments);
reflectivelyMapProperties(arguments);
Expand Down Expand Up @@ -56,6 +60,16 @@ public void setFontSize(double fontSize) {
getModule().update(this);
}

@LuaFunction
public void setShadow(boolean shadow) {
this.shadow = shadow;
}

@LuaFunction
public boolean isShadow() {
return shadow;
}

@Override
public IObjectRenderer getRenderObject() {
return renderer;
Expand All @@ -67,6 +81,7 @@ public void encode(FriendlyByteBuf buffer) {
super.encode(buffer);
buffer.writeUtf(content);
buffer.writeFloat(fontSize);
buffer.writeBoolean(shadow);
}

public static Text decode(FriendlyByteBuf buffer) {
Expand All @@ -86,6 +101,7 @@ public static Text decode(FriendlyByteBuf buffer) {
int sizeY = buffer.readInt();
String content = buffer.readUtf();
float fontSize = buffer.readFloat();
boolean shadow = buffer.readBoolean();

Text clientObject = new Text(player);
clientObject.setId(objectId);
Expand All @@ -97,6 +113,7 @@ public static Text decode(FriendlyByteBuf buffer) {
clientObject.maxY = sizeY;
clientObject.content = content;
clientObject.fontSize = fontSize;
clientObject.shadow = shadow;

return clientObject;
}
Expand Down

0 comments on commit c81e843

Please sign in to comment.