Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[SOLVED]Checking item in hand and onRightClick


Recommended Posts

So, coming from a ModLoader background, I've discovered my previous method from 1.2.5 doesn't work at all. How would I:

 

1) Check what item is in the player's hand

2) How can I implement the Forge equivalent of ML's onRightClick

3) How can I get the block right clicked so I can modify it, replace it, etc.

 

 

Link to post
Share on other sites

From 1.2.5 ?! It won't be easy for you to get used to everything with Forge now...

 

ALL of those are not a part of forge as far as I'm aware, they are a part of MC it self.

 

Modloader "equivalent" of "onRightClick":

Function: onItemRightClick, From: Item.class


public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
        return par1ItemStack;
    }

 

Check what item is in the player's hand:

 

You need a function with acces to EntityPlayer/Minecraft, after you found something that suits you:

 

thePlayerInstance.getCurrentEquippedItem()

 

Getting a block that is right click:

Function: boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)

Found in: Block.class

 

Get the block in the position the player right-clicked in and then do whatever you want.

Link to post
Share on other sites

Didn't help a whole lot, maybe this will help:

 

I need to check what item is in the player's hand. If it is (insert item here), check if it is right clicked on a block. If it is, then check to see if the block is (insert block here). If it is, replace said block with (insert block here).

 

 

Link to post
Share on other sites

Look at the ItemHoe class. It seems like you are trying to do just about the same thing that the hoe does, by checking to see if the block clicked on is dirt, and if it is, it turns it into tilled earth. Just a question, is the item that you are clicking with an item you made or a vanilla item?

If you really want help, give that modder a thank you.

 

Modders LOVE thank yous.

Link to post
Share on other sites

I need to check what item is in the player's hand. If it is (insert whatever item here), check if it is right clicked on a block. If it is, then check to see if the block is (insert whatever block here). If it is, replace said block with (insert whatever block here).

 

 

Link to post
Share on other sites

I'm not sure how to do this without editing base files if your item is vanilla, but if the item is an item you made yourself, then just use the vanilla code from the hoe file. Do you have any code so far in your class?

If you really want help, give that modder a thank you.

 

Modders LOVE thank yous.

Link to post
Share on other sites

What I thought I could do is setup a MouseListener for right clicks, then check the item in the player's hand. (mc.thePlayer.something perhaps). Not sure how I'd get the block right clicked though. Any suggestions? Or the block replacement.

Link to post
Share on other sites

So, coming from a ModLoader background, I've discovered my previous method from 1.2.5 doesn't work at all. How would I:

 

1) Check what item is in the player's hand

2) How can I implement the Forge equivalent of ML's onRightClick

3) How can I get the block right clicked so I can modify it, replace it, etc.

 

This is quite easy to do, if you look into Item.java then you see some methods which every item inherits like this one:

/**
     * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
     */
    public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
    {
        return itemStack;
    }

 

There you have access to the player, so you can see all the info about him and the item being used.

The last question you can do from the clientside by grabbing the mouseOverObject from the minecraft.java which is the result of a raytrace to find what the player is looking at returning the information as a MovingObject(...) (forgot the whole name) which will let you see all the info about it (x,y,z, block ID, sideHit etc.)

 

That should be all you need assuming the rest of your setup is updated to 1.3.X+ standards. If you are not familiar with them you should first start by looking into the basics of them, I recommend this article for that purpose:  http://www.minecraftforge.net/wiki/Basic_Modding

 

 

If you guys dont get it.. then well ya.. try harder...

Link to post
Share on other sites

That helped, but my item(s) are vanilla. I would like to just use a MouseListener from OpenGL, would that work and just check the item when it detects something then?

 

Could you also explain a bit more on the ray tracing method? Didn't follow very well there.

Link to post
Share on other sites

Inside Minecraft.java you will find the above mentioned field it contains whatever the player is looking towards which is within his range. You will understand once you see the field and what info it contains. Also you may want to open it's call hierarchy and see the get function for it to see how it's made :)

 

As long as you got access to a player object, you can find out which item he is holding by a simple method call, you will find this inside the player's class.

 

As long as you can get the player object then sure.

Since you are already on client side, you can use the Minecraft.java's thePlayer field to get the player object.

 

 

If you guys dont get it.. then well ya.. try harder...

Link to post
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.

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



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Experienced modders, I come to you with hat in hand and request if you could share with me your thoughts and suggestions for a direction I should take on implementing a feature in my mod. First, the concept. What I would like to achieve is to provide the end user a json config file in which they can place a list of biomes and provide some addition details/criteria to apply to the world generation about those biomes. The first I would like to achieve is applying a min and max distance that a biome can spawn at from the center of the world. For example, if they wanted to make sure that desert biome was never any closer to 0, 0 then say 200 blocks they could have that in the json and then the world would skip desert as an allowed biome whenever the player is generating terrain before 200 blocks out. So far I have been able to implement my own WorldType and BiomeProvider and strong arm the getBiomeNoise function to check the distance loaded in from center against the value loaded in from the config file and just wholesale swap it for a different hardcoded biome choice, but obvious that brute force attack is not ideal at all. So I have two questions maybe you can offer advise about: 1. I would actually like this feature to allow whatever the existing generation algorithm is to do its things and just make this one additional criteria check, but obviously this seems unlikely. I have been reading up on Mixins but I am not sure yet if this will let me achieve my goals or if I even SHOULD go that route. 2. What do you think is a better strategy for replacing the chosen biome with a new one? Look for the closest neighbor biome and go that route? Whats the best way to do that?   Thanks ahead of time for anyone who even bothered to read this lol.
    • Yeah, I changed the JAVA_HOME variable to the path of my JDK (C:\Program Files\Java\jdk1.8.0_281) and it worked. Thanks.
    • use NetworkHooks#openGui look how minecraft create container, but basically you need the container and a screen tutorials are not the best solution to learn something, read the forge docs and look here in the forum, then try to create a container, if you have problems creating it you can still ask
    • You need to use EntityAttributeCreationEvent to register the attributes for your entity (CowEntity.createAttributes or make your own if you have additional attributes).   Do not create registry entries in static initializers. Use DeferredRegister or @ObjectHolder when using manual registry events.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.