Skip to content

Commit

Permalink
Fix client crash issue if empty recipe is sent (GeyserMC#4485)
Browse files Browse the repository at this point in the history
* Fix client crash issue if empty recipe is sent

Signed-off-by: Joshua Castle <[email protected]>

* More efficent order

Signed-off-by: Joshua Castle <[email protected]>

* Recipes are recipies

Signed-off-by: Joshua Castle <[email protected]>

---------

Signed-off-by: Joshua Castle <[email protected]>
  • Loading branch information
Kas-tle authored Mar 11, 2024
1 parent 0ad7c43 commit a0fd720
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundRecipePacket;
import org.cloudburstmc.protocol.bedrock.packet.UnlockedRecipesPacket;
import org.geysermc.geyser.network.GameProtocol;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
Expand All @@ -47,12 +46,22 @@ public void translate(GeyserSession session, ClientboundRecipePacket packet) {
recipesPacket.getUnlockedRecipes().addAll(getBedrockRecipes(session, packet.getAlreadyKnownRecipes()));
}
case ADD -> {
List<String> recipes = getBedrockRecipes(session, packet.getRecipes());
if (recipes.isEmpty()) {
// Sending an empty list here packet will crash the client as of 1.20.60
return;
}
recipesPacket.setAction(UnlockedRecipesPacket.ActionType.NEWLY_UNLOCKED);
recipesPacket.getUnlockedRecipes().addAll(getBedrockRecipes(session, packet.getRecipes()));
recipesPacket.getUnlockedRecipes().addAll(recipes);
}
case REMOVE -> {
List<String> recipes = getBedrockRecipes(session, packet.getRecipes());
if (recipes.isEmpty()) {
// Sending an empty list here will crash the client as of 1.20.60
return;
}
recipesPacket.setAction(UnlockedRecipesPacket.ActionType.REMOVE_UNLOCKED);
recipesPacket.getUnlockedRecipes().addAll(getBedrockRecipes(session, packet.getRecipes()));
recipesPacket.getUnlockedRecipes().addAll(recipes);
}
}
session.sendUpstreamPacket(recipesPacket);
Expand All @@ -70,5 +79,4 @@ private List<String> getBedrockRecipes(GeyserSession session, String[] javaRecip
}
return recipes;
}
}

}

0 comments on commit a0fd720

Please sign in to comment.