Jump to content

Render Nameplate or image above mob


charsmud

Recommended Posts

I replaced the RenderLivingEvent with RenderLivingEvent.Specials.Pre and it worked!  However, it's over the player's head but not the villager (which I thought I prevented in my VillagerBubbleHandler):

 

 

package village.mechanics;


import net.minecraft.entity.passive.EntityVillager;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.event.ForgeSubscribe;
import cpw.mods.fml.client.FMLClientHandler;

public class VillagerBubbleHandler
{
public VillagerBubbleHandler()
{
}
@ForgeSubscribe
public void onVillagerRender(RenderLivingEvent.Specials.Pre event )
{
	VillageMechanics mechanics = new VillageMechanics();

	if(event.entity instanceof EntityVillager)
	{
		System.out.println("EXECUTED FROM VILLAGERBUBBLEHANDLER");
		mechanics.updateTradeBubble(FMLClientHandler.instance().getClient());
	}
}

}

 

 

Also, the image is distorted like this:

 

SK7E557.png

 

Any ideas? 

Link to comment
Share on other sites

yes, congrats

 

now this happens because when you are rendering the quad, opengl still thinks that you want to render at the current position, it doesnt move the things around for you

 

so you need to translate the openGL matrix to the position of the villager

 

now when you're drawing, 0, 0, 0 is considered the position of the main player, so you need to translate by the difference between you and the target entity

 

GL11.glPushMatrix();//save current gl transform state
GL11.glTranslated(diffX, diffY, diffZ);

//usual render bubble code

GL11.glPopMatrix();//restore saved gl transform state

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

not lines xD

 

too lazy to type out full code *yawn*

 

Also, I'm not sure if the tessellator takes partial ticks into account.  I've just heard nasty things about it so I dont really ever plan on using it.  I guess I'm just one paranoid fellow.  I'll grind out the openGL for now, or at least until my fingers get numb.

 

if it doesn't take into account partial ticks, heres some code to help you out:

	//get the villager variable in whatever way you do it...  not sure how you have it set up.
                EntityClientPlayerMP player = mc.thePlayer;
	double diffX = (villager.prevPosX + (villager.posX - villager.prevPosX) * partialTicks) - (player.prevPosX + (player.posX - player.prevPosX) * partialTicks); 
	double diffY = (villager.prevPosY + (villager.posY - villager.prevPosY) * partialTicks) - (player.prevPosY + (player.posY - player.prevPosY) * partialTicks); 
                double diffZ = (villager.prevPosZ + (villager.posZ - villager.prevPosZ) * partialTicks) - (player.prevPosZ + (player.posZ - player.prevPosZ) * partialTicks); 

 

edit:  you get partialticks for this from the event renderWorldLastEvent

Link to comment
Share on other sites

I've just heard nasty things about it so I dont really ever plan on using it.

its actually a very powerfull tool if you know how to use it

 

Also, I'm not sure if the tessellator takes partial ticks into account.

it doesn't, but it's lot like openGL takes care of it either (you have to take that into account manually)

 

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Ok, I was able to translate it over to the Entity.  However, I think my billboarding is messed up....  The texture is also not over the villager (I have NO idea how to fix this.  xD)  The texture is still screwy like this as well:

 

 

BfE7PTi.png

 

 

package village.mechanics;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraftforge.client.event.RenderLivingEvent;

import org.lwjgl.opengl.GL11;


