Fix for block breaking

This commit is contained in:
AJ Ferguson 2019-09-30 14:17:36 -08:00
parent da0c59446f
commit fe845710b6
2 changed files with 21 additions and 59 deletions

View file

@ -32,6 +32,7 @@ import com.flowpowered.math.vector.Vector3i;
import com.github.steveice10.mc.auth.data.GameProfile;
import com.github.steveice10.mc.auth.exception.request.RequestException;
import com.github.steveice10.mc.protocol.MinecraftProtocol;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
import com.github.steveice10.packetlib.Client;
import com.github.steveice10.packetlib.event.session.ConnectedEvent;
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
@ -64,13 +65,6 @@ import java.util.UUID;
@Getter
public class GeyserSession implements Player {
@Getter
@Setter
private volatile boolean breaking;
@Getter
@Setter
private volatile boolean threadStop;
private final GeyserConnector connector;
private final BedrockServerSession upstream;
@ -101,9 +95,10 @@ public class GeyserSession implements Player {
private boolean spawned;
private boolean closed;
@Getter
@Setter
private Thread breakThread;
private Vector3i blockDiggingPos = Vector3i.ZERO;
@Setter
private BlockFace blockDiggingFace = BlockFace.DOWN;
public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServerSession) {
this.connector = connector;

View file

@ -80,69 +80,36 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
ClientPlayerActionPacket dropItemPacket = new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, position, BlockFace.values()[packet.getFace()]);
session.getDownstream().getSession().send(dropItemPacket);
break;
case STOP_SLEEP:
ClientPlayerStatePacket stopSleepingPacket = new ClientPlayerStatePacket((int) session.getPlayerEntity().getGeyserId(), PlayerState.LEAVE_BED);
session.getDownstream().getSession().send(stopSleepingPacket);
break;
case BLOCK_INTERACT:
ClientPlayerPlaceBlockPacket blockPacket = new ClientPlayerPlaceBlockPacket(position,
BlockFace.values()[packet.getFace()],
Hand.MAIN_HAND, 0, 0, 0, false);
session.getDownstream().getSession().send(blockPacket);
break;
case START_BREAK:
System.out.println("a");
ClientPlayerActionPacket actionPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, position, BlockFace.values()[1]);
session.getDownstream().getSession().send(actionPacket);
session.setThreadStop(false);
session.setBreaking(true);
Thread thread = new Thread() {
@Override
public void run() {
while (session.isThreadStop()) {
try {
Thread.sleep(1);
} catch (Exception e) {
e.printStackTrace();
}
if(session.isBreaking()) {
session.setBreaking(false);
} else {
ClientPlayerActionPacket actionPacket = new ClientPlayerActionPacket(PlayerAction.CANCEL_DIGGING, position, BlockFace.values()[1]);
session.getDownstream().getSession().send(actionPacket);
}
}
}
};
session.setBreakThread(thread);
thread.start();
case STOP_BREAK:
System.out.println("b");
session.getBreakThread().stop();
ClientPlayerActionPacket startBreakingPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, new Position(packet.getBlockPosition().getX(),
packet.getBlockPosition().getY(), packet.getBlockPosition().getZ()), BlockFace.values()[packet.getFace()]);
session.setBlockDiggingPos(packet.getBlockPosition());
session.setBlockDiggingFace(BlockFace.values()[packet.getFace()]);
session.getDownstream().getSession().send(startBreakingPacket);
break;
case ABORT_BREAK:
System.out.println("c");
//ClientPlayerActionPacket actionPacket3 = new ClientPlayerActionPacket(PlayerAction.CANCEL_DIGGING, position, BlockFace.values()[1]);
//session.getDownstream().getSession().send(actionPacket3);
break;
case CONTINUE_BREAK:
System.out.println("d");
session.setBreaking(true);
session.setBlockDiggingFace(BlockFace.values()[packet.getFace()]);
break;
case ABORT_BREAK:
ClientPlayerActionPacket abortBreakingPacket = new ClientPlayerActionPacket(PlayerAction.CANCEL_DIGGING, new Position(packet.getBlockPosition().getX(),
packet.getBlockPosition().getY(), packet.getBlockPosition().getZ()), BlockFace.DOWN);
session.getDownstream().getSession().send(abortBreakingPacket);
break;
case STOP_BREAK:
Vector3i pos = session.getBlockDiggingPos();
ClientPlayerActionPacket stopBreakingPacket = new ClientPlayerActionPacket(PlayerAction.FINISH_DIGGING, new Position(pos.getX(),
pos.getY(), pos.getZ()), session.getBlockDiggingFace());
session.getDownstream().getSession().send(stopBreakingPacket);
break;
}
}