Advertisement
grossik

Untitled

Nov 18th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. package com.example.examplemod;
  2.  
  3. import cz.grossik.farmcraft2.Main;
  4. import net.minecraft.block.Block;
  5. import net.minecraft.block.material.Material;
  6. import net.minecraft.block.properties.IProperty;
  7. import net.minecraft.block.properties.PropertyEnum;
  8. import net.minecraft.block.state.BlockStateContainer;
  9. import net.minecraft.block.state.IBlockState;
  10. import net.minecraft.util.IStringSerializable;
  11. import net.minecraft.util.math.BlockPos;
  12. import net.minecraft.world.World;
  13.  
  14. public class BlockTestW extends Block {
  15.  
  16. public static final PropertyEnum<EnumDirection> SHAPE = PropertyEnum.<EnumDirection>create("shape", EnumDirection.class);
  17.  
  18. public BlockTestW(Material materialIn) {
  19. super(materialIn);
  20. this.setCreativeTab(Main.FarmCraft2Tab);
  21. this.setDefaultState(this.blockState.getBaseState().withProperty(SHAPE, EnumDirection.LEVO_KONEC));
  22. }
  23.  
  24. public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
  25. {
  26. this.setDefaultFacing(worldIn, pos, state);
  27. }
  28.  
  29. private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
  30. {
  31. if (!worldIn.isRemote)
  32. {
  33. EnumDirection blockrailbase$enumraildirection = (EnumDirection)state.getValue(SHAPE);
  34.  
  35. if(worldIn.getBlockState(pos.east()).isFullBlock() && worldIn.getBlockState(pos.west()).isFullBlock() && worldIn.getBlockState(pos.east()).getBlock() != ExampleMod.testB && worldIn.getBlockState(pos.west()).getBlock() != ExampleMod.testB || worldIn.getBlockState(pos.north()).isFullBlock() && worldIn.getBlockState(pos.south()).isFullBlock() && worldIn.getBlockState(pos.north()).getBlock() != ExampleMod.testB && worldIn.getBlockState(pos.south()).getBlock() != ExampleMod.testB) {
  36. blockrailbase$enumraildirection = EnumDirection.OBE_KONEC;
  37. } else if((worldIn.getBlockState(pos.east()).isFullBlock() && worldIn.getBlockState(pos.east()).getBlock() != ExampleMod.testB) || (worldIn.getBlockState(pos.north()).isFullBlock() && worldIn.getBlockState(pos.north()).getBlock() != ExampleMod.testB)){
  38. blockrailbase$enumraildirection = EnumDirection.PRAVO_KONEC;
  39. } else if((worldIn.getBlockState(pos.west()).isFullBlock() && worldIn.getBlockState(pos.west()).getBlock() != ExampleMod.testB) || (worldIn.getBlockState(pos.south()).isFullBlock() && worldIn.getBlockState(pos.south()).getBlock() != ExampleMod.testB)){
  40. blockrailbase$enumraildirection = EnumDirection.LEVO_KONEC;
  41. } else {
  42. blockrailbase$enumraildirection = EnumDirection.OBE_POKRACUJE;
  43. }
  44.  
  45. worldIn.setBlockState(pos, state.withProperty(SHAPE, blockrailbase$enumraildirection));
  46. }
  47. }
  48.  
  49. public IBlockState getStateFromMeta(int meta)
  50. {
  51. return this.getDefaultState().withProperty(SHAPE, EnumDirection.byMetadata(meta));
  52. }
  53.  
  54. public int getMetaFromState(IBlockState state)
  55. {
  56. return ((EnumDirection)state.getValue(SHAPE)).getMetadata();
  57. }
  58.  
  59. protected BlockStateContainer createBlockState()
  60. {
  61. return new BlockStateContainer(this, new IProperty[] {SHAPE});
  62. }
  63.  
  64. public static enum EnumDirection implements IStringSerializable
  65. {
  66. LEVO_KONEC(0, "levo_konec"),
  67. PRAVO_KONEC(1, "pravo_konec"),
  68. OBE_KONEC(2, "obe_konec"),
  69. OBE_POKRACUJE(3, "obe_pokracuje");
  70.  
  71. private static final EnumDirection[] META_LOOKUP = new EnumDirection[values().length];
  72. private final int meta;
  73. private final String name;
  74.  
  75. private EnumDirection(int meta, String name)
  76. {
  77. this.meta = meta;
  78. this.name = name;
  79. }
  80.  
  81. public int getMetadata()
  82. {
  83. return this.meta;
  84. }
  85.  
  86. public String toString()
  87. {
  88. return this.name;
  89. }
  90.  
  91. public static EnumDirection byMetadata(int meta)
  92. {
  93. if (meta < 0 || meta >= META_LOOKUP.length)
  94. {
  95. meta = 0;
  96. }
  97.  
  98. return META_LOOKUP[meta];
  99. }
  100.  
  101. public String getName()
  102. {
  103. return this.name;
  104. }
  105.  
  106. static
  107. {
  108. for (EnumDirection blockrailbase$enumraildirection : values())
  109. {
  110. META_LOOKUP[blockrailbase$enumraildirection.getMetadata()] = blockrailbase$enumraildirection;
  111. }
  112. }
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement