Jump to content

Rendering an Image into the world[Solved]


Lua

Recommended Posts

heard someone saying my name

 

yes you can, but drawTextureModelRectangle does a weird reshape of the texture, so it "works" in gui but in world it would probably look like shit

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

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

heard someone saying my name

 

yes you can, but drawTextureModelRectangle does a weird reshape of the texture, so it "works" in gui but in world it would probably look like shit

Is there a way to draw a simple rectangle without an image. Im looking to do a health bar

Link to comment
Share on other sites

without an image, no

BUT you can make a 1 pixel by 1 pixel image in *insert your favorite image editor here* (mine is paint.net, different from microsoft paint btw)

and make that a texture in minecraft

 

next you can load that texture and use tessellator.setColorOpaque(R, G, B) (or any other color altering function)

 

bind your texture:

Minecraft.getMinecraft().renderEngine.func_xxxx_x(BlankTexture);

set your color

and call this utility method

 

 

public static void drawTexturedQuadFit(double x, double y, double width, double height, double zLevel){

Tessellator tessellator = Tessellator.instance;

tessellator.setColorOpaque(255, 255, 255);

        tessellator.startDrawingQuads();

tessellator.setColorOpaque(255, 255, 255);

        tessellator.addVertexWithUV(x + 0, y + height, zLevel, 0,1);

        tessellator.addVertexWithUV(x + width, y + height, zLevel, 1, 1);

        tessellator.addVertexWithUV(x + width, y + 0, zLevel, 1,0);

        tessellator.addVertexWithUV(x + 0, y + 0, zLevel, 0, 0);

tessellator.setColorOpaque(255, 255, 255);

        tessellator.draw();

}

 

final code:

 

//in drawing method
mc.renderEngine.func_110577_a(blankTexture);//blankTexture is a ResourceLocation btw
RenderHelper.drawTexturedQuadFit(xPosition, yPosition, height, height, 0);

 

remember, drawing a width, height of 1, 1 in the minecraft world represent the size of a block,    1x1 in a gui represent 1 pixel

 

so 100x100 in the world is HUGE but in your gui is like the length of the health bar

 

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

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Hm, didnt seem to render. Heres the code:

	@ForgeSubscribe
public void renderCavemanHealthBar(RenderLivingEvent.Specials.Pre event)
{
	mc = mc.getMinecraft();
	GuiIngame gui = mc.ingameGUI;
	if(event.entity instanceof AC_EntityCaveman)
	{

		System.out.println("Drawing Rect");
		Tessellator tessellator = Tessellator.instance;

		EntityClientPlayerMP player = mc.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, 1.0F, 0.0F);
		GL11.glPushMatrix();

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

		mc.func_110434_K().func_110577_a(new ResourceLocation(Strings.MOD_ID, "/textures/gui/temperature_bar.png"));
		this.drawTexturedQuadFit(20, 20, 20, 20, 0);
		GL11.glPopMatrix();
		GL11.glPopMatrix();

	}
}

 

public static void drawTexturedQuadFit(double x, double y, double width, double height, double zLevel)
{
	Tessellator tessellator = Tessellator.instance;
	tessellator.setColorOpaque(255, 255, 255);
	tessellator.startDrawingQuads();
	tessellator.setColorOpaque(255, 255, 255);
	tessellator.addVertexWithUV(x + 0, y + height, zLevel, 0, 1);
	tessellator.addVertexWithUV(x + width, y + height, zLevel, 1, 1);
	tessellator.addVertexWithUV(x + width, y + 0, zLevel, 1, 0);
	tessellator.addVertexWithUV(x + 0, y + 0, zLevel, 0, 0);
	tessellator.setColorOpaque(255, 255, 255);
	tessellator.draw();
}

 

Link to comment
Share on other sites

System.out.println("Drawing Rect");

 

can you see this in your logs ?

 

if not that mean its a event register problem

if yes it mean your problem is related to your matrix configuration, ill help you figure out the correct matrix if that's the case

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

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

