Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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?

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.

  • Author
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.

Try scaling it in preRenderCallback

Check out my mod, Realms of Chaos, here.

 

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

  • Author
Try scaling it in preRenderCallback

 

What is that/how do I do it? I've never heard of it.

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!

  • Author

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);

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

 

Try making it a subclass of RenderLiving

Check out my mod, Realms of Chaos, here.

 

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

  • Author
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.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.