Search in sources :

Example 1 with SqueezerRecipe

use of blusunrize.immersiveengineering.api.crafting.SqueezerRecipe in project ImmersiveEngineering by BluSunrize.

the class Squeezer method addRecipe.

@ZenMethod
public static void addRecipe(IItemStack output, ILiquidStack fluid, IIngredient input, int energy) {
    if (CraftTweakerHelper.toObject(input) == null)
        return;
    //Either output or fluid must not be null. 
    if (CraftTweakerHelper.toStack(output) == null && (CraftTweakerHelper.toFluidStack(fluid) == null || CraftTweakerHelper.toFluidStack(fluid).getFluid() == null))
        return;
    SqueezerRecipe r = new SqueezerRecipe(CraftTweakerHelper.toFluidStack(fluid), CraftTweakerHelper.toStack(output), CraftTweakerHelper.toObject(input), energy);
    MineTweakerAPI.apply(new Add(r));
}
Also used : SqueezerRecipe(blusunrize.immersiveengineering.api.crafting.SqueezerRecipe) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Example 2 with SqueezerRecipe

use of blusunrize.immersiveengineering.api.crafting.SqueezerRecipe in project ImmersiveEngineering by BluSunrize.

the class TileEntitySqueezer method update.

@Override
public void update() {
    super.update();
    if (isDummy() || isRSDisabled())
        return;
    if (worldObj.isRemote) {
        if (this.processQueue.isEmpty() && animation_piston < .6875)
            animation_piston = Math.min(.6875f, animation_piston + .03125f);
        else if (shouldRenderAsActive()) {
            if (animation_down)
                animation_piston = Math.max(0, animation_piston - .03125f);
            else
                animation_piston = Math.min(.6875f, animation_piston + .03125f);
            if (animation_piston <= 0 && animation_down)
                animation_down = false;
            else if (animation_piston >= .6875 && !animation_down)
                animation_down = true;
        }
    } else {
        boolean update = false;
        if (energyStorage.getEnergyStored() > 0 && processQueue.size() < this.getProcessQueueMaxLength()) {
            final int[] usedInvSlots = new int[8];
            for (MultiblockProcess process : processQueue) if (process instanceof MultiblockProcessInMachine)
                for (int i : ((MultiblockProcessInMachine) process).inputSlots) usedInvSlots[i]++;
            Integer[] preferredSlots = new Integer[] { 0, 1, 2, 3, 4, 5, 6, 7 };
            Arrays.sort(preferredSlots, 0, 8, new Comparator<Integer>() {

                @Override
                public int compare(Integer arg0, Integer arg1) {
                    return Integer.compare(usedInvSlots[arg0], usedInvSlots[arg1]);
                }
            });
            for (int slot : preferredSlots) {
                ItemStack stack = this.getInventory()[slot];
                if (stack != null) {
                    stack = stack.copy();
                    stack.stackSize -= usedInvSlots[slot];
                }
                if (stack != null && stack.stackSize > 0) {
                    SqueezerRecipe recipe = this.findRecipeForInsertion(stack);
                    if (recipe != null) {
                        MultiblockProcessInMachine<SqueezerRecipe> process = new MultiblockProcessInMachine(recipe, slot);
                        if (this.addProcessToQueue(process, true)) {
                            this.addProcessToQueue(process, false);
                            update = true;
                        }
                    }
                }
            }
        }
        EnumFacing fw = mirrored ? facing.rotateYCCW() : facing.rotateY();
        if (this.tanks[0].getFluidAmount() > 0) {
            FluidStack out = Utils.copyFluidStackWithAmount(this.tanks[0].getFluid(), Math.min(this.tanks[0].getFluidAmount(), 80), false);
            BlockPos outputPos = this.getPos().add(0, -1, 0).offset(fw, 2);
            IFluidHandler output = FluidUtil.getFluidHandler(worldObj, outputPos, fw.getOpposite());
            if (output != null) {
                int accepted = output.fill(out, false);
                if (accepted > 0) {
                    int drained = output.fill(Utils.copyFluidStackWithAmount(out, Math.min(out.amount, accepted), false), true);
                    this.tanks[0].drain(drained, true);
                    update = true;
                }
            }
            ItemStack empty = getInventory()[9];
            if (empty != null && tanks[0].getFluidAmount() > 0) {
                ItemStack full = Utils.fillFluidContainer(tanks[0], empty, getInventory()[10], null);
                if (full != null) {
                    if (getInventory()[10] != null && OreDictionary.itemMatches(full, getInventory()[10], true))
                        getInventory()[10].stackSize += full.stackSize;
                    else
                        getInventory()[10] = full;
                    if (--inventory[9].stackSize <= 0)
                        inventory[9] = null;
                }
            }
        }
        if (inventory[8] != null && worldObj.getTotalWorldTime() % 8 == 0) {
            BlockPos outputPos = this.getPos().offset(fw);
            TileEntity outputTile = this.worldObj.getTileEntity(outputPos);
            if (outputTile != null) {
                ItemStack stack = Utils.copyStackWithAmount(inventory[8], 1);
                stack = Utils.insertStackIntoInventory(outputTile, stack, fw.getOpposite());
                if (stack == null)
                    if ((--this.inventory[8].stackSize) <= 0)
                        this.inventory[8] = null;
            }
        }
        if (update) {
            this.markDirty();
            this.markContainingBlockForUpdate(null);
        }
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) TileEntity(net.minecraft.tileentity.TileEntity) SqueezerRecipe(blusunrize.immersiveengineering.api.crafting.SqueezerRecipe) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Aggregations

SqueezerRecipe (blusunrize.immersiveengineering.api.crafting.SqueezerRecipe)2 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)1 ZenMethod (stanhebben.zenscript.annotations.ZenMethod)1