Skip to content

Commit

Permalink
Implement shapeless/complex recipes; fix crawling
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Oct 27, 2024
1 parent c9eeed9 commit 198eeac
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.entity.GeyserDirtyMetadata;
import org.geysermc.geyser.entity.properties.GeyserEntityPropertyManager;
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity;
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.scoreboard.Team;
import org.geysermc.geyser.session.GeyserSession;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket;
import org.cloudburstmc.protocol.bedrock.packet.NetworkSettingsPacket;
import org.cloudburstmc.protocol.bedrock.packet.PlayStatusPacket;
import org.cloudburstmc.protocol.bedrock.packet.PlayerAuthInputPacket;
import org.cloudburstmc.protocol.bedrock.packet.RequestNetworkSettingsPacket;
import org.cloudburstmc.protocol.bedrock.packet.ResourcePackChunkDataPacket;
import org.cloudburstmc.protocol.bedrock.packet.ResourcePackChunkRequestPacket;
Expand All @@ -64,6 +65,7 @@
import org.geysermc.geyser.registry.Registries;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.PendingMicrosoftAuthentication;
import org.geysermc.geyser.text.ChatColor;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.util.LoginEncryptionUtils;
import org.geysermc.geyser.util.MathUtils;
Expand Down Expand Up @@ -94,6 +96,11 @@ public UpstreamPacketHandler(GeyserImpl geyser, GeyserSession session) {
}

private PacketSignal translateAndDefault(BedrockPacket packet) {
if (packet instanceof PlayerAuthInputPacket) {
//System.out.println(packet);
} else {
System.out.println(ChatColor.toANSI(ChatColor.GREEN) + packet + ChatColor.ANSI_RESET);
}
Registries.BEDROCK_PACKET_TRANSLATORS.translate(packet.getClass(), packet, session);
return PacketSignal.HANDLED; // PacketSignal.UNHANDLED will log a WARN publicly
}
Expand Down
18 changes: 16 additions & 2 deletions core/src/main/java/org/geysermc/geyser/session/GeyserSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -1371,14 +1371,28 @@ private void setSneakingPose(boolean sneaking) {
}

