Jump to content

Change Block Texture on Right-Click


Noodly_Doodly

Recommended Posts

override "onBlockActivated"

params in it are :World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ

 

then inside you can check for the player.getHeldItem() and set the blocks metaData

 

if(!world.isRemote) 
{
   if (player.getHeldItem().getItem().equals(Items.apple))
   world.setBlockMetadataWithNotify(x, y, z, metaData, 2);
}
return true;

 

metaData will be 0-15 (16 spots? from what I remember people saying) and all you have to do is register your icons and display the correct one through the GetIcon method.

 

Link to comment
Share on other sites

Sorry for being away for 3 days, but now I have another question. I used the above code, but now I need it to be so that I can switch the block from metadata 0 to metadata 1 and back again an unlimited number of times. No matter where I place my "while (true) {" or "do {" 's, I still can only change the metadata once. How could I do this?

Link to comment
Share on other sites

Do you need to change metadata more than once after every click?

 

While(true) is a terrible idea, as the game will freeze since it will stop 'ticking'.

 

If you want to toggle it every time it's clicked then you can do something like

world.setBlockMetadataWithNotify(x, y, z, metadata == 0 ? 1 : 0, FLAG)

If you want to change independently every tick from the moment it was clicked, however, I suggest a TileEntity.

 

If you want it to change independently every so often from the moment it was clicked you could probably get away with setTickRandomly and using the method that gets called then (onUpdate or onUpdateTick or something)

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

Link to comment
Share on other sites

Read the JavaDoc comments.

 

/**

  * Sets the blocks metadata and if set will then notify blocks that this block changed, depending on the flag. Args:

  * x, y, z, metadata, flag. See setBlock for flag description

  */

 

/**

  * Sets the block ID and metadata at a given location. Args: X, Y, Z, new block ID, new metadata, flags. Flag 1 will

  * cause a block update. Flag 2 will send the change to clients (you almost always want this). Flag 4 prevents the

  * block from being re-rendered, if this is a client world. Flags can be added together.

  */

 

You're probably gonna use 3 (flag 2 + flag 1).

 

Also remember to use world.getBlockMetadata(x, y, z) in place of metadata, you can't use an instance variable as there is only 1 instance of a block ever.

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • @bluedisgusted That actually fully fixed it, thank you so much
    • Hi, I would like to know how to create multiple hitboxes for the player like the ender dragon. I've searched everywhere but I haven't found anything.
    • FOLKWIN EXPERT RECOVERY is the crypto hero we all need in the ongoing battle against cryptocurrency theft. With the rise in popularity of digital assets like Bitcoin and Ethereum, crypto crime has also been on the rise as hackers look to steal funds stored in virtual wallets. Many a crypto investor has fallen victim to clever scams and hacking schemes that drain wallets of their precious coins. But fear not, for FOLKWIN EXPERT RECOVERY has arrived as a beacon of hope for those who have had their hard-earned crypto stolen. This service is like a superhero for tracking down lost or stolen cryptocurrency, utilizing their advanced forensic technology and expertise to follow the blockchain paper trail and identify where your funds have gone. Their team of ethical hackers act like detectives, piecing together crypto transactions and unmasking the thieves behind complex cybercrimes. No case is too difficult for FOLKWIN EXPERT RECOVERY; they have recovered millions in stolen crypto assets from around the globe. Their mission is to reunite victims with their lost funds and bring criminals who prey on cryptocurrency investors to justice. With their help, those who have been robbed of their digital fortunes now have a crypto guardian to call upon in their time of need. FOLKWIN EXPERT RECOVERY gives victims the hope that all is not lost forever when crypto theft occurs.For support, Contact details is: TELEGRAM: @FOLKWIN_EXPERT_RECOVERY, EMAIL: FOLKWINEXPERTRECOVERY at TECH-CENTER dot COM, WEBSITE: WWW.FOLKWINEXPERTRECOVERY.COM .  are the heroes we need in the ongoing battle to make cryptocurrency ownership safe and secure for all. Get FOLKWIN EXPERT RECOVERY on your side when you have issues like this by dialing: Do this and thank me later. God Blessings to all, I'm forever grateful oh God for the successful recovery. I recommend FOLKWIN EXPERT RECOVERY the best ever and i'm so happy i got all my lost money back. Best Regards. Pamela K Ingram.
    • Made it work. As a note, one of the times it didn't recognize the recipe cause the MOD_ID constant I was using somewhere was NOT referencing my MOD_ID but rather another static variable with the same name. Maybe OP is having a similar problem
    • What exactly is the issue?
  • Topics

×
×
  • Create New...

Important Information

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