From 521fe0b254b8eaeb331273219268661168230f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=80=E5=93=A5?= <3523206925@qq.com> Date: Sat, 5 Aug 2023 04:09:03 +0800 Subject: [PATCH] feat: STart working on server-auth movement & block breaking --- .../impl/base/EntityPlayerBaseComponent.java | 30 +++++++++++ .../allay/api/entity/impl/EntityPlayer.java | 52 +++++++++++++++++++ .../cn/allay/server/client/AllayClient.java | 31 ++++++++++- 3 files changed, 111 insertions(+), 2 deletions(-) diff --git a/Allay-API/src/main/java/cn/allay/api/entity/component/impl/base/EntityPlayerBaseComponent.java b/Allay-API/src/main/java/cn/allay/api/entity/component/impl/base/EntityPlayerBaseComponent.java index e78509f7c..9c318f19e 100644 --- a/Allay-API/src/main/java/cn/allay/api/entity/component/impl/base/EntityPlayerBaseComponent.java +++ b/Allay-API/src/main/java/cn/allay/api/entity/component/impl/base/EntityPlayerBaseComponent.java @@ -7,4 +7,34 @@ public interface EntityPlayerBaseComponent extends EntityBaseComponent { @Inject Client getClient(); + + @Inject + void setSprinting(boolean sprinting); + + @Inject + boolean isSprinting(); + + @Inject + void setSneaking(boolean sneaking); + + @Inject + boolean isSneaking(); + + @Inject + void setSwimming(boolean swimming); + + @Inject + boolean isSwimming(); + + @Inject + void setGliding(boolean gliding); + + @Inject + boolean isGliding(); + + @Inject + void setCrawling(boolean crawling); + + @Inject + boolean isCrawling(); } diff --git a/Allay-API/src/main/java/cn/allay/api/entity/impl/EntityPlayer.java b/Allay-API/src/main/java/cn/allay/api/entity/impl/EntityPlayer.java index c258cd53c..f38ff3f1f 100644 --- a/Allay-API/src/main/java/cn/allay/api/entity/impl/EntityPlayer.java +++ b/Allay-API/src/main/java/cn/allay/api/entity/impl/EntityPlayer.java @@ -92,6 +92,10 @@ class EntityPlayerBaseComponentImpl extends EntityBaseComponentImpl info, Function aabbGetter) { super(info, aabbGetter); @@ -138,6 +142,54 @@ public BedrockPacket createSpawnPacket() { public Client getClient() { return client; } + + @Override + @Impl + public void setSprinting(boolean sprinting) { + this.sprinting = sprinting; + } + + @Override + @Impl + public boolean isSprinting() { + return sprinting; + } + + @Override + @Impl + public void setSneaking(boolean sneaking) { + this.sneaking = sneaking; + } + + @Override + @Impl + public boolean isSneaking() { + return sneaking; + } + + @Override + @Impl + public void setSwimming(boolean swimming) { + this.swimming = swimming; + } + + @Override + @Impl + public boolean isSwimming() { + return swimming; + } + + @Override + @Impl + public void setGliding(boolean gliding) { + this.gliding = gliding; + } + + @Override + @Impl + public boolean isGliding() { + return gliding; + } } } diff --git a/Allay-Server/src/main/java/cn/allay/server/client/AllayClient.java b/Allay-Server/src/main/java/cn/allay/server/client/AllayClient.java index 151a80afc..2f0e684e7 100644 --- a/Allay-Server/src/main/java/cn/allay/server/client/AllayClient.java +++ b/Allay-Server/src/main/java/cn/allay/server/client/AllayClient.java @@ -249,7 +249,8 @@ private void sendBasicGameData() { //TODO startGamePacket.setItemDefinitions(ItemTypeRegistry.getRegistry().getItemDefinitions()); //TODO: server-auth-movement - startGamePacket.setAuthoritativeMovementMode(AuthoritativeMovementMode.CLIENT); + startGamePacket.setAuthoritativeMovementMode(AuthoritativeMovementMode.SERVER); + startGamePacket.setServerAuthoritativeBlockBreaking(true); startGamePacket.setCommandsEnabled(true); startGamePacket.setMultiplayerGame(true); startGamePacket.setBroadcastingToLan(true); @@ -533,8 +534,34 @@ public PacketSignal handle(MovePlayerPacket packet) { @Override public PacketSignal handle(PlayerAuthInputPacket packet) { - //TODO + handleBlockAction(packet.getPlayerActions()); + handleInputData(packet.getInputData()); return PacketSignal.HANDLED; } + + protected void handleBlockAction(List blockActions) { + if (blockActions.isEmpty()) return; + for (var action : blockActions) { + //TODO + } + } + + protected void handleInputData(Set inputData) { + for (var input : inputData) { + switch (input) { + case START_SPRINTING -> playerEntity.setSprinting(true); + case STOP_SPRINTING -> playerEntity.setSprinting(false); + case START_SNEAKING -> playerEntity.setSneaking(true); + case STOP_SNEAKING -> playerEntity.setSneaking(false); + case START_SWIMMING -> playerEntity.setSwimming(true); + case STOP_SWIMMING -> playerEntity.setSwimming(false); + case START_GLIDING -> playerEntity.setGliding(true); + case STOP_GLIDING -> playerEntity.setGliding(false); + case START_CRAWLING -> playerEntity.setCrawling(true); + case STOP_CRAWLING -> playerEntity.setCrawling(false); + case START_JUMPING -> {/*TODO*/} + } + } + } } }