/**
* Contains information about the new Mechanics for the past
* @author Charsmud
*
*/
public class VillageMechanics
{
/**
 * Updates Paradox Bar and Renders
 * @param minecraft
 * @param amtOfParadox
 */
public void updateTradeBubble(Minecraft minecraft, RenderLivingEvent.Specials.Pre event)
{
	System.out.println("EXECUTED FROM VILLAGEMECHANICS");
        Tessellator tessellator = Tessellator.instance;

        
        EntityClientPlayerMP player = minecraft.thePlayer;
        
        double diffX = (event.entity.prevPosX + (event.entity.posX - event.entity.prevPosX)) - (player.prevPosX + (player.posX - player.prevPosX)); 
        double diffY = (event.entity.prevPosY + (event.entity.posY - event.entity.prevPosY)) - (player.prevPosY + (player.posY - player.prevPosY)); 
        double diffZ = (event.entity.prevPosZ + (event.entity.posZ - event.entity.prevPosZ)) - (player.prevPosZ + (player.posZ - player.prevPosZ));
        
        GL11.glPushMatrix();//save current gl transform state
        GL11.glTranslated(diffX, diffY, diffZ);

        GL11.glRotatef(-RenderManager.instance.playerViewY, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(RenderManager.instance.playerViewX, 1.0F, 0.0F, 0.0F);

        
	minecraft.renderEngine.bindTexture("/village/images/bubble1.png");
	tessellator.startDrawingQuads();
	tessellator.addVertexWithUV(1, 1, 0, 0, 0);
	tessellator.addVertexWithUV(1, 1, 0+2, 0, 1);
	tessellator.addVertexWithUV(1+1, 1+2, 0, 1, 1);
	tessellator.addVertexWithUV(1, 1+1, 0, 1, 0);

        tessellator.addVertexWithUV(1, 1, 0, 0, 0);
	tessellator.addVertexWithUV(1, 1+1, 0, 1, 0);
	tessellator.addVertexWithUV(1+1, 1+2, 0, 1, 1);
	tessellator.addVertexWithUV(1, 1, 0+2, 0, 1);
	tessellator.draw();

        GL11.glPopMatrix();//restore saved gl transform state

}
}

 

 

OFF-TOPIC: I was going to learn OGL, but I decided with DirectX instead, as OGL was just a bunch of states that were enabled or disabled.... :P

 

Link to comment
Share on other sites

as OGL was just a bunch of states that were enabled or disabled

heu lets not get started with this because i actually prefer openGL to d3dx but lets say that d3dx has more noob-friendly tools and openGL has more access to your ressource.....

 

 

GL11.glRotatef(-RenderManager.instance.playerViewY, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(RenderManager.instance.playerViewX, 1.0F, 0.0F, 0.0F);

 

you want spherical billboarding or cylindrical billboarding ? what you did is for spherical

also i think using i saw in some other thread that RenderManager values were messed up

i think its better to use

entityPlayer.rotationYaw (for Y)

entityPlayer.rotationPitch (for X)

 

 

next:

tessellator.addVertexWithUV(1, 1, 0, 0, 0);
tessellator.addVertexWithUV(1, 1, 0+2, 0, 1);
tessellator.addVertexWithUV(1+1, 1+2, 0, 1, 1);
tessellator.addVertexWithUV(1, 1+1, 0, 1, 0);

 

you have a bunch of extra 1 there

after you did glTranslated(x, y, z) you are directly at the position of the villager

so adding 1 (in the x column, the extra 1 in the y column will make the image be right above the entity,not in it :P) will move your quad by 1 unit in the x direction

 

something centered would look like thsi:

tessellator.addVertexWithUV(-1, 1, 1, 0, 0);
tessellator.addVertexWithUV(-1, 1, -1, 0, 1);
tessellator.addVertexWithUV(1, 1, -1, 1, 1);
tessellator.addVertexWithUV(1, 1, 1, 1, 0);

not saying its the right orientation, jsut saying it would be more centered

 

dont forget to put both planes (and remove the useless one later)

 

tessellator.addVertexWithUV(-1, 1, 1, 0, 0);
tessellator.addVertexWithUV(-1, 1, -1, 0, 1);
tessellator.addVertexWithUV(1, 1, -1, 1, 1);
tessellator.addVertexWithUV(1, 1, 1, 1, 0);

tessellator.addVertexWithUV(-1, 1, 1, 0, 0);
tessellator.addVertexWithUV(1, 1, 1, 1, 0);
tessellator.addVertexWithUV(1, 1, -1, 1, 1);
tessellator.addVertexWithUV(-1, 1, -1, 0, 1);

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

OK, so the image is now centered.  :)  I changed the rotation to this:

 

