mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 03:34:43 +02:00
Fix bugs with pistons
This commit improves piston tracking and fixes a couple of bugs with block tracking. Fixes #2043
This commit is contained in:
@ -0,0 +1,47 @@
|
||||
package com.gmail.nossr50.runnables;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.BlockUtils;
|
||||
|
||||
public class PistonTrackerTask extends BukkitRunnable {
|
||||
private List<Block> blocks;
|
||||
private BlockFace direction;
|
||||
private Block futureEmptyBlock;
|
||||
|
||||
public PistonTrackerTask(List<Block> blocks, BlockFace direction, Block futureEmptyBlock) {
|
||||
this.blocks = blocks;
|
||||
this.direction = direction;
|
||||
this.futureEmptyBlock = futureEmptyBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Check to see if futureEmptyBlock is empty - if it isn't; the blocks didn't move
|
||||
if (!BlockUtils.isPistonPiece(futureEmptyBlock.getState())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mcMMO.getPlaceStore().isTrue(futureEmptyBlock)) {
|
||||
mcMMO.getPlaceStore().setFalse(futureEmptyBlock);
|
||||
}
|
||||
|
||||
for (Block b : blocks) {
|
||||
Block nextBlock = b.getRelative(direction);
|
||||
|
||||
if (nextBlock.hasMetadata(mcMMO.blockMetadataKey)) {
|
||||
mcMMO.getPlaceStore().setTrue(nextBlock);
|
||||
nextBlock.removeMetadata(mcMMO.blockMetadataKey, mcMMO.p);
|
||||
}
|
||||
else if (mcMMO.getPlaceStore().isTrue(nextBlock)) {
|
||||
// Block doesn't have metadatakey but isTrue - set it to false
|
||||
mcMMO.getPlaceStore().setFalse(nextBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ package com.gmail.nossr50.runnables;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.PistonMoveReaction;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
@ -21,10 +20,16 @@ public class StickyPistonTrackerTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!BlockUtils.shouldBeWatched(movedBlock.getState()) || movedBlock.getPistonMoveReaction() != PistonMoveReaction.MOVE || !mcMMO.getPlaceStore().isTrue(movedBlock)) {
|
||||
if (!mcMMO.getPlaceStore().isTrue(movedBlock)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!BlockUtils.isPistonPiece(movedBlock.getState())) {
|
||||
// The block didn't move
|
||||
return;
|
||||
}
|
||||
|
||||
// The sticky piston actually pulled the block so move the PlaceStore data
|
||||
mcMMO.getPlaceStore().setFalse(movedBlock);
|
||||
mcMMO.getPlaceStore().setTrue(block.getRelative(direction));
|
||||
}
|
||||
|
Reference in New Issue
Block a user