Jump to content

[SOLVED][1.8.9] How do you detect whether the player is looking up or down?


careercat1080

Recommended Posts

So I'm trying to make a 3x3 pickaxe. Everything is fine, but whenever I look up or down, it doesn't exactly perform the function I'm asking for. It mines sideways when ever I look up or down.

 

Here's my onBlockDestroyed code:

 

@Override

public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLivingBase playerIn)

{

int x = pos.getX():

int y = pos.getY();

Int z = pos.getZ();

 

if(playerIn.getHorizontalFacing() == EnumFacing.UP || playerIn.getHorizontalFacing() == EnumFacing.DOWN)

{

if(worldIn.getBlockState(new BlockPos(x + 1, y, z)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x + 1, y, z), true);

if(worldIn.getBlockState(new BlockPos(x + 1, y, z + 1)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x + 1, y,  z + 1), true);

if(worldIn.getBlockState(new BlockPos(x + 1, y, z - 1)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x + 1, y,  z - 1), true);

if(worldIn.getBlockState(new BlockPos(x, y, z + 1)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x, y,  z + 1), true);

if(worldIn.getBlockState(new BlockPos(x, y, z - 1)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x, y,  z - 1), true);

if(worldIn.getBlockState(new BlockPos(x - 1, y, z)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x - 1, y,  z), true);

if(worldIn.getBlockState(new BlockPos(x - 1, y, z + 1)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x - 1, y,  z + 1), true);

if(worldIn.getBlockState(new BlockPos(x - 1, y, z - 1)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x - 1, y,  z - 1), true);

} else if(playerIn.getHorizontalFacing() == EnumFacing.EAST || playerIn.getHorizontalFacing() == EnumFacing.WEST)

{

if(worldIn.getBlockState(new BlockPos(x, y + 1, z)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x, y + 1, z), true);

if(worldIn.getBlockState(new BlockPos(x, y + 1, z - 1)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x, y + 1,  z - 1), true);

if(worldIn.getBlockState(new BlockPos(x, y + 1, z + 1)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x, y + 1,  z + 1), true);

if(worldIn.getBlockState(new BlockPos(x, y, z - 1)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x, y,  z - 1), true);

if(worldIn.getBlockState(new BlockPos(x, y, z + 1)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x, y,  z + 1), true);

if(worldIn.getBlockState(new BlockPos(x, y - 1,  z)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x, y - 1,  z), true);

if(worldIn.getBlockState(new BlockPos(x, y - 1, z - 1)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x, y - 1,  z - 1), true);

if(worldIn.getBlockState(new BlockPos(x, y - 1, z + 1)) ==  Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x, y - 1,  z + 1), true);

} else if(playerIn.getHorizontalFacing() == EnumFacing. NORTH || playerIn.getHorizontalFacing() == EnumFacing.SOUTH)

{

if(worldIn.getBlockState(new BlockPos(x, y + 1, z)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x, y + 1, z), true);

if(worldIn.getBlockState(new BlockPos(x + 1, y + 1, z)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x + 1, y + 1,  z), true);

if(worldIn.getBlockState(new BlockPos(x - 1, y + 1, z)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x - 1, y + 1,  z), true);

if(worldIn.getBlockState(new BlockPos(x + 1, y, z)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x + 1, y,  z - 1), true);

if(worldIn.getBlockState(new BlockPos(x - 1, y, z)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x - 1, y,  z), true);

if(worldIn.getBlockState(new BlockPos(x, y - 1,  z)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x, y - 1,  z), true);

if(worldIn.getBlockState(new BlockPos(x + 1, y - 1, z)) == Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x + 1, y - 1,  z), true);

if(worldIn.getBlockState(new BlockPos(x - 1, y - 1, z)) ==  Blocks.stone.getDefaultState())

worldIn.destroyBlock(new BlockPos(x - 1, y - 1,  z), true);

}

 

return true;

}

 

Link to comment
Share on other sites

I wouldn't use where the player is looking at, as you can be looking up and still hit a block from the sides. Get where he hit the block mined, that side is better to use.

 

Ah yes. How would i go about doing that? Would i get the block the player is looking at?

Link to comment
Share on other sites

I see you want it for a 3x3 pick. This is what I did for my hammer in a mod I'm working on.

 

Inside the "onBlockDestroyed" get the

 

MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, (EntityPlayer) playerIn, flag);

 

And then you can switch "movingobjectposition.sideHit"

Link to comment
Share on other sites

I see you want it for a 3x3 pick. This is what I did for my hammer in a mod I'm working on.

 

Inside the "onBlockDestroyed" get the

 

MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, (EntityPlayer) playerIn, flag);

 

And then you can switch "movingobjectposition.sideHit"

 

Thanks!

Link to comment
Share on other sites

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.