Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Dec 2, 2015
2 parents f229f08 + 009e2f7 commit c8daa75
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 46 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -3,6 +3,6 @@ forgeversion=11.15.0.1595-1.8.8

version_major=2
version_minor=1
version_patch=1
version_patch=2

org.gradle.parallel=true
72 changes: 39 additions & 33 deletions src/main/java/mezz/jei/ItemFilter.java
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.item.ItemStack;

import mezz.jei.api.JEIManager;
import mezz.jei.util.ItemStackElement;
import mezz.jei.util.Log;

Expand All @@ -27,8 +28,7 @@ public class ItemFilter {
/** A cache for fast searches while typing or using backspace. Maps filterText to filteredItemMaps */
private final LoadingCache<String, ImmutableList<ItemStackElement>> filteredItemMapsCache;

public ItemFilter(@Nonnull List<ItemStack> itemStacks) {

public ItemFilter() {
filteredItemMapsCache = CacheBuilder.newBuilder()
.maximumWeight(16)
.weigher(new Weigher<String, ImmutableList<ItemStackElement>>() {
Expand All @@ -40,6 +40,10 @@ public int weigh(@Nonnull String key, @Nonnull ImmutableList<ItemStackElement> v
.build(new CacheLoader<String, ImmutableList<ItemStackElement>>() {
@Override
public ImmutableList<ItemStackElement> load(@Nonnull final String filterText) throws Exception {
if (filterText.length() == 0) {
return createBaseList();
}

// Recursive.
// Find a cached filter that is before the one we want, so we don't have to filter the full item list.
// For example, the "", "i", "ir", and "iro" filters contain everything in the "iron" filter and more.
Expand Down Expand Up @@ -72,39 +76,41 @@ public ImmutableList<ItemStackElement> load(@Nonnull final String filterText) th

return ImmutableList.copyOf(filteredItemList);
}
});

// create the recursive base case value, the list with no filter set
ImmutableList.Builder<ItemStackElement> baseList = ImmutableList.builder();

ItemModelMesher itemModelMesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
ModelManager modelManager = itemModelMesher.getModelManager();
for (ItemStack itemStack : itemStacks) {
if (itemStack == null) {
continue;
}

// skip over itemStacks that can't be rendered
try {
if (itemModelMesher.getItemModel(itemStack) == modelManager.getMissingModel()) {
continue;
}
} catch (RuntimeException e) {
try {
Log.error("Couldn't find ItemModelMesher for itemStack {}. Exception: {}", itemStack, e);
} catch (RuntimeException ignored) {

}
continue;
}

ItemStackElement itemStackElement = ItemStackElement.create(itemStack);
if (itemStackElement != null) {
baseList.add(itemStackElement);
}
}
private ImmutableList<ItemStackElement> createBaseList() {
ImmutableList.Builder<ItemStackElement> baseList = ImmutableList.builder();

filteredItemMapsCache.put("", baseList.build());
ItemModelMesher itemModelMesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
ModelManager modelManager = itemModelMesher.getModelManager();

for (ItemStack itemStack : JEIManager.itemRegistry.getItemList()) {
if (itemStack == null) {
continue;
}

// skip over itemStacks that can't be rendered
try {
if (itemModelMesher.getItemModel(itemStack) == modelManager.getMissingModel()) {
continue;
}
} catch (RuntimeException e) {
try {
Log.error("Couldn't find ItemModelMesher for itemStack {}. Exception: {}", itemStack, e);
} catch (RuntimeException ignored) {

}
continue;
}

ItemStackElement itemStackElement = ItemStackElement.create(itemStack);
if (itemStackElement != null) {
baseList.add(itemStackElement);
}
}

return baseList.build();
}
});
}

public boolean setFilterText(@Nonnull String filterText) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mezz/jei/ProxyCommonClient.java
Expand Up @@ -38,7 +38,7 @@ public void loadComplete(@Nonnull FMLLoadCompleteEvent event) {
JEIManager.itemRegistry = new ItemRegistry();
JEIManager.recipeRegistry = JustEnoughItems.pluginRegistry.createRecipeRegistry();

ItemFilter itemFilter = new ItemFilter(JEIManager.itemRegistry.getItemList());
ItemFilter itemFilter = new ItemFilter();
ItemListOverlay itemListOverlay = new ItemListOverlay(itemFilter);
GuiEventHandler guiEventHandler = new GuiEventHandler(itemListOverlay);
MinecraftForge.EVENT_BUS.register(guiEventHandler);
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/mezz/jei/api/gui/IRecipeLayout.java
Expand Up @@ -3,15 +3,24 @@
import javax.annotation.Nonnull;

public interface IRecipeLayout {
/**
* Contains all the itemStacks displayed on this recipe layout.
* Init and set them in your recipe category.
*/
@Nonnull
IGuiItemStackGroup getItemStacks();

/**
* Contains all the fluidStacks displayed on this recipe layout.
* Init and set them in your recipe category.
*/
@Nonnull
IGuiFluidStackGroup getFluidStacks();

/**
* Enables the recipe transfer button and sets its position relative to the recipe layout.
* The button transfers items in the user's inventory into the crafting area to set a recipe.
* Moves the recipe transfer button's position relative to the recipe layout.
* By default the recipe transfer button is at the bottom, to the right of the recipe.
* If it doesn't fit there, you can use this to move it when you init the recipe layout.
*/
void setRecipeTransferButton(int posX, int posY);
}
7 changes: 4 additions & 3 deletions src/main/java/mezz/jei/gui/RecipeLayout.java
Expand Up @@ -16,6 +16,7 @@
import mezz.jei.gui.ingredients.GuiItemStackGroup;

public class RecipeLayout implements IRecipeLayout {
private static final int RECIPE_BUTTON_SIZE = 12;
public static final int recipeTransferButtonIndex = 100;

@Nonnull
Expand All @@ -36,8 +37,9 @@ public RecipeLayout(int index, int posX, int posY, @Nonnull IRecipeCategory reci
this.recipeCategory = recipeCategory;
this.guiItemStackGroup = new GuiItemStackGroup();
this.guiFluidStackGroup = new GuiFluidStackGroup();
this.recipeTransferButton = new GuiButtonExt(recipeTransferButtonIndex + index, 0, 0, 12, 12, "+");
this.recipeTransferButton.visible = false;
int width = recipeCategory.getBackground().getWidth();
int height = recipeCategory.getBackground().getHeight();
this.recipeTransferButton = new GuiButtonExt(recipeTransferButtonIndex + index, posX + width + 2, posY + height - RECIPE_BUTTON_SIZE, RECIPE_BUTTON_SIZE, RECIPE_BUTTON_SIZE, "+");
this.posX = posX;
this.posY = posY;

Expand Down Expand Up @@ -86,7 +88,6 @@ public IGuiFluidStackGroup getFluidStacks() {
public void setRecipeTransferButton(int posX, int posY) {
recipeTransferButton.xPosition = posX + this.posX;
recipeTransferButton.yPosition = posY + this.posY;
recipeTransferButton.visible = true;
}

@Nonnull
Expand Down
Expand Up @@ -56,8 +56,6 @@ public IDrawable getBackground() {

@Override
public void init(@Nonnull IRecipeLayout recipeLayout) {
recipeLayout.setRecipeTransferButton(56, 0);

IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks();

guiItemStacks.init(craftOutputSlot, false, 94, 18);
Expand Down
Expand Up @@ -16,8 +16,6 @@ public String getUid() {

@Override
public void init(@Nonnull IRecipeLayout recipeLayout) {
recipeLayout.setRecipeTransferButton(-14, 36);

IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks();
guiItemStacks.init(inputSlot, false, 0, 0);
guiItemStacks.init(fuelSlot, true, 0, 36);
Expand Down
Expand Up @@ -15,8 +15,6 @@ public String getUid() {

@Override
public void init(@Nonnull IRecipeLayout recipeLayout) {
recipeLayout.setRecipeTransferButton(-14, 0);

IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks();
guiItemStacks.init(inputSlot, true, 0, 0);
guiItemStacks.init(fuelSlot, false, 0, 36);
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/mezz/jei/util/RecipeTransferUtil.java
Expand Up @@ -70,6 +70,9 @@ private static boolean transferRecipe(@Nonnull RecipeLayout recipeLayout, @Nonnu

for (Slot slot : craftingSlots.values()) {
if (slot.getHasStack()) {
if (!slot.canTakeStack(player)) {
return false;
}
filledCraftSlotCount++;
availableItemStacks.add(slot.getStack());
}
Expand Down Expand Up @@ -98,6 +101,19 @@ private static boolean transferRecipe(@Nonnull RecipeLayout recipeLayout, @Nonnu
return false;
}

// check that the slots exist and can be altered
for (Map.Entry<Integer, ItemStack> entry : slotMap.entrySet()) {
int slotIndex = entry.getKey();
if (slotIndex >= container.inventorySlots.size()) {
return false;
}
Slot slot = container.getSlot(slotIndex);
ItemStack stack = entry.getValue();
if (slot == null || !slot.isItemValid(stack)) {
return false;
}
}

if (doTransfer) {
PacketRecipeTransfer packet = new PacketRecipeTransfer(slotMap, craftingSlots.keySet(), inventorySlots.keySet());
JustEnoughItems.common.sendPacketToServer(packet);
Expand Down

0 comments on commit c8daa75

Please sign in to comment.