Created
October 31, 2019 16:57
-
-
Save m00nwtchr/3d8360d0c9340591a22815a8a821662c to your computer and use it in GitHub Desktop.
Custom structure helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package io.github.lukas2005.infinipush; | |
| import com.google.common.collect.Lists; | |
| import java.util.List; | |
| import io.github.lukas2005.infinipush.blocks.CustomPistonBlock; | |
| import net.minecraft.block.Block; | |
| import net.minecraft.block.BlockState; | |
| import net.minecraft.block.Blocks; | |
| import net.minecraft.block.PistonBlock; | |
| import net.minecraft.block.material.PushReaction; | |
| import net.minecraft.block.state.PistonBlockStructureHelper; | |
| import net.minecraft.util.Direction; | |
| import net.minecraft.util.math.BlockPos; | |
| import net.minecraft.world.World; | |
| public class CustomStructureHelper extends PistonBlockStructureHelper { | |
| public static final int PUSH_LIMIT = 1000; | |
| public CustomStructureHelper(World worldIn, BlockPos posIn, Direction pistonFacing, boolean extending) { | |
| super(worldIn, posIn, pistonFacing, extending); | |
| } | |
| @Override | |
| public boolean canMove() { | |
| this.toMove.clear(); | |
| this.toDestroy.clear(); | |
| BlockState blockstate = this.world.getBlockState(this.blockToMove); | |
| if (!CustomPistonBlock.canPush(blockstate, this.world, this.blockToMove, this.moveDirection, false, this.facing)) { | |
| if (this.extending && blockstate.getPushReaction() == PushReaction.DESTROY) { | |
| this.toDestroy.add(this.blockToMove); | |
| return true; | |
| } else { | |
| return false; | |
| } | |
| } else if (!this.addBlockLine(this.blockToMove, this.moveDirection)) { | |
| return false; | |
| } else { | |
| for (int i = 0; i < this.toMove.size(); ++i) { | |
| BlockPos blockpos = this.toMove.get(i); | |
| if (this.world.getBlockState(blockpos).isStickyBlock() && !this.addBranchingBlocks(blockpos)) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| } | |
| @Override | |
| public boolean addBlockLine(BlockPos origin, Direction facingIn) { | |
| BlockState blockstate = this.world.getBlockState(origin); | |
| if (world.isAirBlock(origin)) { | |
| return true; | |
| } else if (!CustomPistonBlock.canPush(blockstate, this.world, origin, this.moveDirection, false, facingIn)) { | |
| return true; | |
| } else if (origin.equals(this.pistonPos)) { | |
| return true; | |
| } else if (this.toMove.contains(origin)) { | |
| return true; | |
| } else { | |
| int i = 1; | |
| if (i + this.toMove.size() > PUSH_LIMIT) { | |
| return false; | |
| } else { | |
| while (blockstate.isStickyBlock()) { | |
| BlockPos blockpos = origin.offset(this.moveDirection.getOpposite(), i); | |
| blockstate = this.world.getBlockState(blockpos); | |
| if (blockstate.isAir(this.world, blockpos) || !CustomPistonBlock.canPush(blockstate, this.world, blockpos, this.moveDirection, false, this.moveDirection.getOpposite()) || blockpos.equals(this.pistonPos)) { | |
| break; | |
| } | |
| ++i; | |
| if (i + this.toMove.size() > PUSH_LIMIT) { | |
| return false; | |
| } | |
| } | |
| int i1 = 0; | |
| for (int j = i - 1; j >= 0; --j) { | |
| this.toMove.add(origin.offset(this.moveDirection.getOpposite(), j)); | |
| ++i1; | |
| } | |
| int j1 = 1; | |
| while (true) { | |
| BlockPos blockpos1 = origin.offset(this.moveDirection, j1); | |
| int k = this.toMove.indexOf(blockpos1); | |
| if (k > -1) { | |
| this.reorderListAtCollision(i1, k); | |
| for (int l = 0; l <= k + i1; ++l) { | |
| BlockPos blockpos2 = this.toMove.get(l); | |
| if (this.world.getBlockState(blockpos2).isStickyBlock() && !this.addBranchingBlocks(blockpos2)) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| blockstate = this.world.getBlockState(blockpos1); | |
| if (blockstate.isAir(world, blockpos1)) { | |
| return true; | |
| } | |
| if (!CustomPistonBlock.canPush(blockstate, this.world, blockpos1, this.moveDirection, true, this.moveDirection) || blockpos1.equals(this.pistonPos)) { | |
| return false; | |
| } | |
| if (blockstate.getPushReaction() == PushReaction.DESTROY) { | |
| this.toDestroy.add(blockpos1); | |
| return true; | |
| } | |
| if (this.toMove.size() >= PUSH_LIMIT) { | |
| return false; | |
| } | |
| this.toMove.add(blockpos1); | |
| ++i1; | |
| ++j1; | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment