Jump to content

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


Recommended Posts

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;

}

 

Posted

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?

Posted

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"

Posted

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

×   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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • UPDATE: this seems to be an Arch-specific issue. Switching to Ubuntu server fixed EVERYTHING.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
  • Topics

×
×
  • Create New...

Important Information

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