-
-
Notifications
You must be signed in to change notification settings - Fork 822
Feature: 26.1, API 2.10.0 #6271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 41 commits
5f9fbe3
58c6603
4d09ef6
09c7cdd
95a2a7b
effb253
fe1a9f9
5dfd49d
3a72865
ee5f111
3b0c9c7
6706c63
f6716f8
7d5d912
dbc4142
1f5329e
7ae010d
e46f28c
082ba3a
df97c0d
f5c539c
9ef0cb8
722abe6
436a9b8
1d96860
3e41ca6
398401f
65fe71c
42488f1
ccafa76
248b60f
61fce61
ff522d0
4c163b8
0b12ed2
b41177d
1827f52
cc7ffe9
c8091af
8455403
80eb8bd
dfb4838
cb97672
2385729
07a5757
b7847c5
0a22e8e
7f8dff2
5e3089c
f4021dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,10 +19,10 @@ loom { | |||||
| } | ||||||
|
|
||||||
| dependencies { | ||||||
| modImplementation(libs.fabric.loader) | ||||||
| modApi(libs.fabric.api) | ||||||
| implementation(libs.fabric.loader) | ||||||
| api(libs.fabric.api) | ||||||
|
|
||||||
| api(project(":mod", configuration = "namedElements")) | ||||||
| api(project(":mod")) | ||||||
| shadowBundle(project(path = ":mod", configuration = "transformProductionFabric")) | ||||||
| shadowBundle(projects.core) | ||||||
| includeTransitive(projects.core) | ||||||
|
|
@@ -47,7 +47,7 @@ dependencies { | |||||
| shadowBundle(projects.api) | ||||||
| shadowBundle(projects.common) | ||||||
|
|
||||||
| modImplementation(libs.cloud.fabric) | ||||||
| implementation(libs.cloud.fabric) | ||||||
| include(libs.cloud.fabric) | ||||||
| include(libs.fabric.permissions.api) | ||||||
| } | ||||||
|
|
@@ -60,23 +60,48 @@ relocate("org.cloudburstmc.netty") | |||||
| relocate("org.cloudburstmc.protocol") | ||||||
| relocate("org.spongepowered.configurate") | ||||||
|
|
||||||
| tasks { | ||||||
| remapJar { | ||||||
| archiveBaseName.set("Geyser-Fabric") | ||||||
| fabricApi { | ||||||
| configureTests { | ||||||
| createSourceSet = true | ||||||
| modId = "geyser-gametest" | ||||||
| enableClientGameTests = false | ||||||
| eula = true | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| remapModrinthJar { | ||||||
| archiveBaseName.set("geyser-fabric") | ||||||
| tasks { | ||||||
| named<Jar>("mergeShadowAndJarJar") { | ||||||
| from ( | ||||||
| zipTree( shadowJar.map { it.outputs.files.singleFile } ).matching { | ||||||
| exclude("fabric.mod.json") | ||||||
| exclude("LICENSE") | ||||||
| }, | ||||||
| zipTree( jar.map { it.outputs.files.singleFile } ).matching { | ||||||
| include("META-INF/jars/**") | ||||||
| include("fabric.mod.json") | ||||||
| include("LICENSE") | ||||||
| } | ||||||
| ) | ||||||
| archiveBaseName.set("Geyser-Fabric") | ||||||
| } | ||||||
|
|
||||||
| shadowJar { | ||||||
| mergeServiceFiles() | ||||||
| getByName("processGametestResources", ProcessResources::class) { | ||||||
| filesMatching("fabric.mod.json") { | ||||||
| expand( | ||||||
| "id" to "geyser", | ||||||
| "name" to "Geyser", | ||||||
| "version" to project.version, | ||||||
| "description" to project.description!!, | ||||||
| "url" to "https://geysermc.org", | ||||||
| "author" to "GeyserMC" | ||||||
| ) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| modrinth { | ||||||
| loaders.add("fabric") | ||||||
| uploadFile.set(tasks.getByPath("remapModrinthJar")) | ||||||
| uploadFile.set(tasks.getByName("renameModrinthJar")) | ||||||
|
||||||
| uploadFile.set(tasks.getByName("renameModrinthJar")) | |
| uploadFile.set(tasks.named<Jar>("mergeShadowAndJarJar")) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| loom.platform=fabric | ||
| loom.platform=fabric |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| /* | ||
| * Copyright (c) 2025 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.gametest; | ||
|
|
||
| import com.google.common.hash.HashCode; | ||
| import com.mojang.datafixers.util.Either; | ||
| import com.mojang.serialization.Codec; | ||
| import com.mojang.serialization.DataResult; | ||
| import com.mojang.serialization.DynamicOps; | ||
| import com.mojang.serialization.JavaOps; | ||
| import com.mojang.serialization.MapCodec; | ||
| import com.mojang.serialization.MapLike; | ||
| import com.mojang.serialization.RecordBuilder; | ||
| import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
| import io.netty.buffer.Unpooled; | ||
| import net.minecraft.core.component.DataComponentType; | ||
| import net.minecraft.core.component.TypedDataComponent; | ||
| import net.minecraft.core.registries.Registries; | ||
| import net.minecraft.gametest.framework.GameTestAssertException; | ||
| import net.minecraft.gametest.framework.GameTestEnvironments; | ||
| import net.minecraft.gametest.framework.GameTestHelper; | ||
| import net.minecraft.gametest.framework.GameTestInstance; | ||
| import net.minecraft.gametest.framework.TestData; | ||
| import net.minecraft.network.RegistryFriendlyByteBuf; | ||
| import net.minecraft.network.chat.Component; | ||
| import net.minecraft.network.chat.MutableComponent; | ||
| import net.minecraft.resources.Identifier; | ||
| import net.minecraft.resources.RegistryOps; | ||
| import net.minecraft.util.ExtraCodecs; | ||
| import net.minecraft.util.HashOps; | ||
| import org.geysermc.geyser.GeyserImpl; | ||
| import org.geysermc.geyser.gametest.registries.GameTestJavaRegistryProvider; | ||
| import org.geysermc.geyser.item.hashing.DataComponentHashers; | ||
| import org.geysermc.geyser.item.hashing.MapHasher; | ||
| 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.DataComponentTypes; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Stream; | ||
|
|
||
| public class GeyserComponentHashTestInstance extends GameTestInstance { | ||
|
|
||
| private static final MapCodec<List<TypedDataComponent<?>>> TYPED_COMPONENT_LIST_CODEC = DataComponentType.PERSISTENT_CODEC | ||
| .dispatchMap("component", list -> list.getFirst().type(), GeyserComponentHashTestInstance::typedComponentListCodec); | ||
| private static final MapCodec<List<TypedDataComponent<?>>> MERGED_TYPED_COMPONENT_LIST_CODEC = TYPED_COMPONENT_LIST_CODEC.codec().listOf() | ||
| .xmap(listOfLists -> listOfLists.stream().flatMap(List::stream).toList(), list -> { | ||
| Map<DataComponentType<?>, List<TypedDataComponent<?>>> split = new HashMap<>(); | ||
| list.forEach(component -> { | ||
| split.compute(component.type(), (type, typeList) -> { | ||
| if (typeList == null) { | ||
| typeList = new ArrayList<>(); | ||
| } | ||
| typeList.add(component); | ||
| return typeList; | ||
| }); | ||
| }); | ||
| return split.values().stream().toList(); | ||
| }).fieldOf("components"); | ||
| private static final MapCodec<List<TypedDataComponent<?>>> MERGED_AND_SINGLE_COMPONENT_MAP_CODEC = Codec.mapEither(MERGED_TYPED_COMPONENT_LIST_CODEC, TYPED_COMPONENT_LIST_CODEC) | ||
| .xmap(Either::unwrap, Either::left); | ||
| // Cursed codec to extract a RegistryOps | ||
| private static final MapCodec<RegistryOps<?>> REGISTRY_OPS_MAP_CODEC = new MapCodec<>() { | ||
| @Override | ||
| public <T> Stream<T> keys(DynamicOps<T> ops) { | ||
| return Stream.empty(); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> DataResult<RegistryOps<?>> decode(DynamicOps<T> ops, MapLike<T> input) { | ||
| if (ops instanceof RegistryOps<T> registryOps) { | ||
| return DataResult.success(registryOps); | ||
| } | ||
| return DataResult.error(() -> "Registry ops required for parsing"); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> RecordBuilder<T> encode(RegistryOps<?> input, DynamicOps<T> ops, RecordBuilder<T> prefix) { | ||
| // noop | ||
| return prefix; | ||
| } | ||
| }; | ||
| public static final MapCodec<GeyserComponentHashTestInstance> MAP_CODEC = RecordCodecBuilder.mapCodec(instance -> | ||
| instance.group( | ||
| REGISTRY_OPS_MAP_CODEC.forGetter(ignored -> null), | ||
| MERGED_AND_SINGLE_COMPONENT_MAP_CODEC.forGetter(testInstance -> testInstance.testCases), | ||
| Codec.BOOL.optionalFieldOf("required", true).forGetter(GameTestInstance::required) | ||
| ).apply(instance, GeyserComponentHashTestInstance::new) | ||
| ); | ||
|
|
||
| private final List<TypedDataComponent<?>> testCases; | ||
|
|
||
| public GeyserComponentHashTestInstance(RegistryOps<?> ops, List<TypedDataComponent<?>> testCases, boolean required) { | ||
| super(new TestData<>(ops.getter(Registries.TEST_ENVIRONMENT) | ||
| .flatMap(getter -> getter.get(GameTestEnvironments.DEFAULT_KEY)).orElseThrow(), | ||
| Identifier.withDefaultNamespace("empty"), 1, 1, required)); | ||
| this.testCases = testCases; | ||
| } | ||
|
|
||
| @Override | ||
| public void run(@NotNull GameTestHelper helper) { | ||
| RegistryOps<Object> javaOps = helper.getLevel().registryAccess().createSerializationContext(JavaOps.INSTANCE); | ||
| RegistryOps<HashCode> hashOps = helper.getLevel().registryAccess().createSerializationContext(HashOps.CRC32C_INSTANCE); | ||
|
|
||
| for (TypedDataComponent<?> testCase : testCases) { | ||
| // Encode vanilla component to buffer | ||
| RegistryFriendlyByteBuf buffer = new RegistryFriendlyByteBuf(Unpooled.buffer(), helper.getLevel().registryAccess()); | ||
| TypedDataComponent.STREAM_CODEC.encode(buffer, testCase); | ||
|
|
||
| // Read with MCPL | ||
| int id = MinecraftTypes.readVarInt(buffer); | ||
| DataComponent<?, ?> mcplComponent = DataComponentTypes.from(id).readDataComponent(buffer); | ||
|
|
||
| Object encodedJavaValue = testCase.encodeValue(javaOps).getOrThrow(); | ||
| // Hash both and compare | ||
| int expected = testCase.encodeValue(hashOps).getOrThrow().asInt(); | ||
| GameTestJavaRegistryProvider registries = new GameTestJavaRegistryProvider(helper.getLevel().registryAccess()); | ||
| int geyser = DataComponentHashers.hash(registries, mcplComponent).asInt(); | ||
|
|
||
| try { | ||
| helper.assertValueEqual(expected, geyser, "hash for component " + encodedJavaValue); | ||
| } catch (GameTestAssertException assertException) { | ||
| GeyserImpl.getInstance().getLogger().info("Hash failed for component " + testCase.type() + " (" + testCase.value() + "), printing values of MapHasher"); | ||
| MapHasher.debug = true; | ||
| DataComponentHashers.hash(registries, mcplComponent); | ||
| MapHasher.debug = false; | ||
| GeyserImpl.getInstance().getLogger().info("The Mojang encoded/expected value is printed in the exception message"); | ||
| throw assertException; | ||
| } | ||
| } | ||
|
|
||
| // Succeed if nothing was thrown | ||
| helper.succeed(); | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull MapCodec<GeyserComponentHashTestInstance> codec() { | ||
| return MAP_CODEC; | ||
| } | ||
|
|
||
| @Override | ||
| protected @NotNull MutableComponent typeDescription() { | ||
| // TODO more descriptive? | ||
| return Component.literal("Geyser Data Component Hash Test"); | ||
| } | ||
|
|
||
| // Generics are NOT friendly!!! | ||
| @SuppressWarnings({"rawtypes", "unchecked"}) | ||
| private static MapCodec<List<TypedDataComponent<?>>> typedComponentListCodec(DataComponentType component) { | ||
| return ExtraCodecs.compactListCodec(component.codecOrThrow(), ExtraCodecs.nonEmptyList(component.codecOrThrow().listOf())) | ||
| .fieldOf("value") | ||
| .xmap( | ||
| values -> ((List<?>) values).stream() | ||
| .map(testCase -> new TypedDataComponent(component, testCase)) | ||
| .map(testCase -> (TypedDataComponent<?>) testCase) | ||
| .toList(), | ||
| typedComponents -> ((List<?>) typedComponents).stream() | ||
| .map(testCase -> ((TypedDataComponent<?>) testCase).value()) | ||
| .toList()); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.