Search in sources :

Example 1 with IBloodOrb

use of WayofTime.bloodmagic.orb.IBloodOrb in project BloodMagic by WayofTime.

the class ContainerAlchemyTable method transferStackInSlot.

@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
    ItemStack itemstack = ItemStack.EMPTY;
    Slot slot = this.inventorySlots.get(index);
    if (slot != null && slot.getHasStack()) {
        ItemStack itemstack1 = slot.getStack();
        itemstack = itemstack1.copy();
        if (index == 8) {
            if (!this.mergeItemStack(itemstack1, 9, 9 + 36, true)) {
                return ItemStack.EMPTY;
            }
            slot.onSlotChange(itemstack1, itemstack);
        } else if (index > 8) {
            if (itemstack1.getItem() instanceof IBloodOrb) {
                if (// TODO: Add alchemy tools to list
                !this.mergeItemStack(itemstack1, 7, 8, false)) {
                    return ItemStack.EMPTY;
                }
            } else if (!this.mergeItemStack(itemstack1, 0, 6, false)) {
                return ItemStack.EMPTY;
            }
        } else if (!this.mergeItemStack(itemstack1, 9, 9 + 36, false)) {
            return ItemStack.EMPTY;
        }
        if (itemstack1.getCount() == 0) {
            slot.putStack(ItemStack.EMPTY);
        } else {
            slot.onSlotChanged();
        }
        if (itemstack1.getCount() == itemstack.getCount()) {
            return ItemStack.EMPTY;
        }
        slot.onTake(playerIn, itemstack1);
    }
    return itemstack;
}
Also used : Slot(net.minecraft.inventory.Slot) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IBloodOrb

use of WayofTime.bloodmagic.orb.IBloodOrb in project BloodMagic by WayofTime.

the class BloodAltar method startCycle.

public void startCycle() {
    if (tileAltar.getWorld() != null)
        tileAltar.getWorld().notifyBlockUpdate(tileAltar.getPos(), tileAltar.getWorld().getBlockState(tileAltar.getPos()), tileAltar.getWorld().getBlockState(tileAltar.getPos()), 3);
    checkTier();
    if ((fluid == null || fluid.amount <= 0) && totalCharge <= 0)
        return;
    if (!isActive)
        progress = 0;
    ItemStack input = tileAltar.getStackInSlot(0);
    if (!input.isEmpty()) {
        // Do recipes
        RecipeBloodAltar recipe = BloodMagicAPI.INSTANCE.getRecipeRegistrar().getBloodAltar(input);
        if (recipe != null) {
            if (recipe.getMinimumTier().ordinal() <= altarTier.ordinal()) {
                this.isActive = true;
                this.recipe = recipe;
                this.liquidRequired = recipe.getSyphon();
                this.consumptionRate = recipe.getConsumeRate();
                this.drainRate = recipe.getDrainRate();
                this.canBeFilled = false;
                return;
            }
        } else if (input.getItem() instanceof IBloodOrb) {
            this.isActive = true;
            this.canBeFilled = true;
            return;
        }
    }
    isActive = false;
}
Also used : RecipeBloodAltar(WayofTime.bloodmagic.api.impl.recipe.RecipeBloodAltar) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IBloodOrb

use of WayofTime.bloodmagic.orb.IBloodOrb in project BloodMagic by WayofTime.

the class BloodAltar method updateAltar.

