From 90e9a1d2ef9beac87ebe0ebde836563c1133fc1c Mon Sep 17 00:00:00 2001 From: Florens Pauwels Date: Wed, 2 Mar 2022 16:01:15 +0100 Subject: [PATCH] Update for 1.18.2 (#154) Co-authored-by: Florens Pauwels --- build.gradle | 21 ++++++---------- gradle.properties | 14 +++++------ settings.gradle | 5 +++- .../dev/emi/trinkets/api/TrinketsApi.java | 25 ++++++++++--------- .../emi/trinkets/data/EntitySlotLoader.java | 17 +++++++++---- .../mixin/ClientPlayNetworkHandlerMixin.java | 3 ++- .../tags/entity_types/some_entities.json | 8 ++++++ .../trinkets/entities/trinkets-testmod.json | 2 +- 8 files changed, 55 insertions(+), 40 deletions(-) create mode 100644 src/testmod/resources/data/trinkets-testmod/tags/entity_types/some_entities.json diff --git a/build.gradle b/build.gradle index f9a4a8e..7f590bb 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { - id 'fabric-loom' version '0.10-SNAPSHOT' - //id "com.github.fudge.forgedflowerloom" version "2.0.0" + id 'fabric-loom' version '0.11-SNAPSHOT' + id 'io.github.juuxel.loom-quiltflower' version '1.6.0' id 'maven-publish' } @@ -13,15 +13,15 @@ group = project.maven_group loom { - accessWidener = file("src/main/resources/trinkets.accesswidener") + accessWidenerPath = file("src/main/resources/trinkets.accesswidener") } repositories { + maven { url = "https://maven.terraformersmc.com" } maven { name = "Ladysnake Libs" url = "https://ladysnake.jfrog.io/artifactory/mods" } - maven { url = "https://jitpack.io" } } sourceSets { @@ -39,19 +39,14 @@ dependencies { // Mod dependencies modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modImplementation "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-base:${project.cca_version}" - include "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-base:${project.cca_version}" - modImplementation "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-entity:${project.cca_version}" - include "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-entity:${project.cca_version}" + modImplementation include("dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cca_version}") + modImplementation include("dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cca_version}") // Dev Runtime testmodImplementation sourceSets.main.output - /*modRuntime("io.github.prospector:modmenu:${project.mod_menu_version}") { + modImplementation("com.terraformersmc:modmenu:${project.mod_menu_version}") { transitive = false - }*/ - //modRuntime ("com.github.SuperCoder7979:databreaker:0.2.5") { - // exclude module : "fabric-loader" - //} + } } processResources { diff --git a/gradle.properties b/gradle.properties index c761988..36a8bba 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,14 +1,14 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx2G -minecraft_version=1.18.1 -yarn_mappings=1.18.1+build.1 -loader_version=0.12.12 +minecraft_version=1.18.2-rc1 +yarn_mappings=1.18.2-rc1+build.2 +loader_version=0.13.3 -mod_version = 3.2.0 +mod_version = 3.2.0-florens maven_group = dev.emi archives_base_name = trinkets -fabric_version=0.46.2+1.18 -cca_version=4.0.0 -mod_menu_version=3.0.0 +fabric_version=0.47.8+1.18.2 +cca_version=4.1.3 +mod_menu_version=3.0.1 diff --git a/settings.gradle b/settings.gradle index 7118d92..d9a4d7b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,10 +1,13 @@ pluginManagement { repositories { - jcenter() maven { name = 'Fabric' url = 'https://maven.fabricmc.net/' } + maven { + name = 'Cotton' + url = 'https://server.bbkr.space/artifactory/libs-release/' + } gradlePluginPortal() } } diff --git a/src/main/java/dev/emi/trinkets/api/TrinketsApi.java b/src/main/java/dev/emi/trinkets/api/TrinketsApi.java index 6ec64b7..2726beb 100644 --- a/src/main/java/dev/emi/trinkets/api/TrinketsApi.java +++ b/src/main/java/dev/emi/trinkets/api/TrinketsApi.java @@ -1,12 +1,6 @@ package dev.emi.trinkets.api; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; import com.mojang.datafixers.util.Function3; - import dev.emi.trinkets.TrinketsMain; import dev.emi.trinkets.TrinketsNetwork; import dev.emi.trinkets.data.EntitySlotLoader; @@ -22,9 +16,15 @@ import net.minecraft.item.ItemStack; import net.minecraft.network.PacketByteBuf; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.tag.ItemTags; -import net.minecraft.tag.Tag; +import net.minecraft.tag.TagKey; import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; public class TrinketsApi { public static final ComponentKey TRINKET_COMPONENT = ComponentRegistryV3.INSTANCE @@ -119,12 +119,13 @@ public static boolean evaluatePredicateSet(Set set, ItemStack stack, static { TrinketsApi.registerTrinketPredicate(new Identifier("trinkets", "all"), (stack, ref, entity) -> TriState.TRUE); TrinketsApi.registerTrinketPredicate(new Identifier("trinkets", "none"), (stack, ref, entity) -> TriState.FALSE); - Identifier trinketsAll = new Identifier("trinkets", "all"); + TagKey trinketsAll = TagKey.of(Registry.ITEM_KEY, new Identifier("trinkets", "all")); + TrinketsApi.registerTrinketPredicate(new Identifier("trinkets", "tag"), (stack, ref, entity) -> { SlotType slot = ref.inventory().getSlotType(); - Tag tag = ItemTags.getTagGroup().getTagOrEmpty(new Identifier("trinkets", slot.getGroup() + "/" + slot.getName())); - Tag all = ItemTags.getTagGroup().getTagOrEmpty(trinketsAll); - if (tag.contains(stack.getItem()) || all.contains(stack.getItem())) { + TagKey tag = TagKey.of(Registry.ITEM_KEY, new Identifier("trinkets", slot.getGroup() + "/" + slot.getName())); + + if (stack.isIn(tag) || stack.isIn(trinketsAll)) { return TriState.TRUE; } return TriState.DEFAULT; diff --git a/src/main/java/dev/emi/trinkets/data/EntitySlotLoader.java b/src/main/java/dev/emi/trinkets/data/EntitySlotLoader.java index 2abd499..e97e66d 100644 --- a/src/main/java/dev/emi/trinkets/data/EntitySlotLoader.java +++ b/src/main/java/dev/emi/trinkets/data/EntitySlotLoader.java @@ -28,6 +28,7 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; import net.fabricmc.fabric.api.resource.ResourceReloadListenerKeys; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.entity.EntityType; import net.minecraft.nbt.NbtCompound; import net.minecraft.network.PacketByteBuf; @@ -35,11 +36,12 @@ import net.minecraft.resource.ResourceManager; import net.minecraft.resource.SinglePreparationResourceReloader; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.tag.ServerTagManagerHolder; +import net.minecraft.tag.TagKey; import net.minecraft.util.Identifier; import net.minecraft.util.JsonHelper; import net.minecraft.util.profiler.Profiler; import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryEntry; public class EntitySlotLoader extends SinglePreparationResourceReloader>>> implements IdentifiableResourceReloadListener { @@ -135,10 +137,15 @@ protected void apply(Map>> loader, ResourceManag try { if (entityName.startsWith("#")) { - types.addAll(ServerTagManagerHolder.getTagManager().getTag(Registry.ENTITY_TYPE_KEY, - new Identifier(entityName.substring(1)), - (identifier) -> new IllegalArgumentException("Unknown entity tag '" + identifier + "'")) - .values()); + // FIXME: registry tags not populated yet, might need to make this lazy + TagKey> tag = TagKey.of(Registry.ENTITY_TYPE_KEY, new Identifier(entityName.substring(1))); + List> entityTypes = Registry.ENTITY_TYPE.getEntryList(tag) + .orElseThrow(() -> new IllegalArgumentException("Unknown entity tag '" + entityName + "'")) + .stream() + .map(RegistryEntry::value) + .toList(); + + types.addAll(entityTypes); } else { types.add(Registry.ENTITY_TYPE.getOrEmpty(new Identifier(entityName)) .orElseThrow(() -> new IllegalArgumentException("Unknown entity '" + entityName + "'"))); diff --git a/src/main/java/dev/emi/trinkets/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/dev/emi/trinkets/mixin/ClientPlayNetworkHandlerMixin.java index f6145cd..d3efcc6 100644 --- a/src/main/java/dev/emi/trinkets/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/dev/emi/trinkets/mixin/ClientPlayNetworkHandlerMixin.java @@ -5,6 +5,7 @@ import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket; +import net.minecraft.util.registry.RegistryEntry; import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.dimension.DimensionType; import org.spongepowered.asm.mixin.Mixin; @@ -22,7 +23,7 @@ public class ClientPlayNetworkHandlerMixin { @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;setId(I)V"), method = "onPlayerRespawn", locals = LocalCapture.CAPTURE_FAILSOFT) - private void onPlayerRespawn(PlayerRespawnS2CPacket packet, CallbackInfo ci, RegistryKey registryKey, DimensionType dimensionType, ClientPlayerEntity clientPlayerEntity, int i, String string, ClientPlayerEntity clientPlayerEntity2) { + private void onPlayerRespawn(PlayerRespawnS2CPacket packet, CallbackInfo ci, RegistryKey registryKey, RegistryEntry registryEntry, ClientPlayerEntity clientPlayerEntity, int i, String string, ClientPlayerEntity clientPlayerEntity2) { if (packet.shouldKeepPlayerAttributes()) { TrinketInventory.copyFrom(clientPlayerEntity, clientPlayerEntity2); ((TrinketPlayerScreenHandler) clientPlayerEntity2.playerScreenHandler).trinkets$updateTrinketSlots(false); diff --git a/src/testmod/resources/data/trinkets-testmod/tags/entity_types/some_entities.json b/src/testmod/resources/data/trinkets-testmod/tags/entity_types/some_entities.json new file mode 100644 index 0000000..b4fba77 --- /dev/null +++ b/src/testmod/resources/data/trinkets-testmod/tags/entity_types/some_entities.json @@ -0,0 +1,8 @@ +{ + "replace": false, + "values": [ + "minecraft:player", + "minecraft:skeleton", + "minecraft:creeper" + ] +} \ No newline at end of file diff --git a/src/testmod/resources/data/trinkets/entities/trinkets-testmod.json b/src/testmod/resources/data/trinkets/entities/trinkets-testmod.json index 2f3855f..a2a3685 100644 --- a/src/testmod/resources/data/trinkets/entities/trinkets-testmod.json +++ b/src/testmod/resources/data/trinkets/entities/trinkets-testmod.json @@ -1,5 +1,5 @@ { - "entities": ["player"], + "entities": ["player", "#some_entities,"], "slots": [ "hand/glove", "hand/ring",