From 572a63fe2079ff41d914d590e63d61be35ecb72b Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 22 Sep 2020 16:16:25 +0200 Subject: [PATCH] re-added curios compat --- .../data/curios/tags/items/belt.json | 7 +++ .../data/curios/tags/items/charm.json | 7 +++ .../data/curios/tags/items/necklace.json | 6 ++ .../data/curios/tags/items/ring.json | 6 ++ .../java/de/ellpeck/naturesaura/Helper.java | 6 +- .../naturesaura/compat/CuriosCompat.java | 62 ++++++++----------- .../naturesaura/data/ItemTagProvider.java | 6 ++ .../renderers/PlayerLayerTrinkets.java | 15 +++-- 8 files changed, 67 insertions(+), 48 deletions(-) create mode 100644 src/generated/resources/data/curios/tags/items/belt.json create mode 100644 src/generated/resources/data/curios/tags/items/charm.json create mode 100644 src/generated/resources/data/curios/tags/items/necklace.json create mode 100644 src/generated/resources/data/curios/tags/items/ring.json diff --git a/src/generated/resources/data/curios/tags/items/belt.json b/src/generated/resources/data/curios/tags/items/belt.json new file mode 100644 index 00000000..9eb1a8aa --- /dev/null +++ b/src/generated/resources/data/curios/tags/items/belt.json @@ -0,0 +1,7 @@ +{ + "replace": false, + "values": [ + "naturesaura:aura_cache", + "naturesaura:aura_trove" + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/curios/tags/items/charm.json b/src/generated/resources/data/curios/tags/items/charm.json new file mode 100644 index 00000000..72503671 --- /dev/null +++ b/src/generated/resources/data/curios/tags/items/charm.json @@ -0,0 +1,7 @@ +{ + "replace": false, + "values": [ + "naturesaura:eye", + "naturesaura:eye_improved" + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/curios/tags/items/necklace.json b/src/generated/resources/data/curios/tags/items/necklace.json new file mode 100644 index 00000000..200e0031 --- /dev/null +++ b/src/generated/resources/data/curios/tags/items/necklace.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "naturesaura:shockwave_creator" + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/curios/tags/items/ring.json b/src/generated/resources/data/curios/tags/items/ring.json new file mode 100644 index 00000000..353316b7 --- /dev/null +++ b/src/generated/resources/data/curios/tags/items/ring.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "naturesaura:death_ring" + ] +} \ No newline at end of file diff --git a/src/main/java/de/ellpeck/naturesaura/Helper.java b/src/main/java/de/ellpeck/naturesaura/Helper.java index cc608981..9fd2c6f6 100644 --- a/src/main/java/de/ellpeck/naturesaura/Helper.java +++ b/src/main/java/de/ellpeck/naturesaura/Helper.java @@ -46,6 +46,7 @@ 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; @@ -331,10 +332,9 @@ public final class Helper { public static ItemStack getEquippedItem(Predicate predicate, PlayerEntity player) { if (Compat.hasCompat("curios")) { - // TODO curios - /* Optional stack = CuriosAPI.getCurioEquipped(predicate, player).map(ImmutableTriple::getRight); + Optional stack = CuriosApi.getCuriosHelper().findEquippedCurio(predicate, player).map(ImmutableTriple::getRight); if (stack.isPresent()) - return stack.get();*/ + return stack.get(); } for (int i = 0; i < player.inventory.getSizeInventory(); i++) { ItemStack slot = player.inventory.getStackInSlot(i); diff --git a/src/main/java/de/ellpeck/naturesaura/compat/CuriosCompat.java b/src/main/java/de/ellpeck/naturesaura/compat/CuriosCompat.java index 12774c15..dfdfe881 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/CuriosCompat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/CuriosCompat.java @@ -7,6 +7,8 @@ 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.tags.ItemTags; import net.minecraft.tags.Tag; import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; @@ -20,41 +22,29 @@ import net.minecraftforge.fml.InterModComms; import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import top.theillusivec4.curios.api.CuriosCapability; +import top.theillusivec4.curios.api.SlotTypeMessage; +import top.theillusivec4.curios.api.SlotTypePreset; +import top.theillusivec4.curios.api.type.capability.ICurio; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Map; -// TODO curios public class CuriosCompat implements ICompat { - @Override - public void setup() { - } - - @Override - public void setupClient() { - - } - - @Override - public void addItemTags(ItemTagProvider provider) { - - } - - /*private static final Map> TYPES = ImmutableMap.>builder() - .put(ModItems.EYE, CurioTags.CHARM) - .put(ModItems.EYE_IMPROVED, CurioTags.CHARM) - .put(ModItems.AURA_CACHE, CurioTags.BELT) - .put(ModItems.AURA_TROVE, CurioTags.BELT) - .put(ModItems.SHOCKWAVE_CREATOR, CurioTags.NECKLACE) - .put(ModItems.DEATH_RING, CurioTags.RING) + private static final Map TYPES = ImmutableMap.builder() + .put(ModItems.EYE, "charm") + .put(ModItems.EYE_IMPROVED, "charm") + .put(ModItems.AURA_CACHE, "belt") + .put(ModItems.AURA_TROVE, "belt") + .put(ModItems.SHOCKWAVE_CREATOR, "necklace") + .put(ModItems.DEATH_RING, "ring") .build(); @Override public void setup() { - FMLJavaModLoadingContext.get().getModEventBus().register(this); // inter mod comms - MinecraftForge.EVENT_BUS.register(this); // capabilities + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::sendImc); + MinecraftForge.EVENT_BUS.addGenericListener(ItemStack.class, this::onCapabilitiesAttach); } @Override @@ -62,16 +52,11 @@ public class CuriosCompat implements ICompat { } - @SubscribeEvent - public void sendImc(InterModEnqueueEvent event) { - TYPES.values().stream().distinct().forEach(t -> { - String path = t.getId().getPath(); - InterModComms.sendTo("curios", CuriosAPI.IMC.REGISTER_TYPE, () -> new CurioIMCMessage(path)); - }); + private void sendImc(InterModEnqueueEvent event) { + TYPES.values().stream().distinct().forEach(t -> InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> new SlotTypeMessage.Builder(t).build())); } - @SubscribeEvent - public void onCapabilitiesAttach(AttachCapabilitiesEvent event) { + private void onCapabilitiesAttach(AttachCapabilitiesEvent event) { ItemStack stack = event.getObject(); if (TYPES.containsKey(stack.getItem())) { event.addCapability(new ResourceLocation(NaturesAura.MOD_ID, "curios"), new ICapabilityProvider() { @@ -82,8 +67,9 @@ public class CuriosCompat implements ICompat { return LazyOptional.empty(); return LazyOptional.of(() -> (T) new ICurio() { @Override - public void onCurioTick(String identifier, int index, LivingEntity livingEntity) { + public void curioTick(String identifier, int index, LivingEntity livingEntity) { stack.getItem().inventoryTick(stack, livingEntity.world, livingEntity, -1, false); + } @Override @@ -92,7 +78,7 @@ public class CuriosCompat implements ICompat { } @Override - public boolean shouldSyncToTracking(String identifier, LivingEntity livingEntity) { + public boolean canSync(String identifier, int index, LivingEntity livingEntity) { return true; } }); @@ -103,7 +89,9 @@ public class CuriosCompat implements ICompat { @Override public void addItemTags(ItemTagProvider provider) { - for (Map.Entry> entry : TYPES.entrySet()) - provider.getBuilder(entry.getValue()).add(entry.getKey()); - }*/ + for (Map.Entry entry : TYPES.entrySet()) { + ITag.INamedTag tag = ItemTags.createOptional(new ResourceLocation("curios", entry.getValue())); + provider.getOrCreateBuilder(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 94ec633b..928cd88f 100644 --- a/src/main/java/de/ellpeck/naturesaura/data/ItemTagProvider.java +++ b/src/main/java/de/ellpeck/naturesaura/data/ItemTagProvider.java @@ -7,6 +7,7 @@ import net.minecraft.data.DataGenerator; import net.minecraft.data.ItemTagsProvider; import net.minecraft.item.Item; import net.minecraft.tags.BlockTags; +import net.minecraft.tags.ITag; import net.minecraft.tags.ItemTags; import net.minecraft.tags.Tag; import net.minecraftforge.common.Tags; @@ -30,4 +31,9 @@ public class ItemTagProvider extends ItemTagsProvider { Compat.addItemTags(this); } + + @Override + public Builder getOrCreateBuilder(ITag.INamedTag tag) { + return super.getOrCreateBuilder(tag); + } } diff --git a/src/main/java/de/ellpeck/naturesaura/renderers/PlayerLayerTrinkets.java b/src/main/java/de/ellpeck/naturesaura/renderers/PlayerLayerTrinkets.java index 53b9c225..367bc47e 100644 --- a/src/main/java/de/ellpeck/naturesaura/renderers/PlayerLayerTrinkets.java +++ b/src/main/java/de/ellpeck/naturesaura/renderers/PlayerLayerTrinkets.java @@ -19,6 +19,9 @@ import net.minecraft.util.math.vector.Vector3f; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.items.IItemHandler; +import top.theillusivec4.curios.api.CuriosApi; +import top.theillusivec4.curios.api.type.capability.ICuriosItemHandler; +import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler; import java.util.HashSet; import java.util.Set; @@ -60,15 +63,11 @@ public class PlayerLayerTrinkets extends LayerRenderer