System.out.println("Drawing Rect");

 

can you see this in your logs ?

 

if not that mean its a event register problem

if yes it mean your problem is related to your matrix configuration, ill help you figure out the correct matrix if that's the case

Yup it prints, so its a 'matrix' problem

Link to comment
Share on other sites

ok, it might take a couple of post, but its going to be fixed in the end

 

original code

public void renderCavemanHealthBar(RenderLivingEvent.Specials.Pre event)
{
	mc = mc.getMinecraft();
	GuiIngame gui = mc.ingameGUI;
	if(event.entity instanceof AC_EntityCaveman)
	{

		System.out.println("Drawing Rect");
		Tessellator tessellator = Tessellator.instance;

		EntityClientPlayerMP player = mc.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, 1.0F, 0.0F);
		GL11.glPushMatrix();

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

		mc.func_110434_K().func_110577_a(new ResourceLocation(Strings.MOD_ID, "/textures/gui/temperature_bar.png"));
		this.drawTexturedQuadFit(20, 20, 20, 20, 0);
		GL11.glPopMatrix();
		GL11.glPopMatrix();

	}
}

well simplify thsi a little and grow from there

 

first thing were gonna do is make SURE we are drawing something, so screw the location of it, lets just make sure its rendering

 

 

public void renderCavemanHealthBar(RenderLivingEvent.Specials.Pre event)
{
	mc = mc.getMinecraft();

		GL11.glPushMatrix();
		GL11.glRotatef(System.nanoTime()/10000000f, 0.0F, 1.0F, 0.0F);//this will make the image rotate, might be too fast or too slow, just add /remove zeros if that the case

		mc.func_110434_K().func_110577_a(new ResourceLocation(Strings.MOD_ID, "/textures/gui/temperature_bar.png"));
		this.drawTexturedQuadFit(-1, -1, 2, 2, 0);//this was a bit big and kinof far away from the entity (the 2 first variable are x, y so technicly you were rendering the image 20 block away in x and 20 block away in y
		GL11.glPopMatrix();

}

 

 

go in 3rd person, you should see something turning above your head

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

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

its not above my head though

is it only off in Y or is it off in XZ too ?

 

in any case lets re-add the translation to the caveman entity

 

public void renderCavemanHealthBar(RenderLivingEvent.Specials.Pre event)
{
	mc = mc.getMinecraft();

		GL11.glPushMatrix();

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));
// btw if you look mathematicly at that its
//int a = 5;
//int b = 2;
diffX = a+(b-a) = a+b-a = b 
// since you're not using the partialTick yet you could simply use the event.entity.posX-player.posX and the effect would be the same
GL11.glTranslated(diffX, diffY, diffZ);//translate to the position of the caveman
		GL11.glRotatef(System.nanoTime()/10000000f, 0.0F, 1.0F, 0.0F);

		mc.func_110434_K().func_110577_a(new ResourceLocation(Strings.MOD_ID, "/textures/gui/temperature_bar.png"));
		this.drawTexturedQuadFit(-1, -1, 2, 2, 0);
		GL11.glPopMatrix();

}

 

also later i suggest you take a look at my texture guide (go on the wiki and search "hydroflame guide to texture") because the way you are creating your ResourceLocation is bad

 

anyway, with this code the image should generally be near the caveman and should be rotating

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

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

this is just an idea, but do you have a special renderer for your caveman? because if yes you should probably do that there since you have control over it. RenderLivingEvent is for very general things or stuff you cannot normally do because you dont want to touch the source code (in your first thread you refer to another thread, in that one he wanted to render stuff over Villagers  which is a vanilla class and that is why he needed a event for it, in my profile picture i use a RenderLivingEvent too because i dont want to modify vanilla code)

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

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

"is it only off in Y or is it off in XZ too ?" Y

"you are creating your ResourceLocation is bad" Why is it bad?

I copied your code but added a check to see if it was the caveman and it didnt render. So I removed that check and the bar was still rotating at the same y

 

