From 02d985bafc4bfb07f9422536ded3a7f04a9e35ef Mon Sep 17 00:00:00 2001 From: gnembon Date: Sat, 18 Jul 2020 17:02:43 -0300 Subject: [PATCH] added doublesided --- docs/scarpet/api/Auxiliary.md | 1 + .../carpet/script/utils/ShapeDispatcher.java | 29 +++++++++++++++++++ .../carpet/script/utils/ShapesRenderer.java | 6 ++++ 3 files changed, 36 insertions(+) diff --git a/docs/scarpet/api/Auxiliary.md b/docs/scarpet/api/Auxiliary.md index 2d3d88c4..e28fc2a9 100644 --- a/docs/scarpet/api/Auxiliary.md +++ b/docs/scarpet/api/Auxiliary.md @@ -96,6 +96,7 @@ Available shapes: * `size` - float. Default font size is 10. * `facing` - text direction, where its facing. Possible options are: `player` (default, text always rotates to face the player), `north`, `south`, `east`, `west`, `up`, `down` + * `doublesided` - if `true` it will make the text visible from the back as well. Default is `false` * `align` - text alignment with regards to `pos`. Default is `center` (displayed text is centered with respect to `pos`), `left` (`pos` indicates beginning of text), and `right` (`pos` indicates the end of text). diff --git a/src/main/java/carpet/script/utils/ShapeDispatcher.java b/src/main/java/carpet/script/utils/ShapeDispatcher.java index 2d3aa29d..f5df01df 100644 --- a/src/main/java/carpet/script/utils/ShapeDispatcher.java +++ b/src/main/java/carpet/script/utils/ShapeDispatcher.java @@ -20,6 +20,7 @@ import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.command.arguments.ParticleArgumentType; import net.minecraft.entity.Entity; +import net.minecraft.nbt.ByteTag; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.DoubleTag; import net.minecraft.nbt.FloatTag; @@ -403,6 +404,7 @@ public class ShapeDispatcher put("align", new StringValue("center")). put("size", new NumericValue(10)). put("value", Value.NULL). + put("doublesided", new NumericValue(0)). build(); @Override protected Set requiredParams() { return Sets.union(super.requiredParams(), required); } @@ -423,6 +425,7 @@ public class ShapeDispatcher int align; float height; String value; + boolean doublesided; @Override protected void init(Map options) @@ -457,6 +460,11 @@ public class ShapeDispatcher else align = -1; } + doublesided = false; + if (options.containsKey("doublesided")) + { + doublesided = options.get("doublesided").getBoolean(); + } raise = NumericValue.asNumber(options.getOrDefault("raise", optional.get("raise"))).getFloat(); tilt = NumericValue.asNumber(options.getOrDefault("tilt", optional.get("tilt"))).getFloat(); @@ -496,6 +504,7 @@ public class ShapeDispatcher hash ^= Float.hashCode(height); hash *= 1099511628211L; hash ^= Float.hashCode(size); hash *= 1099511628211L; hash ^= Integer.hashCode(align); hash *= 1099511628211L; + hash ^= Boolean.hashCode(doublesided); hash *= 1099511628211L; return hash; } @@ -842,6 +851,7 @@ public class ShapeDispatcher put("raise", new FloatParam("raise")); put("tilt", new FloatParam("tilt")); put("facing", new StringChoiceParam("axis", "player", "north", "south", "east", "west", "up", "down")); + put("doublesided", new BoolParam("doublesided")); }}; protected String id; @@ -948,6 +958,25 @@ public class ShapeDispatcher return value; } } + public static class BoolParam extends NumericParam + { + protected BoolParam(String id) + { + super(id); + } + + @Override + public Tag toTag(Value value) + { + return ByteTag.of(value.getBoolean()); + } + + @Override + public Value decode(Tag tag) + { + return new NumericValue(((ByteTag) tag).getByte() > 0); + } + } public static class FloatParam extends NumericParam { protected FloatParam(String id) { super(id); } diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index 9382c269..523f8b46 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -206,6 +206,10 @@ public class ShapesRenderer double d = camera1.getPos().x; double e = camera1.getPos().y; double f = camera1.getPos().z; + if (shape.doublesided) + RenderSystem.disableCull(); + else + RenderSystem.enableCull(); RenderSystem.pushMatrix(); RenderSystem.translatef((float)(v1.x - d), (float)(v1.y - e), (float)(v1.z - f)); RenderSystem.normal3f(0.0F, 1.0F, 0.0F); @@ -259,6 +263,8 @@ public class ShapesRenderer textRenderer.draw(shape.value, text_x, 0.0F, shape.textcolor, false, Rotation3.identity().getMatrix(), immediate, false, shape.textbck, 15728880); immediate.draw(); RenderSystem.popMatrix(); + if (shape.doublesided) + RenderSystem.enableCull(); } }