mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 16:37:38 +01:00
fix: shaped recipe protocol reorder
(cherry picked from commit 9d6752c86f
)
This commit is contained in:
parent
f80d11d719
commit
a14dbf5cdd
@ -10,15 +10,23 @@ import net.minestom.demo.block.placement.DripstonePlacementRule;
|
|||||||
import net.minestom.demo.commands.*;
|
import net.minestom.demo.commands.*;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.command.CommandManager;
|
import net.minestom.server.command.CommandManager;
|
||||||
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.event.server.ServerListPingEvent;
|
import net.minestom.server.event.server.ServerListPingEvent;
|
||||||
import net.minestom.server.extras.lan.OpenToLAN;
|
import net.minestom.server.extras.lan.OpenToLAN;
|
||||||
import net.minestom.server.extras.lan.OpenToLANConfig;
|
import net.minestom.server.extras.lan.OpenToLANConfig;
|
||||||
import net.minestom.server.instance.block.BlockManager;
|
import net.minestom.server.instance.block.BlockManager;
|
||||||
|
import net.minestom.server.item.ItemStack;
|
||||||
|
import net.minestom.server.item.Material;
|
||||||
|
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
|
||||||
import net.minestom.server.ping.ResponseData;
|
import net.minestom.server.ping.ResponseData;
|
||||||
|
import net.minestom.server.recipe.RecipeCategory;
|
||||||
|
import net.minestom.server.recipe.ShapedRecipe;
|
||||||
import net.minestom.server.utils.identity.NamedAndIdentified;
|
import net.minestom.server.utils.identity.NamedAndIdentified;
|
||||||
import net.minestom.server.utils.time.TimeUnit;
|
import net.minestom.server.utils.time.TimeUnit;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
@ -105,6 +113,22 @@ public class Main {
|
|||||||
//responseData.setPlayersHidden(true);
|
//responseData.setPlayersHidden(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var ironBlockRecipe = new ShapedRecipe(
|
||||||
|
"minestom:test", 2, 2, "",
|
||||||
|
RecipeCategory.Crafting.MISC,
|
||||||
|
List.of(
|
||||||
|
new DeclareRecipesPacket.Ingredient(List.of(ItemStack.of(Material.IRON_INGOT))),
|
||||||
|
new DeclareRecipesPacket.Ingredient(List.of(ItemStack.of(Material.IRON_INGOT))),
|
||||||
|
new DeclareRecipesPacket.Ingredient(List.of(ItemStack.of(Material.IRON_INGOT))),
|
||||||
|
new DeclareRecipesPacket.Ingredient(List.of(ItemStack.of(Material.IRON_INGOT)))
|
||||||
|
), ItemStack.of(Material.IRON_BLOCK), true) {
|
||||||
|
@Override
|
||||||
|
public boolean shouldShow(@NotNull Player player) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
MinecraftServer.getRecipeManager().addRecipe(ironBlockRecipe);
|
||||||
|
|
||||||
PlayerInit.init();
|
PlayerInit.init();
|
||||||
|
|
||||||
// VelocityProxy.enable("abcdef");
|
// VelocityProxy.enable("abcdef");
|
||||||
|
@ -89,16 +89,16 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public record DeclaredShapedCraftingRecipe(@NotNull String recipeId, int width, int height,
|
public record DeclaredShapedCraftingRecipe(@NotNull String recipeId,
|
||||||
@NotNull String group, @NotNull RecipeCategory.Crafting category,
|
@NotNull String group, @NotNull RecipeCategory.Crafting category,
|
||||||
@NotNull List<Ingredient> ingredients,
|
int width, int height, @NotNull List<Ingredient> ingredients,
|
||||||
@NotNull ItemStack result, boolean showNotification) implements DeclaredRecipe {
|
@NotNull ItemStack result, boolean showNotification) implements DeclaredRecipe {
|
||||||
public DeclaredShapedCraftingRecipe {
|
public DeclaredShapedCraftingRecipe {
|
||||||
ingredients = List.copyOf(ingredients);
|
ingredients = List.copyOf(ingredients);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DeclaredShapedCraftingRecipe(DeclaredShapedCraftingRecipe packet) {
|
private DeclaredShapedCraftingRecipe(DeclaredShapedCraftingRecipe packet) {
|
||||||
this(packet.recipeId, packet.width, packet.height, packet.group, packet.category, packet.ingredients, packet.result, packet.showNotification);
|
this(packet.recipeId, packet.group, packet.category, packet.width, packet.height, packet.ingredients, packet.result, packet.showNotification);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeclaredShapedCraftingRecipe(@NotNull NetworkBuffer reader) {
|
public DeclaredShapedCraftingRecipe(@NotNull NetworkBuffer reader) {
|
||||||
@ -108,25 +108,25 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
|
|||||||
private static DeclaredShapedCraftingRecipe read(@NotNull NetworkBuffer reader) {
|
private static DeclaredShapedCraftingRecipe read(@NotNull NetworkBuffer reader) {
|
||||||
|
|
||||||
String recipeId = reader.read(STRING);
|
String recipeId = reader.read(STRING);
|
||||||
int width = reader.read(VAR_INT);
|
|
||||||
int height = reader.read(VAR_INT);
|
|
||||||
String group = reader.read(STRING);
|
String group = reader.read(STRING);
|
||||||
RecipeCategory.Crafting category = reader.readEnum(RecipeCategory.Crafting.class);
|
RecipeCategory.Crafting category = reader.readEnum(RecipeCategory.Crafting.class);
|
||||||
|
int width = reader.read(VAR_INT);
|
||||||
|
int height = reader.read(VAR_INT);
|
||||||
List<Ingredient> ingredients = new ArrayList<>();
|
List<Ingredient> ingredients = new ArrayList<>();
|
||||||
for (int slot = 0; slot < width * height; slot++) {
|
for (int slot = 0; slot < width * height; slot++) {
|
||||||
ingredients.add(new Ingredient(reader));
|
ingredients.add(new Ingredient(reader));
|
||||||
}
|
}
|
||||||
ItemStack result = reader.read(ITEM);
|
ItemStack result = reader.read(ITEM);
|
||||||
boolean showNotification = reader.read(BOOLEAN);
|
boolean showNotification = reader.read(BOOLEAN);
|
||||||
return new DeclaredShapedCraftingRecipe(recipeId, width, height, group, category, ingredients, result, showNotification);
|
return new DeclaredShapedCraftingRecipe(recipeId, group, category, width, height, ingredients, result, showNotification);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(@NotNull NetworkBuffer writer) {
|
public void write(@NotNull NetworkBuffer writer) {
|
||||||
writer.write(VAR_INT, width);
|
|
||||||
writer.write(VAR_INT, height);
|
|
||||||
writer.write(STRING, group);
|
writer.write(STRING, group);
|
||||||
writer.writeEnum(RecipeCategory.Crafting.class, category);
|
writer.writeEnum(RecipeCategory.Crafting.class, category);
|
||||||
|
writer.write(VAR_INT, width);
|
||||||
|
writer.write(VAR_INT, height);
|
||||||
for (Ingredient ingredient : ingredients) {
|
for (Ingredient ingredient : ingredients) {
|
||||||
ingredient.write(writer);
|
ingredient.write(writer);
|
||||||
}
|
}
|
||||||
|
@ -59,10 +59,10 @@ public class RecipeManager {
|
|||||||
recipesCache.add(
|
recipesCache.add(
|
||||||
new DeclareRecipesPacket.DeclaredShapedCraftingRecipe(
|
new DeclareRecipesPacket.DeclaredShapedCraftingRecipe(
|
||||||
shapedRecipe.getRecipeId(),
|
shapedRecipe.getRecipeId(),
|
||||||
shapedRecipe.getWidth(),
|
|
||||||
shapedRecipe.getHeight(),
|
|
||||||
shapedRecipe.getGroup(),
|
shapedRecipe.getGroup(),
|
||||||
shapedRecipe.getCategory(),
|
shapedRecipe.getCategory(),
|
||||||
|
shapedRecipe.getWidth(),
|
||||||
|
shapedRecipe.getHeight(),
|
||||||
shapedRecipe.getIngredients(),
|
shapedRecipe.getIngredients(),
|
||||||
shapedRecipe.getResult(),
|
shapedRecipe.getResult(),
|
||||||
shapedRecipe.getShowNotification()));
|
shapedRecipe.getShowNotification()));
|
||||||
|
@ -18,16 +18,14 @@ import net.minestom.server.network.packet.client.ClientPacket;
|
|||||||
import net.minestom.server.network.packet.client.handshake.ClientHandshakePacket;
|
import net.minestom.server.network.packet.client.handshake.ClientHandshakePacket;
|
||||||
import net.minestom.server.network.packet.server.ServerPacket;
|
import net.minestom.server.network.packet.server.ServerPacket;
|
||||||
import net.minestom.server.network.packet.server.common.DisconnectPacket;
|
import net.minestom.server.network.packet.server.common.DisconnectPacket;
|
||||||
import net.minestom.server.network.packet.server.status.ResponsePacket;
|
|
||||||
import net.minestom.server.network.packet.server.login.LoginDisconnectPacket;
|
import net.minestom.server.network.packet.server.login.LoginDisconnectPacket;
|
||||||
import net.minestom.server.network.packet.server.login.LoginSuccessPacket;
|
import net.minestom.server.network.packet.server.login.LoginSuccessPacket;
|
||||||
import net.minestom.server.network.packet.server.login.SetCompressionPacket;
|
import net.minestom.server.network.packet.server.login.SetCompressionPacket;
|
||||||
import net.minestom.server.network.packet.server.play.*;
|
import net.minestom.server.network.packet.server.play.*;
|
||||||
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket.Ingredient;
|
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket.Ingredient;
|
||||||
import net.minestom.server.network.packet.server.status.PongPacket;
|
import net.minestom.server.network.packet.server.status.PongPacket;
|
||||||
|
import net.minestom.server.network.packet.server.status.ResponsePacket;
|
||||||
import net.minestom.server.recipe.RecipeCategory;
|
import net.minestom.server.recipe.RecipeCategory;
|
||||||
import net.minestom.server.utils.crypto.KeyUtils;
|
|
||||||
import org.apache.commons.net.util.Base64;
|
|
||||||
import org.jglrxavpok.hephaistos.nbt.NBT;
|
import org.jglrxavpok.hephaistos.nbt.NBT;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -96,10 +94,10 @@ public class PacketWriteReadTest {
|
|||||||
),
|
),
|
||||||
new DeclareRecipesPacket.DeclaredShapedCraftingRecipe(
|
new DeclareRecipesPacket.DeclaredShapedCraftingRecipe(
|
||||||
"minecraft:torch",
|
"minecraft:torch",
|
||||||
1,
|
|
||||||
2,
|
|
||||||
"",
|
"",
|
||||||
RecipeCategory.Crafting.MISC,
|
RecipeCategory.Crafting.MISC,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
List.of(new Ingredient(List.of(ItemStack.of(Material.COAL))),
|
List.of(new Ingredient(List.of(ItemStack.of(Material.COAL))),
|
||||||
new Ingredient(List.of(ItemStack.of(Material.STICK)))),
|
new Ingredient(List.of(ItemStack.of(Material.STICK)))),
|
||||||
ItemStack.of(Material.TORCH),
|
ItemStack.of(Material.TORCH),
|
||||||
|
Loading…
Reference in New Issue
Block a user