forked from GeyserMC/Geyser
Fix for block breaking
This commit is contained in:
parent
da0c59446f
commit
fe845710b6
2 changed files with 21 additions and 59 deletions
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue