Search in sources :

Example 1 with IBloodAltar

use of WayofTime.alchemicalWizardry.api.tile.IBloodAltar in project BloodMagic by WayofTime.

the class PlayerSacrificeHandler method findAndFillAltar.

public static boolean findAndFillAltar(World world, EntityPlayer player, int amount) {
    int posX = (int) Math.round(player.posX - 0.5f);
    int posY = (int) player.posY;
    int posZ = (int) Math.round(player.posZ - 0.5f);
    IBloodAltar altarEntity = getAltar(world, posX, posY, posZ);
    if (altarEntity == null) {
        return false;
    }
    altarEntity.sacrificialDaggerCall(amount, false);
    altarEntity.startCycle();
    return true;
}
Also used : IBloodAltar(WayofTime.alchemicalWizardry.api.tile.IBloodAltar)

Example 2 with IBloodAltar

use of WayofTime.alchemicalWizardry.api.tile.IBloodAltar in project BloodMagic by WayofTime.

the class RitualEffectFeatheredKnife method performEffect.

@Override
public void performEffect(IMasterRitualStone ritualStone) {
    String owner = ritualStone.getOwner();
    int currentEssence = SoulNetworkHandler.getCurrentEssence(owner);
    World world = ritualStone.getWorld();
    int x = ritualStone.getXCoord();
    int y = ritualStone.getYCoord();
    int z = ritualStone.getZCoord();
    boolean hasPotentia = this.canDrainReagent(ritualStone, ReagentRegistry.potentiaReagent, potentiaDrain, false);
    int timeDelay = hasPotentia ? 10 : 20;
    if (world.getWorldTime() % timeDelay != 0) {
        return;
    }
    IBloodAltar tileAltar = null;
    boolean testFlag = false;
    for (int i = -5; i <= 5; i++) {
        for (int j = -5; j <= 5; j++) {
            for (int k = -10; k <= 10; k++) {
                if (world.getTileEntity(x + i, y + k, z + j) instanceof IBloodAltar) {
                    tileAltar = (IBloodAltar) world.getTileEntity(x + i, y + k, z + j);
                    testFlag = true;
                }
            }
        }
    }
    if (!testFlag) {
        return;
    }
    boolean hasReductus = this.canDrainReagent(ritualStone, ReagentRegistry.reductusReagent, reductusDrain, false);
    double range = hasReductus ? 8 : 15;
    double vertRange = hasReductus ? 8 : 20;
    List<EntityPlayer> list = SpellHelper.getPlayersInRange(world, x + 0.5, y + 0.5, z + 0.5, range, vertRange);
    int entityCount = 0;
    boolean flag = false;
    if (currentEssence < this.getCostPerRefresh() * list.size()) {
        SoulNetworkHandler.causeNauseaToPlayer(owner);
    } else {
        boolean hasMagicales = this.canDrainReagent(ritualStone, ReagentRegistry.magicalesReagent, magicalesDrain, false);
        boolean hasSanctus = this.canDrainReagent(ritualStone, ReagentRegistry.sanctusReagent, sanctusDrain, false);
        EntityPlayer ownerPlayer = SpellHelper.getPlayerForUsername(owner);
        for (EntityPlayer player : list) {
            hasSanctus = hasSanctus && this.canDrainReagent(ritualStone, ReagentRegistry.sanctusReagent, sanctusDrain, false);
            double threshold = hasSanctus ? 0.7d : 0.3d;
            if ((hasMagicales && player == ownerPlayer) || !hasMagicales) {
                if (!SpellHelper.isFakePlayer(world, player)) {
                    if (player.getHealth() / player.getMaxHealth() > threshold) {
                        player.setHealth(player.getHealth() - 1);
                        entityCount++;
                        tileAltar.sacrificialDaggerCall(this.amount, false);
                        if (hasSanctus) {
                            this.canDrainReagent(ritualStone, ReagentRegistry.sanctusReagent, sanctusDrain, true);
                        }
                        if (hasMagicales) {
                            this.canDrainReagent(ritualStone, ReagentRegistry.magicalesReagent, magicalesDrain, true);
                            break;
                        }
                    }
                }
            }
        }
        if (entityCount > 0) {
            if (hasReductus) {
                this.canDrainReagent(ritualStone, ReagentRegistry.reductusReagent, reductusDrain, true);
            }
            if (hasPotentia) {
                this.canDrainReagent(ritualStone, ReagentRegistry.potentiaReagent, potentiaDrain, true);
            }
            SoulNetworkHandler.syphonFromNetwork(owner, this.getCostPerRefresh() * entityCount);
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(net.minecraft.world.World) IBloodAltar(WayofTime.alchemicalWizardry.api.tile.IBloodAltar)

Example 3 with IBloodAltar

use of WayofTime.alchemicalWizardry.api.tile.IBloodAltar in project BloodMagic by WayofTime.

the class RitualEffectAutoAlchemy method performEffect.

@Override
public void performEffect(IMasterRitualStone ritualStone) {
    String owner = ritualStone.getOwner();
    int currentEssence = SoulNetworkHandler.getCurrentEssence(owner);
    World world = ritualStone.getWorld();
    int x = ritualStone.getXCoord();
    int y = ritualStone.getYCoord();
    int z = ritualStone.getZCoord();
    if (currentEssence < this.getCostPerRefresh() * 6) {
        SoulNetworkHandler.causeNauseaToPlayer(owner);
    } else {
        boolean hasPotentia = this.canDrainReagent(ritualStone, ReagentRegistry.potentiaReagent, potentiaDrain, false);
        int flag = 0;
        TileEntity topEntity = world.getTileEntity(x, y + 1, z);
        if (!(topEntity instanceof IBloodAltar) || !(topEntity instanceof IBloodAltar)) {
            return;
        }
        IBloodAltar altar = (IBloodAltar) topEntity;
        ItemStack targetStack = ((IInventory) altar).getStackInSlot(0);
        if (targetStack == null) {
            return;
        }
        ItemStack[] recipe = AlchemyRecipeRegistry.getRecipeForItemStack(targetStack);
        if (recipe != null) {
            TEWritingTable alchemyEntity;
            IInventory outputInv = null;
            IInventory inputInv1 = null;
            IInventory inputInv2 = null;
            TileEntity northEntity = world.getTileEntity(x, y, z - 1);
            TileEntity southEntity = world.getTileEntity(x, y, z + 1);
            TileEntity eastEntity = world.getTileEntity(x + 1, y, z);
            TileEntity westEntity = world.getTileEntity(x - 1, y, z);
            if (northEntity instanceof TEWritingTable) {
                alchemyEntity = (TEWritingTable) northEntity;
                if (southEntity instanceof IInventory && !(southEntity instanceof TEWritingTable)) {
                    outputInv = (IInventory) southEntity;
                }
                if (eastEntity instanceof IInventory && !(eastEntity instanceof TEWritingTable)) {
                    inputInv1 = (IInventory) eastEntity;
                }
                if (westEntity instanceof IInventory && !(westEntity instanceof TEWritingTable)) {
                    inputInv2 = (IInventory) westEntity;
                }
            } else if (southEntity instanceof TEWritingTable) {
                alchemyEntity = (TEWritingTable) southEntity;
                if (northEntity instanceof IInventory && !(northEntity instanceof TEWritingTable)) {
                    outputInv = (IInventory) northEntity;
                }
                if (eastEntity instanceof IInventory && !(eastEntity instanceof TEWritingTable)) {
                    inputInv1 = (IInventory) eastEntity;
                }
                if (westEntity instanceof IInventory && !(westEntity instanceof TEWritingTable)) {
                    inputInv2 = (IInventory) westEntity;
                }
            } else if (eastEntity instanceof TEWritingTable) {
                alchemyEntity = (TEWritingTable) eastEntity;
                if (westEntity instanceof IInventory && !(westEntity instanceof TEWritingTable)) {
                    outputInv = (IInventory) westEntity;
                }
                if (northEntity instanceof IInventory && !(northEntity instanceof TEWritingTable)) {
                    inputInv1 = (IInventory) northEntity;
                }
                if (southEntity instanceof IInventory && !(southEntity instanceof TEWritingTable)) {
                    inputInv2 = (IInventory) southEntity;
                }
            } else if (westEntity instanceof TEWritingTable) {
                alchemyEntity = (TEWritingTable) westEntity;
                if (eastEntity instanceof IInventory && !(eastEntity instanceof TEWritingTable)) {
                    outputInv = (IInventory) eastEntity;
                }
                if (northEntity instanceof IInventory && !(northEntity instanceof TEWritingTable)) {
                    inputInv1 = (IInventory) northEntity;
                }
                if (southEntity instanceof IInventory && !(southEntity instanceof TEWritingTable)) {
                    inputInv2 = (IInventory) southEntity;
                }
            } else {
                return;
            }
            if (alchemyEntity != null && hasPotentia) {
                alchemyEntity.setAccelerationTime(5);
                if (alchemyEntity.isWorking()) {
                    this.canDrainReagent(ritualStone, ReagentRegistry.potentiaReagent, potentiaDrain, true);
                }
            }
            if (outputInv != null) {
                ItemStack outputStack = alchemyEntity.getStackInSlot(6);
                if (outputStack != null) {
                    for (int i = 0; i < outputInv.getSizeInventory(); i++) {
                        ItemStack curStack = outputInv.getStackInSlot(i);
                        if (curStack == null) {
                            ItemStack copyStack = outputStack.copy();
                            copyStack.stackSize = 1;
                            outputStack.stackSize--;
                            if (outputStack.stackSize <= 0) {
                                alchemyEntity.setInventorySlotContents(6, null);
                            } else {
                                alchemyEntity.setInventorySlotContents(6, outputStack);
                            }
                            outputInv.setInventorySlotContents(i, copyStack);
                            flag++;
                            break;
                        } else if (curStack.isItemEqual(outputStack) && curStack.stackSize < curStack.getMaxStackSize() && ItemStack.areItemStackTagsEqual(outputStack, curStack)) {
                            outputStack.stackSize--;
                            if (outputStack.stackSize <= 0) {
                                alchemyEntity.setInventorySlotContents(6, null);
                            } else {
                                alchemyEntity.setInventorySlotContents(6, outputStack);
                            }
                            curStack.stackSize++;
                            outputInv.setInventorySlotContents(i, curStack);
                            flag++;
                            break;
                        }
                    }
                }
                for (int i = 0; i < 5; i++) {
                    ItemStack recItem;
                    if (recipe.length <= i) {
                        recItem = null;
                    } else {
                        recItem = recipe[i];
                    }
                    ItemStack alchStack = alchemyEntity.getStackInSlot(i + 1);
                    if ((recItem == null && alchStack != null) || (alchStack != null && !(areItemStacksEqualWithWildcard(recItem, alchStack)))) {
                        for (int j = 0; j < outputInv.getSizeInventory(); j++) {
                            ItemStack curStack = outputInv.getStackInSlot(j);
                            if (curStack == null) {
                                ItemStack copyStack = alchStack.copy();
                                copyStack.stackSize = 1;
                                alchStack.stackSize--;
                                if (alchStack.stackSize <= 0) {
                                    alchemyEntity.setInventorySlotContents(i + 1, null);
                                } else {
                                    alchemyEntity.setInventorySlotContents(i + 1, alchStack);
                                }
                                outputInv.setInventorySlotContents(j, copyStack);
                                flag++;
                                break;
                            } else if (curStack.isItemEqual(alchStack) && curStack.stackSize < curStack.getMaxStackSize() && ItemStack.areItemStackTagsEqual(alchStack, curStack)) {
                                alchStack.stackSize--;
                                if (alchStack.stackSize <= 0) {
                                    alchemyEntity.setInventorySlotContents(i + 1, null);
                                } else {
                                    alchemyEntity.setInventorySlotContents(i + 1, alchStack);
                                }
                                curStack.stackSize++;
                                outputInv.setInventorySlotContents(j, curStack);
                                flag++;
                                break;
                            }
                        }
                        continue;
                    }
                }
            }
            if (world.getWorldTime() % 10 == 0) {
                if (flag == 0 && inputInv1 != null) {
                    for (int i = 0; i < recipe.length; i++) {
                        ItemStack recItem = recipe[i];
                        if (recItem == null) {
                            continue;
                        }
                        ItemStack alchStack = alchemyEntity.getStackInSlot(i + 1);
                        if (alchStack != null && ((!areItemStacksEqualWithWildcard(recItem, alchStack)) || alchStack.stackSize >= (fillToOne ? 1 : alchStack.getMaxStackSize()))) {
                            continue;
                        }
                        for (int j = 0; j < inputInv1.getSizeInventory(); j++) {
                            ItemStack curItem = inputInv1.getStackInSlot(j);
                            if (curItem == null) {
                                continue;
                            }
                            if (!inputInv1.isItemValidForSlot(j, curItem) || (inputInv1 instanceof ISidedInventory && !((ISidedInventory) inputInv1).canExtractItem(j, curItem, ForgeDirection.DOWN.ordinal()))) {
                                continue;
                            }
                            if (areItemStacksEqualWithWildcard(recItem, curItem)) {
                                if (alchStack == null) {
                                    ItemStack copyStack = recItem.copy();
                                    copyStack.stackSize = 1;
                                    alchemyEntity.setInventorySlotContents(i + 1, copyStack);
                                    curItem.stackSize--;
                                    if (curItem.stackSize <= 0) {
                                        inputInv1.setInventorySlotContents(j, null);
                                    } else {
                                        inputInv1.setInventorySlotContents(j, curItem);
                                    }
                                    flag++;
                                    break;
                                } else {
                                    alchStack.stackSize++;
                                    alchemyEntity.setInventorySlotContents(i + 1, alchStack);
                                    curItem.stackSize--;
                                    if (curItem.stackSize <= 0) {
                                        inputInv1.setInventorySlotContents(j, null);
                                    } else {
                                        inputInv1.setInventorySlotContents(j, curItem);
                                    }
                                    flag++;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (flag == 0 && inputInv2 != null) {
                    for (int i = 0; i < recipe.length; i++) {
                        ItemStack recItem = recipe[i];
                        if (recItem == null) {
                            continue;
                        }
                        ItemStack alchStack = alchemyEntity.getStackInSlot(i + 1);
                        if (alchStack != null && ((!areItemStacksEqualWithWildcard(recItem, alchStack)) || alchStack.stackSize >= (fillToOne ? 1 : alchStack.getMaxStackSize()))) {
                            continue;
                        }
                        for (int j = 0; j < inputInv2.getSizeInventory(); j++) {
                            ItemStack curItem = inputInv2.getStackInSlot(j);
                            if (curItem == null) {
                                continue;
                            }
                            if (areItemStacksEqualWithWildcard(recItem, curItem)) {
                                if (alchStack == null) {
                                    ItemStack copyStack = recItem.copy();
                                    copyStack.stackSize = 1;
                                    alchemyEntity.setInventorySlotContents(i + 1, copyStack);
                                    curItem.stackSize--;
                                    if (curItem.stackSize <= 0) {
                                        inputInv2.setInventorySlotContents(j, null);
                                    } else {
                                        inputInv2.setInventorySlotContents(j, curItem);
                                    }
                                    flag++;
                                    break;
                                } else {
                                    alchStack.stackSize++;
                                    alchemyEntity.setInventorySlotContents(i + 1, alchStack);
                                    curItem.stackSize--;
                                    if (curItem.stackSize <= 0) {
                                        inputInv2.setInventorySlotContents(j, null);
                                    } else {
                                        inputInv2.setInventorySlotContents(j, curItem);
                                    }
                                    flag++;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (flag > 0) {
            world.markBlockForUpdate(x, y, z + 1);
            world.markBlockForUpdate(x, y, z - 1);
            world.markBlockForUpdate(x + 1, y, z);
            world.markBlockForUpdate(x - 1, y, z);
            SoulNetworkHandler.syphonFromNetwork(owner, this.getCostPerRefresh() * flag);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) TEWritingTable(WayofTime.alchemicalWizardry.common.tileEntity.TEWritingTable) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) IBloodAltar(WayofTime.alchemicalWizardry.api.tile.IBloodAltar)

Example 4 with IBloodAltar

use of WayofTime.alchemicalWizardry.api.tile.IBloodAltar in project BloodMagic by WayofTime.

the class CreativeDagger method findAndFillAltar.

public void findAndFillAltar(World world, EntityPlayer player, int amount) {
    int posX = (int) Math.round(player.posX - 0.5f);
    int posY = (int) player.posY;
    int posZ = (int) Math.round(player.posZ - 0.5f);
    IBloodAltar altarEntity = getAltar(world, posX, posY, posZ);
    if (altarEntity == null) {
        return;
    }
    altarEntity.sacrificialDaggerCall(amount, false);
    altarEntity.startCycle();
}
Also used : IBloodAltar(WayofTime.alchemicalWizardry.api.tile.IBloodAltar)

Example 5 with IBloodAltar

use of WayofTime.alchemicalWizardry.api.tile.IBloodAltar in project BloodMagic by WayofTime.

the class RitualEffectLifeConduit method performEffect.

@Override
public void performEffect(IMasterRitualStone ritualStone) {
    String owner = ritualStone.getOwner();
    int currentEssence = SoulNetworkHandler.getCurrentEssence(owner);
    World world = ritualStone.getWorld();
    int x = ritualStone.getXCoord();
    int y = ritualStone.getYCoord();
    int z = ritualStone.getZCoord();
    IBloodAltar tileAltar = null;
    boolean testFlag = false;
    for (int i = -5; i <= 5; i++) {
        for (int j = -5; j <= 5; j++) {
            for (int k = -10; k <= 10; k++) {
                if (world.getTileEntity(x + i, y + k, z + j) instanceof IBloodAltar) {
                    tileAltar = (IBloodAltar) world.getTileEntity(x + i, y + k, z + j);
                    testFlag = true;
                }
            }
        }
    }
    if (!testFlag) {
        return;
    }
    if (!(tileAltar instanceof IFluidHandler)) {
        return;
    }
    int d0 = 15;
    int vertRange = 20;
    EntityPlayer entityOwner = null;
    List<EntityPlayer> list = SpellHelper.getPlayersInRange(world, x, y, z, d0, vertRange);
    for (EntityPlayer player : list) {
        if (SpellHelper.getUsername(player).equals(owner)) {
            entityOwner = player;
        }
    }
    if (entityOwner == null) {
        return;
    }
    int fillAmount = Math.min(currentEssence / 2, ((IFluidHandler) tileAltar).fill(ForgeDirection.UP, new FluidStack(AlchemicalWizardry.lifeEssenceFluid, 10000), false));
    {
        ((IFluidHandler) tileAltar).fill(ForgeDirection.UP, new FluidStack(AlchemicalWizardry.lifeEssenceFluid, fillAmount), true);
        if (entityOwner.getHealth() > 2.0f && fillAmount != 0) {
            entityOwner.setHealth(2.0f);
        }
        SoulNetworkHandler.syphonFromNetwork(owner, fillAmount * 2);
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(net.minecraft.world.World) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) IBloodAltar(WayofTime.alchemicalWizardry.api.tile.IBloodAltar)

Aggregations

IBloodAltar (WayofTime.alchemicalWizardry.api.tile.IBloodAltar)9 World (net.minecraft.world.World)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 TEWritingTable (WayofTime.alchemicalWizardry.common.tileEntity.TEWritingTable)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 IInventory (net.minecraft.inventory.IInventory)1 ISidedInventory (net.minecraft.inventory.ISidedInventory)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)1