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

    • "I want to understand how complex mods with ASM transformation and coremods work, such as Xray or AntiXray. Why do they break when you simply rename packages? What features of their architecture make refactoring difficult? And what techniques are used to protect these mods? I am interested in technical aspects in order to better understand the bytecode and Forge loader system."
    • I can't figure out if you're looking for help trying to steal someone elses work, or cheat at the game....
    • Title: Why Is It So Hard to Rename and Restructure Mods Like Xray or AntiXray? 🤔 Post text: Hey everyone! I’ve been digging into Minecraft modding for a while and have one big question that I can’t figure out on my own. Maybe someone with more experience could help or give me some advice. Here’s the issue: When I take a “normal” Minecraft mod — for example, one that just adds some blocks or new items — I can easily change its structure, package names, or even rebrand it entirely. It’s straightforward. But as soon as I try this with cheat-type mods like XrayMod or AntiXray, everything falls apart. Even if I just rename the classes, refactor the packages, or hide its identity somehow, the mod either breaks or stops working properly. XrayMod in particular is proving to be a nightmare to modify without losing its core function. So my question is — why is this so much harder with cheat mods like Xray? Is there something fundamentally different about how they’re coded, loaded, or protected that prevents simple renaming or restructuring? And if so, how can I actually learn to understand someone else’s cheat mod enough to safely refactor it without breaking the core features? I’ve already been spending over two months trying to figure this out and haven’t gotten anywhere. It feels like there must be some trick or knowledge I’m missing. Would really appreciate any thoughts, tips, or references — maybe there are guides or techniques for understanding cheat-mod internals? Or if you’ve successfully “disguised” a cheat mod like Xray before, I’d love to hear how you did it. Thanks in advance for any help or discussion. ✌️
    • just started making cinamatic contect check it out on my channel or check out my facebook page    Humbug City Minecraft Youtube https://www.youtube.com/watch?v=v2N6OveKwno https://www.facebook.com/profile.php?id=61575866982337  
    • Where did you get the schematic? Source/Link? And do use an own modpack or a pre-configured from curseforge? If yes, which one On a later time, I can make some tests on my own - but I need the schematic and the modpack name
  • Topics

×
×
  • Create New...

Important Information

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