Posted September 6, 20178 yr 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
September 6, 20178 yr 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 September 6, 20178 yr by IceMetalPunk Whatever Minecraft needs, it is most likely not yet another tool tier.
September 6, 20178 yr 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 September 6, 20178 yr 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.
September 6, 20178 yr 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 September 6, 20178 yr 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.
September 7, 20178 yr 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)); }
September 7, 20178 yr 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.
September 7, 20178 yr 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.
September 8, 20178 yr 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.