Heres the code

@ForgeSubscribe
public void renderCavemanHealthBar(RenderLivingEvent.Specials.Pre event)
{
	mc = mc.getMinecraft();
	if(event.entity instanceof AC_EntityCaveman)
	{
		GL11.glPushMatrix();

		double diffX = (event.entity.prevPosX + (event.entity.posX - event.entity.prevPosX)) - (mc.thePlayer.prevPosX + (mc.thePlayer.posX - mc.thePlayer.prevPosX));
		double diffY = (event.entity.prevPosY + (event.entity.posY - event.entity.prevPosY)) - (mc.thePlayer.prevPosY + (mc.thePlayer.posY - mc.thePlayer.prevPosY));
		double diffZ = (event.entity.prevPosZ + (event.entity.posZ - event.entity.prevPosZ)) - (mc.thePlayer.prevPosZ + (mc.thePlayer.posZ - mc.thePlayer.prevPosZ));
		//btw if you look mathematicly at that its
		//int a = 5;
		//int b = 2;
		//	diffX = a+(b-a) = a+b-a = b 
		//since you're not using the partialTick yet you could simply use the event.entity.posX-player.posX and the effect would be the same
		GL11.glTranslated(diffX, diffY, diffZ);//translate to the position of the caveman
		GL11.glRotatef(System.nanoTime() / 10000000f, 0.0F, 1.0F, 0.0F);

		mc.func_110434_K().func_110577_a(new ResourceLocation(Strings.MOD_ID, "/textures/gui/temperature_bar.png"));
		this.drawTexturedQuadFit(- 1, - 1, 2, 2, 0);
		GL11.glPopMatrix();
	}
}

 

@ Your latest reply, I do have a rendercavemen, but what method would I put it in?

Link to comment
Share on other sites

"you are creating your ResourceLocation is bad" Why is it bad?

jsut look at my guide later, no big deal but still...

 

I copied your code but added a check to see if it was the caveman and it didnt render. So I removed that check and the bar was still rotating at the same y

most likely becasue since you removed the caveman check the player you are is also taken into account now so you are renderered with the thing

 

@ Your latest reply, I do have a rendercavemen, but what method would I put it in?

the main one, or maybe maker a smaller that the main render method would call to keep thing clean

example of a generic entity renderer

@Override

public void doRender(Entity entity, double x, double y, double z, float rot, float partialTick)

    {

        GL11.glPushMatrix();

        GL11.glTranslated(x, y, z);

//maybe more transformation

        Minecraft.getMinecraft().renderEngine.func_110577_a(ForgeRevCommonProxy.blankTexture);

        model.render();

        renderTag(entity);

        GL11.glPopMatrix();

    }

 

 

public void renderTag(Entity entity){

//some move/rotate before

//bind the texture

this.drawTexturedQuadFit(-1, -1, 2, 2, 0);

}

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

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Hm well ive started to do it in here now, lets just continue in there and I can move it later if need by. So what next?

ok but letting you know that it is a bad programming habit...

 

 

well you said that the quad was only rendering above your head (or inside you, wtv:P) not above the caveman (or inside him)

 

what we need to do now is try to figure out a way to configure the openGL matrix at the location of the entity

 

when you begin the method renderCavemanHealthBar 0, 0, 0 is considered the position of steve eyes

 

double diffX = (event.entity.prevPosX + (event.entity.posX - event.entity.prevPosX)) - (mc.thePlayer.prevPosX + (mc.thePlayer.posX - mc.thePlayer.prevPosX));
		double diffY = (event.entity.prevPosY + (event.entity.posY - event.entity.prevPosY)) - (mc.thePlayer.prevPosY + (mc.thePlayer.posY - mc.thePlayer.prevPosY));
		double diffZ = (event.entity.prevPosZ + (event.entity.posZ - event.entity.prevPosZ)) - (mc.thePlayer.prevPosZ + (mc.thePlayer.posZ - mc.thePlayer.prevPosZ));
		GL11.glTranslated(diffX, diffY, diffZ);//translate to the position of the caveman

