Skip to content

Commit

Permalink
Merge branch '1.12' of https://github.com/naqaden/JustEnoughItems int…
Browse files Browse the repository at this point in the history
…o naqaden-1.12
  • Loading branch information
mezz committed Dec 10, 2018
2 parents 92cf9db + f57d55c commit 74828af
Show file tree
Hide file tree
Showing 16 changed files with 264 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ curse_project_id=238222

version_major=4
version_minor=14
version_patch=2
version_patch=3
4 changes: 4 additions & 0 deletions src/main/java/mezz/jei/collect/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public Map<C, V> getRow(R row) {
return table.computeIfAbsent(row, rowMappingFunction);
}

public void clear() {
table.clear();
}

public ImmutableTable<R, C, V> toImmutable() {
ImmutableTable.Builder<R, C, V> builder = ImmutableTable.builder();
for (Map.Entry<R, Map<C, V>> entry : table.entrySet()) {
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/mezz/jei/gui/recipes/RecipeGuiLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

import com.google.common.collect.ImmutableList;
import mezz.jei.api.IRecipeRegistry;
import mezz.jei.api.ingredients.IIngredientHelper;
import mezz.jei.api.recipe.IFocus;
import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeWrapper;
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
import mezz.jei.gui.Focus;
import mezz.jei.gui.ingredients.IngredientLookupState;
import mezz.jei.ingredients.IngredientRegistry;
import mezz.jei.util.MathUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
Expand All @@ -23,6 +25,7 @@
public class RecipeGuiLogic implements IRecipeGuiLogic {
private final IRecipeRegistry recipeRegistry;
private final IRecipeLogicStateListener stateListener;
private final IngredientRegistry ingredientRegistry;

private boolean initialState = true;
private IngredientLookupState state;
Expand All @@ -33,17 +36,21 @@ public class RecipeGuiLogic implements IRecipeGuiLogic {
*/
private List<IRecipeWrapper> recipes = Collections.emptyList();

public RecipeGuiLogic(IRecipeRegistry recipeRegistry, IRecipeLogicStateListener stateListener) {
public RecipeGuiLogic(IRecipeRegistry recipeRegistry, IRecipeLogicStateListener stateListener, IngredientRegistry ingredientRegistry) {
this.recipeRegistry = recipeRegistry;
this.stateListener = stateListener;
this.ingredientRegistry = ingredientRegistry;
List<IRecipeCategory> recipeCategories = recipeRegistry.getRecipeCategories();
this.state = new IngredientLookupState(null, recipeCategories, 0, 0);
}

@Override
public <V> boolean setFocus(IFocus<V> focus) {
focus = Focus.check(focus);
final List<IRecipeCategory> recipeCategories = recipeRegistry.getRecipeCategories(focus);
IIngredientHelper<V> ingredientHelper = ingredientRegistry.getIngredientHelper(focus.getValue());
IFocus<?> translatedFocus = ingredientHelper.translateFocus(focus, Focus::new);

final List<IRecipeCategory> recipeCategories = recipeRegistry.getRecipeCategories(translatedFocus);
if (recipeCategories.isEmpty()) {
return false;
}
Expand All @@ -53,7 +60,7 @@ public <V> boolean setFocus(IFocus<V> focus) {
}

int recipeCategoryIndex = getRecipeCategoryIndexToShowFirst(recipeCategories);
IngredientLookupState state = new IngredientLookupState(focus, recipeCategories, recipeCategoryIndex, 0);
IngredientLookupState state = new IngredientLookupState(translatedFocus, recipeCategories, recipeCategoryIndex, 0);
setState(state);

return true;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/mezz/jei/gui/recipes/RecipesGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import mezz.jei.gui.elements.GuiIconButtonSmall;
import mezz.jei.gui.ingredients.GuiIngredient;
import mezz.jei.gui.overlay.IngredientListOverlay;
import mezz.jei.ingredients.IngredientRegistry;
import mezz.jei.input.ClickedIngredient;
import mezz.jei.input.IClickedIngredient;
import mezz.jei.input.IShowsRecipeFocuses;
Expand Down Expand Up @@ -81,8 +82,8 @@ public class RecipesGui extends GuiScreen implements IRecipesGui, IShowsRecipeFo

private boolean init = false;

public RecipesGui(IRecipeRegistry recipeRegistry) {
this.logic = new RecipeGuiLogic(recipeRegistry, this);
public RecipesGui(IRecipeRegistry recipeRegistry, IngredientRegistry ingredientRegistry) {
this.logic = new RecipeGuiLogic(recipeRegistry, this, ingredientRegistry);
this.recipeCatalysts = new RecipeCatalysts();
this.recipeGuiTabs = new RecipeGuiTabs(this.logic);
this.mc = Minecraft.getMinecraft();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import javax.annotation.Nullable;
import java.awt.Color;
import java.util.Collections;
import java.util.List;

import mezz.jei.api.ingredients.IIngredientHelper;
import mezz.jei.config.Constants;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/mezz/jei/plugins/vanilla/VanillaPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
import mezz.jei.plugins.vanilla.furnace.FurnaceFuelCategory;
import mezz.jei.plugins.vanilla.furnace.FurnaceSmeltingCategory;
import mezz.jei.plugins.vanilla.furnace.SmeltingRecipeMaker;
import mezz.jei.plugins.vanilla.ingredients.enchant.EnchantDataHelper;
import mezz.jei.plugins.vanilla.ingredients.enchant.EnchantDataListFactory;
import mezz.jei.plugins.vanilla.ingredients.enchant.EnchantDataRenderer;
import mezz.jei.plugins.vanilla.ingredients.enchant.EnchantedBookCache;
import mezz.jei.plugins.vanilla.ingredients.fluid.FluidStackHelper;
import mezz.jei.plugins.vanilla.ingredients.fluid.FluidStackListFactory;
import mezz.jei.plugins.vanilla.ingredients.fluid.FluidStackRenderer;
Expand All @@ -45,6 +49,7 @@
import net.minecraft.client.gui.inventory.GuiFurnace;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.ContainerBrewingStand;
Expand All @@ -62,7 +67,9 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;

Expand Down Expand Up @@ -126,6 +133,13 @@ public void registerIngredients(IModIngredientRegistration ingredientRegistratio
FluidStackHelper fluidStackHelper = new FluidStackHelper();
FluidStackRenderer fluidStackRenderer = new FluidStackRenderer();
ingredientRegistration.register(VanillaTypes.FLUID, fluidStacks, fluidStackHelper, fluidStackRenderer);

List<EnchantmentData> enchantments = EnchantDataListFactory.create();
EnchantedBookCache enchantedBookCache = new EnchantedBookCache();
MinecraftForge.EVENT_BUS.register(enchantedBookCache);
EnchantDataHelper enchantmentHelper = new EnchantDataHelper(enchantedBookCache, itemStackHelper);
EnchantDataRenderer enchantmentRenderer = new EnchantDataRenderer(itemStackRenderer, enchantedBookCache);
ingredientRegistration.register(() -> EnchantmentData.class, enchantments, enchantmentHelper, enchantmentRenderer);
}

@Override
Expand Down Expand Up @@ -182,5 +196,7 @@ public void register(IModRegistry registry) {
IIngredientBlacklist ingredientBlacklist = registry.getJeiHelpers().getIngredientBlacklist();
// Game freezes when loading player skulls, see https://bugs.mojang.com/browse/MC-65587
ingredientBlacklist.addIngredientToBlacklist(new ItemStack(Items.SKULL, 1, 3));
// hide enchanted books, we display them as special ingredients because vanilla does not properly store the enchantment data by its registry name
ingredientBlacklist.addIngredientToBlacklist(new ItemStack(Items.ENCHANTED_BOOK, 1, OreDictionary.WILDCARD_VALUE));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package mezz.jei.plugins.vanilla.ingredients.enchant;

import javax.annotation.Nullable;
import java.awt.Color;

import com.google.common.base.MoreObjects;
import mezz.jei.api.ingredients.IIngredientHelper;
import mezz.jei.api.recipe.IFocus;
import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

public class EnchantDataHelper implements IIngredientHelper<EnchantmentData> {
private final EnchantedBookCache cache;
private final IIngredientHelper<ItemStack> itemStackHelper;

public EnchantDataHelper(EnchantedBookCache cache, IIngredientHelper<ItemStack> itemStackHelper) {
this.cache = cache;
this.itemStackHelper = itemStackHelper;
}

@Override
@Nullable
public EnchantmentData getMatch(Iterable<EnchantmentData> ingredients, EnchantmentData toMatch) {
for (EnchantmentData enchantData : ingredients) {
if (enchantData.enchantment.getRegistryName() == toMatch.enchantment.getRegistryName()
&& enchantData.enchantmentLevel == toMatch.enchantmentLevel) {
return enchantData;
}
}
return null;
}

@Override
public IFocus<?> translateFocus(IFocus<EnchantmentData> focus, IFocusFactory focusFactory) {
EnchantmentData enchantData = focus.getValue();
ItemStack itemStack = cache.getEnchantedBook(enchantData);
return focusFactory.createFocus(focus.getMode(), itemStack);
}

@Override
public String getDisplayName(EnchantmentData ingredient) {
return ingredient.enchantment.getTranslatedName(ingredient.enchantmentLevel);
}

@Override
public String getUniqueId(EnchantmentData ingredient) {
return "enchantment:" + ingredient.enchantment.getName() + ".lvl" + ingredient.enchantmentLevel;
}

@Override
public String getWildcardId(EnchantmentData ingredient) {
return getUniqueId(ingredient);
}

@Override
public String getModId(EnchantmentData ingredient) {
ResourceLocation registryName = ingredient.enchantment.getRegistryName();
if (registryName == null) {
String stackInfo = getErrorInfo(ingredient);
throw new IllegalStateException("enchantment.getRegistryName() returned null for: " + stackInfo);
}
return registryName.getNamespace();
}

@Override
public String getDisplayModId(EnchantmentData ingredient) {
ItemStack enchantedBook = cache.getEnchantedBook(ingredient);
return this.itemStackHelper.getDisplayModId(enchantedBook);
}

@Override
public Iterable<Color> getColors(EnchantmentData ingredient) {
ItemStack enchantedBook = cache.getEnchantedBook(ingredient);
return this.itemStackHelper.getColors(enchantedBook);
}

@Override
public String getResourceId(EnchantmentData ingredient) {
ResourceLocation registryName = ingredient.enchantment.getRegistryName();
if (registryName == null) {
String stackInfo = getErrorInfo(ingredient);
throw new IllegalStateException("enchantment.getRegistryName() returned null for: " + stackInfo);
}
return registryName.getPath();
}

@Override
public ItemStack getCheatItemStack(EnchantmentData ingredient) {
return cache.getEnchantedBook(ingredient);
}

@Override
public EnchantmentData copyIngredient(EnchantmentData ingredient) {
return new EnchantmentData(ingredient.enchantment, ingredient.enchantmentLevel);
}

@Override
public boolean isIngredientOnServer(EnchantmentData ingredient) {
ItemStack enchantedBook = cache.getEnchantedBook(ingredient);
return this.itemStackHelper.isIngredientOnServer(enchantedBook);
}

@Override
public String getErrorInfo(@Nullable EnchantmentData ingredient) {
if (ingredient == null) {
return "null";
}
MoreObjects.ToStringHelper toStringHelper = MoreObjects.toStringHelper(EnchantmentData.class);

toStringHelper.add("Enchantment", ingredient.enchantment.getName());
toStringHelper.add("Level", ingredient.enchantmentLevel);

return toStringHelper.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package mezz.jei.plugins.vanilla.ingredients.enchant;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentData;

public final class EnchantDataListFactory {
private EnchantDataListFactory() {

}

public static List<EnchantmentData> create() {
List<EnchantmentData> enchantData = new ArrayList<>();

Collection<Enchantment> enchants = ForgeRegistries.ENCHANTMENTS.getValuesCollection();
for (Enchantment enchant : enchants) {
for (int lvl = enchant.getMinLevel(); lvl <= enchant.getMaxLevel(); lvl++) {
enchantData.add(new EnchantmentData(enchant, lvl));
}
}

return enchantData;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package mezz.jei.plugins.vanilla.ingredients.enchant;

import mezz.jei.api.ingredients.IIngredientRenderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.item.ItemStack;

import javax.annotation.Nullable;
import java.util.List;

public class EnchantDataRenderer implements IIngredientRenderer<EnchantmentData> {

private IIngredientRenderer<ItemStack> itemRenderer;
private EnchantedBookCache cache;

public EnchantDataRenderer(IIngredientRenderer<ItemStack> itemRenderer, EnchantedBookCache cache) {
this.itemRenderer = itemRenderer;
this.cache = cache;
}

@Override
public void render(Minecraft minecraft, int xPosition, int yPosition, @Nullable EnchantmentData ingredient) {
if (ingredient != null) {
ItemStack enchantBook = cache.getEnchantedBook(ingredient);
itemRenderer.render(minecraft, xPosition, yPosition, enchantBook);
}
}

@Override
public List<String> getTooltip(Minecraft minecraft, EnchantmentData ingredient, ITooltipFlag tooltipFlag) {
ItemStack enchantBook = cache.getEnchantedBook(ingredient);
return itemRenderer.getTooltip(minecraft, enchantBook, tooltipFlag);
}

@Override
public FontRenderer getFontRenderer(Minecraft minecraft, EnchantmentData ingredient) {
ItemStack enchantBook = cache.getEnchantedBook(ingredient);
return itemRenderer.getFontRenderer(minecraft, enchantBook);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package mezz.jei.plugins.vanilla.ingredients.enchant;

import mezz.jei.collect.Table;
import mezz.jei.startup.PlayerJoinedWorldEvent;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.item.ItemEnchantedBook;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class EnchantedBookCache {
private final Table<ResourceLocation, Integer, ItemStack> cache = Table.hashBasedTable();

public ItemStack getEnchantedBook(EnchantmentData enchantmentData) {
Enchantment enchantment = enchantmentData.enchantment;
ResourceLocation registryName = enchantment.getRegistryName();
if (registryName == null) {
throw new IllegalArgumentException("Enchantment has no registry name: " + enchantment.getName());
}
return cache.computeIfAbsent(registryName, enchantmentData.enchantmentLevel, () -> ItemEnchantedBook.getEnchantedItemStack(enchantmentData));
}

@SubscribeEvent
public void onPlayerJoinedWorldEvent(PlayerJoinedWorldEvent event) {
cache.clear();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package mezz.jei.plugins.vanilla.ingredients.enchant;

import mcp.MethodsReturnNonnullByDefault;
import mezz.jei.util.FieldsAreNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import javax.annotation.Nullable;
import java.awt.Color;
import java.util.Collections;
import java.util.List;

import com.google.common.base.MoreObjects;
import mezz.jei.api.ingredients.IIngredientHelper;
Expand Down
Loading

0 comments on commit 74828af

Please sign in to comment.