Bump Curios, handle curio drop event for ivy, drop items that don't fit

This commit is contained in:
Hubry committed 2020-03-11 01:19:59 +01:00
1 parent 058b03660f
commit 11ea832cbe
5 files changed
+27 -12

No files matched your search

@@ -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"));
}
@@ -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<IItemHandlerModifiable> getAllWornItems(LivingEntity living) {
return CuriosAPI.getCuriosHandler(living).map(h -> {
@@ -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);
}
}
}