Jump to content

[1.12.2] Minimap-like floating text that enlarges


San3001

Recommended Posts

I'd like to create some floating text like this(see attachment) minimap mod JourneyMap, though I have no idea where to start.

Would be appreciated if someone could guide me to some steps I'd need to do

 

I know how to make floating text the armorstand client side way but that doesn't increase size

 

 

image.png.2385e06cf8dcad3b15b10920643dfc9d.png

Link to comment
Share on other sites

6 hours ago, V0idWa1k3r said:

You could try to use the same logic EntityRenderer.drawNameplate has(or maybe even straight up use that method) but scale the drawn textbox with distance to the player.

How does EntityRenderer.drawNameplate work? Do I just input coordinates and text displays there? Can't get it working.

Like, do I put it in a Tick Event? or

Edited by San3001
Link to comment
Share on other sites

5 hours ago, San3001 said:

How does EntityRenderer.drawNameplate work? Do I just input coordinates and text displays there? Can't get it working.

Like, do I put it in a Tick Event? or

Well you obviously need to call it from some kind of event that gets called every frame. RenderWorldLast or RenderTickEvent for example.

 

As for the arguments passed see what Render#renderLivingLabel does.

  • Thanks 1
Link to comment
Share on other sites

11 hours ago, V0idWa1k3r said:

Well you obviously need to call it from some kind of event that gets called every frame. RenderWorldLast or RenderTickEvent for example.

 

As for the arguments passed see what Render#renderLivingLabel does.

 

This doesn't seem to work

 

public RenderManager renderManager = mc.getRenderManager();
	
	@SubscribeEvent
	public void renderTick(TickEvent.RenderTickEvent event) {
		EntityPlayerSP player = mc.player;
		
		EntityRenderer.drawNameplate(renderManager.getFontRenderer(), "text", 0f, 64f, 0f, 0, player.cameraYaw, player.cameraPitch, renderManager.options.thirdPersonView == 2, player.isSneaking());
	
	}

 

Did I mess something up?

Thanks for your help

Link to comment
Share on other sites

How are you registering your event subscriber?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

8 minutes ago, San3001 said:

public RenderManager renderManager = mc.getRenderManager();

when is this initialized? It could be null.

 

10 minutes ago, San3001 said:

TickEvent.RenderTickEvent

This has two phases - you need to check the phase first before doing anything.

 

11 minutes ago, San3001 said:

EntityPlayerSP player = mc.player;

This could be null when RenderTickEvent fires.

 

12 minutes ago, San3001 said:

0f, 64f, 0f

These are your x,y,z coordinates. Are you sure you want it to be drawn at 0, 64, 0?

 

If you are not crashing then your event handler isn't registered. Otherwise fix what I told you to fix.

Link to comment
Share on other sites

1 hour ago, Cadiboo said:

How are you registering your event subscriber?

Doing it in postInit

 

1 hour ago, V0idWa1k3r said:

when is this initialized? It could be null.

 

This has two phases - you need to check the phase first before doing anything.

 

This could be null when RenderTickEvent fires.

 

These are your x,y,z coordinates. Are you sure you want it to be drawn at 0, 64, 0?

 

If you are not crashing then your event handler isn't registered. Otherwise fix what I told you to fix.

Yeah, it was crashing before but I just made a command to change a run boolean I had.

I just wanted it to work to start somewhere.

Right now I just want it to spawn in a static position(0, 64, 0) . I'll change it later

 

I don't know where else to get player or render manager so.. would this work?

renderManager never returns null for some reason, but renderManager.getFontRenderer() does

 

public RenderManager renderManager = mc.getRenderManager();
	
	@SubscribeEvent
	public void renderTick(TickEvent.RenderTickEvent event) {
		if (event.phase == TickEvent.Phase.START || renderManager.getFontRenderer() == null || mc.player == null) {
			return;
		}
		EntityPlayerSP player = mc.player;
		EntityRenderer.drawNameplate(renderManager.getFontRenderer(), "text", 0f, 64f, 0f, 0, player.cameraYaw, player.cameraPitch, renderManager.options.thirdPersonView == 2, player.isSneaking());
	
	}