these lines are suppose to translate the 0, 0, 0 to the location of the caveman. but basicly it should be translated by "the difference in position between the player and the entity"  try getting very close to the caveman to see if the panel doesnt emerge from somewhere. is the caveman really big meaning it could be tottally inside it ? (and you wouldnt be able to see it)

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

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

ah, then all you have to do now is increase the height

and use the proper orientation (so that the image always faces the player)

 

@ForgeSubscribe

public void renderCavemanHealthBar(RenderLivingEvent.Specials.Pre event)

{

mc = mc.getMinecraft();

if(event.entity instanceof AC_EntityCaveman)

{

GL11.glPushMatrix();

 

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

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

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

GL11.glTranslated(diffX, diffY, diffZ);

//GL11.glRotatef(System.nanoTime() / 10000000f, 0.0F, 1.0F, 0.0F); no more of use

GL11.glTranslated(0, 5, 0);//could be 6, 7, 10, 2000, youll have to find the god value yourself

//i highly doubt 2000 is even a good value btw

//its approximatelly the same height as your entity, and a little more

GL11.glRotatef(180.0F - event.entityPlayer.renderYawOffset, 0.0F, 1.0F, 0.0F);//this line should make it always face the player, or always away from the player depending on which direction your plane is facing, experiment with it

mc.func_110434_K().func_110577_a(new ResourceLocation(Strings.MOD_ID, "/textures/gui/temperature_bar.png"));

this.drawTexturedQuadFit(- 1, - 1, 2, 2, 0);

GL11.glPopMatrix();

}

}

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 ive got it how i want it. Now you said I could colour it ? What id like is it to be coloured in green which would be its total health then when the health goes down some of the green should be replaced with red depending on how much damage was taken.

Link to comment
Share on other sites

ok well first, the method i gave you, youll need to change it, remove every setColorxxx

public static void drawTexturedQuadFit(double x, double y, double width, double height, double zLevel)

{

Tessellator tessellator = Tessellator.instance;

//tessellator.setColorOpaque(255, 255, 255);

tessellator.startDrawingQuads();

//tessellator.setColorOpaque(255, 255, 255);

tessellator.addVertexWithUV(x + 0, y + height, zLevel, 0, 1);

tessellator.addVertexWithUV(x + width, y + height, zLevel, 1, 1);

tessellator.addVertexWithUV(x + width, y + 0, zLevel, 1, 0);

tessellator.addVertexWithUV(x + 0, y + 0, zLevel, 0, 0);

//tessellator.setColorOpaque(255, 255, 255);

tessellator.draw();

}

because this will force the quad to be white

 

 

then when the health goes down some of the green should be replaced with red depending on how much damage was taken.

by some of the green you mean something like

[g][g][g][g][g][r][r][r]

*lose life*

[g][g][g][g][r][r][r][r]

 

if thats the case you will need to render a lot of quad, openGL can draw as many quad as you want but it wont subseparate them

but basicly to set a color for the quad use

Tessellator.instance.setColorOpaque(R, B, G); //example setColorOpaque(255, 0, 0); for red

and then if you want to render multiple quad (one for each bar of health), somethign like:

 

pseudo code

for(int i =0; i < caveman.getMaxHealth(); i++){
if caveman.getHealth() > i
render a green quad
else render a red quad
move one unit to the left/right (so that all quads are not one over the other)
}

 

 

 

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 tried it but nothing renders, heres my code

