| 1 | package net.minecraft.block.state;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.block.Block;
|
| 6 | import net.minecraft.block.BlockPistonBase;
|
| 7 | import net.minecraft.block.material.Material;
|
| 8 | import net.minecraft.init.Blocks;
|
| 9 | import net.minecraft.util.BlockPos;
|
| 10 | import net.minecraft.util.EnumFacing;
|
| 11 | import net.minecraft.world.World;
|
| 12 |
|
| 13 | public class BlockPistonStructureHelper
|
| 14 | {
|
| 15 | private final World world;
|
| 16 | private final BlockPos pistonPos;
|
| 17 | private final BlockPos blockToMove;
|
| 18 | private final EnumFacing moveDirection;
|
| 19 | private final List<BlockPos> toMove = Lists.<BlockPos>newArrayList();
|
| 20 | private final List<BlockPos> toDestroy = Lists.<BlockPos>newArrayList();
|
| 21 |
|
| 22 | public BlockPistonStructureHelper(World worldIn, BlockPos posIn, EnumFacing pistonFacing, boolean extending)
|
| 23 | {
|
| 24 | this.world = worldIn;
|
| 25 | this.pistonPos = posIn;
|
| 26 |
|
| 27 | if (extending)
|
| 28 | {
|
| 29 | this.moveDirection = pistonFacing;
|
| 30 | this.blockToMove = posIn.offset(pistonFacing);
|
| 31 | }
|
| 32 | else
|
| 33 | {
|
| 34 | this.moveDirection = pistonFacing.getOpposite();
|
| 35 | this.blockToMove = posIn.offset(pistonFacing, 2);
|
| 36 | }
|
| 37 | }
|
| 38 |
|
| 39 | public boolean canMove()
|
| 40 | {
|
| 41 | this.toMove.clear();
|
| 42 | this.toDestroy.clear();
|
| 43 | Block block = this.world.getBlockState(this.blockToMove).getBlock();
|
| 44 |
|
| 45 | if (!BlockPistonBase.canPush(block, this.world, this.blockToMove, this.moveDirection, false))
|
| 46 | {
|
| 47 | if (block.getMobilityFlag() != 1)
|
| 48 | {
|
| 49 | return false;
|
| 50 | }
|
| 51 | else
|
| 52 | {
|
| 53 | this.toDestroy.add(this.blockToMove);
|
| 54 | return true;
|
| 55 | }
|
| 56 | }
|
| 57 | else if (!this.func_177251_a(this.blockToMove))
|
| 58 | {
|
| 59 | return false;
|
| 60 | }
|
| 61 | else
|
| 62 | {
|
| 63 | for (int i = 0; i < this.toMove.size(); ++i)
|
| 64 | {
|
| 65 | BlockPos blockpos = (BlockPos)this.toMove.get(i);
|
| 66 |
|
| 67 | if (this.world.getBlockState(blockpos).getBlock() == Blocks.slime_block && !this.func_177250_b(blockpos))
|
| 68 | {
|
| 69 | return false;
|
| 70 | }
|
| 71 | }
|
| 72 |
|
| 73 | return true;
|
| 74 | }
|
| 75 | }
|
| 76 |
|
| 77 | private boolean func_177251_a(BlockPos origin)
|
| 78 | {
|
| 79 | Block block = this.world.getBlockState(origin).getBlock();
|
| 80 |
|
| 81 | if (block.getMaterial() == Material.air)
|
| 82 | {
|
| 83 | return true;
|
| 84 | }
|
| 85 | else if (!BlockPistonBase.canPush(block, this.world, origin, this.moveDirection, false))
|
| 86 | {
|
| 87 | return true;
|
| 88 | }
|
| 89 | else if (origin.equals(this.pistonPos))
|
| 90 | {
|
| 91 | return true;
|
| 92 | }
|
| 93 | else if (this.toMove.contains(origin))
|
| 94 | {
|
| 95 | return true;
|
| 96 | }
|
| 97 | else
|
| 98 | {
|
| 99 | int i = 1;
|
| 100 |
|
| 101 | if (i + this.toMove.size() > 12)
|
| 102 | {
|
| 103 | return false;
|
| 104 | }
|
| 105 | else
|
| 106 | {
|
| 107 | while (block == Blocks.slime_block)
|
| 108 | {
|
| 109 | BlockPos blockpos = origin.offset(this.moveDirection.getOpposite(), i);
|
| 110 | block = this.world.getBlockState(blockpos).getBlock();
|
| 111 |
|
| 112 | if (block.getMaterial() == Material.air || !BlockPistonBase.canPush(block, this.world, blockpos, this.moveDirection, false) || blockpos.equals(this.pistonPos))
|
| 113 | {
|
| 114 | break;
|
| 115 | }
|
| 116 |
|
| 117 | ++i;
|
| 118 |
|
| 119 | if (i + this.toMove.size() > 12)
|
| 120 | {
|
| 121 | return false;
|
| 122 | }
|
| 123 | }
|
| 124 |
|
| 125 | int i1 = 0;
|
| 126 |
|
| 127 | for (int j = i - 1; j >= 0; --j)
|
| 128 | {
|
| 129 | this.toMove.add(origin.offset(this.moveDirection.getOpposite(), j));
|
| 130 | ++i1;
|
| 131 | }
|
| 132 |
|
| 133 | int j1 = 1;
|
| 134 |
|
| 135 | while (true)
|
| 136 | {
|
| 137 | BlockPos blockpos1 = origin.offset(this.moveDirection, j1);
|
| 138 | int k = this.toMove.indexOf(blockpos1);
|
| 139 |
|
| 140 | if (k > -1)
|
| 141 | {
|
| 142 | this.func_177255_a(i1, k);
|
| 143 |
|
| 144 | for (int l = 0; l <= k + i1; ++l)
|
| 145 | {
|
| 146 | BlockPos blockpos2 = (BlockPos)this.toMove.get(l);
|
| 147 |
|
| 148 | if (this.world.getBlockState(blockpos2).getBlock() == Blocks.slime_block && !this.func_177250_b(blockpos2))
|
| 149 | {
|
| 150 | return false;
|
| 151 | }
|
| 152 | }
|
| 153 |
|
| 154 | return true;
|
| 155 | }
|
| 156 |
|
| 157 | block = this.world.getBlockState(blockpos1).getBlock();
|
| 158 |
|
| 159 | if (block.getMaterial() == Material.air)
|
| 160 | {
|
| 161 | return true;
|
| 162 | }
|
| 163 |
|
| 164 | if (!BlockPistonBase.canPush(block, this.world, blockpos1, this.moveDirection, true) || blockpos1.equals(this.pistonPos))
|
| 165 | {
|
| 166 | return false;
|
| 167 | }
|
| 168 |
|
| 169 | if (block.getMobilityFlag() == 1)
|
| 170 | {
|
| 171 | this.toDestroy.add(blockpos1);
|
| 172 | return true;
|
| 173 | }
|
| 174 |
|
| 175 | if (this.toMove.size() >= 12)
|
| 176 | {
|
| 177 | return false;
|
| 178 | }
|
| 179 |
|
| 180 | this.toMove.add(blockpos1);
|
| 181 | ++i1;
|
| 182 | ++j1;
|
| 183 | }
|
| 184 | }
|
| 185 | }
|
| 186 | }
|
| 187 |
|
| 188 | private void func_177255_a(int p_177255_1_, int p_177255_2_)
|
| 189 | {
|
| 190 | List<BlockPos> list = Lists.<BlockPos>newArrayList();
|
| 191 | List<BlockPos> list1 = Lists.<BlockPos>newArrayList();
|
| 192 | List<BlockPos> list2 = Lists.<BlockPos>newArrayList();
|
| 193 | list.addAll(this.toMove.subList(0, p_177255_2_));
|
| 194 | list1.addAll(this.toMove.subList(this.toMove.size() - p_177255_1_, this.toMove.size()));
|
| 195 | list2.addAll(this.toMove.subList(p_177255_2_, this.toMove.size() - p_177255_1_));
|
| 196 | this.toMove.clear();
|
| 197 | this.toMove.addAll(list);
|
| 198 | this.toMove.addAll(list1);
|
| 199 | this.toMove.addAll(list2);
|
| 200 | }
|
| 201 |
|
| 202 | private boolean func_177250_b(BlockPos p_177250_1_)
|
| 203 | {
|
| 204 | for (EnumFacing enumfacing : EnumFacing.values())
|
| 205 | {
|
| 206 | if (enumfacing.getAxis() != this.moveDirection.getAxis() && !this.func_177251_a(p_177250_1_.offset(enumfacing)))
|
| 207 | {
|
| 208 | return false;
|
| 209 | }
|
| 210 | }
|
| 211 |
|
| 212 | return true;
|
| 213 | }
|
| 214 |
|
| 215 | public List<BlockPos> getBlocksToMove()
|
| 216 | {
|
| 217 | return this.toMove;
|
| 218 | }
|
| 219 |
|
| 220 | public List<BlockPos> getBlocksToDestroy()
|
| 221 | {
|
| 222 | return this.toDestroy;
|
| 223 | }
|
| 224 | }
|
| 225 |
|