Search in sources :

Example 1 with SimpleRecipeBuilder

use of gregtech.api.recipes.builders.SimpleRecipeBuilder in project GregTech by GregTechCEu.

the class AbstractRecipeLogicTest method trySearchNewRecipe.

@Test
public void trySearchNewRecipe() {
    World world = DummyWorld.INSTANCE;
    // Create an empty recipe map to work with
    RecipeMap<SimpleRecipeBuilder> map = new RecipeMap<>("chemical_reactor", 0, 2, 0, 2, 0, 3, 0, 2, new SimpleRecipeBuilder().EUt(30), false);
    MetaTileEntity at = MetaTileEntities.registerMetaTileEntity(190, new SimpleMachineMetaTileEntity(new ResourceLocation(GTValues.MODID, "chemical_reactor.lv"), map, null, 1, false));
    MetaTileEntity atte = new MetaTileEntityHolder().setMetaTileEntity(at);
    atte.getHolder().setWorld(world);
    map.recipeBuilder().inputs(new ItemStack(Blocks.COBBLESTONE)).outputs(new ItemStack(Blocks.STONE)).EUt(1).duration(1).buildAndRegister();
    AbstractRecipeLogic arl = new AbstractRecipeLogic(atte, map) {

        @Override
        protected long getEnergyInputPerSecond() {
            return Long.MAX_VALUE;
        }

        @Override
        protected long getEnergyStored() {
            return Long.MAX_VALUE;
        }

        @Override
        protected long getEnergyCapacity() {
            return Long.MAX_VALUE;
        }

        @Override
        protected boolean drawEnergy(int recipeEUt, boolean simulate) {
            return true;
        }

        @Override
        protected long getMaxVoltage() {
            return 32;
        }
    };
    arl.isOutputsFull = false;
    arl.invalidInputsForRecipes = false;
    arl.trySearchNewRecipe();
    // no recipe found
    assertTrue(arl.invalidInputsForRecipes);
    assertFalse(arl.isActive);
    assertNull(arl.previousRecipe);
    // put an item in the inventory that will trigger recipe recheck
    arl.getInputInventory().insertItem(0, new ItemStack(Blocks.COBBLESTONE, 16), false);
    // Inputs change. did we detect it ?
    assertTrue(arl.hasNotifiedInputs());
    arl.trySearchNewRecipe();
    assertFalse(arl.invalidInputsForRecipes);
    assertNotNull(arl.previousRecipe);
    assertTrue(arl.isActive);
    assertEquals(15, arl.getInputInventory().getStackInSlot(0).getCount());
    // assert the consumption of the inputs did not mark the arl to look for a new recipe
    assertFalse(arl.hasNotifiedInputs());
    // Save a reference to the old recipe so we can make sure it's getting reused
    Recipe prev = arl.previousRecipe;
    // Finish the recipe, the output should generate, and the next iteration should begin
    arl.update();
    assertEquals(prev, arl.previousRecipe);
    assertTrue(AbstractRecipeLogic.areItemStacksEqual(arl.getOutputInventory().getStackInSlot(0), new ItemStack(Blocks.STONE, 1)));
    assertTrue(arl.isActive);
    // Complete the second iteration, but the machine stops because its output is now full
    arl.getOutputInventory().setStackInSlot(0, new ItemStack(Blocks.STONE, 63));
    arl.getOutputInventory().setStackInSlot(1, new ItemStack(Blocks.STONE, 64));
    arl.update();
    assertFalse(arl.isActive);
    assertTrue(arl.isOutputsFull);
    // Try to process again and get failed out because of full buffer.
    arl.update();
    assertFalse(arl.isActive);
    assertTrue(arl.isOutputsFull);
    // Some room is freed in the output bus, so we can continue now.
    arl.getOutputInventory().setStackInSlot(1, ItemStack.EMPTY);
    arl.update();
    assertTrue(arl.isActive);
    assertFalse(arl.isOutputsFull);
    assertTrue(AbstractRecipeLogic.areItemStacksEqual(arl.getOutputInventory().getStackInSlot(0), new ItemStack(Blocks.STONE, 1)));
}
Also used : MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) SimpleMachineMetaTileEntity(gregtech.api.metatileentity.SimpleMachineMetaTileEntity) Recipe(gregtech.api.recipes.Recipe) SimpleRecipeBuilder(gregtech.api.recipes.builders.SimpleRecipeBuilder) ResourceLocation(net.minecraft.util.ResourceLocation) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) SimpleMachineMetaTileEntity(gregtech.api.metatileentity.SimpleMachineMetaTileEntity) World(net.minecraft.world.World) DummyWorld(gregtech.api.util.world.DummyWorld) ItemStack(net.minecraft.item.ItemStack) RecipeMap(gregtech.api.recipes.RecipeMap) Test(org.junit.Test)

Example 2 with SimpleRecipeBuilder

use of gregtech.api.recipes.builders.SimpleRecipeBuilder in project GregTech by GregTechCEu.

the class RecipeMapTest method findRecipe.

@Test
public void findRecipe() {
    RecipeMap<SimpleRecipeBuilder> map = new RecipeMap<>("chemical_reactor", 0, 2, 0, 2, 0, 3, 0, 2, new SimpleRecipeBuilder().EUt(30), false);
    map.recipeBuilder().notConsumable(new ItemStack(Blocks.COBBLESTONE)).outputs(new ItemStack(Blocks.STONE)).EUt(1).duration(1).buildAndRegister();
    map.recipeBuilder().notConsumable(new ItemStack(Blocks.COBBLESTONE)).outputs(new ItemStack(Blocks.STONE)).EUt(1).duration(1).buildAndRegister();
    map.recipeBuilder().notConsumable(new ItemStack(Blocks.COBBLESTONE)).outputs(new ItemStack(Blocks.STONE)).EUt(2).duration(1).buildAndRegister();
    map.recipeBuilder().inputs(new ItemStack(Blocks.STONE)).notConsumable(FluidRegistry.WATER).outputs(new ItemStack(Blocks.STONE)).EUt(1).duration(1).buildAndRegister();
    assertEquals(3, map.getRecipeList().size());
    Recipe r = map.findRecipe(1, Collections.singletonList(new ItemStack(Blocks.COBBLESTONE)), Collections.singletonList(null), 0, MatchingMode.DEFAULT);
    assertNotNull(r);
    // This test is failing for me locally -dan
    Recipe r2 = map.findRecipe(1, Collections.singletonList(new ItemStack(Blocks.STONE)), Collections.singletonList(new FluidStack(FluidRegistry.WATER, 1)), 0, MatchingMode.DEFAULT);
    assertNotNull(r2);
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) SimpleRecipeBuilder(gregtech.api.recipes.builders.SimpleRecipeBuilder) ItemStack(net.minecraft.item.ItemStack) Test(org.junit.Test)

Example 3 with SimpleRecipeBuilder

use of gregtech.api.recipes.builders.SimpleRecipeBuilder in project GregTech by GregTechCEu.

the class OreRecipeHandler method processCrushedPurified.

