Skip to content

Commit

Permalink
Add blacklist to worktable memory, blacklist non-empty maps
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Dec 8, 2014
1 parent 7ffb9d5 commit 2cb1959
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/main/java/forestry/factory/gadgets/TileWorktable.java
Expand Up @@ -98,6 +98,12 @@ public void sendAll(EntityPlayer player) {
Proxies.net.sendToPlayer(new PacketTileNBT(PacketIds.TILE_NBT, this), player);
}

@Override
public void validate() {
super.validate();
memorized.validate(worldObj);
}

/* RECIPE SELECTION */
public RecipeMemory getMemory() {
return memorized;
Expand Down
29 changes: 27 additions & 2 deletions src/main/java/forestry/factory/recipes/RecipeMemory.java
Expand Up @@ -17,18 +17,20 @@
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemMap;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class RecipeMemory implements INBTTagable {

private final static Container DUMMY_CONTAINER = new ContainerDummy();

public static final class Recipe implements INBTTagable {

private InventoryAdapter matrix;
Expand Down Expand Up @@ -117,16 +119,39 @@ private void sanitizeMatrix() {
}
}

private static final Container DUMMY_CONTAINER = new ContainerDummy();
private static final List<Class<? extends Item>> memoryBlacklist = new ArrayList<Class<? extends Item>>();
static {
memoryBlacklist.add(ItemMap.class); // almost every ItemMap is unique
}

private LinkedList<Recipe> recipes = new LinkedList<Recipe>();
private long lastUpdate;
public final int capacity = 9;

private static boolean isValid(World world, Recipe recipe) {
Item item = recipe.getRecipeOutput(world).getItem();
return item != null && !memoryBlacklist.contains(item.getClass());
}

public void validate(World world) {
LinkedList<Recipe> validRecipes = new LinkedList<Recipe>();
for (Recipe recipe : recipes) {
if (isValid(world, recipe))
validRecipes.add(recipe);
}
this.recipes = validRecipes;
}

public long getLastUpdate() {
return lastUpdate;
}

public void memorizeRecipe(World world, Recipe recipe, InventoryCrafting crafting) {

if (!isValid(world, recipe))
return;

lastUpdate = world.getTotalWorldTime();
recipe.updateLastUse(lastUpdate);

Expand Down

0 comments on commit 2cb1959

Please sign in to comment.