Search in sources :

Example 1 with RecipeChaosAltar

use of net.silentchaos512.gems.api.recipe.altar.RecipeChaosAltar in project SilentGems by SilentChaos512.

the class TileChaosAltar method update.

@Override
public void update() {
    if (world.isRemote)
        return;
    ItemStack inputStack = getStackInSlot(SLOT_INPUT);
    if (StackHelper.isEmpty(inputStack))
        return;
    ItemStack outputStack = getStackInSlot(SLOT_OUTPUT);
    ItemStack catalystStack = getStackInSlot(SLOT_CATALYST);
    // Chaos storage item?
    if (inputStack.getItem() instanceof IChaosStorage) {
        // Charge chaos storage items.
        IChaosStorage chaosStorage = (IChaosStorage) inputStack.getItem();
        int amount = chaosStorage.receiveCharge(inputStack, Math.min(chaosStored, MAX_ITEM_SEND), false);
        chaosStored -= amount;
        // Send update?
        if (amount != 0) {
            sendUpdate();
            updateTimer = -199;
        }
        // Move full items to second slot
        if (chaosStorage.getCharge(inputStack) >= chaosStorage.getMaxCharge(inputStack)) {
            if (StackHelper.isEmpty(outputStack)) {
                setInventorySlotContents(SLOT_OUTPUT, inputStack);
                removeStackFromSlot(SLOT_INPUT);
            }
        }
    } else // Chaos altar recipe?
    {
        RecipeChaosAltar recipe = RecipeChaosAltar.getMatchingRecipe(inputStack, catalystStack);
        if (recipe != null) {
            // Drain Chaos
            int chaosDrained = Math.min(chaosStored, Math.min(TRANSMUTE_CHAOS_PER_TICK, recipe.getChaosCost() - transmuteProgress));
            chaosStored -= chaosDrained;
            // Transmute progress
            transmuteProgress += chaosDrained;
            boolean willFitInOutputSlot = StackHelper.isEmpty(outputStack) || (outputStack.isItemEqual(recipe.getOutput()) && StackHelper.getCount(outputStack) + StackHelper.getCount(recipe.getOutput()) <= outputStack.getMaxStackSize());
            if (transmuteProgress >= recipe.getChaosCost() && willFitInOutputSlot) {
                // Transmute complete
                transmuteProgress = 0;
                if (StackHelper.isEmpty(outputStack))
                    setInventorySlotContents(SLOT_OUTPUT, recipe.getOutput());
                else
                    StackHelper.grow(getStackInSlot(SLOT_OUTPUT), StackHelper.getCount(recipe.getOutput()));
                decrStackSize(SLOT_INPUT, StackHelper.getCount(recipe.getInput()));
            }
            if (chaosDrained != 0)
                sendUpdate();
        } else {
            transmuteProgress = 0;
        }
    }
    // the altar is holding for rendering purposes... Is there a better way?
    if (updateTimer % 200 == 0) {
        sendUpdate();
    }
    ++updateTimer;
}
Also used : IChaosStorage(net.silentchaos512.gems.api.energy.IChaosStorage) RecipeChaosAltar(net.silentchaos512.gems.api.recipe.altar.RecipeChaosAltar) ItemStack(net.minecraft.item.ItemStack)

Example 2 with RecipeChaosAltar

use of net.silentchaos512.gems.api.recipe.altar.RecipeChaosAltar in project SilentGems by SilentChaos512.

the class GuiChaosAltar method drawGuiContainerForegroundLayer.

@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
    if (GemsConfig.DEBUG_MODE) {
        int recipeIndex = tileAltar.getField(2);
        RecipeChaosAltar recipe = recipeIndex >= 0 && recipeIndex < RecipeChaosAltar.ALL_RECIPES.size() ? RecipeChaosAltar.ALL_RECIPES.get(recipeIndex) : null;
        String format = "%s: %,d / %,d";
        // Chaos stored
        this.fontRenderer.drawString(String.format(format, "Chaos", tileAltar.getCharge(), tileAltar.getMaxCharge()), 8, 6, 0x404040);
        // Transmute progress
        this.fontRenderer.drawString(String.format(format, "Trnsm", tileAltar.getField(1), recipe == null ? 0 : recipe.getChaosCost()), 8, 16, 0x404040);
        // Recipe info
        this.fontRenderer.drawString("Recipe: " + recipeIndex + (recipe == null ? "" : " (" + recipe.getOutput().getDisplayName() + ")"), 8, 26, 0x404040);
    }
}
Also used : RecipeChaosAltar(net.silentchaos512.gems.api.recipe.altar.RecipeChaosAltar)

Example 3 with RecipeChaosAltar

use of net.silentchaos512.gems.api.recipe.altar.RecipeChaosAltar in project SilentGems by SilentChaos512.

the class GuiChaosAltar method drawGuiContainerBackgroundLayer.

@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    this.mc.getTextureManager().bindTexture(guiTextures);
    int xPos = (this.width - this.xSize) / 2;
    int yPos = (this.height - this.ySize) / 2;
    this.drawTexturedModalRect(xPos, yPos, 0, 0, this.xSize, this.ySize);
    // Progress arrow
    RecipeChaosAltar recipe = tileAltar.getActiveRecipe();
    if (recipe != null) {
        int progress = tileAltar.getField(1);
        int cost = recipe.getChaosCost();
        int length = cost != 0 && progress > 0 && progress < cost ? progress * 24 / cost : 0;
        drawTexturedModalRect(xPos + 79, yPos + 34, 176, 14, length + 1, 16);
    }
    // Chaos stored
    int chaos = tileAltar.getField(0);
    drawTexturedModalRect(xPos + 79, yPos + 34, 176, 31, 24 * chaos / TileChaosAltar.MAX_CHAOS_STORED, 17);
}
Also used : RecipeChaosAltar(net.silentchaos512.gems.api.recipe.altar.RecipeChaosAltar)

Aggregations

RecipeChaosAltar (net.silentchaos512.gems.api.recipe.altar.RecipeChaosAltar)3 ItemStack (net.minecraft.item.ItemStack)1 IChaosStorage (net.silentchaos512.gems.api.energy.IChaosStorage)1