It doesn't crash anymore but it also still doesn't work.

I feel this is a really lazy way to do this.

Link to comment
Share on other sites

Don’t get the player, get the current view entity

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

1 hour ago, Cadiboo said:

Don’t get the player, get the current view entity

private Minecraft mc = Minecraft.getMinecraft();
	public  RenderManager renderManager = mc.getRenderManager();
	
	@SubscribeEvent
	public void renderTick(TickEvent.RenderTickEvent event) {
		if (event.phase == TickEvent.Phase.START || renderManager.getFontRenderer() == null) {
			return;
		}
		Entity viewEntity = mc.getRenderViewEntity();
		EntityRenderer.drawNameplate(renderManager.getFontRenderer(), "text", 0f, 64f, 0f, 0, viewEntity.rotationYaw, viewEntity.rotationPitch, renderManager.options.thirdPersonView == 2, viewEntity.isSneaking());
	
	}

Like this? Still can't see but it looks like better code

Link to comment
Share on other sites

I did some debugging with your code and here are the results:

11 hours ago, San3001 said:

TickEvent.RenderTickEvent

Turns out this is not the right event to render things in the world because the GL matrices aren't correct. RenderWorldLast works just fine though.

 

11 hours ago, San3001 said:

0f, 64f, 0f

These 3 parameters are the x,y,z relative to the camera's position, not relative to 0,0,0 in the world. So kept like this they will make the text render 64 blocks directly above the camera. So to render at 0, 64, 0 you would need to translate against the camera first by subtracting the camera's position from these coordinates.

 

11 hours ago, San3001 said:

viewEntity.rotationYaw, viewEntity.rotationPitch

These parameters don't want the yaw and pitch, they want the RenderManager.playerViewY and RenderManager.playerViewX instead.

 

11 hours ago, San3001 said:

renderManager.getFontRenderer()

Use Minecraft.fontRenderer instead.

 

After I've applied all these fixes the nameplate did indeed render in the world.

Link to comment
Share on other sites

10 hours ago, V0idWa1k3r said:

I did some debugging with your code and here are the results:

Turns out this is not the right event to render things in the world because the GL matrices aren't correct. RenderWorldLast works just fine though.

 

These 3 parameters are the x,y,z relative to the camera's position, not relative to 0,0,0 in the world. So kept like this they will make the text render 64 blocks directly above the camera. So to render at 0, 64, 0 you would need to translate against the camera first by subtracting the camera's position from these coordinates.

 

These parameters don't want the yaw and pitch, they want the RenderManager.playerViewY and RenderManager.playerViewX instead.

 

Use Minecraft.fontRenderer instead.

 

After I've applied all these fixes the nameplate did indeed render in the world.

private Minecraft mc = Minecraft.getMinecraft();
private  RenderManager renderManager = mc.getRenderManager();
private FontRenderer fontRenderer = mc.fontRenderer;
	
@SubscribeEvent
public void renderTick(RenderWorldLastEvent event) {
	if (fontRenderer == null || mc.player == null || renderManager == null || renderManager.options == null) {
		return;
	}

		
	EntityPlayerSP player = mc.player;
	EntityRenderer.drawNameplate(fontRenderer, "text", 2f, 0f, 0f, 0, renderManager.playerViewY, renderManager.playerViewX, renderManager.options.thirdPersonView == 2, player.isSneaking());
	
}

This works perfectly, thank you so much! Subtracting player position should be easy enough.

