Jump to content

Recommended Posts

Posted

Hello,

 

I'm very new to modding, and new to Java as well (I have tons of experience with other programming languages however) and I have run into a problem when trying to animate my custom rendered model.

 

The block is rendered perfectly, and I got it to animate when it received a redstone signal. However, all blocks in the world would animate, not just the one I was giving a redstone signal to.

 

WAIT!

 

Before you say "Great.... another idiot who doesn't understand static variables," I know that static allows the variable to be shared across all of the blocks in the world, so I removed the static part of my variables. Now, the animation doesn't run. I have tried:

 

public static ModelRenderer PedestalOne;    -> Animation works, but runs on all blocks in the world.

public ModelRenderer PedestalOne;           -> Animation doesn't run.

ModelRenderer PedestalOne;                  -> Animation doesn't run.

 

I have tried various ways to render the model from outside of the Model class, but I am unable to figure this out.

 

Classes:

 

BlueGeneralSiren.java

 

  Reveal hidden contents

 

 

BlueSirenTileEntity.java

 

  Reveal hidden contents

 

 

BlueGeneralSirenRenderer.java

 

  Reveal hidden contents

 

 

GeneralSirenModel.java

 

 

  Reveal hidden contents

 

 

Any help would be appreciated. There is probably a really easy fix for this but I am just overlooking it.

 

-mcrafter

Posted

Hi

 

Although you're not using static variables any more, it won't help because Blocks are "singletons" anyway.  A Block instance stores information about the capabilities of a block, not about the state of the block.  Minecraft uses metadata for that.

http://greyminecraftcoder.blogspot.com.au/2013/07/blocks.html

 

Since you've figured out how to receive redstone signal, I'd suggest the easiest way is probably to store the redstone signal status in the block metadata.  When you render the block, retrieve the metadata and change your render based on that.  BlockTrapDoor does this, for example.

 

Cheers

  TGG

 

Posted

Thank you so much! I have been trying so hard to figure this out on my own. It never occurred to me to use metadata. I was actually trying to make the model render from the block class. Haha.

 

Edit: I'm still confused about how to do this. I need to rotate a part of my model rapidly in succession to create the illusion of motion. How can I make it so that when there is a redstone signal the part will spin, without using public static in my model class file?

Posted

Hello.

 

Since you got a tileEntity, you can store in it the values for the rotation of your model. Use updateEntity to change a variable called rotation (or the name you choose, usually public float). Since every tileEntity is unique, in the renderer you can import the tileEntity for xCoord, yCoord and zCoord (TileEntity tile = world.getTileEntity() and cast it to the entity you are talking about) and then take that particular rotation (tile.rotation), then aplly it to the figure you want to rotate (render.figureX(tile.rotation)). for example:

 

TileEntity

 

public void updateEntity() {

if (!worldObj.isRemote) {

	} else {
		BatRotation += 0.05F;
	}
}

 

 

renderer

 

 

  Reveal hidden contents

 

Posted
  On 10/10/2014 at 4:28 PM, Jordor said:

Hello.

 

Since you got a tileEntity, you can store in it the values for the rotation of your model. Use updateEntity to change a variable called rotation (or the name you choose, usually public float). Since every tileEntity is unique, in the renderer you can import the tileEntity for xCoord, yCoord and zCoord (TileEntity tile = world.getTileEntity() and cast it to the entity you are talking about) and then take that particular rotation (tile.rotation), then aplly it to the figure you want to rotate (render.figureX(tile.rotation)). for example:

 

TileEntity

 


public void updateEntity() {

if (!worldObj.isRemote) {

	} else {
		BatRotation += 0.05F;
	}
}

 

 

renderer

 

 

  Reveal hidden contents

 

 

Would you mind posting the code that is in your TileEntity class please?

  • 3 weeks later...
Posted

The ONLY thing I need to know is how to make it so I only affect the one block instead of all of the blocks in the world.

 

I cannot put

 

TileEntity tile = world.getTileEntity()

 

because there is no reference to "world." in my renderer class.

 

 

Posted
  On 10/30/2014 at 10:19 PM, hi123 said:

The ONLY thing I need to know is how to make it so I only affect the one block instead of all of the blocks in the world.

 

I cannot put

 

TileEntity tile = world.getTileEntity()

 

because there is no reference to "world." in my renderer class.

 

You already have a reference to tileEntity, you don't need the world, but you do need to store the rotation in the tileEntity like Jordor suggested. Such as:

 

public class BlueSirenTileEntity extends TileEntity {
  public float rotation = 0;
}

 

then in the Block, instead of changing the model, change the rotation of the TileEntity:

 

if (par1World.isBlockIndirectlyGettingPowered(par2, par3, par4)){
if (world.isRemote) ((BlueSirenTileEntity)world.getTileEntity(par2, par3, par4)).rotation += 0.05F;
}

 

then just use ((BlueSirenTileEntity)tileentity).rotation in your renderTileEntityAt method to determine how to render the model.

 

Posted

Thank you so much! That little line of code is the only thing I needed to prevent myself from smashing my face into my keyboard!

 

BUT all of the blocks rotate, not just the one I power.

What am I doing wrong?

 

EDIT: Oops! I had old code in my updateEntity() method. It's working perfectly. Thanks!

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.