forked from mezz/JustEnoughItems
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '1.12' of https://github.com/naqaden/JustEnoughItems int…
…o naqaden-1.12
- Loading branch information
Showing
16 changed files
with
264 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ curse_project_id=238222 | |
|
||
version_major=4 | ||
version_minor=14 | ||
version_patch=2 | ||
version_patch=3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/main/java/mezz/jei/plugins/vanilla/ingredients/enchant/EnchantDataHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/mezz/jei/plugins/vanilla/ingredients/enchant/EnchantDataListFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/mezz/jei/plugins/vanilla/ingredients/enchant/EnchantDataRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/mezz/jei/plugins/vanilla/ingredients/enchant/EnchantedBookCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/mezz/jei/plugins/vanilla/ingredients/enchant/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.