Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.5] '\n' formating key unkown in String


bibouche_
 Share

Recommended Posts

Hey, umm, I created a new Menu, in which I ping to a server to get it's Motd, However, I have a '\n' to continue on a new line, but Minecraft displays it as an unknown character and put it on the same line.

The Motd in server.properties is 

         \u00A7ka\u00A7r \u00A73\u00A7nAlcanderia\u00A7r \u00A76Modded \u00A74Survival\u00A7r \u00A7ka\u00A7r\n                    \u00A76[\u00A721.\u00A7416\u00A7r.5\u00A76]

And in the code I get is as a TranslationTextComponent, and then display it with Screen#drawCenteredString()

 

How can I get it to continue on a new line with the '\n' ?

Link to comment
Share on other sites

Oh, wait I think I got the vanilla class

EDIT : they just cut the motd in several pieces and displays with a foreach, so that's not fixing my issue since the '\n' will still not work

 

 

Edited by bibouche_
Link to comment
Share on other sites

if (!this.server.pinged) {
			this.server.pinged         = true;
			this.server.pingToServer   = -2L;
			this.server.serverMOTD     = new TranslationTextComponent("");
			this.server.populationInfo = new TranslationTextComponent("");
			EXECUTOR.submit(() -> {
				try {
					CustomMenu.this.serverPinger.ping(CustomMenu.this.server, () -> { });
				}
				catch (UnknownHostException unknownHostException) {
					CustomMenu.this.server.pingToServer = -1L;
					CustomMenu.this.server.serverMOTD   = new TranslationTextComponent(TextFormatting.DARK_RED + "Cannot resolve host's name");
				}
				catch (Exception exception) {
					CustomMenu.this.server.pingToServer = -1L;
					CustomMenu.this.server.serverMOTD   = new TranslationTextComponent(TextFormatting.DARK_RED + "Unable to connect to server");
				}
			});
		}
		
		if (this.server.pingToServer >= 1L) {
			drawCenteredString(matrixStack, this.font, this.server.serverMOTD, this.width / 2, (int) (this.height / 2 * 1.5) - 52, 14474460);
			drawString(matrixStack, this.font, TextFormatting.GOLD + this.server.populationInfo.getString() + TextFormatting.RESET + " " + new TranslationTextComponent("alcamenu.players").getString(), this.width / 2 - 65, (int) (this.height / 2 * 1.5) - 27, 14474460);
			drawString(matrixStack, this.font, TextFormatting.GOLD + String.valueOf(this.server.pingToServer) + TextFormatting.RESET + " ms", this.width / 2 + 30, (int) (this.height / 2 * 1.5) - 27, 14474460);
		}
		else {
			drawCenteredString(matrixStack, this.font, this.server.serverMOTD, this.width / 2, (int) (this.height / 2 * 1.5) - 52, 0x245791);
		}

 

Link to comment
Share on other sites

I am creating a modded server with launcher, and I don't want players to use the singleplayer, so while being at deleting the singleplayer button, I create a custom MainMenu, and so I wanna display the server informations on the screen

Link to comment
Share on other sites

Letting people enter their Minecraft credentials into your own software is bad practice at best and illegal at worst. Most definitely it is against the GDPR.

If you really cannot use existing infrastructure (i.e. just make a Curse modpack), make an installer that creates a launcher profile in the vanilla launcher, like Forge does.

Link to comment
Share on other sites

We are not getting any credentials at all, they can join with just a pseudo, and a login on the server (with AuthMePlugin), so that the password they enter is just for their profile on our server, we respect privacy and so they will not enter their credentials into the launcher. It's goal is just to verify for the mods and launch a minecraft instance

