| 1 | package net.minecraft.block;
|
| 2 |
|
| 3 | import com.google.common.base.Predicate;
|
| 4 | import net.minecraft.block.properties.IProperty;
|
| 5 | import net.minecraft.block.properties.PropertyBool;
|
| 6 | import net.minecraft.block.properties.PropertyEnum;
|
| 7 | import net.minecraft.block.state.BlockState;
|
| 8 | import net.minecraft.block.state.IBlockState;
|
| 9 | import net.minecraft.util.BlockPos;
|
| 10 | import net.minecraft.world.World;
|
| 11 |
|
| 12 | public class BlockRailPowered extends BlockRailBase
|
| 13 | {
|
| 14 | public static final PropertyEnum<BlockRailBase.EnumRailDirection> SHAPE = PropertyEnum.<BlockRailBase.EnumRailDirection>create("shape", BlockRailBase.EnumRailDirection.class, new Predicate<BlockRailBase.EnumRailDirection>()
|
| 15 | {
|
| 16 | public boolean apply(BlockRailBase.EnumRailDirection p_apply_1_)
|
| 17 | {
|
| 18 | return p_apply_1_ != BlockRailBase.EnumRailDirection.NORTH_EAST && p_apply_1_ != BlockRailBase.EnumRailDirection.NORTH_WEST && p_apply_1_ != BlockRailBase.EnumRailDirection.SOUTH_EAST && p_apply_1_ != BlockRailBase.EnumRailDirection.SOUTH_WEST;
|
| 19 | }
|
| 20 | });
|
| 21 | public static final PropertyBool POWERED = PropertyBool.create("powered");
|
| 22 |
|
| 23 | protected BlockRailPowered()
|
| 24 | {
|
| 25 | super(true);
|
| 26 | this.setDefaultState(this.blockState.getBaseState().withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH).withProperty(POWERED, Boolean.valueOf(false)));
|
| 27 | }
|
| 28 |
|
| 29 | @SuppressWarnings("incomplete-switch")
|
| 30 | protected boolean func_176566_a(World worldIn, BlockPos pos, IBlockState state, boolean p_176566_4_, int p_176566_5_)
|
| 31 | {
|
| 32 | if (p_176566_5_ >= 8)
|
| 33 | {
|
| 34 | return false;
|
| 35 | }
|
| 36 | else
|
| 37 | {
|
| 38 | int i = pos.getX();
|
| 39 | int j = pos.getY();
|
| 40 | int k = pos.getZ();
|
| 41 | boolean flag = true;
|
| 42 | BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = (BlockRailBase.EnumRailDirection)state.getValue(SHAPE);
|
| 43 |
|
| 44 | switch (blockrailbase$enumraildirection)
|
| 45 | {
|
| 46 | case NORTH_SOUTH:
|
| 47 | if (p_176566_4_)
|
| 48 | {
|
| 49 | ++k;
|
| 50 | }
|
| 51 | else
|
| 52 | {
|
| 53 | --k;
|
| 54 | }
|
| 55 |
|
| 56 | break;
|
| 57 |
|
| 58 | case EAST_WEST:
|
| 59 | if (p_176566_4_)
|
| 60 | {
|
| 61 | --i;
|
| 62 | }
|
| 63 | else
|
| 64 | {
|
| 65 | ++i;
|
| 66 | }
|
| 67 |
|
| 68 | break;
|
| 69 |
|
| 70 | case ASCENDING_EAST:
|
| 71 | if (p_176566_4_)
|
| 72 | {
|
| 73 | --i;
|
| 74 | }
|
| 75 | else
|
| 76 | {
|
| 77 | ++i;
|
| 78 | ++j;
|
| 79 | flag = false;
|
| 80 | }
|
| 81 |
|
| 82 | blockrailbase$enumraildirection = BlockRailBase.EnumRailDirection.EAST_WEST;
|
| 83 | break;
|
| 84 |
|
| 85 | case ASCENDING_WEST:
|
| 86 | if (p_176566_4_)
|
| 87 | {
|
| 88 | --i;
|
| 89 | ++j;
|
| 90 | flag = false;
|
| 91 | }
|
| 92 | else
|
| 93 | {
|
| 94 | ++i;
|
| 95 | }
|
| 96 |
|
| 97 | blockrailbase$enumraildirection = BlockRailBase.EnumRailDirection.EAST_WEST;
|
| 98 | break;
|
| 99 |
|
| 100 | case ASCENDING_NORTH:
|
| 101 | if (p_176566_4_)
|
| 102 | {
|
| 103 | ++k;
|
| 104 | }
|
| 105 | else
|
| 106 | {
|
| 107 | --k;
|
| 108 | ++j;
|
| 109 | flag = false;
|
| 110 | }
|
| 111 |
|
| 112 | blockrailbase$enumraildirection = BlockRailBase.EnumRailDirection.NORTH_SOUTH;
|
| 113 | break;
|
| 114 |
|
| 115 | case ASCENDING_SOUTH:
|
| 116 | if (p_176566_4_)
|
| 117 | {
|
| 118 | ++k;
|
| 119 | ++j;
|
| 120 | flag = false;
|
| 121 | }
|
| 122 | else
|
| 123 | {
|
| 124 | --k;
|
| 125 | }
|
| 126 |
|
| 127 | blockrailbase$enumraildirection = BlockRailBase.EnumRailDirection.NORTH_SOUTH;
|
| 128 | }
|
| 129 |
|
| 130 | return this.func_176567_a(worldIn, new BlockPos(i, j, k), p_176566_4_, p_176566_5_, blockrailbase$enumraildirection) ? true : flag && this.func_176567_a(worldIn, new BlockPos(i, j - 1, k), p_176566_4_, p_176566_5_, blockrailbase$enumraildirection);
|
| 131 | }
|
| 132 | }
|
| 133 |
|
| 134 | protected boolean func_176567_a(World worldIn, BlockPos p_176567_2_, boolean p_176567_3_, int distance, BlockRailBase.EnumRailDirection p_176567_5_)
|
| 135 | {
|
| 136 | IBlockState iblockstate = worldIn.getBlockState(p_176567_2_);
|
| 137 |
|
| 138 | if (iblockstate.getBlock() != this)
|
| 139 | {
|
| 140 | return false;
|
| 141 | }
|
| 142 | else
|
| 143 | {
|
| 144 | BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = (BlockRailBase.EnumRailDirection)iblockstate.getValue(SHAPE);
|
| 145 | return p_176567_5_ != BlockRailBase.EnumRailDirection.EAST_WEST || blockrailbase$enumraildirection != BlockRailBase.EnumRailDirection.NORTH_SOUTH && blockrailbase$enumraildirection != BlockRailBase.EnumRailDirection.ASCENDING_NORTH && blockrailbase$enumraildirection != BlockRailBase.EnumRailDirection.ASCENDING_SOUTH ? (p_176567_5_ != BlockRailBase.EnumRailDirection.NORTH_SOUTH || blockrailbase$enumraildirection != BlockRailBase.EnumRailDirection.EAST_WEST && blockrailbase$enumraildirection != BlockRailBase.EnumRailDirection.ASCENDING_EAST && blockrailbase$enumraildirection != BlockRailBase.EnumRailDirection.ASCENDING_WEST ? (((Boolean)iblockstate.getValue(POWERED)).booleanValue() ? (worldIn.isBlockPowered(p_176567_2_) ? true : this.func_176566_a(worldIn, p_176567_2_, iblockstate, p_176567_3_, distance + 1)) : false) : false) : false;
|
| 146 | }
|
| 147 | }
|
| 148 |
|
| 149 | protected void onNeighborChangedInternal(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
|
| 150 | {
|
| 151 | boolean flag = ((Boolean)state.getValue(POWERED)).booleanValue();
|
| 152 | boolean flag1 = worldIn.isBlockPowered(pos) || this.func_176566_a(worldIn, pos, state, true, 0) || this.func_176566_a(worldIn, pos, state, false, 0);
|
| 153 |
|
| 154 | if (flag1 != flag)
|
| 155 | {
|
| 156 | worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(flag1)), 3);
|
| 157 | worldIn.notifyNeighborsOfStateChange(pos.down(), this);
|
| 158 |
|
| 159 | if (((BlockRailBase.EnumRailDirection)state.getValue(SHAPE)).isAscending())
|
| 160 | {
|
| 161 | worldIn.notifyNeighborsOfStateChange(pos.up(), this);
|
| 162 | }
|
| 163 | }
|
| 164 | }
|
| 165 |
|
| 166 | public IProperty<BlockRailBase.EnumRailDirection> getShapeProperty()
|
| 167 | {
|
| 168 | return SHAPE;
|
| 169 | }
|
| 170 |
|
| 171 | /**
|
| 172 | * Convert the given metadata into a BlockState for this Block
|
| 173 | */
|
| 174 | public IBlockState getStateFromMeta(int meta)
|
| 175 | {
|
| 176 | return this.getDefaultState().withProperty(SHAPE, BlockRailBase.EnumRailDirection.byMetadata(meta & 7)).withProperty(POWERED, Boolean.valueOf((meta & 8) > 0));
|
| 177 | }
|
| 178 |
|
| 179 | /**
|
| 180 | * Convert the BlockState into the correct metadata value
|
| 181 | */
|
| 182 | public int getMetaFromState(IBlockState state)
|
| 183 | {
|
| 184 | int i = 0;
|
| 185 | i = i | ((BlockRailBase.EnumRailDirection)state.getValue(SHAPE)).getMetadata();
|
| 186 |
|
| 187 | if (((Boolean)state.getValue(POWERED)).booleanValue())
|
| 188 | {
|
| 189 | i |= 8;
|
| 190 | }
|
| 191 |
|
| 192 | return i;
|
| 193 | }
|
| 194 |
|
| 195 | protected BlockState createBlockState()
|
| 196 | {
|
| 197 | return new BlockState(this, new IProperty[] {SHAPE, POWERED});
|
| 198 | }
|
| 199 | }
|
| 200 |
|