Skip to content

Commit

Permalink
Fix slimeblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Creeperface01 committed Oct 12, 2019
1 parent 4fc454d commit 6318c0e
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ public boolean batchDataPacket(DataPacket packet) {
return false;
}

try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
try (Timing ignored = Timings.getSendDataPacketTiming(packet)) {
DataPacketSendEvent event = new DataPacketSendEvent(this, packet);
this.server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
Expand Down
138 changes: 76 additions & 62 deletions src/main/java/cn/nukkit/block/BlockPistonBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.network.protocol.LevelSoundEventPacket;
import cn.nukkit.utils.Faceable;
import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -212,6 +213,7 @@ private boolean doMove(boolean extending) {
}

List<Block> newBlocks = calculator.getBlocksToMove();

attached = newBlocks.stream().map(Vector3::asBlockVector3).collect(Collectors.toList());

BlockFace side = extending ? direction : direction.getOpposite();
Expand Down Expand Up @@ -313,102 +315,114 @@ public boolean canMove() {
if (block instanceof BlockFlowable) {
this.toDestroy.add(this.blockToMove);
return true;
} else {
return false;
}
} else if (!this.addBlockLine(this.blockToMove)) {

return false;
} else {
for (Block b : new ArrayList<>(this.toMove)) {
if (b.getId() == SLIME_BLOCK && !this.addBranchingBlocks(b)) {
return false;
}
}
}

return true;
if (!this.addBlockLine(this.blockToMove)) {
return false;
}

for (int i = 0; i < this.toMove.size(); ++i) {
Block b = this.toMove.get(i);

if (b.getId() == SLIME_BLOCK && !this.addBranchingBlocks(b)) {
return false;
}
}

return true;
}

private boolean addBlockLine(Block origin) {
Block block = origin.clone();

if (block.getId() == AIR) {
return true;
} else if (!canPush(origin, this.moveDirection, false)) {
}

if (!canPush(origin, this.moveDirection, false)) {
return true;
} else if (origin.equals(this.pistonPos)) {
}

if (origin.equals(this.pistonPos)) {
return true;
} else if (this.toMove.contains(origin)) {
}

if (this.toMove.contains(origin)) {
return true;
} else {
int count = 1;
}

if (count + this.toMove.size() > 12) {
return false;
} else {
while (block.getId() == SLIME_BLOCK) {
block = origin.getSide(this.moveDirection.getOpposite(), count);
if (this.toMove.size() >= 12) {
return false;
}

if (block.getId() == AIR || !canPush(block, this.moveDirection, false) || block.equals(this.pistonPos)) {
break;
}
this.toMove.add(block);

++count;
int count = 1;
List<Block> sticked = new ArrayList<>();

if (count + this.toMove.size() > 12) {
return false;
}
}
while (block.getId() == SLIME_BLOCK) {
block = origin.getSide(this.moveDirection.getOpposite(), count);

int blockCount = 0;
if (block.getId() == AIR || !canPush(block, this.moveDirection, false) || block.equals(this.pistonPos)) {
break;
}

for (int step = count - 1; step >= 0; step--) {
this.toMove.add(origin.getSide(this.moveDirection.getOpposite(), step));
++blockCount;
}
if (++count + this.toMove.size() > 12) {
return false;
}

int steps = 1;
sticked.add(block);
}

while (true) {
Block nextBlock = origin.getSide(this.moveDirection, steps);
int index = this.toMove.indexOf(nextBlock);
int stickedCount = sticked.size();

if (index > -1) {
this.reorderListAtCollision(blockCount, index);
if (stickedCount > 0) {
this.toMove.addAll(Lists.reverse(sticked));
}

for (int l = 0; l <= index + blockCount; ++l) {
Block b = this.toMove.get(l);
int step = 1;

if (b.getId() == SLIME_BLOCK && !this.addBranchingBlocks(b)) {
return false;
}
}
while (true) {
Block nextBlock = origin.getSide(this.moveDirection, step);
int index = this.toMove.indexOf(nextBlock);

return true;
}
if (index > -1) {
this.reorderListAtCollision(stickedCount, index);

if (nextBlock.getId() == AIR || nextBlock.equals(armPos)) {
return true;
}
for (int i = 0; i <= index + stickedCount; ++i) {
Block b = this.toMove.get(i);

if (!canPush(nextBlock, this.moveDirection, true) || nextBlock.equals(this.pistonPos)) {
if (b.getId() == SLIME_BLOCK && !this.addBranchingBlocks(b)) {
return false;
}
}

if (nextBlock instanceof BlockFlowable) {
this.toDestroy.add(nextBlock);
return true;
}
return true;
}

if (this.toMove.size() >= 12) {
return false;
}
if (nextBlock.getId() == AIR || nextBlock.equals(armPos)) {
return true;
}

this.toMove.add(nextBlock);
++blockCount;
++steps;
}
if (!canPush(nextBlock, this.moveDirection, true) || nextBlock.equals(this.pistonPos)) {
return false;
}

if (nextBlock instanceof BlockFlowable) {
this.toDestroy.add(nextBlock);
return true;
}

if (this.toMove.size() >= 12) {
return false;
}

this.toMove.add(nextBlock);
++stickedCount;
++step;
}
}

Expand Down

0 comments on commit 6318c0e

Please sign in to comment.