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

I want to know if there is a code which detects the way player is looking, so i can make something like this:

onblockplaced

if player is looking at north(-180 in minecraft)

then setboundingbox

else

if player is looking at south... etc.

any ideas?

Thing I love most in this forum, is that when you ask for help, moderators don't give you ready code, you have to figure it out yourself.

  • Author

I have this problem, when I place block facing one direction bounding box works perfectly, but if another one is placed(other direction) it changes first ones too... and also after reloading the game, bounding box is set to the default(1F).

 

I'm using this code

 

public static ForgeDirection getFacing(Entity entity){
	int dir = MathHelper.floor_double((entity.rotationYaw * 4 / 360) + 0.5) & 3;
	return ForgeDirection.VALID_DIRECTIONS[Direction.directionToFacing[dir]];
}

public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemstack)
    {
        int l = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
        int dir = MathHelper.floor_double((player.rotationYaw * 4 / 360) + 0.5) & 3;
   
        world.setBlockMetadataWithNotify(x, y, z, l, 2);
        System.out.println(l);
        
         if(getFacing(player) == ForgeDirection.EAST){
        	setBlockBounds(0.625F, 0F, 0.625F, 0.875F, 0.1875F, 0.875F);
        }else
        	if(getFacing(player) == ForgeDirection.NORTH){
        		setBlockBounds(0.625F, 0F, 0.125F, 0.875F, 0.1875F, 0.375F);
        }else
        	if(getFacing(player) == ForgeDirection.SOUTH){
    		setBlockBounds(0.125F, 0F, 0.625F, 0.375F, 0.1875F, 0.875F);
        }else
        	if(getFacing(player) == ForgeDirection.WEST){
        		setBlockBounds(0.125F, 0F, 0.125F, 0.375F, 0.1875F, 0.375F);
        	}
    }

 

I've tried using setblockmetadatawithnotify (stairs use that) but nothing...

anyone?

Thing I love most in this forum, is that when you ask for help, moderators don't give you ready code, you have to figure it out yourself.

Don't use setBlockBounds directly - use the player's facing to determine the metadata for the block, like many vanilla blocks do (e.g. furnace), then override setBlockBoundsBasedOnState and use setBlockBounds in there based on the block's metadata.

 

Look at some vanilla blocks and it should make sense.

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.