Search in sources :

Example 1 with IChaosStorage

use of net.silentchaos512.gems.api.energy.IChaosStorage 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 IChaosStorage

use of net.silentchaos512.gems.api.energy.IChaosStorage in project SilentGems by SilentChaos512.

the class ChaosUtil method sendEnergyTo.

/**
 * Send chaos to an entity. Replaces the old packet spawning methods. Also spawns particles.
 *
 * @return True if the entity was able to receive chaos, false otherwise.
 */
public static boolean sendEnergyTo(World world, BlockPos start, EntityLivingBase target, int amount) {
    if (target instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) target;
        amount -= PlayerDataHandler.get(player).sendChaos(amount, true);
        for (ItemStack stack : getChaosStorageItems(player)) {
            if (stack.getItem() instanceof IChaosStorage) {
                amount -= ((IChaosStorage) stack.getItem()).receiveCharge(stack, amount, false);
                if (amount <= 0) {
                    break;
                }
            }
        }
        NodePacketHelper.spawnParticles(world, start, target.getPositionVector().addVector(0, target.height / 2, 0), 0xFFFF99);
        return true;
    }
    return false;
}
Also used : IChaosStorage(net.silentchaos512.gems.api.energy.IChaosStorage) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IChaosStorage

use of net.silentchaos512.gems.api.energy.IChaosStorage in project SilentGems by SilentChaos512.

the class ChaosUtil method drainChaosFromPlayerAndInventory.

/**
 * Drains chaos from the player, draining from items that can provide chaos first.
 */
public static void drainChaosFromPlayerAndInventory(EntityPlayer player, int amount) {
    int startAmount = amount;
    for (ItemStack stack : getChaosStorageItems(player)) {
        if (stack.getItem() instanceof IChaosStorage) {
            amount -= ((IChaosStorage) stack.getItem()).extractCharge(stack, amount, false);
            if (amount <= 0)
                break;
        }
    }
    PlayerDataHandler.get(player).drainChaos(amount);
}
Also used : IChaosStorage(net.silentchaos512.gems.api.energy.IChaosStorage) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IChaosStorage

use of net.silentchaos512.gems.api.energy.IChaosStorage in project SilentGems by SilentChaos512.

the class ChaosUtil method canPlayerAcceptFullAmount.

// Use getAmountPlayerCanAccept instead
@Deprecated
public static boolean canPlayerAcceptFullAmount(EntityPlayer player, int amount) {
    PlayerData data = PlayerDataHandler.get(player);
    amount -= data.getMaxChaos() - data.getCurrentChaos();
    for (ItemStack stack : getChaosStorageItems(player)) {
        if (stack.getItem() instanceof IChaosStorage) {
            amount -= ((IChaosStorage) stack.getItem()).receiveCharge(stack, amount, true);
        }
    }
    return amount <= 0;
}
Also used : IChaosStorage(net.silentchaos512.gems.api.energy.IChaosStorage) ItemStack(net.minecraft.item.ItemStack) PlayerData(net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)

Example 5 with IChaosStorage

use of net.silentchaos512.gems.api.energy.IChaosStorage in project SilentGems by SilentChaos512.

the class ItemChaosOrb method onUpdate.

@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
    if (worldIn.isRemote || worldIn.getTotalWorldTime() % 20 != 0) {
        return;
    }
    if (entityIn instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entityIn;
        PlayerData data = PlayerDataHandler.get(player);
        // Send Chaos to player
        int amount = extractCharge(stack, data.getChaosChargeSpeed(), true);
        amount = data.sendChaos(amount);
        extractCharge(stack, amount, false);
        // Damage from player send?
        int breakTries = amount / PlayerData.CHAOS_MAX_TRANSFER;
        for (int i = 0; i < breakTries; ++i) {
            if (amount > 0 && SilentGems.random.nextFloat() < getBreakChance(stack)) {
                damageOrb(stack, player);
                break;
            }
        }
        // Try recharge player's items?
        if (isItemSendEnabled(stack)) {
            int totalSentToItems = 0;
            for (ItemStack itemstack : ChaosUtil.getChaosStorageItems(player)) {
                if (itemstack.getItem() != this && itemstack.getItem() instanceof IChaosStorage) {
                    int toSend = Math.min(getCharge(stack), MAX_ITEM_SEND);
                    totalSentToItems += ((IChaosStorage) itemstack.getItem()).receiveCharge(itemstack, toSend, false);
                }
            }
            extractCharge(stack, totalSentToItems, false);
            // Damage from item send? (lower damage chance)
            breakTries = totalSentToItems / MAX_ITEM_SEND;
            for (int i = 0; i < breakTries; ++i) {
                if (SilentGems.random.nextFloat() < getBreakChance(stack) / 3) {
                    damageOrb(stack, player);
                    break;
                }
            }
        }
    }
}
Also used : IChaosStorage(net.silentchaos512.gems.api.energy.IChaosStorage) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) PlayerData(net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)

Aggregations

ItemStack (net.minecraft.item.ItemStack)7 IChaosStorage (net.silentchaos512.gems.api.energy.IChaosStorage)6 PlayerData (net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 RecipeChaosAltar (net.silentchaos512.gems.api.recipe.altar.RecipeChaosAltar)1