Jump to content

make block change on right click?(with a certain item in player hand)[solved]


Recommended Posts

Posted

how would one go about making a block change on rightclick? I mean the proper way, i know some ways to do it (using worldgen to place the new block at the same location as the old block) but what method & parameter would i use to check the item in a payers hand?

Also, I should have you know that you are reading my signature.

Posted

EDIT:

i have found a way to get the item in hand, would the worldplacing method still work?

 
   public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer p5EP) {
    	if(p5EP.inventory.currentItem == 0){
    		//changeblock here
    	}
    }

Also, I should have you know that you are reading my signature.

Posted

you could either check from the block the player is right clicking on or you could use the following from your Item override class

 

public boolean onItemUse(ItemStack tool,
		EntityPlayer player, World world, int x, int y,
		int z, int par7, float xFloat, float yFloat, float zFloat)
{

	if (!player.canPlayerEdit(x, y, z, par7, tool))//can the player edit this block? if he cant then dont do anything
	{
		return false;
	}
world.setBlockAndMetadataWithNotify(x, y, z, 0, Block.blockDiamond.blockID); // sets the block to diamond block with the meta data 0 (used for setting metadata if the block needs it
	world.setBlockWithNotify(x, y, z, Block.blockDiamond.blockID); // sets the block to diamond block with no meta data
}

Posted

i got mine to work (mainly because i wanted to be able to select vanilla Items too not just my mod's items) and a peculiar error popped up:

 

  Reveal hidden contents

 

 

 

my block code:

 

 

  Reveal hidden contents

 

Also, I should have you know that you are reading my signature.

Posted

the corect way would be

private Block toBlock = new BlockNewBlockHere()
public void onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer player) {
     if(player.inventory.currentItem == 0){
      par1World.setBlockId(par2,par3,par4,toBlock.blockID);
     }
    }

The Korecraft Mod

Posted

It probably shoud have been setBlock...

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Posted

i get the same error:

