Skip to content

Commit

Permalink
baubleize the keyring
Browse files Browse the repository at this point in the history
  • Loading branch information
LemmaEOF committed Jul 22, 2018
1 parent 6ae4bea commit b08c7c1
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 20 deletions.
Binary file added libs/Baubles-1.12-1.5.2.jar
Binary file not shown.
11 changes: 5 additions & 6 deletions project.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -189,6 +221,12 @@ public void addInformation(ItemStack stack, @Nullable World worldIn, List<String
tooltip.add(I18n.format("tooltip.fb.keyring_blank"));
}
}
if (!GuiScreen.isShiftKeyDown()) {
tooltip.add(I18n.format("preview.fb.keyring"));
} else {
tooltip.add(I18n.format("tooltip.fb.keyring.0"));
tooltip.add(I18n.format("tooltip.fb.keyring.1"));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import baubles.api.BaublesApi;
import baubles.api.IBauble;
import baubles.api.cap.IBaublesItemHandler;
import com.elytradev.concrete.inventory.ConcreteItemStorage;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -18,6 +19,7 @@
import net.minecraft.util.EnumHand;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.registries.IForgeRegistry;

import java.util.UUID;
Expand Down Expand Up @@ -48,6 +50,11 @@ public EnumAction getItemUseAction(ItemStack stack) {
return EnumAction.BOW;
}

@Override
public BaubleType getBaubleType(ItemStack itemStack) {
return BaubleType.RING;
}

@Override
public boolean canEquip(ItemStack stack, EntityLivingBase player) {
if (stack.getTagCompound() == null) return false;
Expand Down Expand Up @@ -97,7 +104,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);
Expand All @@ -110,17 +117,31 @@ public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase
return stack;
}

@Override
public BaubleType getBaubleType(ItemStack itemStack) {
return BaubleType.RING;
}

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(FRIENDSHIP_BRACELET)) return true;
else if (baubles.getStackInSlot(i).getItem().equals(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;
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/friendshipbracelet/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ item.friendship_bracelet.rename='s Friendship Bracelet
item.bracelet_keyring.name=Bracelet Keyring

#tooltips
tooltip.fb.keyring.0=Teleports you to the owner of the top slot's bracelet
tooltip.fb.keyring.1=Equip to let only owners of bracelets in the keyring teleport to you
tooltip.fb.keyring=Currently selected: %s
tooltip.fb.keyring_blank=No bracelet in top slot
preview.fb.keyring=Hold §dSHIFT §7for info

#messages
msg.fb.notOnline=Player not online!
Expand Down

0 comments on commit b08c7c1

Please sign in to comment.