Search in sources :

Example 6 with IBindable

use of WayofTime.bloodmagic.iface.IBindable in project BloodMagic by WayofTime.

the class NetworkHelper method canSyphonFromContainer.

/**
 * Checks if the ItemStack has a user to be syphoned from.
 *
 * @param stack    - ItemStack to check
 * @param toSyphon - Amount of LP to syphon
 * @return - If syphoning is possible
 */
public static boolean canSyphonFromContainer(ItemStack stack, 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);
    return network.getCurrentEssence() >= toSyphon;
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) IBindable(WayofTime.bloodmagic.iface.IBindable) SoulNetwork(WayofTime.bloodmagic.core.data.SoulNetwork)

Example 7 with IBindable

use of WayofTime.bloodmagic.iface.IBindable in project BloodMagic by WayofTime.

the class RitualExpulsion method performRitual.

@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
    World world = masterRitualStone.getWorldObj();
    int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
    if (currentEssence < getRefreshCost()) {
        masterRitualStone.getOwnerNetwork().causeNausea();
        return;
    }
    if (masterRitualStone.getWorldObj().isRemote)
        return;
    AreaDescriptor expulsionRange = getBlockRange(EXPULSION_RANGE);
    List<UUID> whitelist = Lists.newArrayList();
    BlockPos masterPos = masterRitualStone.getBlockPos();
    TileEntity tile = world.getTileEntity(masterPos.up());
    if (tile != null) {
        IItemHandler handler = Utils.getInventory(tile, null);
        if (handler != null) {
            for (int i = 0; i < handler.getSlots(); i++) {
                ItemStack itemStack = handler.getStackInSlot(i);
                if (!itemStack.isEmpty() && itemStack.getItem() instanceof IBindable) {
                    Binding binding = ((IBindable) itemStack.getItem()).getBinding(itemStack);
                    if (binding != null && !whitelist.contains(binding.getOwnerId()))
                        whitelist.add(binding.getOwnerId());
                }
            }
        }
    }
    final int teleportDistance = 100;
    for (EntityPlayer player : world.getEntitiesWithinAABB(EntityPlayer.class, expulsionRange.getAABB(masterRitualStone.getBlockPos()))) {
        if (player.capabilities.isCreativeMode || player.getGameProfile().getId().equals(masterRitualStone.getOwner()) || whitelist.contains(player.getGameProfile().getId()))
            continue;
        if (teleportRandomly(player, teleportDistance))
            masterRitualStone.getOwnerNetwork().syphon(getRefreshCost() * 1000);
    }
    whitelist.clear();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Binding(WayofTime.bloodmagic.core.data.Binding) IBindable(WayofTime.bloodmagic.iface.IBindable) IItemHandler(net.minecraftforge.items.IItemHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) UUID(java.util.UUID) ItemStack(net.minecraft.item.ItemStack)

Example 8 with IBindable

use of WayofTime.bloodmagic.iface.IBindable 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 9 with IBindable

use of WayofTime.bloodmagic.iface.IBindable 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 10 with IBindable

use of WayofTime.bloodmagic.iface.IBindable 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)

Aggregations

IBindable (WayofTime.bloodmagic.iface.IBindable)10 Binding (WayofTime.bloodmagic.core.data.Binding)8 ItemStack (net.minecraft.item.ItemStack)7 SoulNetwork (WayofTime.bloodmagic.core.data.SoulNetwork)5 BloodOrb (WayofTime.bloodmagic.orb.BloodOrb)3 IBloodOrb (WayofTime.bloodmagic.orb.IBloodOrb)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 TileAltar (WayofTime.bloodmagic.tile.TileAltar)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)2 World (net.minecraft.world.World)2 BloodMagicCraftedEvent (WayofTime.bloodmagic.api.event.BloodMagicCraftedEvent)1 RecipeBloodAltar (WayofTime.bloodmagic.api.impl.recipe.RecipeBloodAltar)1 ItemBindEvent (WayofTime.bloodmagic.event.ItemBindEvent)1 RitualEvent (WayofTime.bloodmagic.event.RitualEvent)1 SoulNetworkEvent (WayofTime.bloodmagic.event.SoulNetworkEvent)1 ItemActivationCrystal (WayofTime.bloodmagic.item.ItemActivationCrystal)1 UUID (java.util.UUID)1 PlayerNotFoundException (net.minecraft.command.PlayerNotFoundException)1