Skip to content

Commit

Permalink
Merge pull request #329 from DrParadox7/PistonFix
Browse files Browse the repository at this point in the history
Final Piston Update - Cleanup
  • Loading branch information
Roadhog360 committed Sep 13, 2023
2 parents 0e7eb0c + 712584b commit d092227
Showing 1 changed file with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void updatePistonState(World world, int x, int y, int z) {
}

if (etfuturum$getPushableBlocks(world, x + xoffset2, y + yoffset2, z + zoffset2, oppositeSide, oppositeSide, x + xoffset, y + yoffset, z + zoffset, Lists.newArrayList(), Lists.newArrayList()) > 12) {
return; //Can't pull
return; //Unable to pull
}
}
world.addBlockEvent(x, y, z, this, 0, side); //pull piston
Expand Down Expand Up @@ -203,10 +203,7 @@ public boolean onBlockEventReceived(World world, int x, int y, int z, int extend
} else if (etfuturum$canPushBlockNested(pushedBlock, world, pushedBlockX, pushedBlockY, pushedBlockZ, side, side)) {
if (pushedBlock.getMobilityFlag() == 1)
{
float chance = pushedBlock instanceof BlockSnow ? -1.0F : 1.0F;
pushedBlock.dropBlockAsItemWithChance(world, pushedBlockX, pushedBlockY, pushedBlockZ, pushedBlockMeta, chance, 0);
world.setBlockToAir(pushedBlockX, pushedBlockY, pushedBlockZ);
return blocksPushed;
return ++blocksPushed;
}
} else {
if (pushedBlockX == pistonX && pushedBlockY == pistonY && pushedBlockZ == pistonZ) {
Expand Down Expand Up @@ -274,49 +271,51 @@ public boolean onBlockEventReceived(World world, int x, int y, int z, int extend
List<BlockPos> removedBlockCoords = Lists.newArrayList();
List<Entity> launchedEntityList = Lists.newArrayList();
List<Entity> pulledEntityList = Lists.newArrayList();
List<BlockPos> obstructionsCoordsList = Lists.newArrayList();

//Check for obstructions before moving blocks
for (BlockPos pushedBlockPos : pushedBlockPosList) {
List<BlockPos> relocationCoordsList = Lists.newArrayList();
List<BlockPos> obstructionsCoordsList = Lists.newArrayList();

if(extending) {
relocationCoordsList.add(new BlockPos(pistonX - xoffset, pistonY - yoffset, pistonZ - zoffset));
}
relocationCoordsList.addAll(pushedBlockPosList);

for (BlockPos relocationBlockPos : relocationCoordsList) {

int destinationX = pushedBlockPos.getX() + xoffset;
int destinationY = pushedBlockPos.getY() + yoffset;
int destinationZ = pushedBlockPos.getZ() + zoffset;
int destinationX = relocationBlockPos.getX() + xoffset;
int destinationY = relocationBlockPos.getY() + yoffset;
int destinationZ = relocationBlockPos.getZ() + zoffset;
BlockPos obstructionCoords = new BlockPos(destinationX, destinationY, destinationZ);
Block destinationBlock = world.getBlock(destinationX, destinationY, destinationZ);


if (!pushedBlockPosList.contains(obstructionCoords)) {
Block destinationBlock = world.getBlock(destinationX, destinationY, destinationZ);

if (destinationBlock.getMaterial() != Material.air) {
if (destinationBlock.getMobilityFlag() == 1) {
obstructionsCoordsList.add(obstructionCoords);
} else if (destinationX == pistonX && destinationY == pistonY && destinationZ == pistonZ)
{
continue;
} else if (destinationX == pistonX && destinationY == pistonY && destinationZ == pistonZ) {
if (destinationBlock == Blocks.piston_head) {
BlockPistonExtension pistonHead = (BlockPistonExtension) destinationBlock;
int pistonHeadMeta = world.getBlockMetadata(destinationX, destinationY, destinationZ);

if (pistonHead instanceof BlockPistonExtension) {
int destinationMeta = world.getBlockMetadata(destinationX, destinationY, destinationZ);

if (Facing.oppositeSide[getDirectionMeta(destinationMeta)] == side) {
continue;
}
}
if (pistonHead instanceof BlockPistonExtension && Facing.oppositeSide[getDirectionMeta(pistonHeadMeta)] == side)
continue;
}
} else {
return false;
}
return false;
}
}
}
//Clear pre-identified obstructions
for (BlockPos obstruction : obstructionsCoordsList) {
Block obstructionBlock = world.getBlock(obstruction.getX(), obstruction.getY(), obstruction.getZ());
int obstructionMeta = world.getBlockMetadata(obstruction.getX(), obstruction.getY(), obstruction.getZ());
float chance = obstructionBlock instanceof BlockSnow ? -1.0f : 1.0f;

obstructionBlock.dropBlockAsItemWithChance(world, obstruction.getX() - xoffset, obstruction.getY() - yoffset, obstruction.getZ() - zoffset, obstructionMeta, chance, 0);
obstructionBlock.dropBlockAsItem(world, obstruction.getX(), obstruction.getY(), obstruction.getZ(), obstructionMeta, 0);
float chance = obstructionBlock instanceof BlockSnow ? -1.0F : 1.0F;

obstructionBlock.dropBlockAsItemWithChance(world, obstruction.getX(), obstruction.getY(), obstruction.getZ(), obstructionMeta, chance, 0);
world.setBlockToAir(obstruction.getX(), obstruction.getY(), obstruction.getZ());
}

Expand Down

0 comments on commit d092227

Please sign in to comment.