private void updateAltar() {
    if (!isActive) {
        if (cooldownAfterCrafting > 0)
            cooldownAfterCrafting--;
        return;
    }
    ItemStack input = tileAltar.getStackInSlot(0);
    if (input.isEmpty())
        return;
    World world = tileAltar.getWorld();
    BlockPos pos = tileAltar.getPos();
    if (world.isRemote)
        return;
    if (!canBeFilled) {
        boolean hasOperated = false;
        int stackSize = input.getCount();
        if (totalCharge > 0) {
            int chargeDrained = Math.min(liquidRequired * stackSize - progress, totalCharge);
            totalCharge -= chargeDrained;
            progress += chargeDrained;
            hasOperated = true;
        }
        if (fluid != null && fluid.amount >= 1) {
            int liquidDrained = Math.min((int) (altarTier.ordinal() >= 2 ? consumptionRate * (1 + consumptionMultiplier) : consumptionRate), fluid.amount);
            if (liquidDrained > (liquidRequired * stackSize - progress))
                liquidDrained = liquidRequired * stackSize - progress;
            fluid.amount = fluid.amount - liquidDrained;
            progress += liquidDrained;
            hasOperated = true;
            if (internalCounter % 4 == 0 && world instanceof WorldServer) {
                WorldServer server = (WorldServer) world;
                server.spawnParticle(EnumParticleTypes.REDSTONE, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 1, 0.2, 0, 0.2, 0);
            }
        } else if (!hasOperated && progress > 0) {
            progress -= (int) (efficiencyMultiplier * drainRate);
            if (internalCounter % 2 == 0 && world instanceof WorldServer) {
                WorldServer server = (WorldServer) world;
                server.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 1, 0.1, 0, 0.1, 0);
            }
        }
        if (hasOperated) {
            if (progress >= liquidRequired * stackSize) {
                ItemStack result = ItemHandlerHelper.copyStackWithSize(recipe.getOutput(), stackSize);
                BloodMagicCraftedEvent.Altar event = new BloodMagicCraftedEvent.Altar(recipe.getInput(), result);
                MinecraftForge.EVENT_BUS.post(event);
                tileAltar.setInventorySlotContents(0, event.getOutput());
                progress = 0;
                if (world instanceof WorldServer) {
                    WorldServer server = (WorldServer) world;
                    server.spawnParticle(EnumParticleTypes.REDSTONE, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 40, 0.3, 0, 0.3, 0);
                }
                this.cooldownAfterCrafting = 30;
                this.isActive = false;
            }
        }
    } else {
        ItemStack contained = tileAltar.getStackInSlot(0);
        if (contained.isEmpty() || !(contained.getItem() instanceof IBloodOrb) || !(contained.getItem() instanceof IBindable))
            return;
        BloodOrb orb = ((IBloodOrb) contained.getItem()).getOrb(contained);
        Binding binding = ((IBindable) contained.getItem()).getBinding(contained);
        if (binding == null || orb == null)
            return;
        if (fluid != null && fluid.amount >= 1) {
            int liquidDrained = Math.min((int) (altarTier.ordinal() >= 2 ? orb.getFillRate() * (1 + consumptionMultiplier) : orb.getFillRate()), fluid.amount);
            int drain = NetworkHelper.getSoulNetwork(binding).add(liquidDrained, (int) (orb.getCapacity() * this.orbCapacityMultiplier));
            fluid.amount = fluid.amount - drain;
            if (drain > 0 && internalCounter % 4 == 0 && world instanceof WorldServer) {
                WorldServer server = (WorldServer) world;
                server.spawnParticle(EnumParticleTypes.SPELL_WITCH, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 1, 0, 0, 0, 0.001);
            }
        }
    }
    tileAltar.getWorld().notifyBlockUpdate(tileAltar.getPos(), tileAltar.getWorld().getBlockState(tileAltar.getPos()), tileAltar.getWorld().getBlockState(tileAltar.getPos()), 3);
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) IBindable(WayofTime.bloodmagic.iface.IBindable) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) BloodOrb(WayofTime.bloodmagic.orb.BloodOrb) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) WorldServer(net.minecraft.world.WorldServer) BloodMagicCraftedEvent(WayofTime.bloodmagic.api.event.BloodMagicCraftedEvent) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) RecipeBloodAltar(WayofTime.bloodmagic.api.impl.recipe.RecipeBloodAltar) TileAltar(WayofTime.bloodmagic.tile.TileAltar)

Example 4 with IBloodOrb

use of WayofTime.bloodmagic.orb.IBloodOrb in project BloodMagic by WayofTime.

the class TileAlchemyTable method getContainedLp.

public int getContainedLp() {
    ItemStack orbStack = getStackInSlot(orbSlot);
    if (!orbStack.isEmpty()) {
        if (orbStack.getItem() instanceof IBloodOrb) {
            NBTTagCompound itemTag = orbStack.getTagCompound();
            if (itemTag == null) {
                return 0;
            }
            String ownerUUID = itemTag.getString(Constants.NBT.OWNER_UUID);
            if (Strings.isNullOrEmpty(ownerUUID)) {
                return 0;
            }
            SoulNetwork network = NetworkHelper.getSoulNetwork(ownerUUID);
            return network.getCurrentEssence();
        }
    }
    return 0;
}
Also used : SoulNetwork(WayofTime.bloodmagic.core.data.SoulNetwork) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IBloodOrb(WayofTime.bloodmagic.orb.IBloodOrb) ItemStack(net.minecraft.item.ItemStack)

Example 5 with IBloodOrb

use of WayofTime.bloodmagic.orb.IBloodOrb 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

IBloodOrb (WayofTime.bloodmagic.orb.IBloodOrb)8 ItemStack (net.minecraft.item.ItemStack)8 Binding (WayofTime.bloodmagic.core.data.Binding)3 SoulNetwork (WayofTime.bloodmagic.core.data.SoulNetwork)3 IBindable (WayofTime.bloodmagic.iface.IBindable)3 BloodOrb (WayofTime.bloodmagic.orb.BloodOrb)3 RecipeBloodAltar (WayofTime.bloodmagic.api.impl.recipe.RecipeBloodAltar)2 IngredientBloodOrb (WayofTime.bloodmagic.core.recipe.IngredientBloodOrb)2 TileAltar (WayofTime.bloodmagic.tile.TileAltar)2 Ingredient (net.minecraft.item.crafting.Ingredient)2 BloodMagicCraftedEvent (WayofTime.bloodmagic.api.event.BloodMagicCraftedEvent)1 ItemBindEvent (WayofTime.bloodmagic.event.ItemBindEvent)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Slot (net.minecraft.inventory.Slot)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 WorldServer (net.minecraft.world.WorldServer)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1