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.

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

Featured Replies

Posted

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;

}

 

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.

  • Author

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?

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"

  • Author

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!

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.