Rainfur Posted June 30, 2013 Share Posted June 30, 2013 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. Quote Link to comment Share on other sites More sharing options...
mickey695 Posted June 30, 2013 Share Posted June 30, 2013 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. Quote Link to comment Share on other sites More sharing options...
Rainfur Posted June 30, 2013 Author Share Posted June 30, 2013 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). Quote Link to comment Share on other sites More sharing options...
mardiff Posted July 1, 2013 Share Posted July 1, 2013 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? Quote If you really want help, give that modder a thank you. Modders LOVE thank yous. Link to comment Share on other sites More sharing options...
EnergyPulse Posted July 1, 2013 Share Posted July 1, 2013 https://github.com/SuitedSlime/SlimeCore/blob/master/src/slimecore/prefab/block/BlockAdvanced.java Lines 38 to 93 , it's a little complex for what you're wanting to do though I think... Quote Link to comment Share on other sites More sharing options...
Rainfur Posted July 1, 2013 Author Share Posted July 1, 2013 That helped, but the block in question is a vanilla MC block. Quote Link to comment Share on other sites More sharing options...
mardiff Posted July 1, 2013 Share Posted July 1, 2013 Tell me exactly what you are trying to do. Quote If you really want help, give that modder a thank you. Modders LOVE thank yous. Link to comment Share on other sites More sharing options...
Rainfur Posted July 1, 2013 Author Share Posted July 1, 2013 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). Quote Link to comment Share on other sites More sharing options...
mardiff Posted July 1, 2013 Share Posted July 1, 2013 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? Quote If you really want help, give that modder a thank you. Modders LOVE thank yous. Link to comment Share on other sites More sharing options...
Rainfur Posted July 1, 2013 Author Share Posted July 1, 2013 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. Quote Link to comment Share on other sites More sharing options...
Mazetar Posted July 1, 2013 Share Posted July 1, 2013 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 Quote If you guys dont get it.. then well ya.. try harder... Link to comment Share on other sites More sharing options...
Rainfur Posted July 1, 2013 Author Share Posted July 1, 2013 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. Quote Link to comment Share on other sites More sharing options...
ObsequiousNewt Posted July 1, 2013 Share Posted July 1, 2013 Use instead onItemUseFirst(...) Quote BEWARE OF GOD --- Co-author of Pentachoron Labs' SBFP Tech. Link to comment Share on other sites More sharing options...
Mazetar Posted July 1, 2013 Share Posted July 1, 2013 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. Quote If you guys dont get it.. then well ya.. try harder... Link to comment Share on other sites More sharing options...
Rainfur Posted July 1, 2013 Author Share Posted July 1, 2013 Thanks. ^.^ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.