3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Fix incorrect patterns in loom and DecoderException in beacons (#3090)

* Fix DecoderException when setting beacon effect

* Fix incorrect patterns applied in loom and remove old version stuff
Dieser Commit ist enthalten in:
David Choo 2022-06-26 19:12:43 -04:00 committet von GitHub
Ursprung 00603c5239
Commit 5d29bda7eb
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 7 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -119,7 +119,7 @@ public class BeaconInventoryTranslator extends AbstractBlockInventoryTranslator
} }
private OptionalInt toJava(int effectChoice) { private OptionalInt toJava(int effectChoice) {
return effectChoice == -1 ? OptionalInt.empty() : OptionalInt.of(effectChoice); return effectChoice == 0 ? OptionalInt.empty() : OptionalInt.of(effectChoice);
} }
@Override @Override

Datei anzeigen

@ -60,7 +60,7 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator {
static { static {
// Added from left-to-right then up-to-down in the order Java presents it // Added from left-to-right then up-to-down in the order Java presents it
int index = 1; int index = 0;
PATTERN_TO_INDEX.put("bl", index++); PATTERN_TO_INDEX.put("bl", index++);
PATTERN_TO_INDEX.put("br", index++); PATTERN_TO_INDEX.put("br", index++);
PATTERN_TO_INDEX.put("tl", index++); PATTERN_TO_INDEX.put("tl", index++);
@ -119,15 +119,16 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator {
@Override @Override
protected boolean shouldHandleRequestFirst(StackRequestActionData action, Inventory inventory) { protected boolean shouldHandleRequestFirst(StackRequestActionData action, Inventory inventory) {
// If the LOOM_MATERIAL slot is not empty, we are crafting a pattern that does not come from an item // If the LOOM_MATERIAL slot is not empty, we are crafting a pattern that does not come from an item
// Remove the CRAFT_NON_IMPLEMENTED_DEPRECATED when 1.17.30 is dropped return action.getType() == StackRequestActionType.CRAFT_LOOM && inventory.getItem(2).isEmpty();
return (action.getType() == StackRequestActionType.CRAFT_NON_IMPLEMENTED_DEPRECATED || action.getType() == StackRequestActionType.CRAFT_LOOM)
&& inventory.getItem(2).isEmpty();
} }
@Override @Override
public ItemStackResponsePacket.Response translateSpecialRequest(GeyserSession session, Inventory inventory, ItemStackRequest request) { public ItemStackResponsePacket.Response translateSpecialRequest(GeyserSession session, Inventory inventory, ItemStackRequest request) {
StackRequestActionData headerData = request.getActions()[0]; StackRequestActionData headerData = request.getActions()[0];
StackRequestActionData data = request.getActions()[1]; StackRequestActionData data = request.getActions()[1];
if (!(headerData instanceof CraftLoomStackRequestActionData)) {
return rejectRequest(request);
}
if (!(data instanceof CraftResultsDeprecatedStackRequestActionData craftData)) { if (!(data instanceof CraftResultsDeprecatedStackRequestActionData craftData)) {
return rejectRequest(request); return rejectRequest(request);
} }
@ -136,15 +137,7 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator {
List<NbtMap> newBlockEntityTag = craftData.getResultItems()[0].getTag().getList("Patterns", NbtType.COMPOUND); List<NbtMap> newBlockEntityTag = craftData.getResultItems()[0].getTag().getList("Patterns", NbtType.COMPOUND);
// Get the pattern that the Bedrock client requests - the last pattern in the Patterns list // Get the pattern that the Bedrock client requests - the last pattern in the Patterns list
NbtMap pattern = newBlockEntityTag.get(newBlockEntityTag.size() - 1); NbtMap pattern = newBlockEntityTag.get(newBlockEntityTag.size() - 1);
String bedrockPattern; String bedrockPattern = ((CraftLoomStackRequestActionData) headerData).getPatternId();
if (headerData instanceof CraftLoomStackRequestActionData loomData) {
// Prioritize this if on 1.17.40
// Remove the below if statement when 1.17.30 is dropped
bedrockPattern = loomData.getPatternId();
} else {
bedrockPattern = pattern.getString("Pattern");
}
// Get the Java index of this pattern // Get the Java index of this pattern
int index = PATTERN_TO_INDEX.getOrDefault(bedrockPattern, -1); int index = PATTERN_TO_INDEX.getOrDefault(bedrockPattern, -1);