added doublesided

This commit is contained in:
gnembon committed 2020-07-18 17:02:43 -03:00
1 parent 57b5bace32
commit 02d985bafc
3 files changed
+36

No files matched your search

+1
View File
@@ -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).
@@ -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<String> 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<String, Value> 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); }
@@ -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();
}
}