Skip to content

Commit

Permalink
Use mcpl staticify PR (#5284)
Browse files Browse the repository at this point in the history
* Use mcpl staticify PR

* Fix missing generic arg

* Update libs.versions.toml
  • Loading branch information
AlexProgrammerDE authored Jan 21, 2025
1 parent 98f9bf6 commit 5836dab
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponent;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.ItemCodecHelper;
import org.geysermc.mcprotocollib.protocol.data.game.setting.Difficulty;

import java.util.HashMap;
Expand Down Expand Up @@ -203,9 +202,9 @@ public void getDecoratedPotData(GeyserSession session, Vector3i pos, Consumer<Li
try {
Map<DataComponentType<?>, DataComponent<?, ?>> components = new HashMap<>();
Int2ObjectMaps.fastForEach(map, entry -> {
DataComponentType type = DataComponentType.from(entry.getIntKey());
DataComponentType<?> type = DataComponentType.from(entry.getIntKey());
ByteBuf buf = Unpooled.wrappedBuffer(entry.getValue());
DataComponent value = type.readDataComponent(ItemCodecHelper.INSTANCE, buf);
DataComponent<?, ?> value = type.readDataComponent(buf);
components.put(type, value);
});
return new DataComponents(components);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtType;
import org.geysermc.geyser.inventory.recipe.GeyserRecipe;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftTypes;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.Ingredient;
Expand Down Expand Up @@ -81,10 +81,10 @@ public abstract class RecipeRegistryLoader implements RegistryLoader<String, Map
// }
// }

private static List<GeyserRecipe> getShapelessRecipes(List<NbtMap> recipes, MinecraftCodecHelper helper) {
private static List<GeyserRecipe> getShapelessRecipes(List<NbtMap> recipes) {
List<GeyserRecipe> deserializedRecipes = new ObjectArrayList<>(recipes.size());
for (NbtMap recipe : recipes) {
ItemStack output = toItemStack(recipe.getCompound("output"), helper);
ItemStack output = toItemStack(recipe.getCompound("output"));
List<NbtMap> rawInputs = recipe.getList("inputs", NbtType.COMPOUND);
Ingredient[] javaInputs = new Ingredient[rawInputs.size()];
for (int i = 0; i < rawInputs.size(); i++) {
Expand All @@ -95,16 +95,16 @@ private static List<GeyserRecipe> getShapelessRecipes(List<NbtMap> recipes, Mine
return deserializedRecipes;
}

private static List<GeyserRecipe> getShapedRecipes(List<NbtMap> recipes, MinecraftCodecHelper helper) {
private static List<GeyserRecipe> getShapedRecipes(List<NbtMap> recipes) {
List<GeyserRecipe> deserializedRecipes = new ObjectArrayList<>(recipes.size());
for (NbtMap recipe : recipes) {
ItemStack output = toItemStack(recipe.getCompound("output"), helper);
ItemStack output = toItemStack(recipe.getCompound("output"));
List<int[]> shape = recipe.getList("shape", NbtType.INT_ARRAY);

// In the recipes mapping, each recipe is mapped by a number
List<ItemStack> letterToRecipe = new ArrayList<>();
for (NbtMap rawInput : recipe.getList("inputs", NbtType.COMPOUND)) {
letterToRecipe.add(toItemStack(rawInput, helper));
letterToRecipe.add(toItemStack(rawInput));
}

Ingredient[] inputs = new Ingredient[shape.size() * shape.get(0).length];
Expand All @@ -126,14 +126,14 @@ private static List<GeyserRecipe> getShapedRecipes(List<NbtMap> recipes, Minecra
* id is the Java item ID as an integer, components is an optional String of the data components serialized
* as bytes in Base64 (so MCProtocolLib can parse the data).
*/
private static ItemStack toItemStack(NbtMap nbt, MinecraftCodecHelper helper) {
private static ItemStack toItemStack(NbtMap nbt) {
int id = nbt.getInt("id");
int count = nbt.getInt("count", 1);
String componentsRaw = nbt.getString("components", null);
if (componentsRaw != null) {
byte[] bytes = Base64.getDecoder().decode(componentsRaw);
ByteBuf buf = Unpooled.wrappedBuffer(bytes);
DataComponents components = helper.readDataComponentPatch(buf);
DataComponents components = MinecraftTypes.readDataComponentPatch(buf);
return new ItemStack(id, count, components);
}
return new ItemStack(id, count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@
import org.geysermc.geyser.GeyserBootstrap;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.registry.Registries;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftTypes;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponent;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.ItemCodecHelper;

import java.io.InputStream;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -71,10 +70,9 @@ public static void populate() {
String encodedValue = componentEntry.getValue().getAsString();
byte[] bytes = Base64.getDecoder().decode(encodedValue);
ByteBuf buf = Unpooled.wrappedBuffer(bytes);
MinecraftCodecHelper helper = new MinecraftCodecHelper();
int varInt = helper.readVarInt(buf);
int varInt = MinecraftTypes.readVarInt(buf);
DataComponentType<?> dataComponentType = DataComponentType.from(varInt);
DataComponent<?, ?> dataComponent = dataComponentType.readDataComponent(ItemCodecHelper.INSTANCE, buf);
DataComponent<?, ?> dataComponent = dataComponentType.readDataComponent(buf);

map.put(dataComponentType, dataComponent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.mcprotocollib.network.ClientSession;
import org.geysermc.mcprotocollib.network.packet.Packet;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;

@Getter
@RequiredArgsConstructor
Expand All @@ -53,13 +52,4 @@ public void disconnect(Component reason, Throwable throwable) {
public boolean isClosed() {
return !this.session.isConnected();
}

/**
* Gets the codec helper for this session.
*
* @return the codec helper for this session
*/
public MinecraftCodecHelper getCodecHelper() {
return (MinecraftCodecHelper) this.session.getCodecHelper();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.geyser.util.BlockEntityUtils;
import org.geysermc.geyser.util.ChunkUtils;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftTypes;
import org.geysermc.mcprotocollib.protocol.data.game.chunk.BitStorage;
import org.geysermc.mcprotocollib.protocol.data.game.chunk.ChunkSection;
import org.geysermc.mcprotocollib.protocol.data.game.chunk.DataPalette;
Expand Down Expand Up @@ -115,7 +116,7 @@ public void translate(GeyserSession session, ClientboundLevelChunkWithLightPacke
ByteBuf in = Unpooled.wrappedBuffer(packet.getChunkData());
boolean extendedCollisionNextSection = false;
for (int sectionY = 0; sectionY < chunkSize; sectionY++) {
ChunkSection javaSection = session.getDownstream().getCodecHelper().readChunkSection(in);
ChunkSection javaSection = MinecraftTypes.readChunkSection(in);
javaChunks[sectionY] = javaSection.getChunkData();
javaBiomes[sectionY] = javaSection.getBiomeData();
boolean extendedCollision = extendedCollisionNextSection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void nameNotUpdating() {
});

// metadata set: invisible, custom name, custom name visible
context.translate(setEntityDataTranslator, new ClientboundSetEntityDataPacket(1298, new EntityMetadata[]{
context.translate(setEntityDataTranslator, new ClientboundSetEntityDataPacket(1298, new EntityMetadata<?, ?>[]{
new ByteEntityMetadata(0, MetadataType.BYTE, (byte) 0x20),
new ObjectEntityMetadata<>(2, MetadataType.OPTIONAL_CHAT, Optional.of(Component.text("tesss"))),
new BooleanEntityMetadata(3, MetadataType.BOOLEAN, true)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protocol-common = "3.0.0.Beta5-20241213.160944-20"
protocol-codec = "3.0.0.Beta5-20241213.160944-20"
raknet = "1.0.0.CR3-20240416.144209-1"
minecraftauth = "4.1.1"
mcprotocollib = "1.21.4-20250118.154631-17"
mcprotocollib = "1.21.4-20250121.131208-18"
adventure = "4.14.0"
adventure-platform = "4.3.0"
junit = "5.9.2"
Expand Down

0 comments on commit 5836dab

Please sign in to comment.