diff --git a/src/api/java/baubles/api/BaubleType.java b/src/api/java/baubles/api/BaubleType.java new file mode 100644 index 00000000..06fa86f2 --- /dev/null +++ b/src/api/java/baubles/api/BaubleType.java @@ -0,0 +1,14 @@ +package baubles.api; + +import org.apache.commons.lang3.NotImplementedException; + +/* + * stub + */ +public enum BaubleType { + AMULET, RING, BELT, TRINKET, HEAD, BODY, CHARM; + + public int[] getValidSlots() { + throw new NotImplementedException("getValidSlots"); + } +} diff --git a/src/api/java/baubles/api/BaublesApi.java b/src/api/java/baubles/api/BaublesApi.java new file mode 100644 index 00000000..9d0b3d66 --- /dev/null +++ b/src/api/java/baubles/api/BaublesApi.java @@ -0,0 +1,20 @@ +package baubles.api; + +import org.apache.commons.lang3.NotImplementedException; + +import baubles.api.cap.IBaublesItemHandler; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; + +/* + * stub + */ +public class BaublesApi { + public static IBaublesItemHandler getBaublesHandler(EntityPlayer player) { + throw new NotImplementedException("getBaublesHandler"); + } + + public static int isBaubleEquipped(EntityPlayer player, Item bauble) { + throw new NotImplementedException("isBaubleEquipped"); + } +} diff --git a/src/api/java/baubles/api/IBauble.java b/src/api/java/baubles/api/IBauble.java new file mode 100644 index 00000000..4694c968 --- /dev/null +++ b/src/api/java/baubles/api/IBauble.java @@ -0,0 +1,60 @@ +package baubles.api; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; + +/** + * + * This interface should be extended by items that can be worn in bauble slots + * + * @author Azanor + */ +public interface IBauble { + + /** + * This method return the type of bauble this is. + * Type is used to determine the slots it can go into. + */ + public BaubleType getBaubleType(ItemStack itemstack); + + /** + * This method is called once per tick if the bauble is being worn by a player + */ + public default void onWornTick(ItemStack itemstack, EntityLivingBase player) { + } + + /** + * This method is called when the bauble is equipped by a player + */ + public default void onEquipped(ItemStack itemstack, EntityLivingBase player) { + } + + /** + * This method is called when the bauble is unequipped by a player + */ + public default void onUnequipped(ItemStack itemstack, EntityLivingBase player) { + } + + /** + * can this bauble be placed in a bauble slot + */ + public default boolean canEquip(ItemStack itemstack, EntityLivingBase player) { + return true; + } + + /** + * Can this bauble be removed from a bauble slot + */ + public default boolean canUnequip(ItemStack itemstack, EntityLivingBase player) { + return true; + } + + /** + * Will bauble automatically sync to client if a change is detected in its NBT or damage values? + * Default is off, so override and set to true if you want to auto sync. + * This sync is not instant, but occurs every 10 ticks (.5 seconds). + */ + public default boolean willAutoSync(ItemStack itemstack, EntityLivingBase player) { + return false; + } +} diff --git a/src/api/java/baubles/api/cap/IBaublesItemHandler.java b/src/api/java/baubles/api/cap/IBaublesItemHandler.java new file mode 100644 index 00000000..a7a0e36c --- /dev/null +++ b/src/api/java/baubles/api/cap/IBaublesItemHandler.java @@ -0,0 +1,12 @@ +package baubles.api.cap; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandlerModifiable; + +/* + * stub + */ +public interface IBaublesItemHandler extends IItemHandlerModifiable { + boolean isItemValidForSlot(int slot, ItemStack stack, EntityLivingBase player); +} diff --git a/src/main/java/com/minelittlepony/unicopia/Unicopia.java b/src/main/java/com/minelittlepony/unicopia/Unicopia.java index ab135023..9f7e7c0c 100644 --- a/src/main/java/com/minelittlepony/unicopia/Unicopia.java +++ b/src/main/java/com/minelittlepony/unicopia/Unicopia.java @@ -43,7 +43,7 @@ import com.minelittlepony.unicopia.world.UWorld; modid = Unicopia.MODID, name = Unicopia.NAME, version = Unicopia.VERSION, - dependencies = "required-after:jumpingcastle" + dependencies = "required-after:jumpingcastle;after:baubles" ) public class Unicopia implements IGuiHandler { public static final String MODID = "unicopia"; diff --git a/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java b/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java index bdf5e02b..e46fd989 100644 --- a/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java +++ b/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java @@ -8,6 +8,7 @@ import javax.annotation.Nullable; import com.minelittlepony.jumpingcastle.api.Target; import com.minelittlepony.unicopia.entity.EntityFakeClientPlayer; +import com.minelittlepony.unicopia.extern.MineLP; import com.minelittlepony.unicopia.init.UEntities; import com.minelittlepony.unicopia.init.UParticles; import com.minelittlepony.unicopia.input.Keyboard; diff --git a/src/main/java/com/minelittlepony/unicopia/extern/BaubleAlicornAmulet.java b/src/main/java/com/minelittlepony/unicopia/extern/BaubleAlicornAmulet.java new file mode 100644 index 00000000..2bc8e16c --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/extern/BaubleAlicornAmulet.java @@ -0,0 +1,49 @@ +package com.minelittlepony.unicopia.extern; + +import com.minelittlepony.unicopia.item.ItemAlicornAmulet; + +import baubles.api.BaubleType; +import baubles.api.BaublesApi; +import baubles.api.IBauble; +import baubles.api.cap.IBaublesItemHandler; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; + +public class BaubleAlicornAmulet extends ItemAlicornAmulet implements IBauble { + + public BaubleAlicornAmulet(String domain, String name) { + super(domain, name); + } + + @Override + public BaubleType getBaubleType(ItemStack itemstack) { + return BaubleType.AMULET; + } + + @Override + public ActionResult onItemRightClick(World world, EntityPlayer player, EnumHand hand) { + ItemStack itemstack = player.getHeldItem(hand); + IBaublesItemHandler iplayer = BaublesApi.getBaublesHandler(player); + + for (int slot : getBaubleType(itemstack).getValidSlots()) { + if (iplayer.getStackInSlot(slot).isEmpty()) { + iplayer.setStackInSlot(slot, itemstack.copy()); + itemstack.setCount(0); + + return new ActionResult(EnumActionResult.SUCCESS, itemstack); + } + } + + return new ActionResult(EnumActionResult.FAIL, itemstack); + } + + @Override + public EntityEquipmentSlot getEquipmentSlot() { + return EntityEquipmentSlot.MAINHAND; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/extern/Baubles.java b/src/main/java/com/minelittlepony/unicopia/extern/Baubles.java new file mode 100644 index 00000000..2767dc0e --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/extern/Baubles.java @@ -0,0 +1,40 @@ +package com.minelittlepony.unicopia.extern; + +import java.util.function.Supplier; + +import baubles.api.BaubleType; +import baubles.api.BaublesApi; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; + +public class Baubles { + + private static boolean checkComplete; + private static boolean modIsActive; + + static boolean isModActive() { + if (!checkComplete) { + checkComplete = true; + + try { + modIsActive = BaubleType.AMULET.getValidSlots().length > 0; + } catch (Exception e) { + modIsActive = false; + } + } + + return modIsActive; + } + + public static T ifActiveElseGet(Supplier yes, Supplier no) { + return (isModActive() ? yes : no).get(); + } + + public static int isBaubleEquipped(EntityPlayer player, Item bauble) { + if (isModActive()) { + return BaublesApi.isBaubleEquipped(player, bauble); + } + + return -1; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/MineLP.java b/src/main/java/com/minelittlepony/unicopia/extern/MineLP.java similarity index 94% rename from src/main/java/com/minelittlepony/unicopia/MineLP.java rename to src/main/java/com/minelittlepony/unicopia/extern/MineLP.java index e1997a32..72650e23 100644 --- a/src/main/java/com/minelittlepony/unicopia/MineLP.java +++ b/src/main/java/com/minelittlepony/unicopia/extern/MineLP.java @@ -1,8 +1,9 @@ -package com.minelittlepony.unicopia; +package com.minelittlepony.unicopia.extern; import com.minelittlepony.MineLittlePony; import com.minelittlepony.pony.data.IPony; import com.minelittlepony.pony.data.PonyRace; +import com.minelittlepony.unicopia.Race; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/minelittlepony/unicopia/init/UItems.java b/src/main/java/com/minelittlepony/unicopia/init/UItems.java index 071669c2..7b0e719c 100644 --- a/src/main/java/com/minelittlepony/unicopia/init/UItems.java +++ b/src/main/java/com/minelittlepony/unicopia/init/UItems.java @@ -53,6 +53,8 @@ import com.minelittlepony.unicopia.edibles.FlowerToxicityDeterminent; import com.minelittlepony.unicopia.edibles.ItemEdible; import com.minelittlepony.unicopia.edibles.Toxicity; import com.minelittlepony.unicopia.edibles.UItemFoodDelegate; +import com.minelittlepony.unicopia.extern.BaubleAlicornAmulet; +import com.minelittlepony.unicopia.extern.Baubles; import com.minelittlepony.unicopia.forgebullshit.BuildInTexturesBakery; import com.minelittlepony.unicopia.forgebullshit.ItemModels; import com.minelittlepony.unicopia.forgebullshit.OreReplacer; @@ -110,7 +112,9 @@ public class UItems { public static final ItemSpell curse = new ItemCurse(Unicopia.MODID, "corrupted_gem"); public static final ItemOfHolding bag_of_holding = new ItemOfHolding(Unicopia.MODID, "bag_of_holding"); - public static final ItemAlicornAmulet alicorn_amulet = new ItemAlicornAmulet(Unicopia.MODID, "alicorn_amulet"); + public static final ItemAlicornAmulet alicorn_amulet = Baubles.ifActiveElseGet( + () -> new BaubleAlicornAmulet(Unicopia.MODID, "alicorn_amulet"), + () -> new ItemAlicornAmulet(Unicopia.MODID, "alicorn_amulet")); public static final ItemSpellbook spellbook = new ItemSpellbook(Unicopia.MODID, "spellbook"); public static final Item staff_meadow_brook = new ItemStaff(Unicopia.MODID, "staff_meadow_brook").setMaxDamage(2); diff --git a/src/main/java/com/minelittlepony/unicopia/item/ItemAlicornAmulet.java b/src/main/java/com/minelittlepony/unicopia/item/ItemAlicornAmulet.java index f204ff65..bc382522 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/ItemAlicornAmulet.java +++ b/src/main/java/com/minelittlepony/unicopia/item/ItemAlicornAmulet.java @@ -28,6 +28,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ActionResult; import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.SoundCategory; @@ -99,9 +100,13 @@ public class ItemAlicornAmulet extends ItemArmor implements IDependable { if (!player.world.isRemote && !entity.isDead) { if (player.getPositionVector().distanceTo(entity.getPositionVector()) < 3) { if (entity.world.rand.nextInt(150) == 0) { - player.setItemStackToSlot(getEquipmentSlot(), entity.getItem()); - entity.setPickupDelay(1000); - entity.setDead(); + + ActionResult result = onItemRightClick(player.world, player, EnumHand.MAIN_HAND); + + if (result.getType() == EnumActionResult.SUCCESS) { + entity.setPickupDelay(1000); + entity.setDead(); + } } } } @@ -213,15 +218,6 @@ public class ItemAlicornAmulet extends ItemArmor implements IDependable { } } - @Override - public ActionResult onItemRightClick(World world, EntityPlayer player, EnumHand hand) { - ActionResult result = super.onItemRightClick(world, player, hand); - - - - return result; - } - @Override public Multimap getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot) { Multimap multimap = HashMultimap.create();; diff --git a/src/main/java/com/minelittlepony/unicopia/player/PlayerInventory.java b/src/main/java/com/minelittlepony/unicopia/player/PlayerInventory.java index 8005261f..6082780a 100644 --- a/src/main/java/com/minelittlepony/unicopia/player/PlayerInventory.java +++ b/src/main/java/com/minelittlepony/unicopia/player/PlayerInventory.java @@ -4,6 +4,7 @@ import java.util.Iterator; import java.util.Map; import com.google.common.collect.Maps; +import com.minelittlepony.unicopia.extern.Baubles; import com.minelittlepony.unicopia.item.IDependable; import com.minelittlepony.unicopia.item.IMagicalItem; import com.minelittlepony.unicopia.util.serialisation.InbtSerialisable; @@ -75,7 +76,7 @@ public class PlayerInventory implements IInventory, IUpdatable, InbtSerialisable } } - return false; + return item instanceof Item && Baubles.isBaubleEquipped(player.getOwner(), (Item)item) != -1; } @Override