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

Hey, I'm trying to make a thrown item that does different blocks on however, I can't seem to figure out how to detect the type of block. here is my onImpact method:

 

	protected void onImpact(MovingObjectPosition par1MovingObjectPosition) {
	System.out.println(par1MovingObjectPosition.getClass().isInstance(Blocks.leaves.getClass()));
        if (par1MovingObjectPosition.entityHit != null)
        {
            byte b0 = 12;
            par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)b0);
        }
        //System.out.println(par1MovingObjectPosition.typeOfHit.toString());
        if (!this.worldObj.isRemote)
        {
            this.setDead();
            this.dropItem(drop, 1);
        }
}

 

I'm trying to print to the console "true" when it hits leaves, however it always prints false. Any suggestions?

MovingObjectPosition is not a Block, so of course it's not an instance of Blocks.leaves.getClass().

 

MovingObjectPosition has a MovingObjectType field 'typeOfHit' that tells you if it struck an ENTITY, BLOCK, or was a MISS. If the type is BLOCK, then you can use your moving object position's blockX, blockY, and blockZ fields to get the block that was struck from the world.

 

Thrown items are Entities, after all, so they have a worldObj field you can use:

protected void onImpact(MovingObjectPosition mop) {
Block block = this.worldObj.getBlock(mop.blockX, mop.blockY, mop.blockZ);

// now you have the block, you can check if it is a leaf block with instanceof
if (block instanceof BlockLeaves) {
// it's a leaf block
}

}

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.