Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author

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.

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.

  • Author

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.

Please show your updated code? You have got me a tad confused.

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

  • Author

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.

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.

  • Author

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)

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.

  • Author

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!

Ah, good point. I hadn't realized that a tile entity was passed into the method >.> so....

 

Yeah. Thanks for that diesieben07 :)

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.