3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-19 14:30:17 +01:00

Fix inabilty to place items into brewing stand

Dieser Commit ist enthalten in:
AJ Ferguson 2020-07-06 23:44:39 -08:00
Ursprung f68632f433
Commit 50176e10a8
3 geänderte Dateien mit 117 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -47,6 +47,7 @@ import org.geysermc.connector.network.translators.PacketTranslatorRegistry;
import org.geysermc.connector.network.translators.effect.EffectRegistry; import org.geysermc.connector.network.translators.effect.EffectRegistry;
import org.geysermc.connector.network.translators.item.ItemRegistry; import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.item.ItemTranslator; import org.geysermc.connector.network.translators.item.ItemTranslator;
import org.geysermc.connector.network.translators.item.PotionMixRegistry;
import org.geysermc.connector.network.translators.sound.SoundHandlerRegistry; import org.geysermc.connector.network.translators.sound.SoundHandlerRegistry;
import org.geysermc.connector.network.translators.sound.SoundRegistry; import org.geysermc.connector.network.translators.sound.SoundRegistry;
import org.geysermc.connector.network.translators.world.WorldManager; import org.geysermc.connector.network.translators.world.WorldManager;
@ -127,6 +128,7 @@ public class GeyserConnector {
ItemRegistry.init(); ItemRegistry.init();
ItemTranslator.init(); ItemTranslator.init();
LocaleUtils.init(); LocaleUtils.init();
PotionMixRegistry.init();
SoundRegistry.init(); SoundRegistry.init();
SoundHandlerRegistry.init(); SoundHandlerRegistry.init();

Datei anzeigen

@ -0,0 +1,113 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*
*/
package org.geysermc.connector.network.translators.item;
import com.nukkitx.protocol.bedrock.data.inventory.PotionMixData;
import java.util.*;
/**
* Generates a {@link Collection} of {@link PotionMixData} that enables the
* Bedrock client to place brewing items into the brewing stand.
* (Does not contain actual potion mixes.)
*
* Designed to replicate Java Edition behavior.
* (Ex: Bedrock cannot normally place glass bottles or fully upgraded
* potions into the brewing stand, but Java can.)
*/
public class PotionMixRegistry {
public static final Collection<PotionMixData> POTION_MIXES;
private PotionMixRegistry() {
}
public static void init() {
// no-op
}
static {
List<ItemEntry> ingredients = new ArrayList<>();
ingredients.add(getNonNull("minecraft:nether_wart"));
ingredients.add(getNonNull("minecraft:redstone"));
ingredients.add(getNonNull("minecraft:glowstone_dust"));
ingredients.add(getNonNull("minecraft:fermented_spider_eye"));
ingredients.add(getNonNull("minecraft:gunpowder"));
ingredients.add(getNonNull("minecraft:dragon_breath"));
ingredients.add(getNonNull("minecraft:sugar"));
ingredients.add(getNonNull("minecraft:rabbit_foot"));
ingredients.add(getNonNull("minecraft:glistering_melon_slice"));
ingredients.add(getNonNull("minecraft:spider_eye"));
ingredients.add(getNonNull("minecraft:pufferfish"));
ingredients.add(getNonNull("minecraft:magma_cream"));
ingredients.add(getNonNull("minecraft:golden_carrot"));
ingredients.add(getNonNull("minecraft:blaze_powder"));
ingredients.add(getNonNull("minecraft:ghast_tear"));
ingredients.add(getNonNull("minecraft:turtle_helmet"));
ingredients.add(getNonNull("minecraft:phantom_membrane"));
List<ItemEntry> inputs = new ArrayList<>();
inputs.add(getNonNull("minecraft:potion"));
inputs.add(getNonNull("minecraft:splash_potion"));
inputs.add(getNonNull("minecraft:lingering_potion"));
ItemEntry glassBottle = getNonNull("minecraft:glass_bottle");
Set<PotionMixData> potionMixes = new HashSet<>();
// Add all types of potions as inputs
ItemEntry fillerIngredient = ingredients.get(0);
for (ItemEntry input : inputs) {
for (Potion potion : Potion.values()) {
potionMixes.add(new PotionMixData(
input.getBedrockId(), potion.getBedrockId(),
fillerIngredient.getBedrockId(), fillerIngredient.getBedrockData(),
glassBottle.getBedrockId(), glassBottle.getBedrockData())
);
}
}
// Add all brewing ingredients
// Also adds glass bottle as input
for (ItemEntry ingredient : ingredients) {
potionMixes.add(new PotionMixData(
glassBottle.getBedrockId(), glassBottle.getBedrockData(),
ingredient.getBedrockId(), ingredient.getBedrockData(),
glassBottle.getBedrockId(), glassBottle.getBedrockData())
);
}
POTION_MIXES = potionMixes;
}
private static ItemEntry getNonNull(String javaIdentifier) {
ItemEntry itemEntry = ItemRegistry.getItemEntry(javaIdentifier);
if (itemEntry == null)
throw new NullPointerException("No item entry exists for java identifier: " + javaIdentifier);
return itemEntry;
}
}

Datei anzeigen

@ -33,7 +33,6 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDeclareRecip
import com.nukkitx.nbt.NbtMap; import com.nukkitx.nbt.NbtMap;
import com.nukkitx.protocol.bedrock.data.inventory.CraftingData; import com.nukkitx.protocol.bedrock.data.inventory.CraftingData;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import com.nukkitx.protocol.bedrock.data.inventory.PotionMixData;
import com.nukkitx.protocol.bedrock.packet.CraftingDataPacket; import com.nukkitx.protocol.bedrock.packet.CraftingDataPacket;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet; import it.unimi.dsi.fastutil.ints.IntSet;
@ -45,16 +44,13 @@ import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.network.translators.item.ItemEntry; import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.network.translators.item.ItemRegistry; import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.item.ItemTranslator; import org.geysermc.connector.network.translators.item.ItemTranslator;
import org.geysermc.connector.network.translators.item.PotionMixRegistry;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Translator(packet = ServerDeclareRecipesPacket.class) @Translator(packet = ServerDeclareRecipesPacket.class)
public class JavaDeclareRecipesTranslator extends PacketTranslator<ServerDeclareRecipesPacket> { public class JavaDeclareRecipesTranslator extends PacketTranslator<ServerDeclareRecipesPacket> {
private static final Collection<PotionMixData> POTION_MIXES =
Arrays.stream(new int[]{372, 331, 348, 376, 289, 437, 353, 414, 382, 375, 462, 378, 396, 377, 370, 469, 470})
.mapToObj(ingredient -> new PotionMixData(0, ingredient, 0, 0, 0, 0)) //TODO: Confirm this is correct behavior.
.collect(Collectors.toList());
@Override @Override
public void translate(ServerDeclareRecipesPacket packet, GeyserSession session) { public void translate(ServerDeclareRecipesPacket packet, GeyserSession session) {
@ -89,7 +85,7 @@ public class JavaDeclareRecipesTranslator extends PacketTranslator<ServerDeclare
} }
} }
} }
craftingDataPacket.getPotionMixData().addAll(POTION_MIXES); craftingDataPacket.getPotionMixData().addAll(PotionMixRegistry.POTION_MIXES);
session.sendUpstreamPacket(craftingDataPacket); session.sendUpstreamPacket(craftingDataPacket);
} }