Search in sources :

Example 1 with ItemBindEvent

use of WayofTime.bloodmagic.event.ItemBindEvent in project BloodMagic by WayofTime.

the class GenericHandler method onInteract.

// Handles binding of IBindable's as well as setting a player's highest orb tier
@SubscribeEvent
public static void onInteract(PlayerInteractEvent.RightClickItem event) {
    if (event.getWorld().isRemote)
        return;
    EntityPlayer player = event.getEntityPlayer();
    if (PlayerHelper.isFakePlayer(player))
        return;
    ItemStack held = event.getItemStack();
    if (!held.isEmpty() && held.getItem() instanceof IBindable) {
        // Make sure it's bindable
        IBindable bindable = (IBindable) held.getItem();
        Binding binding = bindable.getBinding(held);
        if (binding == null) {
            // If the binding is null, let's create one
            if (bindable.onBind(player, held)) {
                ItemBindEvent toPost = new ItemBindEvent(player, held);
                if (// Allow cancellation of binding
                MinecraftForge.EVENT_BUS.post(toPost))
                    return;
                // Bind item to the player
                BindableHelper.applyBinding(held, player);
            }
        // If the binding exists, we'll check if the player's name has changed since they last used it and update that if so.
        } else if (binding.getOwnerId().equals(player.getGameProfile().getId()) && !binding.getOwnerName().equals(player.getGameProfile().getName())) {
            binding.setOwnerName(player.getGameProfile().getName());
            BindableHelper.applyBinding(held, binding);
        }
    }
    if (!held.isEmpty() && held.getItem() instanceof IBloodOrb) {
        IBloodOrb bloodOrb = (IBloodOrb) held.getItem();
        SoulNetwork network = NetworkHelper.getSoulNetwork(player);
        BloodOrb orb = bloodOrb.getOrb(held);
        if (orb == null)
            return;
        if (orb.getTier() > network.getOrbTier())
            network.setOrbTier(orb.getTier());
    }
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) IBindable(WayofTime.bloodmagic.iface.IBindable) SoulNetwork(WayofTime.bloodmagic.core.data.SoulNetwork) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) BloodOrb(WayofTime.bloodmagic.orb.BloodOrb) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) ItemBindEvent(WayofTime.bloodmagic.event.ItemBindEvent) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

Binding (WayofTime.bloodmagic.core.data.Binding)1 SoulNetwork (WayofTime.bloodmagic.core.data.SoulNetwork)1 ItemBindEvent (WayofTime.bloodmagic.event.ItemBindEvent)1 IBindable (WayofTime.bloodmagic.iface.IBindable)1 BloodOrb (WayofTime.bloodmagic.orb.BloodOrb)1 IBloodOrb (WayofTime.bloodmagic.orb.IBloodOrb)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1