Jump to content

[Solved][1.7.10] Rendering a cube with scale not working


Recommended Posts

Posted

Hey everyone

 

I've got a small problem with rendering cubes. I have a RenderShot that should render a shot for an EntityShot, and it basically just renders one cube with varying size. Or at least it should.

Here's the code for the renderer:

 

public class RenderShot extends Render{

private ModelBase model = new ModelBase(){};
private ModelRenderer cubeShot;

public RenderShot(){
	model.textureHeight = 32;
	model.textureWidth = 64;

	cubeShot = new ModelRenderer(model);
                cubeShot.addBox(-2F, -2F, -8F, 4, 4, 16);;
                cubeShot.setTextureSize(64, 32);
}

@Override
public void doRender(Entity entity, double x, double y, double z, float yaw, float partialTickTime) {
	EntityShot shot = (EntityShot)entity;

	GL11.glPushMatrix();

	GL11.glTranslatef((float)x, (float)y, (float)z);
	GL11.glScalef(-1F, -1F, 1F);

	Minecraft.getMinecraft().getTextureManager().bindTexture(Textures.Model.ENERGY_SHOT);

                //rotation works
	cubeShot.rotateAngleX = shot.getRenderPitch();
	cubeShot.rotateAngleY = shot.getRenderYaw() - (float)Math.PI * 0.5f;

                //also correctly calculated
		float scale = 0.0625F * shot.getSizeFactor();
	LogHelper.info(scale);
		cubeShot.render(scale);

		GL11.glPopMatrix();
	}

@Override
protected ResourceLocation getEntityTexture(Entity entity) {
	return Textures.Model.ENERGY_SHOT;
}

}

 

The problem is that it doesn't vary the size even though the scale calculation clearly works (I know cause I print it out).  It always renders all shots the same size, either max scale(wich is a scale of 0.0625) or min scale (wich is about 0.015). It might switch from min to max or the other way around when I restart the game, but it always renders every shot the same size.

 

Does anyone have an idea what could cause that?

Posted

If you're using non-vanilla fields for rendering, you need to implement IEntityAdditionalSpawnData to the entity, as on client-side, it constructs using the constructor that only has a world argument, and won't have any non-vanilla data.

Posted
  Quote
If you're using non-vanilla fields for rendering, you need to implement IEntityAdditionalSpawnData to the entity, as on client-side, it constructs using the constructor that only has a world argument, and won't have any non-vanilla data.

 

I'm actually doing that, its not the problem. shot.getSizeFactor() returns the correct value on the client and the server side. As I said, the scale is calculated properly and as far as I can tell it really should work.

Posted

Put the following in your render class:

@Override
protected void preRenderCallback(EntityLivingBase entity, float p_77041_2_) {
GL11.glScalef(-1f, -1f, 1f);
}

But why are you using -1?

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Posted

Thanks for the suggestion!

Unfortunately that method doesn't seem to exist in Render (which is the parent of the RenderShot) :(.  The shot is also extends EntityFireball and not EntityLivingBase (should have mentioned that in OP). 

 

The -1 is because this shot is fired from a cannon, the model for which I made in Techne. When I imported it it screwed up the rotations and such so I just started to change values until it looked right. Thats also the reason for the "shot.getRenderYaw() - (float)Math.PI * 0.5f". Will clean all that rotation stuff up later though, its kinda messy right now.

 

The scaling I'm worried about happens here though:

		float scale = 0.0625F * shot.getSizeFactor();
	LogHelper.info(scale);
	cubeShot.render(scale);

Posted

Hi

 

Disclaimer: I've never used the ModelRenderer.

 

However the vanilla code looks like this

 

