Search in sources :

Example 31 with EnumDemonWillType

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

the class RitualCrushing method performRitual.

@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
    World world = masterRitualStone.getWorldObj();
    int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
    if (currentEssence < getRefreshCost()) {
        masterRitualStone.getOwnerNetwork().causeNausea();
        return;
    }
    BlockPos pos = masterRitualStone.getBlockPos();
    AreaDescriptor chestRange = getBlockRange(CHEST_RANGE);
    TileEntity tile = world.getTileEntity(chestRange.getContainedPositions(pos).get(0));
    if (tile != null && Utils.getNumberOfFreeSlots(tile, EnumFacing.DOWN) < 1) {
        return;
    }
    List<EnumDemonWillType> willConfig = masterRitualStone.getActiveWillConfig();
    double rawWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.DEFAULT, willConfig);
    double steadfastWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.STEADFAST, willConfig);
    double corrosiveWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.CORROSIVE, willConfig);
    double destructiveWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.DESTRUCTIVE, willConfig);
    double vengefulWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.VENGEFUL, willConfig);
    refreshTime = getRefreshTimeForRawWill(rawWill);
    boolean consumeRawWill = rawWill >= rawWillDrain && refreshTime != defaultRefreshTime;
    boolean isSilkTouch = steadfastWill >= steadfastWillDrain;
    boolean useCuttingFluid = corrosiveWill > 0;
    int fortune = destructiveWill > 0 ? 3 : 0;
    AreaDescriptor crushingRange = getBlockRange(CRUSHING_RANGE);
    boolean hasOperated = false;
    double rawDrain = 0;
    for (BlockPos newPos : crushingRange.getContainedPositions(pos)) {
        if (world.isAirBlock(newPos)) {
            continue;
        }
        IBlockState state = world.getBlockState(newPos);
        Block block = state.getBlock();
        if (block.equals(RegistrarBloodMagicBlocks.RITUAL_CONTROLLER) || block.equals(RegistrarBloodMagicBlocks.RITUAL_STONE) || block.getBlockHardness(state, world, newPos) == -1.0F || Utils.isBlockLiquid(state)) {
            continue;
        }
        boolean isBlockClaimed = false;
        if (useCuttingFluid) {
            ItemStack checkStack = block.getItem(world, newPos, state);
            if (checkStack.isEmpty()) {
                continue;
            }
            ItemStack copyStack = checkStack.copy();
            for (Entry<ItemStack, Integer> entry : cuttingFluidLPMap.entrySet()) {
                ItemStack cuttingStack = entry.getKey();
                int lpDrain = entry.getValue();
                double willDrain = cuttingFluidWillMap.containsKey(cuttingStack) ? cuttingFluidWillMap.get(cuttingStack) : 0;
                if (corrosiveWill < willDrain || currentEssence < lpDrain + getRefreshCost()) {
                    continue;
                }
                cuttingStack = cuttingStack.copy();
                List<ItemStack> input = new ArrayList<>();
                input.add(cuttingStack);
                input.add(copyStack);
                AlchemyTableRecipe recipe = AlchemyTableRecipeRegistry.getMatchingRecipe(input, world, pos);
                if (recipe == null) {
                    continue;
                }
                ItemStack result = recipe.getRecipeOutput(input);
                if (result.isEmpty()) {
                    continue;
                }
                if (tile != null) {
                    result = Utils.insertStackIntoTile(result, tile, EnumFacing.DOWN);
                    if (!result.isEmpty()) {
                        Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, result);
                    }
                } else {
                    Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, result);
                }
                WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.CORROSIVE, willDrain, true);
                corrosiveWill -= willDrain;
                masterRitualStone.getOwnerNetwork().syphon(lpDrain);
                currentEssence -= lpDrain;
                isBlockClaimed = true;
            }
        }
        if (!isBlockClaimed && isSilkTouch && block.canSilkHarvest(world, newPos, state, null)) {
            ItemStack checkStack = block.getItem(world, newPos, state);
            if (checkStack.isEmpty()) {
                continue;
            }
            ItemStack copyStack = checkStack.copy();
            if (steadfastWill >= steadfastWillDrain) {
                WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.STEADFAST, steadfastWillDrain, true);
                steadfastWill -= steadfastWillDrain;
            } else {
                continue;
            }
            if (tile != null)
                copyStack = Utils.insertStackIntoTile(copyStack, tile, EnumFacing.DOWN);
            else
                Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, copyStack);
            if (!copyStack.isEmpty()) {
                Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, copyStack);
            }
        } else if (!isBlockClaimed) {
            if (fortune > 0 && destructiveWill < destructiveWillDrain) {
                fortune = 0;
            }
            List<ItemStack> stackList = block.getDrops(world, newPos, state, fortune);
            for (ItemStack item : stackList) {
                ItemStack copyStack = item.copy();
                if (tile != null) {
                    copyStack = Utils.insertStackIntoTile(copyStack, tile, EnumFacing.DOWN);
                } else {
                    Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, copyStack);
                    continue;
                }
                if (!copyStack.isEmpty()) {
                    Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, copyStack);
                }
            }
            if (fortune > 0) {
                WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.DESTRUCTIVE, destructiveWillDrain, true);
                destructiveWill -= destructiveWillDrain;
            }
        }
        world.destroyBlock(newPos, false);
        masterRitualStone.getOwnerNetwork().syphon(getRefreshCost());
        hasOperated = true;
        if (consumeRawWill) {
            rawDrain += rawWillDrain;
            rawWill -= rawWillDrain;
        }
        break;
    }
    if (hasOperated && tile != null && vengefulWill >= vengefulWillDrain) {
        Pair<ItemStack, Boolean> pair = CompressionRegistry.compressInventory(tile, world);
        if (pair.getRight()) {
            ItemStack returned = pair.getLeft();
            if (returned != null) {
                Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, returned);
            }
            WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.VENGEFUL, vengefulWillDrain, true);
        }
    }
    if (rawDrain > 0) {
        WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.DEFAULT, rawDrain, true);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ArrayList(java.util.ArrayList) AlchemyTableRecipe(WayofTime.bloodmagic.recipe.alchemyTable.AlchemyTableRecipe) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ArrayList(java.util.ArrayList) List(java.util.List) EnumDemonWillType(WayofTime.bloodmagic.soul.EnumDemonWillType) ItemStack(net.minecraft.item.ItemStack)

