From 11ea832cbeb07e76638e8490fc47dd5dcbc7f2b7 Mon Sep 17 00:00:00 2001 From: Hubry Date: Wed, 11 Mar 2020 01:19:59 +0100 Subject: [PATCH] Bump Curios, handle curio drop event for ivy, drop items that don't fit --- build.gradle | 4 ++-- .../client/core/handler/TooltipHandler.java | 2 +- .../integration/curios/CurioIntegration.java | 17 +++++++++++++---- .../vazkii/botania/common/item/ItemKeepIvy.java | 14 ++++++++++---- src/main/resources/META-INF/mods.toml | 2 +- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index 7603909fd..1530e8004 100644 --- a/build.gradle +++ b/build.gradle @@ -99,8 +99,8 @@ dependencies { compileOnly fg.deobf("mezz.jei:jei-1.14.4:6.0.0.11:api") runtimeOnly fg.deobf("mezz.jei:jei-1.14.4:6.0.0.11") - compileOnly fg.deobf("top.theillusivec4.curios:curios:FORGE-1.14.4-1.0.2:api") - runtimeOnly fg.deobf("top.theillusivec4.curios:curios:FORGE-1.14.4-1.0.2") + compileOnly fg.deobf("top.theillusivec4.curios:curios:FORGE-1.14.4-1.0.6.1:api") + runtimeOnly fg.deobf("top.theillusivec4.curios:curios:FORGE-1.14.4-1.0.6.1") } if (System.getenv().BUILD_NUMBER != null) { diff --git a/src/main/java/vazkii/botania/client/core/handler/TooltipHandler.java b/src/main/java/vazkii/botania/client/core/handler/TooltipHandler.java index e5467fb05..2d6523e25 100644 --- a/src/main/java/vazkii/botania/client/core/handler/TooltipHandler.java +++ b/src/main/java/vazkii/botania/client/core/handler/TooltipHandler.java @@ -25,7 +25,7 @@ public final class TooltipHandler { @SubscribeEvent(priority = EventPriority.HIGHEST) public static void onTooltipEvent(ItemTooltipEvent event) { - if(event.getItemStack().hasTag() && ItemNBTHelper.getBoolean(event.getItemStack(), ItemKeepIvy.TAG_KEEP, false)) + if(ItemKeepIvy.hasIvy(event.getItemStack())) event.getToolTip().add(new TranslationTextComponent("botaniamisc.hasKeepIvy")); } diff --git a/src/main/java/vazkii/botania/common/integration/curios/CurioIntegration.java b/src/main/java/vazkii/botania/common/integration/curios/CurioIntegration.java index c909a6338..990661c3e 100644 --- a/src/main/java/vazkii/botania/common/integration/curios/CurioIntegration.java +++ b/src/main/java/vazkii/botania/common/integration/curios/CurioIntegration.java @@ -5,8 +5,6 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.util.Direction; -import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -18,14 +16,14 @@ import org.apache.commons.lang3.tuple.ImmutableTriple; import top.theillusivec4.curios.api.CuriosAPI; import top.theillusivec4.curios.api.capability.CuriosCapability; import top.theillusivec4.curios.api.capability.ICurio; +import top.theillusivec4.curios.api.event.LivingCurioDropRulesEvent; import top.theillusivec4.curios.api.imc.CurioIMCMessage; import vazkii.botania.common.capability.SimpleCapProvider; import vazkii.botania.common.core.handler.EquipmentHandler; import vazkii.botania.common.core.handler.ModSounds; +import vazkii.botania.common.item.ItemKeepIvy; import vazkii.botania.common.item.equipment.bauble.ItemBauble; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.util.function.Predicate; // Classloading-safe way to attach curio behaviour to our items @@ -41,6 +39,17 @@ public class CurioIntegration extends EquipmentHandler { InterModComms.sendTo("curios", CuriosAPI.IMC.REGISTER_TYPE, () -> new CurioIMCMessage("necklace")); } + @SubscribeEvent + public static void keepCurioDrops(LivingCurioDropRulesEvent event) { + event.addOverride(stack -> { + if (ItemKeepIvy.hasIvy(stack)) { + stack.removeChildTag(ItemKeepIvy.TAG_KEEP); + return true; + } + return false; + }, ICurio.DropRule.ALWAYS_KEEP); + } + @Override protected LazyOptional getAllWornItems(LivingEntity living) { return CuriosAPI.getCuriosHandler(living).map(h -> { diff --git a/src/main/java/vazkii/botania/common/item/ItemKeepIvy.java b/src/main/java/vazkii/botania/common/item/ItemKeepIvy.java index a83724633..947778900 100644 --- a/src/main/java/vazkii/botania/common/item/ItemKeepIvy.java +++ b/src/main/java/vazkii/botania/common/item/ItemKeepIvy.java @@ -16,7 +16,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraftforge.event.entity.living.LivingDropsEvent; import net.minecraftforge.event.entity.player.PlayerEvent; -import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import vazkii.botania.common.core.helper.ItemNBTHelper; @@ -38,7 +37,12 @@ public class ItemKeepIvy extends ItemMod { super(props); } - @SubscribeEvent(priority = EventPriority.LOWEST) + public static boolean hasIvy(ItemStack stack) { + return !stack.isEmpty() && stack.hasTag() && ItemNBTHelper.getBoolean(stack, TAG_KEEP, false); + } + + // Curios are handled in CurioIntegration#keepCurioDrops + @SubscribeEvent public static void onPlayerDrops(LivingDropsEvent event) { if(!(event.getEntityLiving() instanceof PlayerEntity)) return; @@ -86,8 +90,10 @@ public class ItemKeepIvy extends ItemMod { ItemStack stack = ItemStack.read(cmp2); if(!stack.isEmpty()) { ItemStack copy = stack.copy(); - ItemNBTHelper.setBoolean(copy, TAG_KEEP, false); - event.getPlayer().inventory.addItemStackToInventory(copy); + stack.removeChildTag(TAG_KEEP); + if (!event.getPlayer().inventory.addItemStackToInventory(copy)) { + event.getPlayer().entityDropItem(copy); + } } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index cb458dc11..12a6486ca 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -29,6 +29,6 @@ Botania is a mod that adds nature magic to Minecraft''' [[dependencies.botania]] modId="curios" mandatory=true - versionRange="[FORGE-1.14.4-1.0.2,)" + versionRange="[FORGE-1.14.4-1.0.6,)" ordering="AFTER" side="BOTH" \ No newline at end of file