diff --git a/libs/Baubles-1.12-1.5.2.jar b/libs/Baubles-1.12-1.5.2.jar new file mode 100644 index 0000000..e99f1d9 Binary files /dev/null and b/libs/Baubles-1.12-1.5.2.jar differ diff --git a/project.gradle b/project.gradle index 8fdbf9f..fcb3d6f 100755 --- a/project.gradle +++ b/project.gradle @@ -27,14 +27,13 @@ if (!ext.early) { repositories { // the skeleton already defines mavenCentral, jcenter, and the Elytra repo // will also have Shadowfacts' maven if the language is set to kotlin - ivy { - //Resolves baubles and jankson - name "endless.blue dependency mirror"; - artifactPattern "https://endless.blue/files/ivy/[module]-[revision].[ext]" - } + flatDir { + // baubles in /libs + dirs 'libs' + } } dependencies { - compile name: "Baubles", version: "1.12-1.5.2" + deobfCompile name: "Baubles-1.12-1.5.2" } } diff --git a/src/main/java/com/elytradev/friendshipbracelet/ItemBraceletKeyring.java b/src/main/java/com/elytradev/friendshipbracelet/ItemBraceletKeyring.java index 71bf640..fb6cec0 100644 --- a/src/main/java/com/elytradev/friendshipbracelet/ItemBraceletKeyring.java +++ b/src/main/java/com/elytradev/friendshipbracelet/ItemBraceletKeyring.java @@ -1,9 +1,12 @@ package com.elytradev.friendshipbracelet; +import baubles.api.BaubleType; import baubles.api.BaublesApi; +import baubles.api.IBauble; import baubles.api.cap.IBaublesItemHandler; import com.elytradev.concrete.inventory.ConcreteItemStorage; import com.elytradev.concrete.inventory.ValidatedItemHandlerView; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.I18n; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.creativetab.CreativeTabs; @@ -31,7 +34,7 @@ import java.util.List; import java.util.UUID; -public class ItemBraceletKeyring extends Item { +public class ItemBraceletKeyring extends Item implements IBauble { public String name; public NBTTagCompound tag; @@ -49,6 +52,16 @@ public EnumAction getItemUseAction(ItemStack stack) { return EnumAction.BOW; } + @Override + public BaubleType getBaubleType(ItemStack itemStack) { + return BaubleType.TRINKET; + } + + @Override + public boolean canEquip(ItemStack stack, EntityLivingBase player) { + return true; + } + @SubscribeEvent public void addCapability(AttachCapabilitiesEvent e) { if (e.getObject() instanceof ItemStack) { @@ -139,7 +152,7 @@ public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase MinecraftServer server = world.getMinecraftServer(); if (!world.isRemote) { EntityPlayer to = server.getPlayerList().getPlayerByUUID(id); - if (isAcceptingTeleports(to)) { + if (isAcceptingTeleports(to, player)) { player.attemptTeleport(to.posX, to.posY, to.posZ); player.playSound(SoundEvents.BLOCK_PORTAL_TRAVEL, 1f, 1f); player.getCooldownTracker().setCooldown(this, 300); @@ -152,12 +165,31 @@ public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase return stack; } - private boolean isAcceptingTeleports(EntityPlayer player) { - IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(player); - for(int i = 0; i < baubles.getSlots(); i++) { + private boolean isAcceptingTeleports(EntityPlayer to, EntityPlayer from) { + IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(to); + for (int i = 0; i < baubles.getSlots(); i++) { ItemStack stackInSlot = baubles.getStackInSlot(i); if (!stackInSlot.isEmpty()) { if (baubles.getStackInSlot(i).getItem().equals(ItemFriendshipBracelet.FRIENDSHIP_BRACELET)) return true; + else if (baubles.getStackInSlot(i).getItem().equals(ItemFriendshipBracelet.BRACELET_KEYRING)) { + return hasKeyringMatch(from, stackInSlot); + } + } + } + return false; + } + + private boolean hasKeyringMatch(EntityPlayer player, ItemStack keyring) { + UUID playerID = player.getPersistentID(); + if (!keyring.hasTagCompound()) return false; + ConcreteItemStorage inv = (ConcreteItemStorage)keyring.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); + if (inv == null) return false; + for (int i = 0; i < 6; i++) { + ItemStack bracelet = inv.getStackInSlot(i); + if (!bracelet.isEmpty() && bracelet.hasTagCompound()) { + if (!bracelet.getTagCompound().hasKey("PlayerIDMost")) return false; + UUID braceletID = bracelet.getTagCompound().getUniqueId("PlayerID"); + if (braceletID.equals(playerID)) return true; } } return false; @@ -189,6 +221,12 @@ public void addInformation(ItemStack stack, @Nullable World worldIn, List