Edited by bibouche_
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Thanks for your reply! I have done it using data generation now. It works well for world generation, and I have realised that I don't care about saplings, so it works well. For anyone looking to do something similar, I include files to show what I did. They are just a bit hacky and incomplete now, but they can probably easily be generalised.   import static net.anju.larus.data.ResourceLocationUtil.prefix; import static net.anju.larus.data.ResourceLocationUtil.slash; @MethodsReturnNonnullByDefault @ParametersAreNonnullByDefault public abstract class LarusFeatureProvider<T> implements DataProvider { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(); protected final Set<FeatureEntry> featureEntries = new HashSet<>(); private final DataGenerator generator; protected LarusFeatureProvider(DataGenerator generator, Registry<T> registry) { this.generator = generator; for (Map.Entry<ResourceKey<T>, T> entry : registry.entrySet()) { ResourceKey<T> key = entry.getKey(); T feature = entry.getValue(); JsonElement jsonElement = getJson(feature); if (jsonElement != null) { FeatureEntry featureEntry = new FeatureEntry(prefix(key.location(), key.getRegistryName()), jsonElement); featureEntries.add(featureEntry); } } } private void addFeatures() { for (FeatureEntry featureEntry : featureEntries) { modifyFeatureEntry(featureEntry); } } protected abstract void modifyFeatureEntry(FeatureEntry featureEntry); @Override public void run(HashCache cache) { addFeatures(); writeFiles(cache, this.generator.getOutputFolder(), featureEntries); } // Actually write out the tables in the output folder private static void writeFiles(HashCache cache, Path outputFolder, Set<FeatureEntry> featureEntries) { for (FeatureEntry featureEntry : featureEntries) { if (featureEntry.isModified()) { ResourceLocation key = featureEntry.resourceLocation; JsonElement jsonElement = featureEntry.jsonElement; Path path = getPath(outputFolder, key); try { DataProvider.save(GSON, cache, jsonElement, path); } catch (IOException e) { LarusMod.LOGGER.error("Couldn't write data {}", key, e); } } } } @Override public String getName() { return "Larus features"; } @Nullable public JsonElement getJson(T feature) { if (feature instanceof ConfiguredFeature<?, ?> configuredFeature) { Optional<JsonElement> optional = ConfiguredFeature.DIRECT_CODEC.encodeStart(JsonOps.INSTANCE, configuredFeature).result(); return optional.orElse(null); } return null; } public static Path getPath(Path outputFolder, ResourceLocation key) { return outputFolder.resolve("data/" + slash(key) + ".json"); } protected static class FeatureEntry { boolean modified = false; private final ResourceLocation resourceLocation; private final JsonElement jsonElement; private FeatureEntry(ResourceLocation resourceLocation, JsonElement jsonElement) { this.resourceLocation = resourceLocation; this.jsonElement = jsonElement; } public JsonElement getJsonElement() { return jsonElement; } protected void markModified() { this.modified = true; } private boolean isModified() { return this.modified; } } } public class LarusLeavesFeatureProvider extends LarusFeatureProvider<ConfiguredFeature<?, ?>> { public LarusLeavesFeatureProvider(DataGenerator generator) { super(generator, BuiltinRegistries.CONFIGURED_FEATURE); } @Override protected void modifyFeatureEntry(FeatureEntry featureEntry) { JsonElement jsonElement = featureEntry.getJsonElement(); if (jsonElement.isJsonObject()) { JsonObject jsonObject = jsonElement.getAsJsonObject(); if (jsonObject.has("config")) { JsonObject config = jsonObject.get("config").getAsJsonObject(); if (config.has("foliage_provider")) { JsonObject mcFoliage = config.get("foliage_provider").getAsJsonObject(); JsonObject larusFoliage = larusFoliage(mcFoliage); if (larusFoliage != null) { config.add("foliage_provider", larusFoliage); featureEntry.markModified(); } } } } } @Nullable protected JsonObject larusFoliage(JsonObject mcFoliage) { JsonElement type = mcFoliage.get("type"); if (type.getAsString().equals("minecraft:simple_state_provider")) { JsonObject state = mcFoliage.get("state").getAsJsonObject(); // Change leaves String mcLeaves = state.get("Name").getAsString(); LarusLeavesBlock larusLeavesBlock = larusLeavesBlock(mcLeaves); if (larusLeavesBlock == null || larusLeavesBlock.getRegistryName() == null) return null; String larusLeaves = larusLeavesBlock.getRegistryName().toString(); state.add("Name", new JsonPrimitive(larusLeaves)); // Transform properties JsonObject mcProperties = state.get("Properties").getAsJsonObject(); transformProperties(mcProperties, larusLeavesBlock); } else { LarusMod.LOGGER.warn("Unexpected type for MC foliage " + mcFoliage); } return mcFoliage; } protected void transformProperties(JsonObject properties, LarusLeavesBlock larusLeavesBlock) { if (larusLeavesBlock instanceof LarusDeciduousLeavesBlock) properties.add("leafy", new JsonPrimitive("green")); } @Nullable protected LarusLeavesBlock larusLeavesBlock(String mcLeaves) { switch (mcLeaves) { case "minecraft:oak_leaves" -> { return LarusBlocks.OAK_LEAVES.get(); } case "minecraft:birch_leaves" -> { return LarusBlocks.BIRCH_LEAVES.get(); } case "minecraft:acacia_leaves" -> { return LarusBlocks.ACACIA_LEAVES.get(); } case "minecraft:jungle_leaves" -> { return LarusBlocks.JUNGLE_LEAVES.get(); } case "minecraft:dark_oak_leaves" -> { return LarusBlocks.DARK_OAK_LEAVES.get(); } case "minecraft:spruce_leaves" -> { return LarusBlocks.SPRUCE_LEAVES.get(); } } return null; } }  
    • the reason for that is the PlayerModel positions and rotations are set after the RenderPlayerEvent.Pre is fired change to Event to RenderPlayerEvent.Post
    • you can use BiomeLoadingEvent, loop through the Features you get from the Event and remove the Feature if it's the AmethystGeode Feature
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.