Jump to content

Recommended Posts

Posted

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.

 

 

Posted

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.

Posted

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

 

 

Posted

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.

Posted

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

 

 

Posted

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.

Posted

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.

Posted

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

Posted

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.

Posted

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

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.