3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Fix for block breaking

Dieser Commit ist enthalten in:
AJ Ferguson 2019-09-30 14:17:36 -08:00
Ursprung da0c59446f
Commit fe845710b6
2 geänderte Dateien mit 21 neuen und 59 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

@ -80,69 +80,36 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
ClientPlayerActionPacket dropItemPacket = new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, position, BlockFace.values()[packet.getFace()]); ClientPlayerActionPacket dropItemPacket = new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, position, BlockFace.values()[packet.getFace()]);
session.getDownstream().getSession().send(dropItemPacket); session.getDownstream().getSession().send(dropItemPacket);
break; break;
case STOP_SLEEP: case STOP_SLEEP:
ClientPlayerStatePacket stopSleepingPacket = new ClientPlayerStatePacket((int) session.getPlayerEntity().getGeyserId(), PlayerState.LEAVE_BED); ClientPlayerStatePacket stopSleepingPacket = new ClientPlayerStatePacket((int) session.getPlayerEntity().getGeyserId(), PlayerState.LEAVE_BED);
session.getDownstream().getSession().send(stopSleepingPacket); session.getDownstream().getSession().send(stopSleepingPacket);
break; break;
case BLOCK_INTERACT: case BLOCK_INTERACT:
ClientPlayerPlaceBlockPacket blockPacket = new ClientPlayerPlaceBlockPacket(position, ClientPlayerPlaceBlockPacket blockPacket = new ClientPlayerPlaceBlockPacket(position,
BlockFace.values()[packet.getFace()], BlockFace.values()[packet.getFace()],
Hand.MAIN_HAND, 0, 0, 0, false); Hand.MAIN_HAND, 0, 0, 0, false);
session.getDownstream().getSession().send(blockPacket); session.getDownstream().getSession().send(blockPacket);
break; break;
case START_BREAK: case START_BREAK:
System.out.println("a"); ClientPlayerActionPacket startBreakingPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, new Position(packet.getBlockPosition().getX(),
ClientPlayerActionPacket actionPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, position, BlockFace.values()[1]); packet.getBlockPosition().getY(), packet.getBlockPosition().getZ()), BlockFace.values()[packet.getFace()]);
session.getDownstream().getSession().send(actionPacket); session.setBlockDiggingPos(packet.getBlockPosition());
session.setBlockDiggingFace(BlockFace.values()[packet.getFace()]);
session.setThreadStop(false); session.getDownstream().getSession().send(startBreakingPacket);
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();
break; 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: case CONTINUE_BREAK:
System.out.println("d"); session.setBlockDiggingFace(BlockFace.values()[packet.getFace()]);
break;
session.setBreaking(true); 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; break;
} }
} }