Edited by San3001
Adding some text
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I am getting an error message that my mods and my server are not on the same minecraft version when they clearly are. My server and my mods are on 1.20.1 and the error says that the server is 1.20 even though it's on forge 47.2.30.  
    • .Omg, I'm so freaking blind I didn't notice that, it works now, thank you so much @Xoroshio
    • On the one off the last lines of code you have put && boots.isEmpty() Instead of && !boots.isEmpty() is that a typo?
    • I'm trying to apply effects to the emerald armor but it doesn't work, I read that the onArmorTick() method doesn't work anymore, but I tried with inventoryTick, onInventoryTick and onArmorTick but they don't apply the effect either, I don't know if I'm writing it wrong, so I need help to fix it. This is the code in question: public class ModArmorItem extends ArmorItem{ private static final Map<ArmorMaterial, MobEffectInstance> MATERIAL_TO_EFFECT_MAP = (new ImmutableMap.Builder<ArmorMaterial, MobEffectInstance>()) .put(ModArmorMaterials.EMERALD, new MobEffectInstance( MobEffects.HERO_OF_THE_VILLAGE, 200, 1, false, false, true)) .build(); public ModArmorItem(ArmorMaterial pMaterial, Type pType, Properties pProperties) { super(pMaterial, pType, pProperties); } @Override public void onArmorTick(ItemStack stack, Level world, Player player){ if (!world.isClientSide()) { if (hasFullSuitOfArmorOn(player)) { evaluateArmorEffects(player); } } } private void evaluateArmorEffects(Player player) { for (Map.Entry<ArmorMaterial,MobEffectInstance> entry : MATERIAL_TO_EFFECT_MAP.entrySet()){ ArmorMaterial mapArmorMaterial = entry.getKey(); MobEffectInstance mapStatusEffect = entry.getValue(); if (hasCorrectArmorOn(mapArmorMaterial, player)) { addStatusEffectForMaterial(player, mapArmorMaterial, mapStatusEffect); } } } private void addStatusEffectForMaterial(Player player, ArmorMaterial mapArmorMaterial, MobEffectInstance mapStatusEffect) { boolean hasPlayerEffect = player.hasEffect(mapStatusEffect.getEffect()); if (hasCorrectArmorOn(mapArmorMaterial, player) && !hasPlayerEffect) { player.addEffect(new MobEffectInstance(mapStatusEffect)); } } private boolean hasCorrectArmorOn(ArmorMaterial material, Player player) { for (ItemStack armorStack : player.getInventory().armor){ if (!(armorStack.getItem() instanceof ArmorItem)) { return false; } } ArmorItem helmet = ((ArmorItem)player.getInventory().getArmor(3).getItem()); ArmorItem brestplace = ((ArmorItem)player.getInventory().getArmor(2).getItem()); ArmorItem leggins = ((ArmorItem)player.getInventory().getArmor(1).getItem()); ArmorItem boots = ((ArmorItem)player.getInventory().getArmor(0).getItem()); return helmet.getMaterial() == material && brestplace.getMaterial() == material && leggins.getMaterial() == material && boots.getMaterial() == material; } private boolean hasFullSuitOfArmorOn(Player player){ ItemStack helmet = player.getInventory().getArmor(3); ItemStack breastplace = player.getInventory().getArmor(2); ItemStack leggins = player.getInventory().getArmor(1); ItemStack boots = player.getInventory().getArmor(0); return !helmet.isEmpty() && !breastplace.isEmpty() && !leggins.isEmpty() && boots.isEmpty(); } } And here is the armor   public static final RegistryObject<Item> EMERALD_HELMET = ITEMS.register( "emerald_helmet", () -> new ModArmorItem(ModArmorMaterials.EMERALD, ArmorItem.Type.HELMET, new Item.Properties()) ); public static final RegistryObject<Item> EMERALD_CHESTPLATE = ITEMS.register( "emerald_chestplate", () -> new ModArmorItem(ModArmorMaterials.EMERALD, ArmorItem.Type.CHESTPLATE, new Item.Properties()) ); public static final RegistryObject<Item> EMERALD_LEGGINS = ITEMS.register( "emerald_leggins", () -> new ModArmorItem(ModArmorMaterials.EMERALD, ArmorItem.Type.LEGGINGS, new Item.Properties()) ); public static final RegistryObject<Item> EMERALD_BOOTS = ITEMS.register( "emerald_boots", () -> new ModArmorItem(ModArmorMaterials.EMERALD, ArmorItem.Type.BOOTS, new Item.Properties()) ); I hope you can help me. Thanks.
    • so ive been having this issue for a little bit, and have honestly no clue on how to fix it. I'm using minecraft 1.20.1 for clarification.  Here is the latest log: https://pastebin.com/neMuxELv
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.