Jump to content

[SOLVED] TESR's Acting as One instead of Individually


TheMoleTractor

Recommended Posts

This is my first forge post, although I have been using the forums for quite a while for help.

 

Anyways, here my issue (of which I can't even find a similar issue anywhere)

 

I have a block that uses a TESR and have multiple textures; essentially just a crop block (Sapphire Crop) that grows and is shear-able. All is working fine but it seems that when I have more than one, they all act as the same block and mirror the others qualities. For instance if I have two down and shear one, the other, although not dropping a berry, acts as if sheared texture-wise.

 

I have tried using multiple blocks (shearing drops a berry and replaces the current crop with another with one less berry) but the new crop resets the direction it's facing.

 

If anybody wants to see code, I can post it. I'd really prefer to keep it to one block, but don't honestly see that being a possibility. Really any help or suggestions are greatly appreciated.

 

Thanks!

TheMoleTractor

Link to comment
Share on other sites

Sounds like you are mis-using a the static modifier. Show your code.

 

Block class: http://pastebin.com/aiVQUHWR

 

Renderer class: http://pastebin.com/ssWWzb9T

 

My TileEntity class is empty so I did not post it. My more recent fiddling is on my desktop at home, somewhere I am currently not, but it has a different block for each stage, the issue there is the same I am having with this version...each block of the same stage will grow at the same time still.

 

With this version, shearing causes all Sapphire Crop blocks placed to act (visually) as if they were sheared.

Link to comment
Share on other sites

As diesieben07, you are using a static modifier incorrectly. See how your calling BlockSaphireCrop.getBerryAmount()? That should really be in your tile entity and not static. You can get access to a tile entity via the world and coords params that are passed in. THEN you can get the correct berry amount.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

As diesieben07, you are using a static modifier incorrectly. See how your calling BlockSaphireCrop.getBerryAmount()? That should really be in your tile entity and not static. You can get access to a tile entity via the world and coords params that are passed in. THEN you can get the correct berry amount.

 

I put the declaration and the get/set functions in the TileEntitySapphireCrop.class, have no problem finding it with the "world.getBlockTileEntity(x, y, z);", but am a tad bit perplexed on how to call my get function, as it requests a static operator to call it.

Link to comment
Share on other sites

Whoops, sorry. There are a couple syntax errors now, I'm trying to figure out how to call the TileEntity methods to get and set the berry amount while they do not have static modifiers.

 

Block class: http://pastebin.com/cufSaHqk

Render class: http://pastebin.com/f2F7LFXd

TileEntity class: http://pastebin.com/zavQkdQj

 

I am not sure what to do with the TileEntity class.

Link to comment
Share on other sites

First, you would get the tile entity at the given coordinates.

Then you would check to see if the tile entity retrieved is an instance of your tile entity, and also not equal to null.

Then you would cast the tile entity to your tile entity.

Next you would retrieve your berry amount from the caster tile entity.

Do all your rendering.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

First, you would get the tile entity at the given coordinates.

Then you would check to see if the tile entity retrieved is an instance of your tile entity, and also not equal to null.

Then you would cast the tile entity to your tile entity.

Next you would retrieve your berry amount from the caster tile entity.

Do all your rendering.

 

I changed it all and it works perfectly! Thanks so much!

I'm linking the code just...because. I still have to write the NBT reading/writing because upon exiting the game and returning, all the crops go back to fully grown, but I am sure I can figure that out myself.

 

One quick question:

A weird problem I had before (not an issue anymore due to the change in code) was when I sheared it or placed a berry onto the crop (calling the onBlockActivated method), my bAmt++; seemed to be called two times which is why I had the 14 (now 7 again, thank goodness...such a smaller switch in my render class). Is there any reason it acted twice?

 

Working classes (minus the NBT reading + writing):

 

Block class: http://pastebin.com/Y663XY27

Render class: http://pastebin.com/kUvEUUYe

TileEntity class: http://pastebin.com/X8rWKtsH (didn't change from before)

Link to comment
Share on other sites

It was called twice because it was being called once server side, then once client side.

 

To fix this, surround your code inside onBlockActivated with a check against !world.isRemote (server side). This stops you from having to sync the data.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

It was called twice because it was being called once server side, then once client side.

 

To fix this, surround your code inside onBlockActivated with a check against !world.isRemote (server side). This stops you from having to sync the data.

 

I'll keep that in mind in case it ever comes up again in my modding ventures.

 

Thanks again! Topic Solved!

Link to comment
Share on other sites

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.