Skip to content

Commit

Permalink
feat: STart working on server-auth movement & block breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Aug 4, 2023
1 parent 0a32ea8 commit 521fe0b
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
52 changes: 52 additions & 0 deletions Allay-API/src/main/java/cn/allay/api/entity/impl/EntityPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class EntityPlayerBaseComponentImpl extends EntityBaseComponentImpl<EntityPlayer
public static final Identifier IDENTIFIER = EntityBaseComponentImpl.IDENTIFIER;

protected Client client;
protected boolean sprinting;
protected boolean sneaking;
protected boolean swimming;
protected boolean gliding;

public EntityPlayerBaseComponentImpl(EntityInitInfo<EntityPlayer> info, Function<EntityPlayer, AABBdc> aabbGetter) {
super(info, aabbGetter);
Expand Down Expand Up @@ -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;
}
}
}

31 changes: 29 additions & 2 deletions Allay-Server/src/main/java/cn/allay/server/client/AllayClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<PlayerBlockActionData> blockActions) {
if (blockActions.isEmpty()) return;
for (var action : blockActions) {
//TODO
}
}

protected void handleInputData(Set<PlayerAuthInputData> 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*/}
}
}
}
}
}

0 comments on commit 521fe0b

Please sign in to comment.