@ForgeSubscribe
public void renderCavemanHealthBar(RenderLivingEvent.Specials.Pre event)
{
	mc = mc.getMinecraft();
	if(event.entity instanceof AC_EntityCaveman)
	{
		GL11.glPushMatrix();

		double diffX = (event.entity.prevPosX + (event.entity.posX - event.entity.prevPosX)) - (mc.thePlayer.prevPosX + (mc.thePlayer.posX - mc.thePlayer.prevPosX));
		double diffY = (event.entity.prevPosY + (event.entity.posY - event.entity.prevPosY)) - (mc.thePlayer.prevPosY + (mc.thePlayer.posY - mc.thePlayer.prevPosY));
		double diffZ = (event.entity.prevPosZ + (event.entity.posZ - event.entity.prevPosZ)) - (mc.thePlayer.prevPosZ + (mc.thePlayer.posZ - mc.thePlayer.prevPosZ));
		GL11.glTranslated(diffX, diffY, diffZ);//translate to the position of the caveman
		//GL11.glRotatef(System.nanoTime() / 10000000f, 0.0F, 1.0F, 0.0F); no more of use
		GL11.glTranslated(0.45, 3.5, 0);//could be 6, 7, 10, 2000, youll have to find the god value yourself
		//i highly doubt 2000 is even a good value btw
		//its approximatelly the same height as your entity, and a little more
		GL11.glRotatef(200.0F - event.entity.renderYawOffset, 0.0F, 1.0F, 0.0F);//this line should make it always face the player, or always away from the player depending on which direction your plane is facing, experiment with it

		mc.func_110434_K().func_110577_a(new ResourceLocation(Strings.MOD_ID, "/textures/gui/health_bar.png"));
		this.drawTexturedQuadFit(- 1, - 1, 2, 2, 0);
		GL11.glPopMatrix();
	}
}

public static void drawTexturedQuadFit(double x, double y, double width, double height, double zLevel)
{
	caveman = caveman.getCaveman();
	Tessellator tessellator = Tessellator.instance;
	if(caveman != null)
	{
		for(int i = 0; i < caveman.func_110138_aP(); i++)
		{
			if(caveman.func_110138_aP() > i)
			{
				tessellator.startDrawingQuads();
				tessellator.setColorOpaque(0, 255, 0);
				tessellator.addVertexWithUV(x + 0, y + height, zLevel, 0, 1);
				tessellator.addVertexWithUV(x + width, y + height, zLevel, 1, 1);
				tessellator.addVertexWithUV(x + width, y + 0, zLevel, 1, 0);
				tessellator.addVertexWithUV(x + 0, y + 0, zLevel, 0, 0);
				tessellator.setColorOpaque(0, 255, 0);
				tessellator.draw();
			}
			else
			{
				tessellator.startDrawingQuads();
				tessellator.setColorOpaque(255, 0, 0);
				tessellator.addVertexWithUV(x + 0, y + height, zLevel, 0, 1);
				tessellator.addVertexWithUV(x + width, y + height, zLevel, 1, 1);
				tessellator.addVertexWithUV(x + width, y + 0, zLevel, 1, 0);
				tessellator.addVertexWithUV(x + 0, y + 0, zLevel, 0, 0);
				tessellator.setColorOpaque(255, 0, 0);
				tessellator.draw();
			}
		}
	}
}

Link to comment
Share on other sites

GL11.glRotatef(200.0F - event.entity.renderYawOffset, 0.0F, 1.0F, 0.0F);

depending on the orientation its possible the quad you render is facing away from you , opengl only render 1 side of each quad you ask him to

 

try thsi

GL11.glRotatef(event.entity.renderYawOffset, 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

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

    • I'm developing a dimension, but it's kinda resource intensive so some times during player teleporting it lags behind making the player phase down into the void, so im trying to implement some kind of pregeneration to force the game loading a small set of chunks in the are the player will teleport to. Some of the things i've tried like using ServerLevel and ServerChunkCache methods like getChunk() dont actually trigger chunk generation if the chunk isn't already on persistent storage (already generated) or placing tickets, but that doesn't work either. Ideally i should be able to check when the task has ended too. I've peeked around some pregen engines, but they're too complex for my current understanding of the system of which I have just a basic understanding (how ServerLevel ,ServerChunkCache  and ChunkMap work) of. Any tips or other classes I should be looking into to understand how to do this correctly?
    • 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.
  • Topics

×
×
  • Create New...

Important Information

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