Search in sources :

Example 11 with Binding

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

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

the class BindableHelper method applyBinding.

public static void applyBinding(ItemStack stack, EntityPlayer player) {
    Binding binding = new Binding(player.getGameProfile().getId(), player.getGameProfile().getName());
    applyBinding(stack, binding);
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding)

Example 13 with Binding

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

the class ItemLavaCrystal method getContainerItem.

@Override
public ItemStack getContainerItem(ItemStack stack) {
    Binding binding = getBinding(stack);
    if (binding != null)
        NetworkHelper.getSoulNetwork(binding.getOwnerId()).syphon(25);
    ItemStack returnStack = new ItemStack(this);
    returnStack.setTagCompound(stack.getTagCompound());
    return returnStack;
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) ItemStack(net.minecraft.item.ItemStack)

Example 14 with Binding

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

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

the class TileTeleposer method initiateTeleport.

public void initiateTeleport() {
    if (!getWorld().isRemote && canInitiateTeleport() && getBlockType() instanceof BlockTeleposer) {
        ItemStack focusStack = getStackInSlot(0);
        ItemTelepositionFocus focus = (ItemTelepositionFocus) focusStack.getItem();
        Binding binding = focus.getBinding(focusStack);
        if (binding == null)
            return;
        BlockPos focusPos = focus.getBlockPos(getStackInSlot(0));
        World focusWorld = focus.getWorld(getStackInSlot(0));
        if (focusWorld == null)
            return;
        TileEntity boundTile = focusWorld.getTileEntity(focusPos);
        if (boundTile instanceof TileTeleposer && boundTile != this) {
            final int focusLevel = (getStackInSlot(0).getItemDamage() + 1);
            final int lpToBeDrained = (int) (0.5F * Math.sqrt((pos.getX() - focusPos.getX()) * (pos.getX() - focusPos.getX()) + (pos.getY() - focusPos.getY() + 1) * (pos.getY() - focusPos.getY() + 1) + (pos.getZ() - focusPos.getZ()) * (pos.getZ() - focusPos.getZ())));
            if (NetworkHelper.getSoulNetwork(binding).syphonAndDamage(PlayerHelper.getPlayerFromUUID(binding.getOwnerId()), lpToBeDrained * (focusLevel * 2 - 1) * (focusLevel * 2 - 1) * (focusLevel * 2 - 1))) {
                int blocksTransported = 0;
                for (int i = -(focusLevel - 1); i <= (focusLevel - 1); i++) {
                    for (int j = 0; j <= (focusLevel * 2 - 2); j++) {
                        for (int k = -(focusLevel - 1); k <= (focusLevel - 1); k++) {
                            TeleposeEvent event = new TeleposeEvent(getWorld(), pos.add(i, 1 + j, k), focusWorld, focusPos.add(i, 1 + j, k));
                            if (Utils.swapLocations(event.initalWorld, event.initialBlockPos, event.finalWorld, event.finalBlockPos) && !MinecraftForge.EVENT_BUS.post(event)) {
                                blocksTransported++;
                            }
                        }
                    }
                }
                NetworkHelper.syphonFromContainer(focusStack, lpToBeDrained * blocksTransported);
                List<Entity> originalWorldEntities;
                List<Entity> focusWorldEntities;
                AxisAlignedBB originalArea = new AxisAlignedBB(pos.getX(), pos.getY() + 1, pos.getZ(), pos.getX() + 1, Math.min(focusWorld.getHeight(), pos.getY() + 2 * focusLevel), pos.getZ() + 1).expand(focusLevel - 1, 0, focusLevel - 1);
                originalWorldEntities = getWorld().getEntitiesWithinAABB(Entity.class, originalArea);
                AxisAlignedBB focusArea = new AxisAlignedBB(focusPos.getX(), focusPos.getY() + 1, focusPos.getZ(), focusPos.getX() + 1, Math.min(focusWorld.getHeight(), focusPos.getY() + 2 * focusLevel), focusPos.getZ() + 1).expand(focusLevel - 1, 0, focusLevel - 1);
                focusWorldEntities = focusWorld.getEntitiesWithinAABB(Entity.class, focusArea);
                if (focusWorld.equals(getWorld())) {
                    if (!originalWorldEntities.isEmpty()) {
                        for (Entity entity : originalWorldEntities) {
                            TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, binding.getOwnerId(), true));
                        }
                    }
                    if (!focusWorldEntities.isEmpty()) {
                        for (Entity entity : focusWorldEntities) {
                            TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, binding.getOwnerId(), true));
                        }
                    }
                }
            // FIXME - Fix cross-dimension teleports causing major desync
            // } else {
            // if (!originalWorldEntities.isEmpty()) {
            // for (Entity entity : originalWorldEntities) {
            // TeleportQueue.getInstance().addITeleport(new Teleports.TeleportToDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, focusStack.getTagCompound().getString(Constants.NBT.OWNER_UUID), getWorld(), focusWorld.provider.getDimension(), true));
            // }
            // }
            // 
            // if (!focusWorldEntities.isEmpty()) {
            // for (Entity entity : focusWorldEntities) {
            // TeleportQueue.getInstance().addITeleport(new Teleports.TeleportToDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, focusStack.getTagCompound().getString(Constants.NBT.OWNER_UUID), focusWorld, getWorld().provider.getDimension(), true));
            // }
            // }
            // }
            }
        }
    }
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) BlockTeleposer(WayofTime.bloodmagic.block.BlockTeleposer) World(net.minecraft.world.World) Teleports(WayofTime.bloodmagic.ritual.portal.Teleports) TileEntity(net.minecraft.tileentity.TileEntity) TeleposeEvent(WayofTime.bloodmagic.event.TeleposeEvent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) ItemTelepositionFocus(WayofTime.bloodmagic.item.ItemTelepositionFocus)

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