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 have this code

	public IBlockState getStateFromMeta(int meta)
	{
		IBlockState iblockstate = this.getDefaultState();
		   /**
	     * Get the Index of this Facing (0-5). The order is D-U-N-S-W-E
	     */
		switch(meta) {
			case 0:
				iblockstate = iblockstate.withProperty(FACING,EnumFacing.DOWN);
				break;
			case 1:
				iblockstate = iblockstate.withProperty(FACING,EnumFacing.UP);
				break;
			case 2:
				iblockstate = iblockstate.withProperty(FACING,EnumFacing.NORTH);
				break;
			case 3:
				iblockstate = iblockstate.withProperty(FACING,EnumFacing.SOUTH);
				break;
			case 4:
				iblockstate = iblockstate.withProperty(FACING,EnumFacing.WEST);
				break;
			case 5:
				iblockstate = iblockstate.withProperty(FACING,EnumFacing.EAST);
				break;				
			
		}

		return iblockstate;
	}

 

Isn't there a better way to do this?  There is the  "EnumFacing.getHorizontal(meta))" but i need the UP and DOWN also

Have you tried a simple iteration over the enum's values, comparing to their ordinals?

 

for (EnumFacing face : EnumFacing.values()) {
	if (meta == face.ordinal()) {
		iblockstate = iblockstate.withProperty(FACING, face);
		break;
	}
}

Or, even smaller, just use the array index directly:

iblockstate = iblockstate.withProperty(FACING, EnumFacing.values()[meta]);

You might want to do some sanitizing on that version, but it's pretty concise as-is.

Edited by IceMetalPunk

Whatever Minecraft needs, it is most likely not yet another tool tier.

Seriously?

Can't you people even look at the Enum? Or other blocks that use it?

EnumFacing.getFront(meta)

 


    /**
     * Get a Facing by it's index (0-5). The order is D-U-N-S-W-E. Named getFront for legacy reasons.
     */
    public static EnumFacing getFront(int index)
    {
        return VALUES[MathHelper.abs(index % VALUES.length)];
    }

 

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

The takeaway lesson here: Use your IDE to explore and walk through the vanilla classes to see:

 

  • A) What's on offer.
  • B) How vanilla uses things

Edited by jeffryfisher

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

I solved it this way on block placing

 

Horizontal placing, like furnace.

	@Override
	public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing blockFaceClickedOn, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
	{
		  // find the quadrant the player is facing
		EnumFacing enumfacing = (placer == null) ? EnumFacing.NORTH : EnumFacing.fromAngle(placer.rotationYaw);

		  // Place allways same up and down direction
		return this.getDefaultState().withProperty(PROPERTYFACING, enumfacing);
	}		  		

 

 

And every direction placing, like piston

	@Override
	public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing blockFaceClickedOn, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
	{
		  return this.getDefaultState().withProperty(PROPERTYFACING, BlockPistonBase.getFacingFromEntity(pos, placer));
		  
	}		  		

 

PROPERTYFACING is set like so

public static final PropertyDirection PROPERTYFACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);

 

And you need a json in blockstates, that has poperties facing and 6 models in block, one for each side.

 

Sigh.

 

public static final PropertyDirection PROPERTYFACING = BlockHorizontal.FACING;

 

Magic, you're done here. The property already exists, utilize it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Thank you all.  Draco18s : getFront(meta) is the answer.

 

Dustpuppy: or one model with rotations in the blockstate :)

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.