ModelRenderer::
    public void render(float p_78785_1_)
    {
        if (!this.isHidden)
        {
            if (this.showModel)
            {
                if (!this.compiled)
                {
                    this.compileDisplayList(p_78785_1_);
                }

I think this "compileDisplayList" means that it will accept the scale factor on the first call, but after that it will ignore it (i.e. it caches the display list and doesn't update it again).

 

So I would suggest that you either use GL11.glScalef(factor, factor, factor) before the call to the render(), or if that doesn't work, use multiple copies of ModelRenderer, one for each size of shot.  (Or just discard your cubeShot and generate a fresh one every time you change the size).

 

-TGG

 

Posted
  Quote
Hi

 

Disclaimer: I've never used the ModelRenderer.

 

However the vanilla code looks like this

 

Code: [select]

 

ModelRenderer::

    public void render(float p_78785_1_)

    {

        if (!this.isHidden)

        {

            if (this.showModel)

            {

                if (!this.compiled)

                {

                    this.compileDisplayList(p_78785_1_);

                }

 

I think this "compileDisplayList" means that it will accept the scale factor on the first call, but after that it will ignore it (i.e. it caches the display list and doesn't update it again).

 

So I would suggest that you either use GL11.glScalef(factor, factor, factor) before the call to the render(), or if that doesn't work, use multiple copies of ModelRenderer, one for each size of shot.  (Or just discard your cubeShot and generate a fresh one every time you change the size).

 

-TGG

 

Hi

yeah it just occured to me that there really was no reason not to do it in glScalef. So I moved it there and it works fine now, thanks!

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Start by following the docs to get a workspace setup: https://docs.minecraftforge.net/en/latest/gettingstarted/ Then poke around some of the tutorials, https://www.mcjty.eu/docs/1.20/ used to be the goto, but not sure if there are any updates for regular forge or not, but if you've brushed up on Java, it will be enough to get you started. Poke around the Minecraft and Forge sources to see how things are done. Read the FAQ for information on how to post code/logs when you run into issues. Share as much info on issues you have as possible. Use github to host projects, chances of someone helping are higher when they can actually see all your code and/or build it themselves. And finally, keep it on the forums, don't direct message people with questions, most people do not provide personal support like that. Also keep in mind forums posts are not always immediately answered, if you're looking for a quicker response, you can always try the Minecraft Forge discord server.
    • Hello, I have a Forge Minecraft sever (I host it at g-portal.com) which has always worked fine and I had no problems, but today it doesn't wanna work anymore. Today I started the server and the status said online, but after a few seconds it said this: "Start failed". And then out of nowhere it restarted itself and the same thing happened again and again and now it's in an infinite loop where it just keeps failing and then restarts. Here's the download link for the server logs: https://www.mediafire.com/file/sq30dgoonjevib1/2025-07-06-1.log/file Does anyone know how to fix this? If yes I would really appreciate help. Best wishes, Gabs1107
    • I'm experiencing a critical issue on a dedicated Arch Linux server running the latest Forge for Minecraft 1.20.1. When a player exits a Nether portal (not enters, and not via /tp) or teleports into the End via portal, the server completely freezes for 1–10 minutes. During this time, all commands are unresponsive, and the game world essentially locks up. This is with watchdog disabled. Environment: OS: Arch Linux (latest packages) Java: OpenJDK 17 (up to date) Forge Version: Latest 1.20.1 (tested multiple versions from the past ~3 months) Mods: None (issue occurs on a clean install) Server Type: Proxmox VM with: 4 virtual cores 64 GB RAM (63 GB allocated via -Xmx and -Xms flags) Observed Behavior: Observed Behavior: The server freezes for 1–10 minutes when: Exiting a Nether portal (entering does not trigger the issue) Entering or exiting the End using a portal Teleporting using commands (e.g., /tp) works only for the Nether; teleporting to the End via command also causes a freeze The issue occurs anywhere in the world, not tied to specific coordinates or builds During the freeze: The server becomes completely unresponsive to all commands and player actions No crash reports, no errors, and no warnings are logged CPU usage remains under 50%, and RAM usage stays around 6–14 GB After 1–10 minutes, the server recovers automatically and resumes normal operation
    • Hey man, I just found this section in your code.  Try to do this: { "parent": "minecraft:item/generated", "textures": { "layer0": "testmod:item/alexandrite" } } This means your png should be named alexandrite.png. Hope it helps  
  • Topics

×
×
  • Create New...

Important Information

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