public void setSwimming(boolean swimming) {
if (swimming) {
if (!swimming && playerEntity.getFlag(EntityFlag.CRAWLING)) {
// Do not update bounding box.
playerEntity.setFlag(EntityFlag.SWIMMING, false);
playerEntity.updateBedrockMetadata();
return;
}
toggleSwimmingPose(swimming, EntityFlag.SWIMMING);
}

public void setCrawling(boolean crawling) {
toggleSwimmingPose(crawling, EntityFlag.CRAWLING);
}

private void toggleSwimmingPose(boolean crawling, EntityFlag flag) {
if (crawling) {
this.pose = Pose.SWIMMING;
playerEntity.setBoundingBoxHeight(0.6f);
} else {
this.pose = Pose.STANDING;
playerEntity.setBoundingBoxHeight(playerEntity.getDefinition().height());
}
playerEntity.setFlag(EntityFlag.SWIMMING, swimming);
playerEntity.setFlag(flag, crawling);
playerEntity.updateBedrockMetadata();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public void translate(GeyserSession session, AnimatePacket packet) {
return;
}

System.out.println("wewewewewewewewewewewe");
if (packet.getAction() == AnimatePacket.Action.SWING_ARM) {
session.armSwingPending();
// Delay so entity damage can be processed first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@
import org.cloudburstmc.protocol.bedrock.data.PlayerActionType;
import org.cloudburstmc.protocol.bedrock.data.PlayerBlockActionData;
import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition;
import org.cloudburstmc.protocol.bedrock.packet.AnimatePacket;
import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket;
import org.cloudburstmc.protocol.bedrock.packet.PlayStatusPacket;
import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket;
import org.geysermc.geyser.api.block.custom.CustomBlockState;
import org.geysermc.geyser.entity.type.Entity;
import org.geysermc.geyser.entity.type.ItemFrameEntity;
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity;
import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.level.block.Blocks;
import org.geysermc.geyser.level.block.type.Block;
Expand All @@ -49,32 +45,28 @@
import org.geysermc.geyser.session.cache.SkullCache;
import org.geysermc.geyser.translator.item.CustomItemTranslator;
import org.geysermc.geyser.util.BlockUtils;
import org.geysermc.geyser.util.CooldownUtils;
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.InteractAction;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PlayerAction;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundInteractPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundSwingPacket;

import java.util.List;

final class BedrockBlockActions {

static void translate(GeyserSession session, List<PlayerBlockActionData> playerActions) {
SessionPlayerEntity entity = session.getPlayerEntity();

// Send book update before any player action
session.getBookEditCache().checkForSend();

for (PlayerBlockActionData blockActionData : playerActions) {
handle(session, entity, blockActionData);
handle(session, blockActionData);
}
}

private static void handle(GeyserSession session, SessionPlayerEntity entity, PlayerBlockActionData blockActionData) {
private static void handle(GeyserSession session, PlayerBlockActionData blockActionData) {
PlayerActionType action = blockActionData.getAction();
Vector3i vector = blockActionData.getBlockPosition();
int blockFace = blockActionData.getFace();
Expand Down Expand Up @@ -198,34 +190,6 @@ private static void handle(GeyserSession session, SessionPlayerEntity entity, Pl
// Handled in BedrockInventoryTransactionTranslator
case STOP_BREAK -> {
}
case DIMENSION_CHANGE_SUCCESS -> {
//sometimes the client doesn't feel like loading
PlayStatusPacket spawnPacket = new PlayStatusPacket();
spawnPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
session.sendUpstreamPacket(spawnPacket);

UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
attributesPacket.setRuntimeEntityId(entity.getGeyserId());
attributesPacket.getAttributes().addAll(entity.getAttributes().values());
session.sendUpstreamPacket(attributesPacket);
}
case MISSED_SWING -> {
// Java edition sends a cooldown when hitting air.
// Normally handled by BedrockLevelSoundEventTranslator, but there is no sound on Java for this.
CooldownUtils.sendCooldown(session);

// TODO Re-evaluate after pre-1.20.10 is no longer supported?
if (session.getArmAnimationTicks() == -1) {
session.sendDownstreamGamePacket(new ServerboundSwingPacket(Hand.MAIN_HAND));
session.activateArmAnimationTicking();

// Send packet to Bedrock so it knows
AnimatePacket animatePacket = new AnimatePacket();
animatePacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId());
animatePacket.setAction(AnimatePacket.Action.SWING_ARM);
session.sendUpstreamPacket(animatePacket);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.cloudburstmc.math.vector.Vector3i;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType;
import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket;
import org.cloudburstmc.protocol.bedrock.packet.PlayStatusPacket;
import org.cloudburstmc.protocol.bedrock.packet.PlayerActionPacket;
import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket;
import org.geysermc.geyser.entity.type.Entity;
Expand Down Expand Up @@ -103,6 +104,18 @@ public void translate(GeyserSession session, PlayerActionPacket packet) {
session.sendDownstreamGamePacket(interactPacket);
}
}
case DIMENSION_CHANGE_SUCCESS -> {
SessionPlayerEntity entity = session.getPlayerEntity();
// Sometimes the client doesn't feel like loading
PlayStatusPacket spawnPacket = new PlayStatusPacket();
spawnPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
session.sendUpstreamPacket(spawnPacket);

UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
attributesPacket.setRuntimeEntityId(entity.getGeyserId());
attributesPacket.getAttributes().addAll(entity.getAttributes().values());
session.sendUpstreamPacket(attributesPacket);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.geyser.translator.protocol.bedrock.BedrockInventoryTransactionTranslator;
import org.geysermc.geyser.util.CooldownUtils;
import org.geysermc.geyser.util.MathUtils;
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
Expand All @@ -65,18 +66,23 @@

@Translator(packet = PlayerAuthInputPacket.class)
public final class BedrockPlayerAuthInputTranslator extends PacketTranslator<PlayerAuthInputPacket> {
private Set<PlayerAuthInputData> data = Set.of();

@Override
public void translate(GeyserSession session, PlayerAuthInputPacket packet) {
if (!data.equals(packet.getInputData())) {
System.out.println(data);
this.data = packet.getInputData();
}
SessionPlayerEntity entity = session.getPlayerEntity();

boolean wasJumping = session.getInputCache().wasJumping();
session.getInputCache().processInputs(packet);

processVehicleInput(session, packet, wasJumping);

BedrockMovePlayerTranslator.translate(session, packet);

processVehicleInput(session, packet, wasJumping);

Set<PlayerAuthInputData> inputData = packet.getInputData();
for (PlayerAuthInputData input : inputData) {
switch (input) {
Expand Down Expand Up @@ -110,6 +116,8 @@ public void translate(GeyserSession session, PlayerAuthInputPacket packet) {
}
case START_SWIMMING -> session.setSwimming(true);
case STOP_SWIMMING -> session.setSwimming(false);
case START_CRAWLING -> session.setCrawling(true);
case STOP_CRAWLING -> session.setCrawling(false);
case START_FLYING -> { // Since 1.20.30
if (session.isCanFly()) {
if (session.getGameMode() == GameMode.SPECTATOR) {
Expand Down Expand Up @@ -151,6 +159,7 @@ public void translate(GeyserSession session, PlayerAuthInputPacket packet) {
sendPlayerGlideToggle(session, entity);
}
case STOP_GLIDING -> sendPlayerGlideToggle(session, entity);
case MISSED_SWING -> CooldownUtils.sendCooldown(session); // Java edition sends a cooldown when hitting air.
}
}
if (entity.getVehicle() instanceof BoatEntity) {
Expand Down Expand Up @@ -249,7 +258,7 @@ private static void processVehicleInput(GeyserSession session, PlayerAuthInputPa
if (currentJumpingTicks < 0) {
session.getInputCache().setJumpingTicks(++currentJumpingTicks);
if (currentJumpingTicks == 0) {
session.getPlayerEntity().setVehicleJumpStrength(0);
session.getInputCache().setJumpScale(0);
}
}

Expand Down
Loading

0 comments on commit 198eeac

Please sign in to comment.