Search in sources :

Example 1 with IDemonWillGem

use of WayofTime.bloodmagic.soul.IDemonWillGem in project BloodMagic by WayofTime.

the class TileSoulForge method drainDemonWill.

@Override
public double drainDemonWill(EnumDemonWillType type, double amount, boolean doDrain) {
    ItemStack stack = this.getStackInSlot(soulSlot);
    if (stack.isEmpty() || !(stack.getItem() instanceof IDemonWillGem)) {
        return 0;
    }
    IDemonWillGem willGem = (IDemonWillGem) stack.getItem();
    double drained = amount;
    double current = willGem.getWill(type, stack);
    if (current < drained) {
        drained = current;
    }
    if (doDrain) {
        drained = willGem.drainWill(type, stack, drained, true);
    }
    return drained;
}
Also used : IDemonWillGem(WayofTime.bloodmagic.soul.IDemonWillGem) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IDemonWillGem

use of WayofTime.bloodmagic.soul.IDemonWillGem in project BloodMagic by WayofTime.

the class TileDemonCrucible method update.

@Override
public void update() {
    if (getWorld().isRemote) {
        return;
    }
    internalCounter++;
    if (getWorld().isBlockPowered(getPos())) {
        // TODO: Fill the contained gem if it is there.
        ItemStack stack = this.getStackInSlot(0);
        if (stack.getItem() instanceof IDemonWillGem) {
            IDemonWillGem gemItem = (IDemonWillGem) stack.getItem();
            for (EnumDemonWillType type : EnumDemonWillType.values()) {
                if (willMap.containsKey(type)) {
                    double current = willMap.get(type);
                    double fillAmount = Math.min(gemDrainRate, current);
                    if (fillAmount > 0) {
                        fillAmount = gemItem.fillWill(type, stack, fillAmount, true);
                        if (willMap.get(type) - fillAmount <= 0) {
                            willMap.remove(type);
                        } else {
                            willMap.put(type, willMap.get(type) - fillAmount);
                        }
                    }
                }
            }
        }
    } else {
        ItemStack stack = this.getStackInSlot(0);
        if (!stack.isEmpty()) {
            if (stack.getItem() instanceof IDemonWillGem) {
                IDemonWillGem gemItem = (IDemonWillGem) stack.getItem();
                for (EnumDemonWillType type : EnumDemonWillType.values()) {
                    double currentAmount = WorldDemonWillHandler.getCurrentWill(getWorld(), pos, type);
                    double drainAmount = Math.min(maxWill - currentAmount, gemDrainRate);
                    double filled = WorldDemonWillHandler.fillWillToMaximum(getWorld(), pos, type, drainAmount, maxWill, false);
                    filled = gemItem.drainWill(type, stack, filled, false);
                    if (filled > 0) {
                        filled = gemItem.drainWill(type, stack, filled, true);
                        WorldDemonWillHandler.fillWillToMaximum(getWorld(), pos, type, filled, maxWill, true);
                    }
                }
            } else if (// TODO: Limit the speed of this process
            stack.getItem() instanceof IDiscreteDemonWill) {
                IDiscreteDemonWill willItem = (IDiscreteDemonWill) stack.getItem();
                EnumDemonWillType type = willItem.getType(stack);
                double currentAmount = WorldDemonWillHandler.getCurrentWill(getWorld(), pos, type);
                double needed = maxWill - currentAmount;
                double discreteAmount = willItem.getDiscretization(stack);
                if (needed >= discreteAmount) {
                    double filled = willItem.drainWill(stack, discreteAmount);
                    if (filled > 0) {
                        WorldDemonWillHandler.fillWillToMaximum(getWorld(), pos, type, filled, maxWill, true);
                        if (stack.getCount() <= 0) {
                            this.setInventorySlotContents(0, ItemStack.EMPTY);
                        }
                    }
                }
            }
        }
    }
}
Also used : IDemonWillGem(WayofTime.bloodmagic.soul.IDemonWillGem) IDiscreteDemonWill(WayofTime.bloodmagic.soul.IDiscreteDemonWill) ItemStack(net.minecraft.item.ItemStack) EnumDemonWillType(WayofTime.bloodmagic.soul.EnumDemonWillType)