2013-03-06 17:00:03 [iNFO] [ForgeModLoader] Forge Mod Loader version 4.7.4.520 for Minecraft 1.4.7 loading
2013-03-06 17:00:05 [iNFO] [sTDOUT] 27 achievements
2013-03-06 17:00:05 [iNFO] [sTDOUT] 210 recipes
2013-03-06 17:00:05 [iNFO] [sTDOUT] Setting user: Player923, -
2013-03-06 17:00:05 [iNFO] [sTDERR] Client asked for parameter: server
2013-03-06 17:00:05 [iNFO] [sTDOUT] LWJGL Version: 2.4.2
2013-03-06 17:00:06 [iNFO] [ForgeModLoader] Attempting early MinecraftForge initialization
2013-03-06 17:00:06 [iNFO] [sTDOUT] MinecraftForge v6.6.0.497 Initialized
2013-03-06 17:00:06 [iNFO] [ForgeModLoader] MinecraftForge v6.6.0.497 Initialized
2013-03-06 17:00:06 [iNFO] [sTDOUT] Replaced 84 ore recipies
2013-03-06 17:00:06 [iNFO] [ForgeModLoader] Completed early MinecraftForge initialization
2013-03-06 17:00:06 [iNFO] [ForgeModLoader] Searching C:\Users\gamer\MCP\jars\mods for mods
2013-03-06 17:00:07 [iNFO] [ForgeModLoader] Forge Mod Loader has identified 4 mods to load
2013-03-06 17:00:08 [iNFO] [ForgeModLoader] Configured a dormant chunk cache size of 0
2013-03-06 17:00:08 [iNFO] [sTDOUT] Starting up SoundSystem...
2013-03-06 17:00:08 [iNFO] [sTDOUT] Initializing LWJGL OpenAL
2013-03-06 17:00:08 [iNFO] [sTDOUT]     (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)
2013-03-06 17:00:09 [iNFO] [sTDOUT] OpenAL initialized.
2013-03-06 17:00:09 [iNFO] [ForgeModLoader] Forge Mod Loader has successfully loaded 4 mods
2013-03-06 17:00:36 [iNFO] [ForgeModLoader] Loading dimension 0 (48698) (net.minecraft.server.integrated.IntegratedServer@178ef53)
2013-03-06 17:00:36 [iNFO] [ForgeModLoader] Loading dimension 1 (48698) (net.minecraft.server.integrated.IntegratedServer@178ef53)
2013-03-06 17:00:36 [iNFO] [ForgeModLoader] Loading dimension -1 (48698) (net.minecraft.server.integrated.IntegratedServer@178ef53)
2013-03-06 17:01:00 [iNFO] [sTDERR] net.minecraft.util.ReportedException: Ticking memory connection
2013-03-06 17:01:00 [iNFO] [sTDERR] 	at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:64)
2013-03-06 17:01:00 [iNFO] [sTDERR] 	at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:108)
2013-03-06 17:01:00 [iNFO] [sTDERR] 	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:703)
2013-03-06 17:01:00 [iNFO] [sTDERR] 	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:599)
2013-03-06 17:01:00 [iNFO] [sTDERR] 	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:123)
2013-03-06 17:01:00 [iNFO] [sTDERR] 	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:497)
2013-03-06 17:01:00 [iNFO] [sTDERR] 	at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
2013-03-06 17:01:00 [iNFO] [sTDERR] Caused by: java.lang.NullPointerException
2013-03-06 17:01:00 [iNFO] [sTDERR] 	at tuskiomi.common.TGrayCobble.onBlockClicked(TGrayCobble.java:27)
2013-03-06 17:01:00 [iNFO] [sTDERR] 	at net.minecraft.item.ItemInWorldManager.onBlockClicked(ItemInWorldManager.java:184)
2013-03-06 17:01:00 [iNFO] [sTDERR] 	at net.minecraft.network.NetServerHandler.handleBlockDig(NetServerHandler.java:509)
2013-03-06 17:01:00 [iNFO] [sTDERR] 	at net.minecraft.network.packet.Packet14BlockDig.processPacket(Packet14BlockDig.java:67)
2013-03-06 17:01:00 [iNFO] [sTDERR] 	at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:80)
2013-03-06 17:01:00 [iNFO] [sTDERR] 	at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:136)
2013-03-06 17:01:00 [iNFO] [sTDERR] 	at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:57)
2013-03-06 17:01:00 [iNFO] [sTDERR] 	... 6 more
2013-03-06 17:01:01 [iNFO] [ForgeModLoader] Unloading dimension 0
2013-03-06 17:01:01 [iNFO] [ForgeModLoader] Unloading dimension -1
2013-03-06 17:01:01 [iNFO] [ForgeModLoader] Unloading dimension 1
2013-03-06 17:01:02 [iNFO] [sTDERR] java.lang.NullPointerException
2013-03-06 17:01:02 [sEVERE] [ForgeModLoader] Fatal errors were detected during the transition from SERVER_STARTED to SERVER_STOPPED. Loading cannot continue
2013-03-06 17:01:02 [iNFO] [sTDERR] 	at tuskiomi.common.TGrayCobble.onBlockClicked(TGrayCobble.java:27)
2013-03-06 17:01:02 [iNFO] [sTDERR] 	at net.minecraft.client.multiplayer.PlayerControllerMP.clickBlock(PlayerControllerMP.java:205)
2013-03-06 17:01:02 [sEVERE] [ForgeModLoader] 
mcp [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
tuskiomi [hello, tuskiomis mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
2013-03-06 17:01:02 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.clickMouse(Minecraft.java:1320)
2013-03-06 17:01:02 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1805)
2013-03-06 17:01:02 [sEVERE] [ForgeModLoader] The following problems were captured during this phase
2013-03-06 17:01:02 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:846)
2013-03-06 17:01:02 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.run(Minecraft.java:771)
2013-03-06 17:01:02 [iNFO] [sTDERR] 	at java.lang.Thread.run(Unknown Source)
2013-03-06 17:01:02 [iNFO] [sTDERR] Exception in thread "Server thread" cpw.mods.fml.common.LoaderException
2013-03-06 17:01:02 [iNFO] [sTDERR] 	at cpw.mods.fml.common.LoadController.transition(LoadController.java:117)
2013-03-06 17:01:02 [iNFO] [sTDERR] 	at cpw.mods.fml.common.Loader.serverStopped(Loader.java:752)
2013-03-06 17:01:02 [iNFO] [sTDERR] 	at cpw.mods.fml.common.FMLCommonHandler.handleServerStopped(FMLCommonHandler.java:459)
2013-03-06 17:01:02 [iNFO] [sTDERR] 	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:559)
2013-03-06 17:01:02 [iNFO] [sTDERR] 	at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
2013-03-06 17:01:12 [iNFO] [sTDOUT] Stopping!
2013-03-06 17:01:12 [iNFO] [sTDOUT] SoundSystem shutting down...
2013-03-06 17:01:12 [iNFO] [sTDOUT]     Author: Paul Lamb, www.paulscode.com

Also, I should have you know that you are reading my signature.

Posted

just going on a hunch here, but have you tried using null checks (given that your error is caused by a null value) is just add a few bits like

