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)));
}
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);
}
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);
}
Aggregations