Search in sources :

Example 1 with LivingArmourDowngradeRecipe

use of WayofTime.bloodmagic.recipe.LivingArmourDowngradeRecipe in project BloodMagic by WayofTime.

the class ArmourDowngradeRecipeMaker method getRecipes.

@Nonnull
public static List<ArmourDowngradeRecipeJEI> getRecipes() {
    List<LivingArmourDowngradeRecipe> recipeList = LivingArmourDowngradeRecipeRegistry.getRecipeList();
    ArrayList<ArmourDowngradeRecipeJEI> recipes = new ArrayList<>();
    for (LivingArmourDowngradeRecipe recipe : recipeList) recipes.add(new ArmourDowngradeRecipeJEI(recipe));
    return recipes;
}
Also used : ArrayList(java.util.ArrayList) LivingArmourDowngradeRecipe(WayofTime.bloodmagic.recipe.LivingArmourDowngradeRecipe) Nonnull(javax.annotation.Nonnull)

Example 2 with LivingArmourDowngradeRecipe

use of WayofTime.bloodmagic.recipe.LivingArmourDowngradeRecipe in project BloodMagic by WayofTime.

the class RitualLivingArmourDowngrade 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 masterPos = masterRitualStone.getBlockPos();
    AreaDescriptor downgradeRange = getBlockRange(DOWNGRADE_RANGE);
    boolean isActivatorPresent = false;
    for (EntityPlayer player : world.getEntitiesWithinAABB(EntityPlayer.class, downgradeRange.getAABB(masterRitualStone.getBlockPos()))) {
        if (player.getGameProfile().getId().equals(masterRitualStone.getOwner())) {
            ItemStack keyStack = getStackFromItemFrame(world, masterPos, masterRitualStone.getDirection());
            if (keyStack.isEmpty()) {
                return;
            }
            List<ITextComponent> textList = LivingArmourDowngradeRecipeRegistry.getDialogForProcessTick(keyStack, internalTimer);
            if (textList != null) {
                ChatUtil.sendChat(player, textList.toArray(new ITextComponent[textList.size()]));
            }
            internalTimer++;
            if (player.isSneaking()) {
                double distance2 = masterPos.offset(EnumFacing.UP).distanceSqToCenter(player.posX, player.posY, player.posZ);
                if (distance2 > 1) {
                    return;
                }
                BlockPos chestPos = masterPos.offset(masterRitualStone.getDirection(), 2).offset(EnumFacing.UP);
                TileEntity tile = world.getTileEntity(chestPos);
                if (tile == null) {
                    return;
                }
                IItemHandler inv = Utils.getInventory(tile, null);
                if (inv != null) {
                    List<ItemStack> recipeList = new ArrayList<>();
                    for (int i = 0; i < inv.getSlots(); i++) {
                        ItemStack invStack = inv.getStackInSlot(i);
                        if (!invStack.isEmpty()) {
                            recipeList.add(invStack);
                        }
                    }
                    LivingArmourDowngradeRecipe recipe = LivingArmourDowngradeRecipeRegistry.getMatchingRecipe(keyStack, recipeList, world, masterPos);
                    if (recipe != null) {
                        LivingArmourUpgrade upgrade = recipe.getRecipeOutput();
                        if (LivingArmour.hasFullSet(player)) {
                            ItemStack chestStack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
                            LivingArmour armour = ItemLivingArmour.getLivingArmour(chestStack);
                            if (armour != null) {
                                if (armour.canApplyUpgrade(player, upgrade)) {
                                    if (armour.upgradeArmour(player, upgrade)) {
                                        ItemLivingArmour.setLivingArmour(chestStack, armour);
                                        recipe.consumeInventory(inv);
                                        EntityLightningBolt lightning = new EntityLightningBolt(world, chestPos.getX(), chestPos.getY(), chestPos.getZ(), true);
                                        world.spawnEntity(lightning);
                                        masterRitualStone.setActive(false);
                                    }
                                } else {
                                // TODO: You are not able to receive my blessing...
                                // TODO: Need to add a timer that will stop it from working.
                                }
                            }
                        }
                    }
                }
            }
            return;
        }
    }
    if (!isActivatorPresent) {
        internalTimer = 0;
    }
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) ItemLivingArmour(WayofTime.bloodmagic.item.armour.ItemLivingArmour) LivingArmour(WayofTime.bloodmagic.livingArmour.LivingArmour) LivingArmourUpgrade(WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade) ITextComponent(net.minecraft.util.text.ITextComponent) ArrayList(java.util.ArrayList) EntityLightningBolt(net.minecraft.entity.effect.EntityLightningBolt) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) LivingArmourDowngradeRecipe(WayofTime.bloodmagic.recipe.LivingArmourDowngradeRecipe) ItemStack(net.minecraft.item.ItemStack)

Aggregations

LivingArmourDowngradeRecipe (WayofTime.bloodmagic.recipe.LivingArmourDowngradeRecipe)2 ArrayList (java.util.ArrayList)2 ItemLivingArmour (WayofTime.bloodmagic.item.armour.ItemLivingArmour)1 LivingArmour (WayofTime.bloodmagic.livingArmour.LivingArmour)1 LivingArmourUpgrade (WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade)1 Nonnull (javax.annotation.Nonnull)1 EntityLightningBolt (net.minecraft.entity.effect.EntityLightningBolt)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 World (net.minecraft.world.World)1 IItemHandler (net.minecraftforge.items.IItemHandler)1