if(player != null){

or

if(player.inventory.getCurrentItem() != null){

 

again this is just a hunch as i don't know what is on line 27 of TGrayCobble, where it seems throwing a null pointer exception

Posted
  On 3/8/2013 at 8:41 AM, Yagoki said:

just going on a hunch here, but have you tried using null checks (given that your error is caused by a null value) is just add a few bits like

if(player != null){

or

if(player.inventory.getCurrentItem() != null){

 

again this is just a hunch as i don't know what is on line 27 of TGrayCobble, where it seems throwing a null pointer exception

if(p5EP.inventory.getCurrentItem().itemID == 1){

Also, I should have you know that you are reading my signature.

Posted

my code along w/ another error

 

  Reveal hidden contents

 

 

 

ERROR:

 

  Reveal hidden contents

 

Also, I should have you know that you are reading my signature.

Posted

you can do it two ways... one is to just on block activated then check the players current item and the other(more laggy unless is meant for more than 1 use) is to have a on right clicked in the item

The Korecraft Mod

Posted

is my error considered a bug? because i honestly have no clue here, i get the same error if i  try to place the block above it (which is air).

Also, I should have you know that you are reading my signature.

Posted

If the player's hand is empty the ItemStack is null, not item ID 0. You can either null check or try/catch.

 

    public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer p5EP) {
     if( p5ep != null && && p5EP.inventory.getCurrentItem().itemID != null){
      if(p5EP.inventory.getCurrentItem().itemID == 1 && par2 * par3 != 0 && par2 * par4 != 0){
       par1World.setBlock(par2, par3, par4, 4);
      }
     }
     System.out.println("debug tick.");
    }

 

Thought I should add:

When null checking, go from least specific to most specific.

For example:

if(Object1.method1() != null && Object1 != null){
System.out.println(Object1.method1().toString());
}

This will cause a null pointer exception if Object1 is null because it is trying to call a method (method1) from a null object. However, if you did this:

if(Object1 != null && Object1.method1() != null){
System.out.println(Object1.method1().toString());
}

This will not cause a null pointer exception because it will break out of the if statement before it tries to call a method from a null object.

Posted

thanks :D really heped allot. also, i'm *relatively* new to java. i've bben doing the language for 6 months or so , thanks for the format tip!

Also, I should have you know that you are reading my signature.

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Ready to unlock unbeatable savings on Temu? Our exclusive Temu code [ald244107] is your ultimate secret weapon for a $100 OFF discount, plus so much more this year! Whether you're making your first purchase or returning for another shopping spree, this verified promo code gives you an instant boost, with up to 50% off your next order and even deeper discounts on clearance items. With Temu coupon code [ald244107], you're not just getting a flat $100 discount; you're stacking it on top of already fantastic sales! New users can grab an extra 100% off selected products, while loyal customers automatically qualify for that sweet $100 OFF when they apply the code at checkout. Imagine slashing prices by up to 90% on everything from trending electronics and stylish fashion to essential home goods and top-rated beauty products, all available across the USA, Canada, UK, and countless other countries! 🔥 Top Temu Code [ald244107] Benefits:  * For New Users: Use ald244107 for 50% off your first order + an additional $100 OFF.  * For Existing Customers: Apply ald244107 to get an instant $100 OFF on your next purchase.  * Global Reach: Valid across the USA, UK, Canada, Germany, France, Japan, Chile, Colombia, Malaysia, Mexico, South Korea, Philippines, Saudi Arabia, Qatar, Pakistan, and many more.  * Best of 2025: Secure up to $200 OFF plus incredible bonus discounts with ald244107. Maximize Your Savings: Featured Temu Deals for 2025 (Code: ald244107)  * ✅ Temu Flash Sales: Don't miss out! Score $100 off during limited-time offers with ald244107.  * ✅ Temu First Order Bonanza: Use ald244107 for a powerful 50% + $100 OFF on your initial purchase.  * ✅ Temu US Shopper Advantage: Instantly save $100 on your orders with ald244107.  * ✅ International Temu Discounts: ald244107 works seamlessly to give you savings in Japan, Germany, Chile, and beyond.  * ✅ Temu Community Favorite: Enjoy $100 OFF for both new and old users, a widely praised deal!  * ✅ Temu Coupon Bundles 2025: Combine $100 OFF with up to 50% slash deals for ultimate savings.  * ✅ 100% OFF Free Gift Code: Use ald244107 to claim a free gift – no invitation or referral needed!  * ✅ Temu Welcome Bonus: Get a delightful $100 OFF instantly upon signing up for an account.  * ✅ Free Temu Code for New Accounts: Apply ald244107 for immediate, hassle-free savings.  * ✅ Temu Clearance Blowout 2025: Use ald244107 for jaw-dropping 85–100% discounts on clearance items. This Temu code [ald244107] is more than just a discount; it's your all-access pass to complimentary shipping, exclusive first-order perks, and stackable coupon bundles across an immense selection of electronics, trendy fashion, essential home goods, and premium beauty products. Truly unlock up to 90% OFF plus an additional $100 OFF on eligible orders! 💡 Pro Tip: Always remember to apply ald244107 during checkout on the Temu app or website. Your instant $100 discount activates automatically, even if you're a returning customer! Where Does Temu Code [ald244107] Work? (Global Availability)  * 🇺🇸 Temu USA – ald244107  * 🇯🇵 Temu Japan – ald244107  * 🇲🇽 Temu Mexico – ald244107  * 🇨🇱 Temu Chile – ald244107  * 🇨🇴 Temu Colombia – ald244107  * 🇲🇾 Temu Malaysia – ald244107  * 🇵🇭 Temu Philippines – ald244107  * 🇰🇷 Temu Korea – ald244107  * 🇵🇰 Temu Pakistan – ald244107  * 🇫🇮 Temu Finland – ald244107  * 🇸🇦 Temu Saudi Arabia – ald244107  * 🇶🇦 Temu Qatar – ald244107  * 🇫🇷 Temu France – ald244107  * 🇩🇪 Temu Germany – ald244107 Hear From Happy Shoppers: User Reviews We love hearing about your experiences! Here's what some satisfied customers are saying about using the Temu code [ald244107]:  * Alice W., USA ⭐️⭐️⭐️⭐️⭐️ (5/5) "Great experience! Temu's promo code {ald244107} saved me a lot on my first order. Highly recommend this offer!"  * James T., UK ⭐️⭐️⭐️⭐️ (4/5) "Very happy with the quality and prices on Temu. The $100 credits offer was a nice bonus using {ald244107}. Will shop again."  * Sara M., Canada ⭐️⭐️⭐️ (3/5) "Got some decent deals with the {ald244107} code, though shipping took a bit longer than expected. Overall satisfied with the credits." Trending Verified Temu Deals for 2025 Stay ahead of the curve with the most popular and verified Temu deals for 2025. Our community consistently confirms the effectiveness of Temu code [ald244107] for maximum savings across a wide range of products. Don't miss out on these trending opportunities to save big! FAQs: Everything You Need to Know About Temu Code [ald244107] Q: What is Temu code [ald244107] and what does it offer? A: Temu code [ald244107] is a verified promo code that provides users with a $100 discount, plus additional savings of up to 50% or even 90% on various items. It's valid for both new and existing customers on the Temu platform. Q: How do I apply Temu code [ald244107]? A: Simply enter [ald244107] in the coupon or promo code field during checkout on the Temu app or website to apply your discounts automatically. Q: Does Temu code [ald244107] benefit new users specifically? A: Yes, ald244107 offers fantastic benefits for new users, including an exclusive 50% off their very first order in addition to the $100 discount. Q: Is Temu code [ald244107] also valid for existing customers? A: Absolutely! Loyal Temu customers can also enjoy a flat $100 OFF discount by seamlessly applying ald244107 at checkout. Q: In which countries can I use Temu code [ald244107]? A: This code boasts widespread global availability, working in numerous countries including the USA, UK, Canada, Germany, France, Japan, Saudi Arabia, Qatar, and many more listed above. Q: Can Temu code [ald244107] be combined with other offers? A: Temu code [ald244107] is strategically designed to provide savings on top of existing deals, making it often stackable with other promotions for truly maximizing your discounts. Unlock Huge Savings with Temu Code [ald244107] – Your Best Bet for 2025! Don't let these incredible savings slip away! Whether you're exploring Temu for the first time or returning for more great finds, the Temu code [ald244107] is your ultimate tool for significant discounts, exciting free gifts, and unbeatable deals. Apply it today and see how much you can save! Happy shopping! [ald244107]  
    • I've tried the java version you linked to and got a new exit code of 127 Here is the new console log I also tried making sure that I had Java 8 selected with the version of Java 8 I already had installed and got the same exit code Here is the console log with that installation in case it has any differences I do notice both say 'Java checker returned some invalid data we don't understand:' followed by 'Minecraft might not start properly.' which could be some issues.  
    • Thank you so much! I didnt see it in the log😭😭  
    • So im completely new to modding in general, i have some experience in Behavior packs in minecraft bedrock and i would like to modify entities stats and attributes like in a behavior pack (health, damage, speed, xp drop...). The problem is that i cant find any information online on how to do that, and I have no clue on what to do and where to start. I am currently modding in 1.20.4 with IntelliJ if that helps. My final objective is to buff mobs health and damage (double it for exemple), but since there is no entity file anywhere i don't know how to change it... 😢
    • Hey there, nothing to do with the code, I am just suggesting you use Intelij IDEA. Trust me, it is the best.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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