Its not so much getting where the player is looking, in the item class there are methods for getting the players location, and wherever you click it will adjust automagically. Take for example onItemUse....
This is a snippet from a mod I quit building...
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
par3World.setBlockWithNotify(par4, par5, par6, 0);
return true;
}
When you click with this item, you will remove blocks from wherever you clicked....However if you absolutely must have it be where a player is looking, which is usually used for getting something at a distance....here is another snippet for you.....
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{
MovingObjectPosition movingobjectposition = entityplayer.rayTrace(70D, 1.0F);
if (movingobjectposition == null)
{
return itemstack;
}
Vec3 vec3d = movingobjectposition.hitVec;
double d = vec3d.xCoord;
double d1 = vec3d.yCoord;
double d2 = vec3d.zCoord;
int i = MathHelper.floor_double(d);
int j = MathHelper.floor_double(d1);
int k = MathHelper.floor_double(d2);
int l = Block.fire.blockID;
world.setBlockWithNotify(i, j, k, l);
//world.playSoundEffect((double)par4 + 0.5D, (double)par5 + 0.5D, (double)par6 + 0.5D, "fire.ignite", 1.0F, itemRand.nextFloat() * 0.4F + 0.8F);
return itemstack;
}
Its not so much getting where the player is looking, in the item class there are methods for getting the players location, and wherever you click it will adjust automagically. Take for example onItemUse....
This is a snippet from a mod I quit building...
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
par3World.setBlockWithNotify(par4, par5, par6, 0);
return true;
}
When you click with this item, you will remove blocks from wherever you clicked....However if you absolutely must have it be where a player is looking, which is usually used for getting something at a distance....here is another snippet for you.....
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{
MovingObjectPosition movingobjectposition = entityplayer.rayTrace(70D, 1.0F);
if (movingobjectposition == null)
{
return itemstack;
}
Vec3 vec3d = movingobjectposition.hitVec;
double d = vec3d.xCoord;
double d1 = vec3d.yCoord;
double d2 = vec3d.zCoord;
int i = MathHelper.floor_double(d);
int j = MathHelper.floor_double(d1);
int k = MathHelper.floor_double(d2);
int l = Block.fire.blockID;
world.setBlockWithNotify(i, j, k, l);
//world.playSoundEffect((double)par4 + 0.5D, (double)par5 + 0.5D, (double)par6 + 0.5D, "fire.ignite", 1.0F, itemRand.nextFloat() * 0.4F + 0.8F);
return itemstack;
}
Good Luck...hope this helped
well i was testing it and i still have a similar problem but i don't think the problem is on your code i think its on the world.setblocktoair() and another problem is that when i right click the block that i right clicked changes for a second and comes back to the default block
here's the code
I don't know if this would work but could you just check what direction the player is facing and modify the variables accordingly? i.e north, south, east, west.
Why are you trying to find where the player looks? Are you making a pick or a super weapon? Does the player need to actually swing it and break a block like a normal pick does, because if so then you could accomplish this in a far simpler way.
Why are you trying to find where the player looks? Are you making a pick or a super weapon? Does the player need to actually swing it and break a block like a normal pick does, because if so then you could accomplish this in a far simpler way.
Could you tell me how to do it?
thanks in advance
This is a snippet from a mod I quit building...
When you click with this item, you will remove blocks from wherever you clicked....However if you absolutely must have it be where a player is looking, which is usually used for getting something at a distance....here is another snippet for you.....
Good Luck...hope this helped
Find out how I generate....coolAlias...world structure generation and rotation tool...
well i was testing it and i still have a similar problem but i don't think the problem is on your code i think its on the world.setblocktoair() and another problem is that when i right click the block that i right clicked changes for a second and comes back to the default block
here's the code
Find out how I generate....coolAlias...world structure generation and rotation tool...
Here is the link: video
~Oneric
for random videos
1.yes
2.yes
3.yes