Example 32 with EnumDemonWillType

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

the class RitualMeteor method performRitual.

@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
    World world = masterRitualStone.getWorldObj();
    int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
    BlockPos pos = masterRitualStone.getBlockPos();
    List<EnumDemonWillType> willConfig = masterRitualStone.getActiveWillConfig();
    double corrosiveWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.CORROSIVE, willConfig);
    double destructiveWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.DESTRUCTIVE, willConfig);
    double rawWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.DEFAULT, willConfig);
    double steadfastWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.STEADFAST, willConfig);
    double vengefulWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.VENGEFUL, willConfig);
    AreaDescriptor itemDetectionRange = getBlockRange(ITEM_RANGE);
    List<EntityItem> itemList = world.getEntitiesWithinAABB(EntityItem.class, itemDetectionRange.getAABB(pos));
    double radiusModifier = getRadiusModifier(rawWill);
    double explosionModifier = getExplosionModifier(steadfastWill);
    double fillerChance = getFillerChance(corrosiveWill);
    boolean successful = false;
    for (EntityItem entityItem : itemList) {
        ItemStack stack = entityItem.getItem();
        Meteor meteor = MeteorRegistry.getMeteorForItem(stack);
        if (meteor != null) {
            EntityMeteor entityMeteor = new EntityMeteor(world, pos.getX(), 260, pos.getZ(), 0, -0.1, 0, radiusModifier, explosionModifier, fillerChance);
            entityMeteor.setMeteorStack(stack.copy());
            world.spawnEntity(entityMeteor);
            entityItem.setDead();
            if (destructiveWill >= destructiveWillDrain && currentEssence >= 1000000000) {
                masterRitualStone.getOwnerNetwork().syphon(1000000);
            } else {
                masterRitualStone.setActive(false);
            }
            successful = true;
            break;
        }
    }
    if (successful) {
        if (rawWill > 0) {
            WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.DEFAULT, rawWill, true);
        }
        if (corrosiveWill > 0) {
            WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.CORROSIVE, corrosiveWill, true);
        }
        if (steadfastWill > 0) {
            WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.STEADFAST, steadfastWill, true);
        }
    }
}
Also used : Meteor(WayofTime.bloodmagic.meteor.Meteor) EntityMeteor(WayofTime.bloodmagic.entity.projectile.EntityMeteor) EntityMeteor(WayofTime.bloodmagic.entity.projectile.EntityMeteor) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) EnumDemonWillType(WayofTime.bloodmagic.soul.EnumDemonWillType) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 33 with EnumDemonWillType

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

the class RitualAnimalGrowth method performRitual.

