Posted September 10, 201213 yr From the method onItemRightClick I want to change the block I'm pointing the cursor. From where I can get the coordinates of that block? I've tried from EntityPlayer, but all I found was the method getLookvec(), but gives me values that I do not understand Thank you very much in advance
September 10, 201213 yr It's in entity player, I think it's rayTrace(...) Hope that helped. So, what would happen if I did push that shiny red button over there? ... Really? ... Can I try it? ... Damn.
September 11, 201213 yr Author Thanks for your help Atrain99, but this method look for 2 args, distance and partialTickTime and I don't have the distance. I can calculate the distance to a Entity but not to a Block. I'll keep looking for any clues Thanks a lot. (Sorry. I not speak English and is very difficult for me to explain properly. I'm from Spain) EDIT: I found in Minecraft class a object called "objectMouseOver". This object have 3 variables called blockX, blockY and blockZ. This object stores the coordinates of the block where the mouse are. To acces to this object, I create a Minecraft instance in my item class, like this: public class ItemCreator extends Item { @Instance private Minecraft instance; protected ItemCreator(int id) { super(id); } public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer player) { if(Minecraft.getMinecraft().objectMouseOver!=null) { int xm=Minecraft.getMinecraft().objectMouseOver.blockX; int ym=Minecraft.getMinecraft().objectMouseOver.blockY; int zm=Minecraft.getMinecraft().objectMouseOver.blockZ; player.addChatMessage("X: "+xm+" Y:"+ym+"Z: "+zm); } return par1ItemStack; } It's the good way to do it or I,m create a monster?
September 11, 201213 yr You aren't creating a Minecraft instance, you are just getting the singleton instance. It's also a bit silly that you have a variable to hold the minecraft instance but then you never assign or use it .
September 11, 201213 yr Author You aren't creating a Minecraft instance, you are just getting the singleton instance. It's also a bit silly that you have a variable to hold the minecraft instance but then you never assign or use it . The code is only a example to view the result. I'm only learning about mods development with Forge. My intention is that when using an object on a block, that block is a reference to create a structure. Then I need the values x, y and z of the block to which I am pointing the cursor and objectMouseOver gives me these values. My question is if I'm using the correct method. Thanks for your answer
September 11, 201213 yr You aren't creating a Minecraft instance, you are just getting the singleton instance. It's also a bit silly that you have a variable to hold the minecraft instance but then you never assign or use it . The code is only a example to view the result. I'm only learning about mods development with Forge. My intention is that when using an object on a block, that block is a reference to create a structure. Then I need the values x, y and z of the block to which I am pointing the cursor and objectMouseOver gives me these values. My question is if I'm using the correct method. Thanks for your answer It's rayTrace(distance to scan for blocks, and I don't know what this arg is); So, what would happen if I did push that shiny red button over there? ... Really? ... Can I try it? ... Damn.
September 12, 201213 yr Author It's rayTrace(distance to scan for blocks, and I don't know what this arg is); @SideOnly(Side.CLIENT) /** * Performs a ray trace for the distance specified and using the partial tick time. Args: distance, partialTickTime */ public MovingObjectPosition rayTrace(double par1, float par3) { Vec3 var4 = this.getPosition(par3); Vec3 var5 = this.getLook(par3); Vec3 var6 = var4.addVector(var5.xCoord * par1, var5.yCoord * par1, var5.zCoord * par1); return this.worldObj.rayTraceBlocks(var4, var6); } The second argument is partialTickTime. I do not know how to get those values. I will do some tests with this method. Regards
September 13, 201213 yr Items can use MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, true); movingobjectposition should have the info you need. The downfall is, its limited to the players reach. But using it as an example you can easily make one where you set the reach. (and allow its use outside of the Item class)
September 20, 201213 yr var3.rayTrace(200, 1.0F).blockX var3 is entityplayer 200 is "reach" so if you want you can have the raytrace work for let's say 100 blocks, change that to 100 edit: I'm awful at explaining, so here's my code, it's easy to figure out (I'm telling minecraft to send a packet to the location I'm looking at with the variables positionx positiony positionz and strength) if (var2.currentScreen == null && !Keyboard.isKeyDown(pulseboltKey) && pulseboltKeyDown) { this.sendExplosion((int)var3.rayTrace(200, 1.0F).blockX, (int)var3.rayTrace(200, 1.0F).blockY, (int)var3.rayTrace(200, 1.0F).blockZ, 6); this.explosionTimer = 0; }
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.