Search in sources :

Example 16 with Binding

use of WayofTime.bloodmagic.core.data.Binding 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)

Example 17 with Binding

use of WayofTime.bloodmagic.core.data.Binding in project BloodMagic by WayofTime.

the class NetworkHelper method syphonFromContainer.

/**
 * Syphons a player from within a container.
 *
 * @param stack    - ItemStack in the Container.
 * @param toSyphon - Amount of LP to syphon
 * @return - If the syphon was successful.
 */
public static // TODO: Change to a String, int?
boolean syphonFromContainer(// TODO: Change to a String, int?
ItemStack stack, // TODO: Change to a String, int?
int toSyphon) {
    if (!(stack.getItem() instanceof IBindable))
        return false;
    Binding binding = ((IBindable) stack.getItem()).getBinding(stack);
    if (binding == null)
        return false;
    SoulNetwork network = getSoulNetwork(binding);
    SoulNetworkEvent.ItemDrainInContainerEvent event = new SoulNetworkEvent.ItemDrainInContainerEvent(stack, binding.getOwnerId(), toSyphon);
    return !(MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) && network.syphon(event.syphon) >= toSyphon;
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) IBindable(WayofTime.bloodmagic.iface.IBindable) SoulNetwork(WayofTime.bloodmagic.core.data.SoulNetwork) SoulNetworkEvent(WayofTime.bloodmagic.event.SoulNetworkEvent)

Example 18 with Binding

use of WayofTime.bloodmagic.core.data.Binding in project BloodMagic by WayofTime.

the class BlockAltar method getComparatorInputOverride.

@Override
public int getComparatorInputOverride(IBlockState state, World world, BlockPos pos) {
    if (world.isRemote)
        return 0;
    TileEntity tile = world.getTileEntity(pos);
    if (tile != null && tile instanceof TileAltar) {
        TileAltar altar = (TileAltar) tile;
        ItemStack orbStack = altar.getStackInSlot(0);
        if (world.getBlockState(pos.down()).getBlock() instanceof BlockDecorative) {
            if (orbStack.getItem() instanceof IBloodOrb && orbStack.getItem() instanceof IBindable) {
                BloodOrb orb = ((IBloodOrb) orbStack.getItem()).getOrb(orbStack);
                Binding binding = ((IBindable) orbStack.getItem()).getBinding(orbStack);
                if (orb != null && binding != null) {
                    SoulNetwork soulNetwork = NetworkHelper.getSoulNetwork(binding);
                    int maxEssence = orb.getCapacity();
                    int currentEssence = soulNetwork.getCurrentEssence();
                    int level = currentEssence * 15 / maxEssence;
                    return Math.min(15, level) % 16;
                }
            }
        } else {
            int maxEssence = altar.getCapacity();
            int currentEssence = altar.getCurrentBlood();
            int level = currentEssence * 15 / maxEssence;
            return Math.min(15, level) % 16;
        }
    }
    return 0;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Binding(WayofTime.bloodmagic.core.data.Binding) IBindable(WayofTime.bloodmagic.iface.IBindable) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) BloodOrb(WayofTime.bloodmagic.orb.BloodOrb) SoulNetwork(WayofTime.bloodmagic.core.data.SoulNetwork) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) ItemStack(net.minecraft.item.ItemStack) TileAltar(WayofTime.bloodmagic.tile.TileAltar)

Example 19 with Binding

use of WayofTime.bloodmagic.core.data.Binding in project BloodMagic by WayofTime.

the class ItemBoundSword method addInformation.

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
    if (!stack.hasTagCompound())
        return;
    if (TextHelper.canTranslate("tooltip.bloodmagic.bound.sword.desc"))
        tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.bound.sword.desc"));
    tooltip.add(TextHelper.localize("tooltip.bloodmagic." + (getActivated(stack) ? "activated" : "deactivated")));
    Binding binding = getBinding(stack);
    if (binding != null)
        tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName()));
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 20 with Binding

use of WayofTime.bloodmagic.core.data.Binding in project BloodMagic by WayofTime.

the class ItemActivationCrystal method addInformation.

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
    tooltip.add(TextHelper.localize("tooltip.bloodmagic.activation_crystal." + getItemType(stack).getInternalName()));
    if (!stack.hasTagCompound())
        return;
    Binding binding = getBinding(stack);
    if (binding != null)
        tooltip.add(TextHelper.localizeEffect("tooltip.bloodmagic.currentOwner", binding.getOwnerName()));
    super.addInformation(stack, world, tooltip, flag);
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

Binding (WayofTime.bloodmagic.core.data.Binding)23 ItemStack (net.minecraft.item.ItemStack)11 IBindable (WayofTime.bloodmagic.iface.IBindable)8 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)7 SoulNetwork (WayofTime.bloodmagic.core.data.SoulNetwork)6 BloodOrb (WayofTime.bloodmagic.orb.BloodOrb)4 IBloodOrb (WayofTime.bloodmagic.orb.IBloodOrb)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 BlockPos (net.minecraft.util.math.BlockPos)4 TileEntity (net.minecraft.tileentity.TileEntity)3 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)3 World (net.minecraft.world.World)3 TileAltar (WayofTime.bloodmagic.tile.TileAltar)2 BloodMagicCraftedEvent (WayofTime.bloodmagic.api.event.BloodMagicCraftedEvent)1 RecipeBloodAltar (WayofTime.bloodmagic.api.impl.recipe.RecipeBloodAltar)1 BlockTeleposer (WayofTime.bloodmagic.block.BlockTeleposer)1 ItemBindEvent (WayofTime.bloodmagic.event.ItemBindEvent)1 RitualEvent (WayofTime.bloodmagic.event.RitualEvent)1 SoulNetworkEvent (WayofTime.bloodmagic.event.SoulNetworkEvent)1 TeleposeEvent (WayofTime.bloodmagic.event.TeleposeEvent)1