@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
    World world = masterRitualStone.getWorldObj();
    int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
    if (currentEssence < getRefreshCost()) {
        masterRitualStone.getOwnerNetwork().causeNausea();
        return;
    }
    int maxGrowths = currentEssence / getRefreshCost();
    int totalGrowths = 0;
    BlockPos pos = masterRitualStone.getBlockPos();
    AreaDescriptor chestRange = getBlockRange(CHEST_RANGE);
    TileEntity chest = world.getTileEntity(chestRange.getContainedPositions(pos).get(0));
    IItemHandler itemHandler = null;
    if (chest != null) {
        itemHandler = Utils.getInventory(chest, null);
    }
    List<EnumDemonWillType> willConfig = masterRitualStone.getActiveWillConfig();
    double rawWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.DEFAULT, willConfig);
    double steadfastWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.STEADFAST, willConfig);
    double corrosiveWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.CORROSIVE, willConfig);
    double destructiveWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.DESTRUCTIVE, willConfig);
    double vengefulWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.VENGEFUL, willConfig);
    refreshTime = getRefreshTimeForRawWill(rawWill);
    boolean consumeRawWill = rawWill >= rawWillDrain && refreshTime != defaultRefreshTime;
    double vengefulDrain = 0;
    double steadfastDrain = 0;
    double destructiveDrain = 0;
    boolean decreaseBreedTimer = vengefulWill >= vengefulWillDrain;
    boolean breedAnimals = steadfastWill >= steadfastWillDrain && itemHandler != null;
    boolean kamikaze = destructiveWill >= destructiveWillDrain;
    AreaDescriptor growingRange = getBlockRange(GROWTH_RANGE);
    AxisAlignedBB axis = growingRange.getAABB(masterRitualStone.getBlockPos());
    List<EntityAnimal> animalList = world.getEntitiesWithinAABB(EntityAnimal.class, axis);
    boolean performedEffect = false;
    for (EntityAnimal animal : animalList) {
        if (animal.getGrowingAge() < 0) {
            animal.addGrowth(5);
            totalGrowths++;
            performedEffect = true;
        } else if (animal.getGrowingAge() > 0) {
            if (decreaseBreedTimer) {
                if (vengefulWill >= vengefulWillDrain) {
                    animal.setGrowingAge(Math.max(0, animal.getGrowingAge() - getBreedingDecreaseForWill(vengefulWill)));
                    vengefulDrain += vengefulWillDrain;
                    vengefulWill -= vengefulWillDrain;
                    performedEffect = true;
                } else {
                    decreaseBreedTimer = false;
                }
            }
        } else {
            if (kamikaze) {
                if (destructiveWill >= destructiveWillDrain) {
                    if (!animal.isPotionActive(RegistrarBloodMagic.SACRIFICIAL_LAMB)) {
                        animal.addPotionEffect(new PotionEffect(RegistrarBloodMagic.SACRIFICIAL_LAMB, 1200));
                        destructiveDrain += destructiveWillDrain;
                        destructiveWill -= destructiveWillDrain;
                        performedEffect = true;
                    }
                } else {
                    kamikaze = false;
                }
            }
            if (breedAnimals) {
                if (steadfastWill >= steadfastWillDrain) {
                    if (!animal.isInLove()) {
                        for (int slot = 0; slot < itemHandler.getSlots(); slot++) {
                            ItemStack foodStack = itemHandler.getStackInSlot(slot);
                            if (foodStack != null && animal.isBreedingItem(foodStack) && itemHandler.extractItem(slot, 1, true) != null) {
                                animal.setInLove(null);
                                itemHandler.extractItem(slot, 1, false);
                                steadfastDrain += steadfastWillDrain;
                                steadfastWill -= steadfastWillDrain;
                                performedEffect = true;
                                break;
                            }
                        }
                    }
                } else {
                    breedAnimals = false;
                }
            }
        }
        if (totalGrowths >= maxGrowths) {
            break;
        }
    }
    if (performedEffect && consumeRawWill) {
        WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.DEFAULT, rawWillDrain, true);
    }
    if (vengefulDrain > 0) {
        WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.VENGEFUL, vengefulDrain, true);
    }
    if (steadfastDrain > 0) {
        WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.STEADFAST, steadfastDrain, true);
    }
    if (destructiveDrain > 0) {
        WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.DESTRUCTIVE, destructiveDrain, true);
    }
    masterRitualStone.getOwnerNetwork().syphon(totalGrowths * getRefreshCost());
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IItemHandler(net.minecraftforge.items.IItemHandler) PotionEffect(net.minecraft.potion.PotionEffect) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) EnumDemonWillType(WayofTime.bloodmagic.soul.EnumDemonWillType) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) ItemStack(net.minecraft.item.ItemStack)

Example 34 with EnumDemonWillType

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

the class TileSoulForge method update.

