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

    • nvm, still not working, i couldnt try it until now,
    • Thanks for the feedback. But it seems there is not really an easy way for this, most of the code is hard-coded and could not be accessed directly. 😞 I worked around this by using the "RenderHandEvent" and "RenderPlayerEvent" to create a dedicated render for my crossbow item.
    • I'm wondering how to go about creating a block that is essentially an Ender Chest (its contents are the same regardless of which chest you check), but where any player in that world can see the contents of the Ender Chest. I was thinking of modifying the saved data for a world, but I'm struggling to understand how that even works. Are there any tutorials out there on tools I can use to work on this sort of problem?  EDIT: I just found this post: is this about what I should be looking at for 1.16.5?    
    • Hey guys I have created a mod that assigns levels to mobs and scales them up using capabilities, everything works great but because of the recent changes to capabilities I am unable to find examples on how to save the level of my mobs so that it remains the same if I restart the server. I will upload all my files relating to the capability and hope you guys can lead me in the right direction   package com.chickenwand3.rpgmod.core.capabilities.entity; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityInject; import net.minecraftforge.common.capabilities.CapabilityManager; @SuppressWarnings("removal") public class CapabilityMobLevel { @CapabilityInject(MobLevel.class) public static Capability<MobLevel> MOB_LEVEL_CAPABILITY = null; public static void register() { CapabilityManager.INSTANCE.register(MobLevel.class); } } package com.chickenwand3.rpgmod.core.capabilities.entity; public class DefaultMobLevel implements MobLevel { public int mobLevel; public float mobMaxHealth; public float mobCurrentHealth; public boolean crazy; public boolean isCrazy() { return crazy; } public float getMaxHealth() { return mobMaxHealth; } public float getCurrentHealth() { return mobCurrentHealth; } } package com.chickenwand3.rpgmod.core.capabilities.entity; public interface MobLevel { } package com.chickenwand3.rpgmod.core.capabilities.entity; import com.chickenwand3.rpgmod.RPGMod; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.monster.Zombie; import net.minecraft.world.item.enchantment.Enchantments; import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(modid = RPGMod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class MobLevelEventHandler { @SubscribeEvent public static void onAttachCapabilitiesEvent(AttachCapabilitiesEvent<Entity> event) { if (event.getObject() instanceof Mob && !event.getObject().getCommandSenderWorld().isClientSide) { MobLevelProvider providerMobLevel = new MobLevelProvider(); event.addCapability(new ResourceLocation(RPGMod.MODID, "moblevel"), providerMobLevel); event.addListener(providerMobLevel::invalidate); } } @SubscribeEvent public static void OnSpawn(final EntityJoinWorldEvent event) { if (event.getEntity()instanceof Mob target && !event.getWorld().isClientSide) { target.getCapability(CapabilityMobLevel.MOB_LEVEL_CAPABILITY).ifPresent(mobLevel -> { DefaultMobLevel actualMobLevel = (DefaultMobLevel) mobLevel; actualMobLevel.mobLevel = (randomizeMobLevel()); if (superCrazy(actualMobLevel.mobLevel)) { actualMobLevel.crazy = true; } if (actualMobLevel.crazy) { if (!target.getMainHandItem().isEmpty()) { target.getMainHandItem().enchant(Enchantments.FIRE_ASPECT, 1); } if (event.getEntity()instanceof Zombie zombie) { zombie.getAttribute(Attributes.SPAWN_REINFORCEMENTS_CHANCE).setBaseValue(0.99D); } System.out.println("Super Crazy " + target.getName() + " has spawned!"); } actualMobLevel.mobMaxHealth = (target.getMaxHealth() * actualMobLevel.mobLevel * 2); actualMobLevel.mobCurrentHealth = actualMobLevel.mobMaxHealth; target.getAttribute(Attributes.MOVEMENT_SPEED) .setBaseValue(target.getAttributeValue(Attributes.MOVEMENT_SPEED) * (1 + (actualMobLevel.mobLevel - 1.0) / 10.0)); if (target.getAttribute(Attributes.ATTACK_DAMAGE) != null) { target.getAttribute(Attributes.ATTACK_DAMAGE) .setBaseValue(target.getAttributeValue(Attributes.ATTACK_DAMAGE) * (1 + (actualMobLevel.mobLevel - 1.0) / 2.0)); } }); } } private static int randomizeMobLevel() { boolean roll = true; int level = 1; while (roll) { if (Math.random() > .5) { level += 1; roll = true; } else { roll = false; } } return level; } private static boolean superCrazy(int level) { boolean result = false; if (level >= 5) { if (Math.random() < .25) { result = true; } else result = false; } return result; } } package com.chickenwand3.rpgmod.core.capabilities.entity; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.common.util.LazyOptional; import javax.annotation.Nonnull; import javax.annotation.Nullable; public class MobLevelProvider implements ICapabilitySerializable<CompoundTag> { private final DefaultMobLevel mobLevel = new DefaultMobLevel(); private final LazyOptional<MobLevel> mobLevelOptional = LazyOptional.of(() -> mobLevel); public void invalidate() { mobLevelOptional.invalidate(); } @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { return mobLevelOptional.cast(); } @Override public CompoundTag serializeNBT() { if (CapabilityMobLevel.MOB_LEVEL_CAPABILITY == null) { return new CompoundTag(); } else { CompoundTag compoundNBT = new CompoundTag(); compoundNBT.putInt("mobLevel", mobLevel.mobLevel); compoundNBT.putFloat("mobCurrentHealth", mobLevel.mobCurrentHealth); compoundNBT.putFloat("mobMaxHealth", mobLevel.mobMaxHealth); compoundNBT.putBoolean("crazy", mobLevel.crazy); return compoundNBT; } } @Override public void deserializeNBT(CompoundTag nbt) { if (CapabilityMobLevel.MOB_LEVEL_CAPABILITY != null) { mobLevel.mobLevel = (nbt.getInt("mobLevel")); float mobCurrentHealth = nbt.getFloat("mobCurrentHealth"); mobLevel.mobCurrentHealth = (mobCurrentHealth); float mobMaxHealth = nbt.getFloat("mobMaxHealth"); mobLevel.mobMaxHealth = (mobMaxHealth); boolean crazy = nbt.getBoolean("crazy"); mobLevel.crazy = (crazy); } } }  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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