From c0bf5f0d939b62948ccc012bcfc93381b75da23c Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 19 Dec 2021 16:35:03 +0100 Subject: [PATCH] bring back curios compat --- build.gradle | 5 ++- .../java/de/ellpeck/naturesaura/Helper.java | 10 +++--- .../de/ellpeck/naturesaura/compat/Compat.java | 4 +-- .../naturesaura/compat/CuriosCompat.java | 31 +++++++++---------- .../naturesaura/data/ItemTagProvider.java | 7 +++++ .../renderers/PlayerLayerTrinkets.java | 10 +++--- 6 files changed, 38 insertions(+), 29 deletions(-) diff --git a/build.gradle b/build.gradle index c784a72c..d08d1087 100644 --- a/build.gradle +++ b/build.gradle @@ -111,9 +111,8 @@ dependencies { compileOnly fg.deobf("vazkii.patchouli:Patchouli:1.18.1-61:api") runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:1.18.1-61") - // TODO Curios -/* runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.16.5-4.0.5.0") - compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.16.5-4.0.5.0:api")*/ + runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.18.1-5.0.3.0") + compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:1.18.1-5.0.3.0:api") // TODO Enchantability /* compile fg.deobf("quarris.enchantability:Enchantability:11.0.48")*/ diff --git a/src/main/java/de/ellpeck/naturesaura/Helper.java b/src/main/java/de/ellpeck/naturesaura/Helper.java index 1b527144..e35ffbe7 100644 --- a/src/main/java/de/ellpeck/naturesaura/Helper.java +++ b/src/main/java/de/ellpeck/naturesaura/Helper.java @@ -6,6 +6,7 @@ import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge; import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityImpl; import de.ellpeck.naturesaura.chunk.AuraChunk; +import de.ellpeck.naturesaura.compat.Compat; import de.ellpeck.naturesaura.misc.LevelData; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -39,7 +40,9 @@ import net.minecraftforge.items.IItemHandler; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.IForgeRegistry; import net.minecraftforge.registries.IForgeRegistryEntry; +import org.apache.commons.lang3.tuple.ImmutableTriple; import org.lwjgl.opengl.GL11; +import top.theillusivec4.curios.api.CuriosApi; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -290,12 +293,11 @@ public final class Helper { } public static ItemStack getEquippedItem(Predicate predicate, Player player) { - // TODO Curios -/* if (Compat.hasCompat("curios")) { - Optional stack = CuriosApi.getCuriosHelper().findEquippedCurio(predicate, player).map(ImmutableTriple::getRight); + if (Compat.hasCompat("curios")) { + var stack = CuriosApi.getCuriosHelper().findEquippedCurio(predicate, player).map(ImmutableTriple::getRight); if (stack.isPresent()) return stack.get(); - }*/ + } for (var i = 0; i < player.getInventory().getContainerSize(); i++) { var slot = player.getInventory().getItem(i); if (!slot.isEmpty() && predicate.test(slot)) diff --git a/src/main/java/de/ellpeck/naturesaura/compat/Compat.java b/src/main/java/de/ellpeck/naturesaura/compat/Compat.java index 5bc9499c..4d153214 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/Compat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/Compat.java @@ -16,8 +16,8 @@ public final class Compat { private static final Map> MODULE_TYPES = ImmutableMap.>builder() .put("patchouli", PatchouliCompat::new) - /* .put("curios", CuriosCompat::new) - .put("enchantability", EnchantibilityCompat::new)*/ + .put("curios", CuriosCompat::new) + //.put("enchantability", EnchantibilityCompat::new) .build(); private static final Map MODULES = new HashMap<>(); diff --git a/src/main/java/de/ellpeck/naturesaura/compat/CuriosCompat.java b/src/main/java/de/ellpeck/naturesaura/compat/CuriosCompat.java index d66a89e5..1c2f45f7 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/CuriosCompat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/CuriosCompat.java @@ -1,18 +1,14 @@ -// TODO Curios -/* package de.ellpeck.naturesaura.compat; import com.google.common.collect.ImmutableMap; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.data.ItemTagProvider; import de.ellpeck.naturesaura.items.ModItems; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.tags.ITag; +import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.ItemTags; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilityProvider; @@ -58,14 +54,18 @@ public class CuriosCompat implements ICompat { } private void onCapabilitiesAttach(AttachCapabilitiesEvent event) { - ItemStack stack = event.getObject(); + var stack = event.getObject(); if (TYPES.containsKey(stack.getItem())) { event.addCapability(new ResourceLocation(NaturesAura.MOD_ID, "curios"), new ICapabilityProvider() { private final LazyOptional curio = LazyOptional.of(() -> new ICurio() { @Override - public void curioTick(String identifier, int index, LivingEntity livingEntity) { - stack.getItem().inventoryTick(stack, livingEntity.level, livingEntity, -1, false); + public void curioTick(SlotContext slotContext) { + stack.getItem().inventoryTick(stack, slotContext.entity().level, slotContext.entity(), -1, false); + } + @Override + public ItemStack getStack() { + return stack; } @Override @@ -74,7 +74,7 @@ public class CuriosCompat implements ICompat { } @Override - public boolean canSync(String identifier, int index, LivingEntity livingEntity) { + public boolean canSync(SlotContext slotContext) { return true; } }); @@ -92,10 +92,9 @@ public class CuriosCompat implements ICompat { @Override public void addItemTags(ItemTagProvider provider) { - for (Map.Entry entry : TYPES.entrySet()) { - ITag.INamedTag tag = ItemTags.createOptional(new ResourceLocation("curios", entry.getValue())); - provider.getOrCreateBuilder(tag).add(entry.getKey()); + for (var entry : TYPES.entrySet()) { + var tag = ItemTags.createOptional(new ResourceLocation("curios", entry.getValue())); + provider.tag(tag).add(entry.getKey()); } } } -*/ diff --git a/src/main/java/de/ellpeck/naturesaura/data/ItemTagProvider.java b/src/main/java/de/ellpeck/naturesaura/data/ItemTagProvider.java index ec957be5..4596e9a8 100644 --- a/src/main/java/de/ellpeck/naturesaura/data/ItemTagProvider.java +++ b/src/main/java/de/ellpeck/naturesaura/data/ItemTagProvider.java @@ -8,6 +8,8 @@ import net.minecraft.data.tags.BlockTagsProvider; import net.minecraft.data.tags.ItemTagsProvider; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ItemTags; +import net.minecraft.tags.Tag; +import net.minecraft.world.item.Item; import net.minecraftforge.common.Tags; import net.minecraftforge.common.data.ExistingFileHelper; @@ -31,4 +33,9 @@ public class ItemTagProvider extends ItemTagsProvider { Compat.addItemTags(this); } + @Override + public TagAppender tag(Tag.Named p_126549_) { + // super is protected, but CuriosCompat needs this + return super.tag(p_126549_); + } } diff --git a/src/main/java/de/ellpeck/naturesaura/renderers/PlayerLayerTrinkets.java b/src/main/java/de/ellpeck/naturesaura/renderers/PlayerLayerTrinkets.java index 45df7a21..d4fde826 100644 --- a/src/main/java/de/ellpeck/naturesaura/renderers/PlayerLayerTrinkets.java +++ b/src/main/java/de/ellpeck/naturesaura/renderers/PlayerLayerTrinkets.java @@ -5,6 +5,7 @@ import com.mojang.math.Vector3f; import de.ellpeck.naturesaura.ModConfig; import de.ellpeck.naturesaura.api.render.ITrinketItem; import de.ellpeck.naturesaura.api.render.ITrinketItem.RenderType; +import de.ellpeck.naturesaura.compat.Compat; import net.minecraft.client.model.PlayerModel; import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.renderer.MultiBufferSource; @@ -17,6 +18,8 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.items.IItemHandler; +import top.theillusivec4.curios.api.CuriosApi; import java.util.HashSet; import java.util.Set; @@ -57,14 +60,13 @@ public class PlayerLayerTrinkets extends RenderLayer