Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-16 04:50:07 +01:00
Somewhat fix: firework recipe not showing up in recipe book (#4873)
* Somewhat fix firework crafting * Use instanceof instead of casting
Dieser Commit ist enthalten in:
Ursprung
f62cef7acb
Commit
96f00981df
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 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.geyser.item.type;
|
||||||
|
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
|
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
||||||
|
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
|
||||||
|
|
||||||
|
public interface BedrockRequiresTagItem {
|
||||||
|
|
||||||
|
void addRequiredNbt(GeyserSession session, @Nullable DataComponents components, BedrockItemBuilder builder);
|
||||||
|
}
|
@ -27,6 +27,8 @@ package org.geysermc.geyser.item.type;
|
|||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrays;
|
import it.unimi.dsi.fastutil.ints.IntArrays;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.cloudburstmc.nbt.NbtList;
|
||||||
import org.cloudburstmc.nbt.NbtMap;
|
import org.cloudburstmc.nbt.NbtMap;
|
||||||
import org.cloudburstmc.nbt.NbtMapBuilder;
|
import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||||
import org.cloudburstmc.nbt.NbtType;
|
import org.cloudburstmc.nbt.NbtType;
|
||||||
@ -41,7 +43,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.item.component.Fireworks;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class FireworkRocketItem extends Item {
|
public class FireworkRocketItem extends Item implements BedrockRequiresTagItem {
|
||||||
public FireworkRocketItem(String javaIdentifier, Builder builder) {
|
public FireworkRocketItem(String javaIdentifier, Builder builder) {
|
||||||
super(javaIdentifier, builder);
|
super(javaIdentifier, builder);
|
||||||
}
|
}
|
||||||
@ -58,14 +60,16 @@ public class FireworkRocketItem extends Item {
|
|||||||
fireworksNbt.putByte("Flight", (byte) fireworks.getFlightDuration());
|
fireworksNbt.putByte("Flight", (byte) fireworks.getFlightDuration());
|
||||||
|
|
||||||
List<Fireworks.FireworkExplosion> explosions = fireworks.getExplosions();
|
List<Fireworks.FireworkExplosion> explosions = fireworks.getExplosions();
|
||||||
if (explosions.isEmpty()) {
|
if (!explosions.isEmpty()) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<NbtMap> explosionNbt = new ArrayList<>();
|
List<NbtMap> explosionNbt = new ArrayList<>();
|
||||||
for (Fireworks.FireworkExplosion explosion : explosions) {
|
for (Fireworks.FireworkExplosion explosion : explosions) {
|
||||||
explosionNbt.add(translateExplosionToBedrock(explosion));
|
explosionNbt.add(translateExplosionToBedrock(explosion));
|
||||||
}
|
}
|
||||||
fireworksNbt.putList("Explosions", NbtType.COMPOUND, explosionNbt);
|
fireworksNbt.putList("Explosions", NbtType.COMPOUND, explosionNbt);
|
||||||
|
} else {
|
||||||
|
// This is the default firework
|
||||||
|
fireworksNbt.put("Explosions", NbtList.EMPTY);
|
||||||
|
}
|
||||||
builder.putCompound("Fireworks", fireworksNbt.build());
|
builder.putCompound("Fireworks", fireworksNbt.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,4 +142,20 @@ public class FireworkRocketItem extends Item {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addRequiredNbt(GeyserSession session, @Nullable DataComponents components, BedrockItemBuilder builder) {
|
||||||
|
if (components != null) {
|
||||||
|
Fireworks fireworks = components.get(DataComponentType.FIREWORKS);
|
||||||
|
if (fireworks != null) {
|
||||||
|
// Already translated
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NbtMapBuilder fireworksNbt = NbtMap.builder();
|
||||||
|
fireworksNbt.putByte("Flight", (byte) 1);
|
||||||
|
fireworksNbt.put("Explosions", NbtList.EMPTY);
|
||||||
|
builder.putCompound("Fireworks", fireworksNbt.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ import org.geysermc.geyser.inventory.GeyserItemStack;
|
|||||||
import org.geysermc.geyser.item.Items;
|
import org.geysermc.geyser.item.Items;
|
||||||
import org.geysermc.geyser.item.components.Rarity;
|
import org.geysermc.geyser.item.components.Rarity;
|
||||||
import org.geysermc.geyser.item.type.Item;
|
import org.geysermc.geyser.item.type.Item;
|
||||||
|
import org.geysermc.geyser.item.type.BedrockRequiresTagItem;
|
||||||
import org.geysermc.geyser.level.block.type.Block;
|
import org.geysermc.geyser.level.block.type.Block;
|
||||||
import org.geysermc.geyser.registry.BlockRegistries;
|
import org.geysermc.geyser.registry.BlockRegistries;
|
||||||
import org.geysermc.geyser.registry.Registries;
|
import org.geysermc.geyser.registry.Registries;
|
||||||
@ -148,6 +149,12 @@ public final class ItemTranslator {
|
|||||||
if (components.get(DataComponentType.HIDE_TOOLTIP) != null) hideTooltips = true;
|
if (components.get(DataComponentType.HIDE_TOOLTIP) != null) hideTooltips = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fixes fireworks crafting recipe: they always contain a tag
|
||||||
|
// TODO remove once all items have their default components
|
||||||
|
if (javaItem instanceof BedrockRequiresTagItem requiresTagItem) {
|
||||||
|
requiresTagItem.addRequiredNbt(session, components, nbtBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
Rarity rarity = javaItem.rarity();
|
Rarity rarity = javaItem.rarity();
|
||||||
boolean enchantmentGlint = javaItem.glint();
|
boolean enchantmentGlint = javaItem.glint();
|
||||||
if (components != null) {
|
if (components != null) {
|
||||||
|
@ -25,7 +25,11 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.translator.protocol.java;
|
package org.geysermc.geyser.translator.protocol.java;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.*;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntIterator;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition;
|
import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition;
|
||||||
@ -40,7 +44,11 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.descriptor.ItemTagDescri
|
|||||||
import org.cloudburstmc.protocol.bedrock.packet.CraftingDataPacket;
|
import org.cloudburstmc.protocol.bedrock.packet.CraftingDataPacket;
|
||||||
import org.cloudburstmc.protocol.bedrock.packet.TrimDataPacket;
|
import org.cloudburstmc.protocol.bedrock.packet.TrimDataPacket;
|
||||||
import org.geysermc.geyser.GeyserImpl;
|
import org.geysermc.geyser.GeyserImpl;
|
||||||
import org.geysermc.geyser.inventory.recipe.*;
|
import org.geysermc.geyser.inventory.recipe.GeyserRecipe;
|
||||||
|
import org.geysermc.geyser.inventory.recipe.GeyserShapedRecipe;
|
||||||
|
import org.geysermc.geyser.inventory.recipe.GeyserShapelessRecipe;
|
||||||
|
import org.geysermc.geyser.inventory.recipe.GeyserStonecutterData;
|
||||||
|
import org.geysermc.geyser.inventory.recipe.TrimRecipe;
|
||||||
import org.geysermc.geyser.registry.Registries;
|
import org.geysermc.geyser.registry.Registries;
|
||||||
import org.geysermc.geyser.registry.type.ItemMapping;
|
import org.geysermc.geyser.registry.type.ItemMapping;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
@ -58,7 +66,17 @@ import org.geysermc.mcprotocollib.protocol.data.game.recipe.data.SmithingTransfo
|
|||||||
import org.geysermc.mcprotocollib.protocol.data.game.recipe.data.StoneCuttingRecipeData;
|
import org.geysermc.mcprotocollib.protocol.data.game.recipe.data.StoneCuttingRecipeData;
|
||||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundUpdateRecipesPacket;
|
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundUpdateRecipesPacket;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.geysermc.geyser.util.InventoryUtils.LAST_RECIPE_NET_ID;
|
import static org.geysermc.geyser.util.InventoryUtils.LAST_RECIPE_NET_ID;
|
||||||
@ -191,6 +209,9 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
|
|||||||
case CRAFTING_SPECIAL_MAPCLONING -> {
|
case CRAFTING_SPECIAL_MAPCLONING -> {
|
||||||
craftingDataPacket.getCraftingData().add(MultiRecipeData.of(UUID.fromString("85939755-ba10-4d9d-a4cc-efb7a8e943c4"), context.getAndIncrementNetId()));
|
craftingDataPacket.getCraftingData().add(MultiRecipeData.of(UUID.fromString("85939755-ba10-4d9d-a4cc-efb7a8e943c4"), context.getAndIncrementNetId()));
|
||||||
}
|
}
|
||||||
|
case CRAFTING_SPECIAL_FIREWORK_ROCKET -> {
|
||||||
|
craftingDataPacket.getCraftingData().add(MultiRecipeData.of(UUID.fromString("00000000-0000-0000-0000-000000000002"), context.getAndIncrementNetId()));
|
||||||
|
}
|
||||||
default -> {
|
default -> {
|
||||||
List<GeyserRecipe> recipes = Registries.RECIPES.get(recipe.getType());
|
List<GeyserRecipe> recipes = Registries.RECIPES.get(recipe.getType());
|
||||||
if (recipes != null) {
|
if (recipes != null) {
|
||||||
@ -427,7 +448,7 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// Strip NBT - tools won't appear in the recipe book otherwise
|
// Strip NBT - tools won't appear in the recipe book otherwise
|
||||||
output = output.toBuilder().tag(null).build();
|
// output = output.toBuilder().tag(null).build(); // TODO confirm???
|
||||||
ItemDescriptorWithCount[][] inputCombinations = combinations(session, recipe.ingredients());
|
ItemDescriptorWithCount[][] inputCombinations = combinations(session, recipe.ingredients());
|
||||||
if (inputCombinations == null) {
|
if (inputCombinations == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -451,7 +472,7 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// Strip NBT - tools won't appear in the recipe book otherwise
|
// Strip NBT - tools won't appear in the recipe book otherwise
|
||||||
output = output.toBuilder().tag(null).build();
|
//output = output.toBuilder().tag(null).build(); // TODO confirm this is still true???
|
||||||
ItemDescriptorWithCount[][] inputCombinations = combinations(session, recipe.ingredients());
|
ItemDescriptorWithCount[][] inputCombinations = combinations(session, recipe.ingredients());
|
||||||
if (inputCombinations == null) {
|
if (inputCombinations == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -475,7 +496,7 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// See above
|
// See above
|
||||||
output = output.toBuilder().tag(null).build();
|
//output = output.toBuilder().tag(null).build();
|
||||||
ItemDescriptorWithCount[][] inputCombinations = combinations(session, recipe.ingredients());
|
ItemDescriptorWithCount[][] inputCombinations = combinations(session, recipe.ingredients());
|
||||||
if (inputCombinations == null) {
|
if (inputCombinations == null) {
|
||||||
return null;
|
return null;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren