Files
NotEnoughItems/src/main/java/codechicken/nei/recipe/stackinfo/DefaultStackStringifyHandler.java
T
slprimeandslprime adf2065305 Create Bookmarks Groups; Search Recipe (#451)
* Create Bookmarks Groups; Search Recipe

* fix crash after DnD; add remove group function

* change hiddenhandler handlerId

* Pull all Bookmarked Items: use groups

* Optimize Chain Algorithm

* remove println

* fix input V in ME terminal

* Add Search Recipe Icon

* fix recipe extra information

* Change Search Recipe Algorithm

* fixed rounding in chain calculation

* fix creating groups for 2-line recipes

* fix fast DnD and recipe tooltip

* Bookmarks Recipe Chains: fluid canner

* Bookmarks Recipe Chains: fluid cell

* Open GuiRecipe: normalizeItemStack

---------

Co-authored-by: slprime <[email protected]>
2024-02-04 13:09:24 +01:00

59 lines
1.9 KiB
Java

package codechicken.nei.recipe.stackinfo;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
import codechicken.nei.api.IStackStringifyHandler;
import cpw.mods.fml.common.registry.GameData;
public class DefaultStackStringifyHandler implements IStackStringifyHandler {
public NBTTagCompound convertItemStackToNBT(ItemStack stack, boolean saveStackSize) {
final String strId = Item.itemRegistry.getNameForObject(stack.getItem());
if (strId == null) {
return null;
}
final NBTTagCompound nbTag = new NBTTagCompound();
nbTag.setString("strId", strId);
nbTag.setInteger("Count", saveStackSize ? stack.stackSize : 1);
nbTag.setShort("Damage", (short) stack.getItemDamage());
if (stack.hasTagCompound()) {
nbTag.setTag("tag", stack.getTagCompound());
}
return nbTag;
}
public ItemStack convertNBTToItemStack(NBTTagCompound nbtTag) {
final String strId = nbtTag.getString("strId");
nbtTag = (NBTTagCompound) nbtTag.copy();
nbtTag.setShort("id", (short) GameData.getItemRegistry().getId(strId)); // getObject
final ItemStack stack = ItemStack.loadItemStackFromNBT(nbtTag);
if (stack != null) {
stack.stackSize = nbtTag.getInteger("Count");
}
return stack;
}
public FluidStack getFluid(ItemStack stack) {
FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack);
if (fluidStack == null && stack.getItem() instanceof IFluidContainerItem) {
fluidStack = ((IFluidContainerItem) stack.getItem()).getFluid(stack);
}
return fluidStack;
}
}