use of net.minecraft.text.LiteralText in project dynmap by webbukkit.
the class FabricServer method broadcastMessage.
@Override
public void broadcastMessage(String msg) {
Text component = new LiteralText(msg);
server.getPlayerManager().broadcast(component, MessageType.SYSTEM, Util.NIL_UUID);
Log.info(stripChatColor(msg));
}
use of net.minecraft.text.LiteralText in project BlockMeter by ModProg.
the class ClientMeasureBox method drawText.
/**
* Draws a text with orientation and position
*
* @param stack
* @param x
* @param y
* @param z
* @param yaw
* @param pitch
* @param text
* @param playerPos
*/
private void drawText(final MatrixStack stack, final double x, final double y, final double z, final float yaw, final float pitch, final String text, final Vec3d playerPos) {
@SuppressWarnings("resource") final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
final LiteralText literalText = new LiteralText(text);
float size = 0.03f;
final int constDist = 10;
if (AutoConfig.getConfigHolder(ModConfig.class).getConfig().minimalLabelSize) {
final float dist = (float) Math.sqrt((x - playerPos.x) * (x - playerPos.x) + (y - playerPos.y) * (y - playerPos.y) + (z - playerPos.z) * (z - playerPos.z));
if (dist > constDist)
size = dist * size / constDist;
}
stack.push();
stack.translate(x, y + 0.15, z);
stack.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(180.0F - yaw));
stack.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(-pitch));
stack.scale(size, -size, 0.001f);
final int width = textRenderer.getWidth(literalText);
stack.translate((-width / 2), 0.0, 0.0);
final Matrix4f model = stack.peek().getPositionMatrix();
final BufferBuilder buffer = Tessellator.getInstance().getBuffer();
int textColor = color.getSignColor();
final ModConfig conf = BlockMeterClient.getConfigManager().getConfig();
if (conf.backgroundForLabels) {
final float[] colors = this.color.getColorComponents();
buffer.begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
buffer.vertex(model, -1, -1, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
buffer.vertex(model, -1, 8, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
buffer.vertex(model, width, 8, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
buffer.vertex(model, width, -1, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
Tessellator.getInstance().draw();
float[] components = color.getColorComponents();
float luminance = (0.299f * components[0] + 0.587f * components[1] + 0.114f * components[2]);
textColor = luminance < 0.4f ? DyeColor.WHITE.getSignColor() : DyeColor.BLACK.getSignColor();
}
final VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(buffer);
textRenderer.draw(literalText, 0.0f, 0.0f, textColor, // shadow
!conf.backgroundForLabels, // matrix
model, // draw buffer
immediate, // seeThrough
true, // backgroundColor => underlineColor,
0, // light
15728880);
immediate.draw();
stack.pop();
}
use of net.minecraft.text.LiteralText in project FabricWaystones by LordDeatHunter.
the class WaystonesEventManager method registerEvents.
public static void registerEvents() {
ServerLifecycleEvents.SERVER_STARTED.register((server) -> {
if (Waystones.WAYSTONE_STORAGE == null) {
Waystones.WAYSTONE_STORAGE = new WaystoneStorage(server);
}
});
ServerLifecycleEvents.SERVER_STOPPED.register((server) -> {
Waystones.WAYSTONE_STORAGE.loadOrSaveWaystones(true);
Waystones.WAYSTONE_STORAGE = null;
});
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
PacketByteBuf data = PacketByteBufs.create();
data.writeNbt(Config.getInstance().toNbtCompound());
ServerPlayNetworking.send(handler.player, Utils.ID("waystone_config_update"), data);
Waystones.WAYSTONE_STORAGE.sendToPlayer(handler.player);
Waystones.WAYSTONE_STORAGE.sendCompatData(handler.player);
});
ServerLifecycleEvents.SERVER_STARTING.register(WaystonesWorldgen::registerVanillaVillageWorldgen);
ServerPlayerEvents.AFTER_RESPAWN.register((oldPlayer, newPlayer, alive) -> ((PlayerEntityMixinAccess) newPlayer).syncData());
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(CommandManager.literal("waystones").then(CommandManager.literal("reload").requires(source -> source.hasPermissionLevel(1)).executes(context -> {
Config.getInstance().loadConfig();
PacketByteBuf data = PacketByteBufs.create();
data.writeNbt(Config.getInstance().toNbtCompound());
for (ServerPlayerEntity player : context.getSource().getServer().getPlayerManager().getPlayerList()) {
ServerPlayNetworking.send(player, Utils.ID("waystone_config_update"), data);
}
ServerPlayerEntity player = context.getSource().getPlayer();
if (player != null) {
player.sendMessage(new LiteralText("§6[§eWaystones§6] §3has successfully reloaded!"), false);
}
return 1;
})).then(CommandManager.literal("display").executes(context -> {
ServerPlayerEntity player = context.getSource().getPlayer();
if (player == null) {
return 1;
}
Config.getInstance().print(player);
return 1;
}))));
}
use of net.minecraft.text.LiteralText in project FabricWaystones by LordDeatHunter.
the class WaystoneBlockScreen method init.
@Override
protected void init() {
super.init();
this.nameField = new TextFieldWidget(this.textRenderer, this.x + 28, this.y + 106, 93, 10, new LiteralText("")) {
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
boolean bl = mouseX >= (double) this.x && mouseX < (double) (this.x + this.width) && mouseY >= (double) this.y && mouseY < (double) (this.y + this.height);
if (bl && button == 1) {
this.setText("");
}
return super.mouseClicked(mouseX, mouseY, button);
}
@Override
public boolean isVisible() {
return canEdit() && page == Page.CONFIG;
}
@Override
public boolean changeFocus(boolean lookForwards) {
return isVisible() && super.changeFocus(lookForwards);
}
@Override
public boolean isMouseOver(double mouseX, double mouseY) {
return isVisible() && mouseX >= (double) this.x && mouseX < (double) (this.x + this.width) && mouseY >= (double) this.y && mouseY < (double) (this.y + this.height);
}
};
this.nameField.setMaxLength(16);
this.nameField.setEditableColor(0xFFFFFF);
this.nameField.setDrawsBackground(false);
this.nameField.setFocusUnlocked(true);
String waystone = Waystones.WAYSTONE_STORAGE.getName(((WaystoneBlockScreenHandler) handler).getWaystone());
this.nameField.setText(waystone == null ? "" : waystone);
this.nameField.setChangedListener((s) -> {
boolean settable = !((WaystoneBlockScreenHandler) handler).getName().equals(s);
ToggleableButton button = ((ToggleableButton) buttons.get(4));
if (button.isToggled() == settable) {
button.toggle();
}
});
this.addDrawableChild(this.nameField);
}
use of net.minecraft.text.LiteralText in project FabricWaystones by LordDeatHunter.
the class Config method print.
public void print(ServerPlayerEntity player) {
var q = new LinkedList<JsonObject>();
q.add(toJson(configData));
while (!q.isEmpty()) {
var current = q.poll();
for (var entry : current.entrySet()) {
var key = entry.getKey();
var value = entry.getValue();
if (value.isJsonObject()) {
q.add(value.getAsJsonObject());
continue;
}
player.sendMessage(new LiteralText("§6[§e" + key + "§6] §3 " + value), false);
}
}
}
Aggregations