Advertisement
jfmachine

Chest only faces one direction?

Dec 22nd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. public static final PropertyDirection FACING = PropertyDirection.create("facing");
  2.  
  3. public LeafChest(String name, Material materialIn) {
  4. //irrelevant code omitted from paste for clarity
  5.  
  6. //irrelevant code omitted from paste for clarity
  7. setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
  8.  
  9. //irrelevant code omitted from paste for clarity
  10. }
  11. @Override
  12. public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
  13.  
  14. if(stack.hasDisplayName()) {
  15. TileEntity tileentity = worldIn.getTileEntity(pos);
  16. if(tileentity instanceof TileEntityLeafChest) {
  17. ((TileEntityLeafChest)tileentity).setCustomName(stack.getDisplayName());
  18. }
  19. }
  20.  
  21. }
  22.  
  23. @Override
  24. public IBlockState getStateFromMeta(int meta) {
  25. IBlockState state = this.getDefaultState();
  26. state = state.withProperty(FACING, EnumFacing.getFront(meta));
  27. return state;
  28. }
  29.  
  30. @Override
  31. public int getMetaFromState(IBlockState state) {
  32. return ((EnumFacing)state.getValue(FACING)).getIndex();
  33. }
  34.  
  35. @Override
  36. protected BlockStateContainer createBlockState() {
  37. return new BlockStateContainer(this, new IProperty[] {FACING});
  38. }
  39.  
  40. //Facing
  41. @Override
  42. public IBlockState getStateForPlacement(World worldIn, BlockPos pos,EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
  43. {
  44. IBlockState iBlockState = worldIn.getBlockState(pos.offset(facing.getOpposite()));
  45. if(iBlockState.getBlock() == this)
  46. {
  47. EnumFacing enumFacing = (EnumFacing)iBlockState.getValue(FACING);
  48. if(enumFacing == facing)
  49. {
  50. return this.getDefaultState().withProperty(FACING, facing.getOpposite());
  51. }
  52. }
  53. return this.getDefaultState().withProperty(FACING, facing);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement