Advertisement
Guest User

Untitled

a guest
May 24th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. package TechnicianLP.FactorialRevolution.common.blocks.blockstate;
  2.  
  3. import com.google.common.collect.ImmutableSet;
  4.  
  5. import TechnicianLP.FactorialRevolution.common.FactorialRevolution;
  6. import TechnicianLP.FactorialRevolution.common.blocks.blocks.belt.BlockBelt;
  7. import TechnicianLP.FactorialRevolution.common.blocks.blockstate.property.EConnection;
  8. import TechnicianLP.FactorialRevolution.common.blocks.blockstate.property.PropertyConnection;
  9. import net.minecraft.block.Block;
  10. import net.minecraft.block.properties.IProperty;
  11. import net.minecraft.block.properties.PropertyBool;
  12. import net.minecraft.block.properties.PropertyDirection;
  13. import net.minecraft.block.properties.PropertyEnum;
  14. import net.minecraft.block.state.BlockStateContainer;
  15. import net.minecraft.block.state.IBlockState;
  16. import net.minecraft.util.EnumFacing;
  17. import net.minecraft.util.IStringSerializable;
  18. import net.minecraft.util.math.BlockPos;
  19. import net.minecraft.world.IBlockAccess;
  20. import net.minecraftforge.common.property.IUnlistedProperty;
  21.  
  22. public class BeltStateSupplier extends AStateSupplier {
  23.  
  24. /** facing of outputside */
  25. public static final PropertyDirection FACING = PropertyDirection.create("facing", ImmutableSet.copyOf(EnumFacing.HORIZONTALS));
  26.  
  27. /** where do belts connect (visual) */
  28. public static final PropertyConnection CONNECTIONS_V = PropertyConnection.create("connections_v", true, EnumFacing.HORIZONTALS);
  29.  
  30. /** where do belts connect (real) */
  31. public static final PropertyConnection CONNECTIONS_R = PropertyConnection.create("connections_r", false, EnumFacing.HORIZONTALS);
  32.  
  33. /** what type of belt? */
  34. public static final PropertyEnum<BeltTier> TIER = PropertyEnum.create("tier", BeltTier.class);
  35.  
  36. /** is this solid on the top? */
  37. public static final PropertyBool FRAMED = PropertyBool.create("framed");
  38.  
  39. @Override
  40. public BlockStateContainer createBlockState(Block b) {
  41. return createBlockState(b, new IProperty[] { FACING, CONNECTIONS_V, TIER, FRAMED }, new IProperty[0], new IUnlistedProperty[] { CONNECTIONS_R });
  42. }
  43.  
  44. @Override
  45. public IBlockState getDefaultState(IBlockStateWrapper base) {
  46. base.withProperty(FACING, EnumFacing.NORTH);
  47.  
  48. // base.withProperty(CONNECTIONS_R, EConnection.______);
  49.  
  50. base.withProperty(CONNECTIONS_V, EConnection.______);
  51.  
  52. base.withProperty(TIER, BeltTier.BASIC);
  53.  
  54. base.withProperty(FRAMED, false);
  55.  
  56. return base.state;
  57. }
  58.  
  59. @Override
  60. public IBlockState getActualState(IBlockStateWrapper state, IBlockAccess worldIn, BlockPos pos) {
  61. FactorialRevolution.LOGGER.info("actual state:" + state.state);
  62.  
  63. EnumFacing facing = state.getValue(FACING);
  64. BeltTier tier = state.getValue(TIER);
  65.  
  66. IBlockState south = worldIn.getBlockState(pos.offset(facing.getOpposite()));
  67. if (south.getBlock() instanceof BlockBelt) {
  68. if (south.getValue(FACING) == facing) {
  69. FactorialRevolution.LOGGER.info("dafuq?");
  70.  
  71. // state.withProperty(CONNECTIONS_R,
  72. // state.getValue(CONNECTIONS_R).add(EnumFacing.SOUTH));
  73.  
  74. if (south.getValue(TIER) == tier)
  75. state.withProperty(CONNECTIONS_V, state.getValue(CONNECTIONS_V).add(EnumFacing.SOUTH));
  76. }
  77. }
  78.  
  79. IBlockState north = worldIn.getBlockState(pos.offset(facing));
  80. if (north.getBlock() instanceof BlockBelt) {
  81. if (north.getValue(FACING) == facing) {
  82. // state.withProperty(CONNECTIONS_R,
  83. // state.getValue(CONNECTIONS_R).add(EnumFacing.NORTH));
  84.  
  85. if (north.getValue(TIER) == tier)
  86. state.withProperty(CONNECTIONS_V, state.getValue(CONNECTIONS_V).add(EnumFacing.NORTH));
  87. }
  88. }
  89.  
  90. IBlockState west = worldIn.getBlockState(pos.offset(facing.rotateYCCW()));
  91. if (west.getBlock() instanceof BlockBelt) {
  92. if (west.getValue(FACING) == facing.rotateY()) {
  93. // state.withProperty(CONNECTIONS_R,
  94. // state.getValue(CONNECTIONS_R).add(EnumFacing.WEST));
  95.  
  96. state.withProperty(CONNECTIONS_V, state.getValue(CONNECTIONS_V).add(EnumFacing.WEST));
  97. }
  98. }
  99.  
  100. IBlockState east = worldIn.getBlockState(pos.offset(facing.rotateY()));
  101. if (east.getBlock() instanceof BlockBelt) {
  102. if (east.getValue(FACING) == facing.rotateYCCW()) {
  103. // state.withProperty(CONNECTIONS_R,
  104. // state.getValue(CONNECTIONS_R).add(EnumFacing.EAST));
  105.  
  106. state.withProperty(CONNECTIONS_V, state.getValue(CONNECTIONS_V).add(EnumFacing.EAST));
  107. }
  108. }
  109.  
  110. // EConnection real = state.getValue(CONNECTIONS_R);
  111. // if (real.isConnected(EnumFacing.NORTH))
  112. // state.withProperty(CONNECTIONS_V,
  113. // state.getValue(CONNECTIONS_V).add(EnumFacing.NORTH));
  114. // if (real.isConnected(EnumFacing.SOUTH))
  115. // state.withProperty(CONNECTIONS_V,
  116. // state.getValue(CONNECTIONS_V).add(EnumFacing.SOUTH));
  117.  
  118. return state.state;
  119. }
  120.  
  121. @Override
  122. public int getMetaFromState(IBlockStateWrapper state) {
  123. int meta = 0;
  124.  
  125. EnumFacing facing = state.getValue(FACING);
  126. meta += (facing.ordinal() - 2) << 2;
  127.  
  128. BeltTier type = state.getValue(TIER);
  129. meta += type.ordinal();
  130.  
  131. return meta;
  132. }
  133.  
  134. @Override
  135. public IBlockState getStateFromMeta(int meta, IBlockStateWrapper defalt) {
  136. FactorialRevolution.LOGGER.info("gsfm1: " + defalt.state);
  137. defalt.withProperty(FACING, EnumFacing.values()[((meta >> 2) & 3) + 2]);
  138. defalt.withProperty(TIER, BeltTier.values()[meta & 3]);
  139. FactorialRevolution.LOGGER.info("gsfm2: " + defalt.state);
  140. return defalt.state;
  141. }
  142.  
  143. public static enum BeltTier implements IStringSerializable {
  144. BASIC("basic"), FAST("fast"), EXPRESS("express"), SPEEDY("speedy");
  145.  
  146. String name;
  147.  
  148. private BeltTier(String type) {
  149. name = type;
  150. }
  151.  
  152. @Override
  153. public String getName() {
  154. return name;
  155. }
  156.  
  157. }
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement