Search in sources :

Example 1 with AlloyRecipe

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

the class TileEntityAlloySmelter method update.

@Override
public void update() {
    ApiUtils.checkForNeedlessTicking(this);
    if (!world.isRemote && formed && !isDummy()) {
        boolean a = active;
        if (burnTime > 0) {
            boolean doneWork = false;
            if (process > 0) {
                if (inventory.get(0).isEmpty() || inventory.get(1).isEmpty()) {
                    process = 0;
                    processMax = 0;
                } else {
                    AlloyRecipe recipe = getRecipe();
                    if (recipe != null && recipe.time != processMax) {
                        processMax = 0;
                        process = 0;
                        active = false;
                    } else {
                        process--;
                        doneWork = true;
                        if (!active)
                            active = true;
                    }
                }
                markContainingBlockForUpdate(null);
            }
            if (--burnTime % 10 == 0)
                markContainingBlockForUpdate(null);
            if (process <= 0) {
                if (processMax > 0) {
                    AlloyRecipe recipe = getRecipe();
                    if (recipe != null) {
                        boolean flip = !recipe.input0.matchesItemStack(inventory.get(0));
                        Utils.modifyInvStackSize(inventory, flip ? 1 : 0, -recipe.input0.inputSize);
                        Utils.modifyInvStackSize(inventory, flip ? 0 : 1, -recipe.input1.inputSize);
                        if (!inventory.get(3).isEmpty())
                            inventory.get(3).grow(recipe.output.copy().getCount());
                        else
                            inventory.set(3, recipe.output.copy());
                    }
                    processMax = 0;
                }
                AlloyRecipe recipe = getRecipe();
                if (recipe != null) {
                    this.process = recipe.time;
                    if (!doneWork)
                        process--;
                    this.processMax = recipe.time;
                    this.active = true;
                }
            }
        } else {
            if (active)
                active = false;
        }
        if (burnTime <= 10 && getRecipe() != null && (process > 10 || processMax == 0)) {
            ItemStack fuel = inventory.get(2);
            if (TileEntityFurnace.isItemFuel(fuel)) {
                lastBurnTime = TileEntityFurnace.getItemBurnTime(fuel);
                burnTime += lastBurnTime;
                Item itemFuel = fuel.getItem();
                fuel.shrink(1);
                if (fuel.isEmpty())
                    inventory.set(2, itemFuel.getContainerItem(fuel));
                markContainingBlockForUpdate(null);
            }
        }
        if (a != active) {
            this.markDirty();
            TileEntity tileEntity;
            for (int yy = -1; yy <= 1; yy++) for (int xx = -1; xx <= 1; xx++) for (int zz = -1; zz <= 1; zz++) {
                tileEntity = Utils.getExistingTileEntity(world, getPos().add(xx, yy, zz));
                if (tileEntity != null)
                    tileEntity.markDirty();
                markBlockForUpdate(getPos().add(xx, yy, zz), null);
                world.addBlockEvent(getPos().add(xx, yy, zz), IEContent.blockStoneDevice, 1, active ? 1 : 0);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Item(net.minecraft.item.Item) AlloyRecipe(blusunrize.immersiveengineering.api.crafting.AlloyRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 2 with AlloyRecipe

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

the class AlloySmelter method addRecipe.

@ZenMethod
public static void addRecipe(IItemStack output, IIngredient first, IIngredient second, int time) {
    Object oFirst = CraftTweakerHelper.toObject(first), oSecond = CraftTweakerHelper.toObject(second);
    if (oFirst == null || oSecond == null)
        return;
    AlloyRecipe r = new AlloyRecipe(CraftTweakerHelper.toStack(output), oFirst, oSecond, time);
    CraftTweakerAPI.apply(new Add(r));
}
Also used : AlloyRecipe(blusunrize.immersiveengineering.api.crafting.AlloyRecipe) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Aggregations

AlloyRecipe (blusunrize.immersiveengineering.api.crafting.AlloyRecipe)2 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ZenMethod (stanhebben.zenscript.annotations.ZenMethod)1