Example 3 with IDemonWillGem

use of WayofTime.bloodmagic.soul.IDemonWillGem in project BloodMagic by WayofTime.

the class TileSoulForge method consumeSouls.

public double consumeSouls(EnumDemonWillType type, double requested) {
    ItemStack soulStack = getStackInSlot(soulSlot);
    if (soulStack != null) {
        if (soulStack.getItem() instanceof IDemonWill && ((IDemonWill) soulStack.getItem()).getType(soulStack) == type) {
            IDemonWill soul = (IDemonWill) soulStack.getItem();
            double souls = soul.drainWill(type, soulStack, requested);
            if (soul.getWill(type, soulStack) <= 0) {
                setInventorySlotContents(soulSlot, ItemStack.EMPTY);
            }
            return souls;
        }
        if (soulStack.getItem() instanceof IDemonWillGem) {
            IDemonWillGem soul = (IDemonWillGem) soulStack.getItem();
            return soul.drainWill(type, soulStack, requested, true);
        }
    }
    return 0;
}
Also used : IDemonWillGem(WayofTime.bloodmagic.soul.IDemonWillGem) IDemonWill(WayofTime.bloodmagic.soul.IDemonWill) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IDemonWillGem

use of WayofTime.bloodmagic.soul.IDemonWillGem in project BloodMagic by WayofTime.

the class ContainerSoulForge 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 == 5) {
            if (!this.mergeItemStack(itemstack1, 6, 6 + 36, true)) {
                return ItemStack.EMPTY;
            }
            slot.onSlotChange(itemstack1, itemstack);
        } else if (index > 5) {
            if (itemstack1.getItem() instanceof IDemonWill || itemstack1.getItem() instanceof IDemonWillGem) {
                if (!this.mergeItemStack(itemstack1, 4, 5, false)) {
                    return ItemStack.EMPTY;
                }
            } else if (!this.mergeItemStack(itemstack1, 0, 4, false)) {
                return ItemStack.EMPTY;
            }
        } else if (!this.mergeItemStack(itemstack1, 6, 42, 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 : IDemonWillGem(WayofTime.bloodmagic.soul.IDemonWillGem) Slot(net.minecraft.inventory.Slot) IDemonWill(WayofTime.bloodmagic.soul.IDemonWill) ItemStack(net.minecraft.item.ItemStack)

Example 5 with IDemonWillGem

use of WayofTime.bloodmagic.soul.IDemonWillGem in project BloodMagic by WayofTime.

the class TileSoulForge method fillDemonWill.

@Override
public double fillDemonWill(EnumDemonWillType type, double amount, boolean doFill) {
    if (amount <= 0) {
        return 0;
    }
    if (!canFill(type)) {
        return 0;
    }
    ItemStack stack = this.getStackInSlot(soulSlot);
    if (stack.isEmpty() || !(stack.getItem() instanceof IDemonWillGem)) {
        return 0;
    }
    IDemonWillGem willGem = (IDemonWillGem) stack.getItem();
    return willGem.fillWill(type, stack, amount, doFill);
}
Also used : IDemonWillGem(WayofTime.bloodmagic.soul.IDemonWillGem) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IDemonWillGem (WayofTime.bloodmagic.soul.IDemonWillGem)6 ItemStack (net.minecraft.item.ItemStack)6 IDemonWill (WayofTime.bloodmagic.soul.IDemonWill)2 IDiscreteDemonWill (WayofTime.bloodmagic.soul.IDiscreteDemonWill)2 EnumDemonWillType (WayofTime.bloodmagic.soul.EnumDemonWillType)1 TileDemonCrucible (WayofTime.bloodmagic.tile.TileDemonCrucible)1 Slot (net.minecraft.inventory.Slot)1