fix label text to work with 1.16
This commit is contained in:
1 parent
eb79ea98e7
commit
e38fb896c2
2 files changed
+32
-20
No files matched your search
@@ -30,6 +30,8 @@ import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.particle.ParticleEffect;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
@@ -37,9 +39,7 @@ import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -48,7 +48,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
@@ -236,7 +235,7 @@ public class ShapeDispatcher
|
||||
put("box", creator(Box::new));
|
||||
put("sphere", creator(Sphere::new));
|
||||
put("cylinder", creator(Cylinder::new));
|
||||
put("label", creator(Text::new));
|
||||
put("label", creator(DisplayedText::new));
|
||||
}};
|
||||
private static Function<Map<String, Value>,ExpiringShape> creator(Supplier<ExpiringShape> shapeFactory)
|
||||
{
|
||||
@@ -393,7 +392,7 @@ public class ShapeDispatcher
|
||||
}
|
||||
}
|
||||
|
||||
public static class Text extends ExpiringShape
|
||||
public static class DisplayedText extends ExpiringShape
|
||||
{
|
||||
private final Set<String> required = ImmutableSet.of("pos", "text");
|
||||
private final Map<String, Value> optional = ImmutableMap.<String, Value>builder().
|
||||
@@ -410,7 +409,7 @@ public class ShapeDispatcher
|
||||
protected Set<String> requiredParams() { return Sets.union(super.requiredParams(), required); }
|
||||
@Override
|
||||
protected Set<String> optionalParams() { return Sets.union(super.optionalParams(), optional.keySet()); }
|
||||
public Text() { }
|
||||
public DisplayedText() { }
|
||||
|
||||
Vec3d pos;
|
||||
String text;
|
||||
@@ -424,18 +423,18 @@ public class ShapeDispatcher
|
||||
float indent;
|
||||
int align;
|
||||
float height;
|
||||
String value;
|
||||
Text value;
|
||||
|
||||
@Override
|
||||
protected void init(Map<String, Value> options)
|
||||
{
|
||||
super.init(options);
|
||||
pos = vecFromValue(options.get("pos"));
|
||||
text = options.get("text").getString();
|
||||
value = text;
|
||||
value = ((FormattedTextValue)options.get("text")).getText();
|
||||
text = value.getString();
|
||||
if (options.containsKey("value"))
|
||||
{
|
||||
value = options.get("value").getString();
|
||||
value = ((FormattedTextValue)options.get("value")).getText();
|
||||
}
|
||||
textcolor = rgba2argb(color);
|
||||
textbck = rgba2argb(fillColor);
|
||||
@@ -887,10 +886,24 @@ public class ShapeDispatcher
|
||||
@Override
|
||||
public Value validate(Map<String, Value> options, CarpetContext cc, Value value)
|
||||
{
|
||||
if (value instanceof FormattedTextValue)
|
||||
return new StringValue(((FormattedTextValue) value).getText().asFormattedString());
|
||||
if (!(value instanceof FormattedTextValue))
|
||||
value = new FormattedTextValue(new LiteralText(value.getString()));
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag toTag(Value value)
|
||||
{
|
||||
if (!(value instanceof FormattedTextValue))
|
||||
value = new FormattedTextValue(new LiteralText(value.getString()));
|
||||
return StringTag.of(((FormattedTextValue)value).serialize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Value decode(Tag tag)
|
||||
{
|
||||
return FormattedTextValue.deserialize(tag.asString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,15 +9,14 @@ import net.minecraft.client.render.BufferBuilder;
|
||||
import net.minecraft.client.render.Camera;
|
||||
import net.minecraft.client.render.Tessellator;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.util.math.AffineTransformation;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.client.util.math.Matrix4f;
|
||||
import net.minecraft.client.util.math.Rotation3;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.World;
|
||||
@@ -192,12 +191,12 @@ public class ShapesRenderer
|
||||
}
|
||||
}
|
||||
|
||||
public static class RenderedText extends RenderedShape<ShapeDispatcher.Text>
|
||||
public static class RenderedText extends RenderedShape<ShapeDispatcher.DisplayedText>
|
||||
{
|
||||
|
||||
protected RenderedText(MinecraftClient client, ShapeDispatcher.ExpiringShape shape)
|
||||
{
|
||||
super(client, (ShapeDispatcher.Text)shape);
|
||||
super(client, (ShapeDispatcher.DisplayedText)shape);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -253,14 +252,14 @@ public class ShapesRenderer
|
||||
float text_x = 0;
|
||||
if (shape.align == 0)
|
||||
{
|
||||
text_x = (float)(-textRenderer.getStringWidth(shape.value)) / 2.0F;
|
||||
text_x = (float)(-textRenderer.getWidth(shape.value.getString())) / 2.0F;
|
||||
}
|
||||
else if (shape.align == 1)
|
||||
{
|
||||
text_x = (float)(-textRenderer.getStringWidth(shape.value));
|
||||
text_x = (float)(-textRenderer.getWidth(shape.value.getString()));
|
||||
}
|
||||
VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
|
||||
textRenderer.draw(shape.value, text_x, 0.0F, shape.textcolor, false, Rotation3.identity().getMatrix(), immediate, false, shape.textbck, 15728880);
|
||||
textRenderer.draw(shape.value, text_x, 0.0F, shape.textcolor, false, AffineTransformation.identity().getMatrix(), immediate, false, shape.textbck, 15728880);
|
||||
immediate.draw();
|
||||
RenderSystem.popMatrix();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user