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

    • Betafort Recovery has emerged as a prominent figure in the realm of cryptocurrency recovery, gaining a reputation for their exceptional ability to retrieve lost Bitcoin (BTC) and other cryptocurrencies. Their expertise and track record have made them a beacon of hope for individuals facing the distressing situation of lost or inaccessible crypto assets.  
    • When you name a method like that, with no return value, it is a constructor. The constructor must have the same name as the class it constructs, in this case, ModItems. I would strongly advise reading up on some basic Java tutorials, because you will definitely be running into a lot more issues as you go along without the basics. *I should also add that the Forge documentation is a reference, not a tutorial. Even following tutorials, you should know Java basics, otherwise the smallest of mistakes will trip you up as you copy someone elses code.
    • so, I'm starting modding and I'm following the official documantation for forge: https://docs.minecraftforge.net, but in the registries part it is not working as it is in the docs:   public class ModItems { private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, DarkStarvation.MOD_ID); public static final RegistryObject<Item> TEST_ITEM = ITEMS.register("test_item", () -> new Item(new Item.Properties())); public DarkStarvation(FMLJavaModLoadingContext context) { ITEMS.register(context.getModEventBus()); } } in 'public DarkStarvation(...' the DarkStarvation has this error: Invalid method declaration; return type required and the getModEventBus(): Cannot resolve method 'getModEventBus' in 'FMLJavaModLoadingContext' please help, I asked gpt but it is saying that I'm using an old method, but I'm following the latest version of Forge Docs???
    • I merged your second post with the original , there is no need to post a new thread asking for an answer. If someone sees your post and can help, they will reply. If you are seeking a quicker response, you could try asking in the Minecraft Forge diacord.
    • Create a new instance and start with cobblemon - if this works, add the rest of your mods in groups   Maybe another mod is conflicting - like Sodium/Iris or Radical Cobblemon Trainers
  • Topics

×
×
  • Create New...

Important Information

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