Compare commits

...
13 changed files with 242 additions and 94 deletions

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
dependencies {
api('com.github.GTNewHorizons:CodeChickenCore:1.4.3:dev')
implementation('com.github.GTNewHorizons:GTNHLib:0.6.32:dev')
implementation('com.github.GTNewHorizons:GTNHLib:0.6.36:dev')
shadowImplementation('org.apache.commons:commons-csv:1.10.0')
@@ -9,6 +9,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -306,18 +307,33 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
if (recipeId == null || !removeFullRecipe) {
this.grid.removeRecipe(slot.itemIndex, removeFullRecipe);
return true;
}
if (group.crafting != null && group.crafting.recipeRelations.containsKey(recipeId)) {
boolean removed = false;
if (group.crafting != null && group.collapsed && removeFullRecipe) {
this.grid.removeGroup(groupId);
return true;
} else if (group.crafting != null) {
Set<RecipeId> recipes = group.crafting.recipeRelations.getOrDefault(recipeId, Collections.emptySet());
for (RecipeId relRecipeId : group.crafting.recipeRelations.get(recipeId)) {
removed = this.grid.removeRecipe(relRecipeId, groupId) || removed;
if (removeFullRecipe && recipes.isEmpty()) {
for (Map.Entry<RecipeId, Set<RecipeId>> entry : group.crafting.recipeRelations.entrySet()) {
if (entry.getValue().contains(recipeId)) {
recipes = entry.getValue();
break;
}
}
}
return removed;
if (!recipes.isEmpty()) {
boolean removed = false;
for (RecipeId relRecipeId : recipes) {
removed = this.grid.removeRecipe(relRecipeId, groupId) || removed;
}
return removed;
}
}
return this.grid.removeRecipe(recipeId, groupId);
@@ -1153,6 +1169,11 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
return true;
}
public void clearTooltips() {
this.acceptsFollowingTooltipLineHandler = null;
this.recipeChainTooltipLineHandler = null;
}
@Deprecated
public void addItem(ItemStack stack, boolean saveSize) {
addItem(saveSize ? stack : StackInfo.withAmount(stack, 0));
@@ -9,9 +9,11 @@ import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -32,6 +34,7 @@ import codechicken.nei.util.NBTJson;
public class FavoriteRecipes {
private static final Set<NBTTagCompound> tools = new HashSet<>();
private static final Map<NBTTagCompound, RecipeId> items = new HashMap<>();
private static final Map<String, RecipeId> fluids = new HashMap<>();
private static File favoriteFile;
@@ -123,6 +126,10 @@ public class FavoriteRecipes {
}
items.put(itemStackNBT, recipeId);
if (NEIServerUtils.isItemTool(stack)) {
tools.add(itemStackNBT);
}
}
} catch (IllegalArgumentException | JsonSyntaxException | IllegalStateException e) {
@@ -143,7 +150,19 @@ public class FavoriteRecipes {
recipeId = fluids.get(getFluidKey(stack));
}
return recipeId;
if (recipeId != null) {
return recipeId;
}
if (NEIServerUtils.isItemTool(stack)
&& (stack.stackTagCompound == null || !stack.stackTagCompound.hasKey("GT.ToolStats"))) {
for (NBTTagCompound nbt : tools) {
if (NEIServerUtils.areStacksSameTypeCraftingWithNBT(stack, StackInfo.loadFromNBT(nbt))) {
return items.get(nbt);
}
}
}
}
return null;
@@ -176,6 +195,10 @@ public class FavoriteRecipes {
if (recipeId != null) {
items.put(itemStackNBT, recipeId);
if (NEIServerUtils.isItemTool(stack)) {
tools.add(itemStackNBT);
}
if (fluidKey != null) {
fluids.put(fluidKey, recipeId);
}
@@ -14,6 +14,7 @@ import net.minecraftforge.oredict.OreDictionary;
import codechicken.nei.api.ItemFilter;
import codechicken.nei.api.ItemInfo;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.StackInfo;
/**
* Simply an {@link ItemStack} with position. Mainly used in the recipe handlers.
@@ -145,7 +146,7 @@ public class PositionedStack {
* NBT-friendly version of {@link #contains(ItemStack)}
*/
public boolean containsWithNBT(ItemStack ingredient) {
for (ItemStack item : items) if (NEIServerUtils.areStacksSameTypeCraftingWithNBT(item, ingredient)) return true;
for (ItemStack item : items) if (StackInfo.equalItemAndNBT(item, ingredient, true)) return true;
return false;
}
@@ -1,7 +1,5 @@
package codechicken.nei.api;
import java.util.Optional;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
@@ -20,8 +18,6 @@ public interface IStackStringifyHandler {
return null;
}
default Optional<ItemStack> getContainerItem(ItemStack stack) {
return null;
}
default void pauseItemDamageSound(boolean pause) {}
}
@@ -9,7 +9,6 @@ import java.util.Map;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
@@ -296,7 +295,7 @@ public abstract class ShortcutInputHandler {
recipe.getIngredients().stream().forEach(ingr -> {
final List<ItemStack> permutations = ingr.getPermutations();
for (int index = 0; index < permutations.size(); index++) {
if (FavoriteRecipes.getFavorite(permutations.get(index)) != null) {
if (FavoriteRecipes.contains(permutations.get(index))) {
ingr.setActiveIndex(index);
break;
}
@@ -470,15 +469,15 @@ public abstract class ShortcutInputHandler {
private static void autocraftingIgnoreInventory(RecipeChainMath math) {
final GuiContainer guiContainer = NEIClientUtils.getGuiContainer();
final InventoryPlayer playerInventory = guiContainer.mc.thePlayer.inventory;
final List<ItemStack> playerInventory = AutoCraftingManager.getInventoryItems(guiContainer).values();
final RecipeId rootRecipeId = math.createMasterRoot();
for (BookmarkItem item : math.recipeIngredients) {
if (item.amount > 0 && rootRecipeId.equals(item.recipeId)) {
long amount = 0;
for (ItemStack stack : playerInventory.mainInventory) {
if (stack != null && NEIClientUtils.areStacksSameTypeCraftingWithNBT(stack, item.itemStack)) {
for (ItemStack stack : playerInventory) {
if (NEIClientUtils.areStacksSameTypeCraftingWithNBT(stack, item.itemStack)) {
amount += StackInfo.getAmount(stack);
}
}
@@ -494,7 +493,7 @@ public abstract class ShortcutInputHandler {
BookmarksGridSlot slot) {
if (slot != null) {
return slot.getRecipeId();
return slot.isIngredient() ? null : slot.getRecipeId();
} else if (ItemPanels.itemPanel.contains(mousex, mousey)
|| ItemPanels.itemPanel.historyPanel.contains(mousex, mousey)) {
return FavoriteRecipes.getFavorite(stack);
@@ -1,13 +1,14 @@
package codechicken.nei.recipe;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import codechicken.nei.ItemPanels;
import codechicken.nei.ItemStackAmount;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.RestartableTask;
@@ -25,17 +26,17 @@ public class AutoCraftingManager {
@Override
public void execute() {
final GuiContainer guiContainer = NEIClientUtils.getGuiContainer();
final InventoryPlayer playerInventory = guiContainer.mc.thePlayer.inventory;
final ItemStackAmount inventory = ItemStackAmount.of(Arrays.asList(playerInventory.mainInventory));
final List<BookmarkItem> initialItems = prepareInitialItems(math, inventory);
final List<BookmarkItem> initialItems = prepareInitialItems(math, getInventoryItems(guiContainer));
boolean processed = false;
boolean changed = false;
StackInfo.pauseItemDamageSound(true);
do {
changed = false;
RecipeChainIterator iterator = new RecipeChainIterator(math, initialItems);
iterator.updateInventory(playerInventory.mainInventory);
iterator.updateInventory(getInventoryItems(guiContainer));
while (iterator.hasNext() && !interrupted(guiContainer)) {
final Map<RecipeId, Long> recipes = iterator.next();
@@ -61,12 +62,14 @@ public class AutoCraftingManager {
if (craft) {
changed = true;
processed = true;
iterator.updateInventory(playerInventory.mainInventory);
iterator.updateInventory(getInventoryItems(guiContainer));
}
}
} while (changed && !interrupted(guiContainer));
StackInfo.pauseItemDamageSound(false);
if (processed && !changed && !interrupted(guiContainer)) {
NEIClientUtils.playClickSound();
}
@@ -106,6 +109,7 @@ public class AutoCraftingManager {
AutoCraftingManager.math = math;
if (AutoCraftingManager.math != null) {
ItemPanels.bookmarkPanel.clearTooltips();
math.createMasterRoot();
task.restart();
}
@@ -115,4 +119,16 @@ public class AutoCraftingManager {
return AutoCraftingManager.math != null && !task.interrupted();
}
public static ItemStackAmount getInventoryItems(GuiContainer guiContainer) {
final ItemStackAmount inventory = new ItemStackAmount();
for (Slot slot : guiContainer.inventorySlots.inventorySlots) {
if (slot.getHasStack() && !(slot instanceof SlotCrafting) && slot.canTakeStack(guiContainer.mc.thePlayer)) {
inventory.add(slot.getStack());
}
}
return inventory;
}
}
@@ -6,7 +6,6 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.gui.inventory.GuiContainer;
@@ -15,6 +14,7 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import codechicken.lib.inventory.InventoryUtils;
import codechicken.nei.FastTransferManager;
@@ -339,9 +339,20 @@ public class DefaultOverlayHandler implements IOverlayHandler {
if (!istack.isContainerItem && pstack.getMaxStackSize() == 1
&& pstack.getItem().hasContainerItem(pstack)) {
final Optional<ItemStack> containerItem = StackInfo.getContainerItem(pstack);
if (containerItem != null && containerItem.isPresent()) {
istack.isContainerItem = pstack.getItem() == containerItem.get().getItem();
final NBTTagCompound tagCompound = pstack.getTagCompound();
if (tagCompound != null && tagCompound.hasKey("GT.ToolStats")) {
istack.isContainerItem = true;
} else {
final boolean isPausedItemDamageSound = StackInfo.isPausedItemDamageSound();
StackInfo.pauseItemDamageSound(true);
final ItemStack containerItem = pstack.getItem().getContainerItem(pstack);
if (containerItem != null) {
istack.isContainerItem = pstack.getItem() == containerItem.getItem();
}
StackInfo.pauseItemDamageSound(isPausedItemDamageSound);
}
}
}
@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
@@ -31,6 +30,7 @@ public class StackInfo {
private static final Map<String, HashMap<String, String[]>> guidfilters = new HashMap<>();
private static final ItemStackMap<String> guidcache = new ItemStackMap<>();
private static final LRUCache<ItemStackKey, FluidStack> fluidcache = new LRUCache<>(200);
private static boolean isPausedItemDamageSound = false;
static {
stackStringifyHandlers.add(new DefaultStackStringifyHandler());
@@ -74,14 +74,16 @@ public class StackInfo {
return stack;
}
public static Optional<ItemStack> getContainerItem(ItemStack stack) {
Optional<ItemStack> result = null;
for (int i = stackStringifyHandlers.size() - 1; i >= 0 && result == null; i--) {
result = stackStringifyHandlers.get(i).getContainerItem(stack);
public static void pauseItemDamageSound(boolean pause) {
if (isPausedItemDamageSound != (isPausedItemDamageSound = pause)) {
for (IStackStringifyHandler handler : stackStringifyHandlers) {
handler.pauseItemDamageSound(pause);
}
}
}
return result;
public static boolean isPausedItemDamageSound() {
return isPausedItemDamageSound;
}
public static ItemStack withAmount(ItemStack stack, long customCount) {
@@ -6,11 +6,12 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import codechicken.nei.ItemStackAmount;
import codechicken.nei.NEIClientUtils;
@@ -22,6 +23,19 @@ import codechicken.nei.recipe.StackInfo;
public class RecipeChainMath {
private static class ContainerItemResult {
public ItemStack stack;
public ItemStack containerItem;
public long leftSteps;
public ContainerItemResult(ItemStack stack, long leftSteps, ItemStack containerItem) {
this.stack = stack;
this.leftSteps = leftSteps;
this.containerItem = containerItem;
}
}
private static final ItemStack ROOT_ITEM = new ItemStack(Blocks.fire);
private static final RecipeId ROOT_RECIPE_ID = RecipeId
.of(ROOT_ITEM, "recipe-autocrafting", Collections.emptyList());
@@ -64,6 +78,7 @@ public class RecipeChainMath {
for (Map.Entry<RecipeId, Long> entry : multipliers.entrySet()) {
if (entry.getValue() > 1 || collapsedRecipes.contains(entry.getKey())) {
collectPreferredItems(entry.getKey(), this.preferredItems, new HashSet<>());
removeLoop(entry.getKey(), this.preferredItems, new HashSet<>());
this.outputRecipes.put(entry.getKey(), entry.getValue());
}
}
@@ -80,6 +95,7 @@ public class RecipeChainMath {
.noneMatch(resItem -> resItem.recipeId.equals(recipeId))) {
final Map<BookmarkItem, BookmarkItem> references = new HashMap<>(this.preferredItems);
collectPreferredItems(recipeId, references, new HashSet<>());
removeLoop(recipeId, references, new HashSet<>());
final int depth = getMaxDepth(recipeId, references);
if (maxDepth < depth || maxDepth == depth && entry.getValue() > maxMultiplier) {
@@ -121,15 +137,26 @@ public class RecipeChainMath {
for (BookmarkItem ingrItem : this.recipeIngredients) {
if (ingrItem.factor > 0 && recipeId.equals(ingrItem.recipeId) && !preferredItems.containsKey(ingrItem)) {
BookmarkItem activeItem = null;
BookmarkItem prefItem = null;
for (BookmarkItem item : this.recipeResults) {
if (item.factor > (prefItem == null ? 0 : prefItem.factor) && item.containsItems(ingrItem)
&& !visited.contains(item.recipeId)) {
prefItem = item;
if (item.factor > 0 && !visited.contains(item.recipeId) && item.containsItems(ingrItem)) {
if ((activeItem == null || item.factor > activeItem.factor) && NEIClientUtils
.areStacksSameTypeCraftingWithNBT(ingrItem.itemStack, item.itemStack)) {
activeItem = item;
} else if (prefItem == null || item.factor > prefItem.factor) {
prefItem = item;
}
}
}
if (activeItem != null) {
prefItem = activeItem;
}
if (prefItem != null) {
preferredItems.put(ingrItem, prefItem);
collectPreferredItems(prefItem.recipeId, preferredItems, visited);
@@ -143,8 +170,8 @@ public class RecipeChainMath {
private int getMaxDepth(RecipeId recipeId, Map<BookmarkItem, BookmarkItem> preferredItems) {
int maxDepth = 0;
for (BookmarkItem ingrItem : this.recipeIngredients) {
if (ingrItem.factor > 0 && recipeId.equals(ingrItem.recipeId) && preferredItems.containsKey(ingrItem)) {
for (BookmarkItem ingrItem : preferredItems.keySet()) {
if (ingrItem.factor > 0 && recipeId.equals(ingrItem.recipeId)) {
maxDepth = Math.max(maxDepth, getMaxDepth(preferredItems.get(ingrItem).recipeId, preferredItems) + 1);
}
}
@@ -152,6 +179,24 @@ public class RecipeChainMath {
return maxDepth;
}
private void removeLoop(RecipeId recipeId, Map<BookmarkItem, BookmarkItem> preferredItems, Set<RecipeId> visited) {
visited.add(recipeId);
for (BookmarkItem ingrItem : this.recipeIngredients) {
if (ingrItem.factor > 0 && recipeId.equals(ingrItem.recipeId) && preferredItems.containsKey(ingrItem)) {
BookmarkItem prefItem = preferredItems.get(ingrItem);
if (visited.contains(prefItem.recipeId)) {
preferredItems.remove(ingrItem);
} else {
removeLoop(prefItem.recipeId, preferredItems, visited);
}
}
}
visited.remove(recipeId);
}
public RecipeId createMasterRoot() {
final List<BookmarkItem> rootIngredients = new ArrayList<>();
@@ -255,10 +300,14 @@ public class RecipeChainMath {
for (RecipeId recipeId : this.outputRecipes.keySet()) {
collectPreferredItems(recipeId, this.preferredItems, new HashSet<>());
removeLoop(recipeId, this.preferredItems, new HashSet<>());
}
}
public RecipeChainMath refresh() {
final boolean isPausedItemDamageSound = StackInfo.isPausedItemDamageSound();
StackInfo.pauseItemDamageSound(true);
resetCalculation();
if (this.outputRecipes.containsKey(ROOT_RECIPE_ID)) {
@@ -292,6 +341,7 @@ public class RecipeChainMath {
}
}
StackInfo.pauseItemDamageSound(isPausedItemDamageSound);
return this;
}
@@ -384,22 +434,13 @@ public class RecipeChainMath {
ItemStack bStack = this.containerItems.get(i);
if (bStack != null && NEIClientUtils.areStacksSameTypeCraftingWithNBT(aStack, bStack)) {
final ContainerItemResult result = getToolsContainerItems(bStack, steps);
while (bStack != null && steps > 0) {
final Optional<ItemStack> containerItem = StackInfo.getContainerItem(bStack);
bStack = result.stack;
steps = result.leftSteps;
steps--;
if (containerItem != null && containerItem.isPresent()) {
bStack = containerItem.get();
if (aStack.getItem() != bStack.getItem()) {
this.containerItems.add(bStack);
bStack = null;
}
} else {
bStack = null;
}
if (result.containerItem != null) {
this.containerItems.add(result.containerItem);
}
this.containerItems.set(i, bStack);
@@ -412,6 +453,60 @@ public class RecipeChainMath {
return steps;
}
private ContainerItemResult getToolsContainerItems(ItemStack aStack, long steps) {
final NBTTagCompound tagCompound = aStack.getTagCompound();
if (tagCompound != null && tagCompound.hasKey("GT.ToolStats")) {
final int damagePerContainerCraft = getGTToolDamagePerContainerCraft(aStack);
if (damagePerContainerCraft > 0) {
final NBTTagCompound toolStats = tagCompound.getCompoundTag("GT.ToolStats");
final long maxDamage = toolStats.getLong("MaxDamage");
final long damage = toolStats.getLong("Damage");
final long leftSteps = (maxDamage - damage) / damagePerContainerCraft;
final long availableSteps = Math.min(steps, Math.max(1, leftSteps));
steps -= availableSteps;
if ((damage + availableSteps * damagePerContainerCraft) == maxDamage || leftSteps <= 0) {
aStack = null;
} else {
toolStats.setLong("Damage", damage + availableSteps * damagePerContainerCraft);
}
return new ContainerItemResult(aStack, steps, null);
}
}
final Item item = aStack.getItem();
while (aStack != null && steps > 0) {
aStack = item.getContainerItem(aStack);
steps--;
if (aStack != null && item != aStack.getItem()) {
return new ContainerItemResult(null, steps, aStack);
}
}
return new ContainerItemResult(aStack, steps, null);
}
private int getGTToolDamagePerContainerCraft(ItemStack aStack) {
try {
final Object toolStats = aStack.getItem().getClass().getMethod("getToolStats", ItemStack.class)
.invoke(aStack.getItem(), aStack);
return (int) toolStats.getClass().getMethod("getToolDamagePerContainerCraft").invoke(toolStats);
} catch (Throwable th) {
th.printStackTrace();
}
return 0;
}
private boolean hasContainerItem(ItemStack aStack) {
if (aStack.getItem().hasContainerItem(aStack)) {
@@ -7,10 +7,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
@@ -22,6 +19,8 @@ import codechicken.nei.ItemsTooltipLineHandler;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.bookmark.BookmarkItem;
import codechicken.nei.recipe.AutoCraftingManager;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.Recipe.RecipeId;
import codechicken.nei.recipe.StackInfo;
@@ -57,14 +56,9 @@ public class RecipeChainTooltipLineHandler implements ITooltipLineHandler {
final List<ItemStack> remainder = new ArrayList<>();
final ItemStackAmount inventory = new ItemStackAmount();
final GuiContainer currentGui = NEIClientUtils.getGuiContainer();
final EntityClientPlayerMP thePlayer = currentGui.mc.thePlayer;
if (this.lastShiftKey) {
for (Slot slot : currentGui.inventorySlots.inventorySlots) {
if (slot.getHasStack() && !(slot instanceof SlotCrafting) && slot.canTakeStack(thePlayer)) {
inventory.add(slot.getStack());
}
}
if (this.lastShiftKey && !(currentGui instanceof GuiRecipe<?>)) {
inventory.putAll(AutoCraftingManager.getInventoryItems(currentGui));
}
if (!this.math.outputRecipes.isEmpty()) {
@@ -89,7 +83,10 @@ public class RecipeChainTooltipLineHandler implements ITooltipLineHandler {
if (amount >= item.amount) {
final long itemAmount = item.factor * this.math.outputRecipes.get(item.recipeId);
amount += itemAmount - amount % itemAmount;
if (itemAmount > 0) {
amount += itemAmount - amount % itemAmount;
}
this.math.outputRecipes.put(
item.recipeId,
Math.max(this.math.outputRecipes.get(item.recipeId), amount / item.factor));
@@ -1,7 +1,5 @@
package codechicken.nei.recipe.stackinfo;
import java.util.Optional;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -58,14 +56,4 @@ public class DefaultStackStringifyHandler implements IStackStringifyHandler {
return fluidStack;
}
@Override
public Optional<ItemStack> getContainerItem(ItemStack stack) {
if (stack.getItem().hasContainerItem(stack)) {
return Optional.ofNullable(stack.getItem().getContainerItem(stack));
}
return null;
}
}
@@ -1,7 +1,7 @@
package codechicken.nei.recipe.stackinfo;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Optional;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -21,7 +21,7 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
protected static Method getFluidFromDisplayStack = null;
public static boolean replaceAE2FCFluidDrop = false;
private static Class<?> gtMetaGeneratedTool = null;
private static Method getContainerItem = null;
private static Field playSound = null;
static {
try {
@@ -36,10 +36,11 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
getFluidFromDisplayStack = gtUtility.getMethod("getFluidFromDisplayStack", ItemStack.class);
getFluidDisplayStack = gtUtility.getMethod("getFluidDisplayStack", FluidStack.class, boolean.class);
gtMetaGeneratedTool = ReflectionHelper.getClass(loader, "gregtech.api.items.MetaGeneratedTool");
getContainerItem = gtMetaGeneratedTool
.getDeclaredMethod("getContainerItem", ItemStack.class, boolean.class, boolean.class);
getContainerItem.setAccessible(true);
gtMetaGeneratedTool = ReflectionHelper.getClass(
loader,
"gregtech.api.items.MetaGeneratedTool",
"gregtech.api.items.GT_MetaGenerated_Tool");
playSound = gtMetaGeneratedTool.getDeclaredField("playSound");
} catch (Exception ignored) {
/* Do nothing */
}
@@ -114,15 +115,13 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
}
@Override
public Optional<ItemStack> getContainerItem(ItemStack stack) {
if (getContainerItem != null && gtMetaGeneratedTool.isInstance(stack.getItem())
&& stack.getItem().hasContainerItem(stack)) {
public void pauseItemDamageSound(boolean pause) {
if (playSound != null) {
try {
return Optional.ofNullable((ItemStack) getContainerItem.invoke(stack.getItem(), stack, false, true));
} catch (Exception ex) {}
playSound.setBoolean(null, !pause);
} catch (Exception e) {}
}
return null;
}
}