        GL11.glRotatef(-player.rotationYaw, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(player.rotationPitch, 1.0F, 0.0F, 0.0F);

 

And now it rotates wierdly....  I probably want cylindrical billboarding (that's just spinning in the center axis, right?  xD). 

 

Off-Topic:  let's not get into Direct3D vs OGL, that never ends well, and they both have their benefits.  :)

Link to comment
Share on other sites

and they both have their benefits.

no, not d3dx ... ahahah just kidding *stfu hydroflame*

 

 

yes cylindrical billboarding would be just aroudn the y axis, if that what you want

remove:

 GL11.glRotatef(player.rotationPitch, 1.0F, 0.0F, 0.0F);

this line tell openGL to rotate to face you on a "up-down" way

 

while the other one makes the billboard face you in a "left-right" way

 

 

And now it rotates wierdly

what do you mean by that ? it "jumps/ lag ?

 

or some other visual bug

 

if its the lag you want to do the same as you did with the position using "partialTicks"

 

partialTick hold the current "percentage" of the frame completed, what happens if that you are rendering the screen many more times then you are updating the position and orientation of the characters. so partialTicks tell you how much of the frame is done so far, 25%? 50? 75? 90?

by using it you can interpolate between the last known position and the "current position"

 

 

        (1)                      (2)                    (3)                      (4)

villager.prevPosX + (villager.posX - villager.prevPosX) * partialTicks

 

 

so you take the difference between 2 and 3, thsi gives you the movement different that the character did in the last frame

multiply by 4 gives you how much of the frame we are done, then add 1 will give you technicly where the character was ~20 tick ago (since position is updated every 20 tick)

so yes technicly what you are seeing is always the past of the actual player mouvement. but this isnt call of duty or another fast space game so this method is somewhat ok to use

 

off-topic

a real method would be to try to predict player movement, aka, if the player is going foward in a tunnel, chances are hes not goign to suddently stop and look at the wall :P

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

it would be a possibility, but openGL (specially version 1) has some utility method to do that

remember when we said you need to translate the iamge to the position of the mob ? well you can also translate it from there after that (and rotate it)

 

//setup code to get the matrxi to the right position

GL11.glTranslated(0, 0.5, 0);//move the whole thing 0.5 unit in the air
GL11.glRotated(90, 0, 1, 0);//rotate around the y axis by 90 degree

//WATCHOUT, doing translate THEN rotate wil not give the same result as rotate THEN translate
(also, it might be -90 instead of +90, not sure what your specific case needs)

//resotre core

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

I am translating then rotating.  Here's the rotating + translating code:

 

 

        GL11.glTranslated(diffX, diffY + 3, diffZ);

        //GL11.glTranslated(0, 3, 0);//move the whole thing 0.5 unit in the air
        GL11.glRotatef(-90, 1, 0, 0);//rotate around the y axis by 90 degree

        GL11.glRotatef(-player.rotationYaw, 0.0F, 0.0F, 1.0F);

 

 

And here's the whole file:

 

 

package village.mechanics;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraftforge.client.event.RenderLivingEvent;

import org.lwjgl.opengl.GL11;


/**
* Contains information about the new Mechanics for the past
* @author Charsmud
*
*/
public class VillageMechanics
{
/**
 * Updates Paradox Bar and Renders
 * @param minecraft
 * @param amtOfParadox
 */
public void updateTradeBubble(Minecraft minecraft, RenderLivingEvent.Specials.Pre event)
{
	System.out.println("EXECUTED FROM VILLAGEMECHANICS");
        Tessellator tessellator = Tessellator.instance;

        
        EntityClientPlayerMP player = minecraft.thePlayer;
        
        double diffX = (event.entity.prevPosX + (event.entity.posX - event.entity.prevPosX)) - (player.prevPosX + (player.posX - player.prevPosX)); 
        double diffY = (event.entity.prevPosY + (event.entity.posY - event.entity.prevPosY)) - (player.prevPosY + (player.posY - player.prevPosY)); 
        double diffZ = (event.entity.prevPosZ + (event.entity.posZ - event.entity.prevPosZ)) - (player.prevPosZ + (player.posZ - player.prevPosZ));
        
        GL11.glPushMatrix();
        GL11.glTranslated(diffX, diffY + 3, diffZ);

        //GL11.glTranslated(0, 3, 0);//move the whole thing 0.5 unit in the air
        GL11.glRotatef(-90, 1, 0, 0);//rotate around the y axis by 90 degree

        GL11.glRotatef(-player.rotationYaw, 0.0F, 0.0F, 1.0F);


        
	minecraft.renderEngine.bindTexture("/village/images/bubble1.png");
	tessellator.startDrawingQuads();
	tessellator.addVertexWithUV(-1, 1, 1, 0, 0);
	tessellator.addVertexWithUV(-1, 1, -1, 0, 1);
	tessellator.addVertexWithUV(1, 1, -1, 1, 1);
	tessellator.addVertexWithUV(1, 1, 1, 1, 0);

	tessellator.addVertexWithUV(-1, 1, 1, 0, 0);
	tessellator.addVertexWithUV(1, 1, 1, 1, 0);
	tessellator.addVertexWithUV(1, 1, -1, 1, 1);
	tessellator.addVertexWithUV(-1, 1, -1, 0, 1);
	tessellator.draw();

        GL11.glPopMatrix();//restore saved gl transform state

}
}

 

Link to comment
Share on other sites

Tessellator tessellator = Tessellator.instance;

 

       

        EntityClientPlayerMP player = minecraft.thePlayer;

       

        double diffX = (event.entity.prevPosX + (event.entity.posX - event.entity.prevPosX)) - (player.prevPosX + (player.posX - player.prevPosX));

        double diffY = (event.entity.prevPosY + (event.entity.posY - event.entity.prevPosY)) - (player.prevPosY + (player.posY - player.prevPosY));

        double diffZ = (event.entity.prevPosZ + (event.entity.posZ - event.entity.prevPosZ)) - (player.prevPosZ + (player.posZ - player.prevPosZ));

       

        GL11.glPushMatrix();

        GL11.glTranslated(diffX, diffY + 3, diffZ);

        GL11.glRotatef(-player.rotationYaw, 0.0F, 0.0F, 1.0F);

        GL11.glPushMatrix();

 

        GL11.glRotatef(-90, 1, 0, 0);//noted 1

        GL11.glTranslated(0, 3, 0);//noted 2

 

 

 

       

minecraft.renderEngine.bindTexture("/village/images/bubble1.png");

tessellator.startDrawingQuads();

tessellator.addVertexWithUV(-1, 1, 1, 0, 0);//your +1 everywhere in y is redundant btw it should be included in a glTranslated

tessellator.addVertexWithUV(-1, 1, -1, 0, 1);

tessellator.addVertexWithUV(1, 1, -1, 1, 1);

tessellator.addVertexWithUV(1, 1, 1, 1, 0);

 

tessellator.addVertexWithUV(-1, 1, 1, 0, 0);

tessellator.addVertexWithUV(1, 1, 1, 1, 0);

tessellator.addVertexWithUV(1, 1, -1, 1, 1);

tessellator.addVertexWithUV(-1, 1, -1, 0, 1);

tessellator.draw();

 

        GL11.glPopMatrix();

        GL11.glPopMatrix();//restore saved gl transform state

 

try this instead, if that acts weird, switch the line commented "noted 1" and "noted 2"

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

oh

GL11.glRotatef(-player.rotationYaw, 0.0F, 0.0F, 1.0F);

you had that ^ i copied it without thinking

 

 

change it to thjat

GL11.glRotatef(-player.rotationYaw, 0.0F, 1.0F, 0.0F);

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

well ... this is getting hard besaude its like 1 line to switch or not, so either wait til i have time to do it manually or try to play around to make it fit correctly okay ? :\

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Figured it out!  :D  After some experimentation, I figured out that this line was controlling the distance from the center:

        GL11.glTranslated(0, 3, 0);//noted 2

 

I changed i to 0, -1, 0 and it was right above the head!  :D  Thanks very much for all the help! :)

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://mclo.gs/4UC49Ao
    • Way back in the Forge 1.17 days, work started for adding JPMS (Java Platform Module Support) to ModLauncher and ForgeModLoader. This has been used internally by Forge and some libraries for a while now, but mods (those with mods.toml specifically) have not been able to take advantage of it. As of Forge 1.21.1 and 1.21.3, this is now possible!   What is JPMS and what does it mean for modders? JPMS is the Java Platform Module System, introduced in Java 9. It allows you to define modules, which are collections of packages and resources that can be exported or hidden from other modules. This allows for much more fine-tuned control over visibility, cleaner syntax for service declarations and support for sealed types across packages. For example, you might have a mod with a module called `com.example.mod` that exports `com.example.mod.api` and `com.example.mod.impl` to other mods, but hides `com.example.mod.internal` from them. This would allow you to have a clean API for other mods to use, while keeping your internal implementation details hidden from IDE hints, helping prevent accidental usage of internals that might break without prior notice. This is particularly useful if you'd like to use public records with module-private constructors or partially module-private record components, as you can create a sealed interface that only your record implements, having the interface be exported and the record hidden. It's also nice for declaring and using services, as you'll get compile-time errors from the Java compiler for typos and the like, rather than deferring to runtime errors. In more advanced cases, you can also have public methods that are only accessible to specific other modules -- handy if you want internal interactions between multiple of your own mods.   How do I bypass it? We understand there may be drama in implementing a system that prevents mods from accessing each other's internals when necessary (like when a mod is abandoned or you need to fix a compat issue) -- after all, we are already modding a game that doesn't have explicit support for Java mods yet. We have already thought of this and are offering APIs from day one to selectively bypass module restrictions. Let me be clear: Forge mods are not required to use JPMS. If you don't want to use it, you don't have to. The default behaviour is to have fully open, fully exported automatic modules. In Java, you can use the `Add-Opens` and `Add-Exports` manifest attributes to selectively bypass module restrictions of other mods at launch time, and we've added explicit support for these when loading your Forge mods. At compile-time, you can use existing solutions such as the extra-java-module-info Gradle plugin to deal with non-modular dependencies and add extra opens and exports to other modules. Here's an example on how to make the internal package `com.example.examplemod.internal` open to your mod in your build.gradle: tasks.named('jar', Jar) { manifest { attributes([ 'Add-Opens' : 'com.example.examplemod/com.example.examplemod.internal' 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors // (...) ]) } } With the above in your mod's jar manifest, you can now reflectively access the classes inside that internal package. Multiple entries are separated with a space, as per Java's official spec. You can also use Add-Exports to directly call without reflection, however you'd need to use the Gradle plugin mentioned earlier to be able to compile. The syntax for Add-Exports is the same as Add-Opens, and instructions for the compile-time step with the Gradle plugin are detailed later in this post. Remember to prefer the opens and exports keywords inside module-info.java for sources you control. The Add-Opens/Add-Exports attributes are only intended for forcing open other mods.   What else is new with module support? Previously, the runtime module name was always forced to the first mod ID in your `mods.toml` file and all packages were forced fully open and exported. Module names are now distinguished from mod IDs, meaning the module name in your module-info.java can be different from the mod ID in your `mods.toml`. This allows you to have a more descriptive module name that doesn't have to be the same as your mod ID, however we strongly recommend including your mod ID as part of your module name to aid troubleshooting. The `Automatic-Module-Name` manifest attribute is now also honoured, allowing you to specify a module name for your mod without needing to create a `module-info.java` file. This is particularly useful for mods that don't care about JPMS features but want to have a more descriptive module name and easier integration with other mods that do use JPMS.   How do I use it? The first step is to create a `module-info.java` file in your mod's source directory. This file should be in the same package as your main mod class, and should look something like this: open module com.example.examplemod { requires net.minecraftforge.eventbus; requires net.minecraftforge.fmlcore; requires net.minecraftforge.forge; requires net.minecraftforge.javafmlmod; requires net.minecraftforge.mergetool.api; requires org.slf4j; requires logging; } For now, we're leaving the whole module open to reflection, which is a good starting point. When we know we want to close something off, we can remove the open modifier from the module and open or export individual packages instead. Remember that you need to be open to Forge (module name net.minecraftforge.forge), otherwise it can't call your mod's constructor. Next is fixing modules in Gradle. While Forge and Java support modules properly, Gradle does not put automatic modules on the module path by default, meaning that the logging module (from com.mojang:logging) is not found. To fix this, add the Gradle plugin and add a compile-time module definition for that Mojang library: plugins { // (...) id 'org.gradlex.extra-java-module-info' version "1.9" } // (...) extraJavaModuleInfo { failOnMissingModuleInfo = false automaticModule("com.mojang:logging", "logging") } The automatic module override specified in your build.gradle should match the runtime one to avoid errors. You can do the same for any library or mod dependency that is missing either a module-info or explicit Automatic-Module-Name, however be aware that you may need to update your mod once said library adds one. That's all you need to get started with module support in your mods. You can learn more about modules and how to use them at dev.java.
    • Faire la mise à jour grâce à ce lien m'a aider personnellement, merci à @Paint_Ninja. https://www.amd.com/en/support 
    • When I came across the 'Exit Code: I got a 1 error in my Minecraft mods, so I decided to figure out what was wrong. First, I took a look at the logs. In the mods folder (usually where you'd find logs or crash reports), I found the latest.log file or the corresponding crash report. I read it through carefully, looking for any lines with errors or warnings. Then I checked the Minecraft Forge support site, where you can often find info on what causes errors and how to fix them. I then disabled half of my mods and tried running the game. If the error disappeared, it meant that the problem was with the disabled mod. I repeated this several times to find the problem mod.
    • I have no idea - switch to a pre-configured modpack and use it as working base    
  • Topics

×
×
  • Create New...

Important Information

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