Search in sources :

Example 1 with ICatalyst

use of WayofTime.alchemicalWizardry.common.ICatalyst in project BloodMagic by WayofTime.

the class TEWritingTable method updateEntity.

@Override
public void updateEntity() {
    int progressNeeded = 100;
    long worldTime = worldObj.getWorldTime();
    if (worldObj.isRemote) {
        return;
    }
    if (accelerationTime > 0) {
        accelerationTime--;
    }
    if (containsPotionFlask() && containsRegisteredPotionIngredient()) {
        if (containsCatalyst()) {
            if (getStackInSlot(6) == null) {
                progress++;
                if (worldTime % 4 == 0) {
                    SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
                }
                if (progress >= progressNeeded) {
                    ItemStack flaskStack = inv[this.getPotionFlaskPosition()];
                    ItemStack ingredientStack = inv[this.getRegisteredPotionIngredientPosition()];
                    ItemStack catalystStack = inv[this.getCatalystPosition()];
                    if (flaskStack == null || ingredientStack == null || catalystStack == null) {
                        progress = 0;
                        if (worldObj != null) {
                            worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
                        }
                        return;
                    }
                    int potionID = AlchemicalPotionCreationHandler.getPotionIDForStack(ingredientStack);
                    int catalystLevel = ((ICatalyst) catalystStack.getItem()).getCatalystLevel();
                    boolean isConcentration = ((ICatalyst) catalystStack.getItem()).isConcentration();
                    if (potionID == -1 || catalystLevel < 0) {
                        progress = 0;
                        if (worldObj != null) {
                            worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
                        }
                        return;
                    }
                    if (isConcentration) {
                        ((AlchemyFlask) flaskStack.getItem()).setConcentrationOfPotion(flaskStack, potionID, catalystLevel);
                    } else {
                        ((AlchemyFlask) flaskStack.getItem()).setDurationFactorOfPotion(flaskStack, potionID, catalystLevel);
                    }
                    this.setInventorySlotContents(6, flaskStack);
                    this.decrStackSize(this.getPotionFlaskPosition(), 1);
                    this.decrStackSize(this.getCatalystPosition(), 1);
                    this.decrStackSize(this.getRegisteredPotionIngredientPosition(), 1);
                    progress = 0;
                    if (worldObj != null) {
                        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
                    }
                }
            }
        } else if (containsBindingAgent()) {
            if (getStackInSlot(6) == null) {
                progress++;
                if (worldTime % 4 == 0) {
                    SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
                }
                if (progress >= progressNeeded) {
                    ItemStack flaskStack = inv[this.getPotionFlaskPosition()];
                    ItemStack ingredientStack = inv[this.getRegisteredPotionIngredientPosition()];
                    ItemStack agentStack = inv[this.getBindingAgentPosition()];
                    if (flaskStack == null || ingredientStack == null || agentStack == null) {
                        progress = 0;
                        if (worldObj != null) {
                            worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
                        }
                        return;
                    }
                    int potionEffectNumber = ((AlchemyFlask) flaskStack.getItem()).getNumberOfPotionEffects(flaskStack);
                    int potionID = AlchemicalPotionCreationHandler.getPotionIDForStack(ingredientStack);
                    int tickDuration = AlchemicalPotionCreationHandler.getPotionTickDurationForStack(ingredientStack);
                    float successChance = ((IBindingAgent) agentStack.getItem()).getSuccessRateForPotionNumber(potionEffectNumber);
                    if (potionID == -1) {
                        progress = 0;
                        if (worldObj != null) {
                            worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
                        }
                        return;
                    }
                    ((AlchemyFlask) flaskStack.getItem()).addPotionEffect(flaskStack, potionID, tickDuration);
                    if (successChance > worldObj.rand.nextFloat()) {
                        this.setInventorySlotContents(6, flaskStack);
                    } else {
                        worldObj.createExplosion(null, xCoord + 0.5, yCoord + 1, zCoord + 0.5, 2, false);
                    }
                    this.decrStackSize(this.getPotionFlaskPosition(), 1);
                    this.decrStackSize(this.getBindingAgentPosition(), 1);
                    this.decrStackSize(this.getRegisteredPotionIngredientPosition(), 1);
                    progress = 0;
                    if (worldObj != null) {
                        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
                    }
                }
            }
        }
    } else if (this.containsBlankSlate() && this.containsPotionFlask()) {
        if (getStackInSlot(6) == null) {
            progress++;
            if (worldTime % 4 == 0) {
                SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
            }
            if (progress >= progressNeeded) {
                ItemStack flaskStack = inv[this.getPotionFlaskPosition()];
                ItemStack blankSlate = inv[this.getBlankSlatePosition()];
                if (flaskStack == null || blankSlate == null) {
                    progress = 0;
                    if (worldObj != null) {
                        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
                    }
                    return;
                }
                ((AlchemyFlask) flaskStack.getItem()).setIsPotionThrowable(true, flaskStack);
                this.setInventorySlotContents(6, flaskStack);
                this.decrStackSize(this.getPotionFlaskPosition(), 1);
                this.decrStackSize(this.getBlankSlatePosition(), 1);
                progress = 0;
                if (worldObj != null) {
                    worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
                }
            }
        }
    } else if (this.containsFillingAgent() && this.containsPotionFlask()) {
        if (getStackInSlot(6) == null) {
            progress++;
            if (worldTime % 4 == 0) {
                SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
            }
            if (progress >= progressNeeded) {
                ItemStack flaskStack = inv[this.getPotionFlaskPosition()];
                ItemStack fillingAgent = inv[this.getFillingAgentPosition()];
                if (flaskStack == null || fillingAgent == null) {
                    progress = 0;
                    if (worldObj != null) {
                        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
                    }
                    return;
                }
                int potionEffects = ((AlchemyFlask) flaskStack.getItem()).getNumberOfPotionEffects(flaskStack);
                int potionFillAmount = ((IFillingAgent) fillingAgent.getItem()).getFilledAmountForPotionNumber(potionEffects);
                flaskStack.setItemDamage(Math.max(0, flaskStack.getItemDamage() - potionFillAmount));
                this.setInventorySlotContents(6, flaskStack);
                this.decrStackSize(this.getPotionFlaskPosition(), 1);
                this.decrStackSize(this.getFillingAgentPosition(), 1);
                progress = 0;
                if (worldObj != null) {
                    worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
                }
            }
        }
    } else if (this.containsPotionFlask() && this.containsCombinationCatalyst()) {
        // TODO
        if (getStackInSlot(6) == null && CombinedPotionRegistry.hasCombinablePotionEffect(inv[this.getPotionFlaskPosition()])) {
            progress++;
            if (worldTime % 4 == 0) {
                SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
            }
            if (progress >= progressNeeded) {
                ItemStack flaskStack = inv[this.getPotionFlaskPosition()];
                ItemStack combinationCatalyst = inv[this.getCombinationCatalystPosition()];
                if (flaskStack == null || combinationCatalyst == null) {
                    progress = 0;
                    if (worldObj != null) {
                        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
                    }
                    return;
                }
                ItemStack newFlask = CombinedPotionRegistry.applyPotionEffect(flaskStack);
                if (newFlask != null) {
                    this.setInventorySlotContents(6, newFlask);
                    this.decrStackSize(this.getPotionFlaskPosition(), 1);
                    this.decrStackSize(this.getCombinationCatalystPosition(), 1);
                    progress = 0;
                    if (worldObj != null) {
                        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
                    }
                }
            }
        }
    } else {
        if (!isRecipeValid()) {
            progress = 0;
            return;
        }
        if (progress <= 0) {
            progress = 0;
            amountUsed = this.getAmountNeeded(getStackInSlot(0));
            if (worldObj != null) {
                worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
            }
        }
        int acceleration = this.getSpeedIncrease();
        if (getStackInSlot(6) == null) {
            if (!SoulNetworkHandler.syphonFromNetworkWhileInContainer(getStackInSlot(0), amountUsed * acceleration)) {
                return;
            }
            if (worldTime % 4 == 0) {
                SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
            }
            progress += acceleration;
            if (progress >= progressNeeded) {
                progress = 0;
                this.setInventorySlotContents(6, getResultingItemStack());
                ItemStack[] composedRecipe = new ItemStack[5];
                for (int i = 0; i < 5; i++) {
                    composedRecipe[i] = inv[i + 1];
                }
                this.decrementSlots(this.getRecipeForItems(composedRecipe, inv[0]));
                if (worldObj != null) {
                    worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
                }
            }
        } else if (getStackInSlot(6).getItem() == getResultingItemStack().getItem() && getResultingItemStack().stackSize <= (getStackInSlot(6).getMaxStackSize() - getStackInSlot(6).stackSize)) {
            if (worldTime % 4 == 0) {
                SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
            }
            if (!SoulNetworkHandler.syphonFromNetworkWhileInContainer(getStackInSlot(0), amountUsed * acceleration)) {
                return;
            }
            progress += acceleration;
            if (progress >= progressNeeded) {
                progress = 0;
                ItemStack result = getResultingItemStack().copy();
                result.stackSize += getStackInSlot(6).stackSize;
                this.setInventorySlotContents(6, result);
                ItemStack[] composedRecipe = new ItemStack[5];
                for (int i = 0; i < 5; i++) {
                    composedRecipe[i] = inv[i + 1];
                }
                this.decrementSlots(this.getRecipeForItems(composedRecipe, inv[0]));
                if (worldObj != null) {
                    worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
                }
            }
        }
    }
}
Also used : IFillingAgent(WayofTime.alchemicalWizardry.common.IFillingAgent) ICatalyst(WayofTime.alchemicalWizardry.common.ICatalyst) ItemStack(net.minecraft.item.ItemStack) AlchemyFlask(WayofTime.alchemicalWizardry.common.items.potion.AlchemyFlask)

Aggregations

ICatalyst (WayofTime.alchemicalWizardry.common.ICatalyst)1 IFillingAgent (WayofTime.alchemicalWizardry.common.IFillingAgent)1 AlchemyFlask (WayofTime.alchemicalWizardry.common.items.potion.AlchemyFlask)1 ItemStack (net.minecraft.item.ItemStack)1