Jump to content

Recommended Posts

Posted

Hey, I was having some fun with custom model rendering blocks and stuff and I wanted the center cube of the model to rotate. But however, the way I was doing it, the more blocks you have, the faster the spinning gets. I want to know how I would make that per-block or something.

 

Doing the actual rendering: https://github.com/mrkirby153/StevesBoats/blob/master/src/main/java/me/mrkirby153/StevesBoats/blocks/renderers/TileEntityBlockCrafterRenderer.java

Model Class: https://github.com/mrkirby153/StevesBoats/blob/master/src/main/java/me/mrkirby153/StevesBoats/models/ModelBlockCrafter.java

 

Let me know if I forgot something

Posted

Save the rotation value in the TileEntity. (not static)

 

Have the renderer read the value from the TileEntity, edit it as needed, and save back.

 

In my TileEntity:

public float rotation;

 

In my Renderer:

tile.rotation += 0.25F;

if (tile.rotation > 360) tile.rotation = 0F;

GL11.glRotatef(tile.rotation, 1F, 0F, 0F);

 

Posted

I would say save it to NBT to be safe

 

@Override
public void writeToNBT(NBTTagCompound tag)
{
      tag.setInteger("rot", rot);
}

@Override
public void readFromNBT(NBTTagCompound tag)
{
      rot = tag.getInteger("rot");
}

Posted

No need to save it, its just visual.

Now I've long replaced my Techne models with OBJ's so lets see if I can get this from memory.

 

In TileEntityBlockCrafter.java add:

public float rotation; // you want this a float for better speed control

 

In ModelBlockCrafter.java add:

public void rotateCube(float rotation)
{
    this.CenterCube.rotateAngleY = rotation;
}

 

Now in TileEntityBlockCrafterRenderer.java before this.model.render:

((TileEntityBlockCrafter)te).rotation += 0.25F; // Change this number to change speed
if (((TileEntityBlockCrafter)te).rotation > 180) ((TileEntityBlockCrafter)te).rotation = -180F; // I believe Techne uses -180 to 180, instead of 0 to 360
this.model.rotateCube(((TileEntityBlockCrafter)te).rotation);

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.

Announcements



×
×
  • Create New...

Important Information

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