public static void processCrushedPurified(OrePrefix purifiedPrefix, Material material, OreProperty property) {
    ItemStack crushedCentrifugedStack = OreDictUnifier.get(OrePrefix.crushedCentrifuged, material);
    ItemStack dustStack = OreDictUnifier.get(OrePrefix.dustPure, material);
    Material byproductMaterial = GTUtility.selectItemInList(1, material, property.getOreByProducts(), Material.class);
    ItemStack byproductStack = OreDictUnifier.get(OrePrefix.dust, byproductMaterial);
    RecipeMaps.FORGE_HAMMER_RECIPES.recipeBuilder().input(purifiedPrefix, material).outputs(dustStack).duration(10).EUt(16).buildAndRegister();
    RecipeMaps.MACERATOR_RECIPES.recipeBuilder().input(purifiedPrefix, material).outputs(dustStack).chancedOutput(byproductStack, 1400, 850).duration(400).buildAndRegister();
    ModHandler.addShapelessRecipe(String.format("purified_ore_to_dust_%s", material), dustStack, 'h', new UnificationEntry(purifiedPrefix, material));
    if (!crushedCentrifugedStack.isEmpty()) {
        RecipeMaps.THERMAL_CENTRIFUGE_RECIPES.recipeBuilder().input(purifiedPrefix, material).outputs(crushedCentrifugedStack, OreDictUnifier.get(OrePrefix.dustTiny, byproductMaterial, 3)).buildAndRegister();
    }
    if (material.hasProperty(PropertyKey.GEM)) {
        ItemStack exquisiteStack = OreDictUnifier.get(OrePrefix.gemExquisite, material);
        ItemStack flawlessStack = OreDictUnifier.get(OrePrefix.gemFlawless, material);
        ItemStack gemStack = OreDictUnifier.get(OrePrefix.gem, material);
        ItemStack flawedStack = OreDictUnifier.get(OrePrefix.gemFlawed, material);
        ItemStack chippedStack = OreDictUnifier.get(OrePrefix.gemChipped, material);
        if (material.hasFlag(HIGH_SIFTER_OUTPUT)) {
            RecipeBuilder<SimpleRecipeBuilder> builder = RecipeMaps.SIFTER_RECIPES.recipeBuilder().input(purifiedPrefix, material).chancedOutput(exquisiteStack, 500, 150).chancedOutput(flawlessStack, 1500, 200).chancedOutput(gemStack, 5000, 1000).chancedOutput(dustStack, 2500, 500).duration(400).EUt(16);
            if (!flawedStack.isEmpty())
                builder.chancedOutput(flawedStack, 2000, 500);
            if (!chippedStack.isEmpty())
                builder.chancedOutput(chippedStack, 3000, 350);
            builder.buildAndRegister();
        } else {
            RecipeBuilder<SimpleRecipeBuilder> builder = RecipeMaps.SIFTER_RECIPES.recipeBuilder().input(purifiedPrefix, material).chancedOutput(exquisiteStack, 300, 100).chancedOutput(flawlessStack, 1000, 150).chancedOutput(gemStack, 3500, 500).chancedOutput(dustStack, 5000, 750).duration(400).EUt(16);
            if (!flawedStack.isEmpty())
                builder.chancedOutput(flawedStack, 2500, 300);
            if (!exquisiteStack.isEmpty())
                builder.chancedOutput(chippedStack, 3500, 400);
            builder.buildAndRegister();
        }
    }
    processMetalSmelting(purifiedPrefix, material, property);
}
Also used : UnificationEntry(gregtech.api.unification.stack.UnificationEntry) SimpleRecipeBuilder(gregtech.api.recipes.builders.SimpleRecipeBuilder) Material(gregtech.api.unification.material.Material) ItemStack(net.minecraft.item.ItemStack)

Aggregations

SimpleRecipeBuilder (gregtech.api.recipes.builders.SimpleRecipeBuilder)3 ItemStack (net.minecraft.item.ItemStack)3 Test (org.junit.Test)2 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)1 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)1 SimpleMachineMetaTileEntity (gregtech.api.metatileentity.SimpleMachineMetaTileEntity)1 Recipe (gregtech.api.recipes.Recipe)1 RecipeMap (gregtech.api.recipes.RecipeMap)1 Material (gregtech.api.unification.material.Material)1 UnificationEntry (gregtech.api.unification.stack.UnificationEntry)1 DummyWorld (gregtech.api.util.world.DummyWorld)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 World (net.minecraft.world.World)1 FluidStack (net.minecraftforge.fluids.FluidStack)1