@Override
public void update() {
    if (!getWorld().isRemote) {
        for (EnumDemonWillType type : EnumDemonWillType.values()) {
            double willInWorld = WorldDemonWillHandler.getCurrentWill(getWorld(), pos, type);
            double filled = Math.min(willInWorld, worldWillTransferRate);
            if (filled > 0) {
                filled = this.fillDemonWill(type, filled, false);
                filled = WorldDemonWillHandler.drainWill(getWorld(), pos, type, filled, false);
                if (filled > 0) {
                    this.fillDemonWill(type, filled, true);
                    WorldDemonWillHandler.drainWill(getWorld(), pos, type, filled, true);
                }
            }
        }
    }
    if (!hasSoulGemOrSoul()) {
        burnTime = 0;
        return;
    }
    double soulsInGem = getWill(EnumDemonWillType.DEFAULT);
    List<ItemStack> inputList = new ArrayList<>();
    for (int i = 0; i < 4; i++) if (!getStackInSlot(i).isEmpty())
        inputList.add(getStackInSlot(i));
    RecipeTartaricForge recipe = BloodMagicAPI.INSTANCE.getRecipeRegistrar().getTartaricForge(inputList);
    if (recipe != null && (soulsInGem >= recipe.getMinimumSouls() || burnTime > 0)) {
        if (canCraft(recipe)) {
            burnTime++;
            if (burnTime == ticksRequired) {
                if (!getWorld().isRemote) {
                    double requiredSouls = recipe.getSoulDrain();
                    if (requiredSouls > 0) {
                        if (!getWorld().isRemote && soulsInGem >= recipe.getMinimumSouls()) {
                            consumeSouls(EnumDemonWillType.DEFAULT, requiredSouls);
                        }
                    }
                    if (!getWorld().isRemote && soulsInGem >= recipe.getMinimumSouls())
                        craftItem(recipe);
                }
                burnTime = 0;
            } else if (burnTime > ticksRequired + 10) {
                burnTime = 0;
            }
        } else {
            burnTime = 0;
        }
    } else {
        burnTime = 0;
    }
}
Also used : ArrayList(java.util.ArrayList) EnumDemonWillType(WayofTime.bloodmagic.soul.EnumDemonWillType) ItemStack(net.minecraft.item.ItemStack) RecipeTartaricForge(WayofTime.bloodmagic.api.impl.recipe.RecipeTartaricForge)

Example 35 with EnumDemonWillType

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

the class TileDemonCrystal method growCrystalWithWillAmount.

/**
 * Encourages the crystal to grow by a large percentage by telling it to
 * drain will from the aura.
 *
 * @param willDrain          The amount of drain that is needed for the crystal to grow
 *                           successfully for the desired amount. Can be more than the base
 *                           amount.
 * @param progressPercentage
 * @return percentage actually grown.
 */
public double growCrystalWithWillAmount(double willDrain, double progressPercentage) {
    if (crystalCount >= 7) {
        return 0;
    }
    IBlockState state = getWorld().getBlockState(pos);
    int meta = this.getBlockType().getMetaFromState(state);
    EnumDemonWillType type = EnumDemonWillType.values()[meta];
    double value = WorldDemonWillHandler.getCurrentWill(getWorld(), pos, type);
    double percentDrain = willDrain <= 0 ? 1 : Math.min(1, value / willDrain);
    if (percentDrain <= 0) {
        return 0;
    }
    // Verification that you can actually drain the will from this chunk, for future proofing.
    WorldDemonWillHandler.drainWill(getWorld(), pos, type, percentDrain * willDrain, true);
    progressToNextCrystal += percentDrain * progressPercentage;
    checkAndGrowCrystal();
    return percentDrain * progressPercentage;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumDemonWillType(WayofTime.bloodmagic.soul.EnumDemonWillType)

Aggregations

EnumDemonWillType (WayofTime.bloodmagic.soul.EnumDemonWillType)65 ItemStack (net.minecraft.item.ItemStack)21 BlockPos (net.minecraft.util.math.BlockPos)14 EntityPlayer (net.minecraft.entity.player.EntityPlayer)13 World (net.minecraft.world.World)13 PotionEffect (net.minecraft.potion.PotionEffect)6 TileEntity (net.minecraft.tileentity.TileEntity)6 EntitySentientSpecter (WayofTime.bloodmagic.entity.mob.EntitySentientSpecter)5 IDemonWill (WayofTime.bloodmagic.soul.IDemonWill)5 IBlockState (net.minecraft.block.state.IBlockState)5 EntityLivingBase (net.minecraft.entity.EntityLivingBase)5 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)5 ISentientSwordEffectProvider (WayofTime.bloodmagic.iface.ISentientSwordEffectProvider)4 DemonWillHolder (WayofTime.bloodmagic.soul.DemonWillHolder)4 EntitySlime (net.minecraft.entity.monster.EntitySlime)4 IMob (net.minecraft.entity.monster.IMob)4 ArrayList (java.util.ArrayList)3 EntitySentientArrow (WayofTime.bloodmagic.entity.projectile.EntitySentientArrow)2 IDiscreteDemonWill (WayofTime.bloodmagic.soul.IDiscreteDemonWill)2 List (java.util.List)2