add DummyWorld to use in Log crafting recipe checks

This commit is contained in:
Thiakil committed 2019-06-07 21:55:44 +08:00
1 parent 28c13c8322
commit 75d1fd7f12
2 files changed
+37 -4

No files matched your search

@@ -19,6 +19,7 @@ import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.StackUtils;
import mekanism.common.world.DummyWorld;
import net.minecraft.block.BlockPlanks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
@@ -402,6 +403,7 @@ public final class OreDictManager {
return false;
}
};
DummyWorld dummyWorld = new DummyWorld();
InventoryCrafting tempCrafting = new InventoryCrafting(tempContainer, 3, 3);
@@ -414,17 +416,17 @@ public final class OreDictManager {
for (ItemStack logEntry : logs) {
if (logEntry.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
for (int j = 0; j < 16; j++) {
addSawmillLog(tempCrafting, new ItemStack(logEntry.getItem(), 1, j));
addSawmillLog(tempCrafting, new ItemStack(logEntry.getItem(), 1, j), dummyWorld);
}
} else {
addSawmillLog(tempCrafting, StackUtils.size(logEntry, 1));
addSawmillLog(tempCrafting, StackUtils.size(logEntry, 1), dummyWorld);
}
}
}
private static void addSawmillLog(InventoryCrafting tempCrafting, ItemStack log) {
private static void addSawmillLog(InventoryCrafting tempCrafting, ItemStack log, DummyWorld world) {
tempCrafting.setInventorySlotContents(0, log);
ItemStack resultEntry = MekanismUtils.findMatchingRecipe(tempCrafting, null);
ItemStack resultEntry = MekanismUtils.findMatchingRecipe(tempCrafting, world);
if (!resultEntry.isEmpty()) {
RecipeHandler.addPrecisionSawmillRecipe(log, StackUtils.size(resultEntry, 6), new ItemStack(MekanismItems.Sawdust),
@@ -0,0 +1,31 @@
package mekanism.common.world;
import net.minecraft.world.DimensionType;
import net.minecraft.world.World;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.chunk.IChunkProvider;
/**
* Dummy object for providing something to CraftingManager#findMatchingRecipe during startup, to prevent in-dev non-null assertions from breaking things
*/
public class DummyWorld extends World {
public DummyWorld() {
super(null, null, new WorldProvider() {
@Override
public DimensionType getDimensionType() {
return DimensionType.OVERWORLD;
}
}, null, false);
}
@Override
protected IChunkProvider createChunkProvider() {
throw new UnsupportedOperationException();
}
@Override
protected boolean isChunkLoaded(int x, int z, boolean allowEmpty) {
return false;
}
}