Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

 

 

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.

  • 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?

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

  • 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 :)

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.

  • 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

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)

 

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.