Skip to content

Commit

Permalink
fix tests due to world being null
Browse files Browse the repository at this point in the history
  • Loading branch information
PrototypeTrousers committed May 29, 2021
1 parent 9245604 commit a32225b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import gregtech.api.recipes.*;
import gregtech.api.recipes.builders.*;
import gregtech.api.render.*;
import gregtech.api.util.world.DummyWorld;
import net.minecraft.init.*;
import net.minecraft.item.*;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.world.World;
import org.junit.*;

import static org.junit.Assert.*;
Expand All @@ -22,6 +25,8 @@ public static void init() {
@Test
public void trySearchNewRecipe() {

World world = DummyWorld.INSTANCE;

// Create an empty recipe map to work with
RecipeMap<SimpleRecipeBuilder> map = new RecipeMap<>("chemical_reactor",
0,
Expand All @@ -43,6 +48,7 @@ public void trySearchNewRecipe() {
1));

MetaTileEntity atte = new MetaTileEntityHolder().setMetaTileEntity(at);
atte.getHolder().setWorld(world);
map.recipeBuilder()
.inputs(new ItemStack(Blocks.COBBLESTONE))
.outputs(new ItemStack(Blocks.STONE))
Expand Down Expand Up @@ -72,14 +78,14 @@ public void trySearchNewRecipe() {
// 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.getMetaTileEntity().isInputsDirty());
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.getMetaTileEntity().isInputsDirty());
assertFalse(arl.hasNotifiedInputs());

// Save a reference to the old recipe so we can make sure it's getting reused
Recipe prev = arl.previousRecipe;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import gregtech.api.recipes.RecipeMap;
import gregtech.api.recipes.RecipeMaps;
import gregtech.api.recipes.builders.BlastRecipeBuilder;
import gregtech.api.util.world.DummyWorld;
import gregtech.common.metatileentities.electric.multiblockpart.MetaTileEntityFluidHatch;
import gregtech.common.metatileentities.electric.multiblockpart.MetaTileEntityItemBus;
import gregtech.common.metatileentities.electric.multiblockpart.MetaTileEntityMultiblockPart;
Expand All @@ -20,6 +21,7 @@
import net.minecraft.init.Bootstrap;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandlerModifiable;

import org.junit.BeforeClass;
Expand All @@ -43,6 +45,8 @@ private static ResourceLocation gregtechId(String name) {
@Test
public void trySearchNewRecipe() {

World world = DummyWorld.INSTANCE;

// Create an empty recipe map to work with
RecipeMap<BlastRecipeBuilder> map = new RecipeMap<>("blast_furnace",
1,
Expand Down Expand Up @@ -94,6 +98,8 @@ public boolean checkRecipe(Recipe recipe, boolean consumeIfSuccess) {
e.printStackTrace();
}

mbt.getHolder().setWorld(world);

//Controller and isAttachedToMultiBlock need the world so we fake it here.
MetaTileEntityItemBus importItemBus = new MetaTileEntityItemBus(gregtechId("item_bus.export.lv"), 1, false) {
@Override
Expand Down Expand Up @@ -209,14 +215,14 @@ protected IMultipleTankHandler getOutputTank() {
// put an item in the inventory that will trigger recipe recheck
mbl.getInputInventory().insertItem(0, new ItemStack(Blocks.COBBLESTONE, 16), false);
// Inputs change. did we detect it ?
assertTrue(mbt.isInputsDirty());
assertTrue(mbl.hasNotifiedInputs());
mbl.trySearchNewRecipe();
assertFalse(mbl.invalidInputsForRecipes);
assertNotNull(mbl.previousRecipe);
assertTrue(mbl.isActive);
assertEquals(15, mbl.getInputInventory().getStackInSlot(0).getCount());
//assert the consumption of the inputs did not mark the arl to look for a new recipe
assertFalse(mbt.isInputsDirty());
assertFalse(mbl.hasNotifiedInputs());

// Save a reference to the old recipe so we can make sure it's getting reused
Recipe prev = mbl.previousRecipe;
Expand Down Expand Up @@ -244,7 +250,7 @@ protected IMultipleTankHandler getOutputTank() {

// Some room is freed in the output bus, so we can continue now.
mbl.getOutputInventory().setStackInSlot(1, ItemStack.EMPTY);
assertTrue(mbt.isOutputsDirty());
assertTrue(mbl.hasNotifiedOutputs());
mbl.updateWorkable();
assertTrue(mbl.isActive);
assertFalse(mbl.isOutputsFull);
Expand Down

0 comments on commit a32225b

Please sign in to comment.