Draft for unified build script

This commit is contained in:
Johann Bernhardt committed 2021-11-12 02:30:01 +01:00
1 parent 492c99b8e3
commit d3dbdbe09c
182 files changed
+488 -971

No files matched your search

+287
View File
@@ -0,0 +1,287 @@
package codechicken.nei.api;
import codechicken.nei.ItemList;
import codechicken.nei.ItemSorter;
import codechicken.nei.ItemStackSet;
import codechicken.nei.KeyManager;
import codechicken.nei.KeyManager.KeyState;
import codechicken.nei.LayoutManager;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.OffsetPositioner;
import codechicken.nei.SearchField;
import codechicken.nei.SearchField.ISearchProvider;
import codechicken.nei.SubsetWidget;
import codechicken.nei.SubsetWidget.SubsetTag;
import codechicken.nei.api.ItemFilter.ItemFilterProvider;
import codechicken.nei.config.Option;
import codechicken.nei.config.OptionKeyBind;
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiUsageRecipe;
import codechicken.nei.recipe.ICraftingHandler;
import codechicken.nei.recipe.IUsageHandler;
import codechicken.nei.recipe.RecipeInfo;
import net.minecraft.block.Block;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import org.lwjgl.input.Keyboard;
import java.util.Collections;
import java.util.Comparator;
/**
* This is the main class that handles item property configuration.
* WARNING: DO NOT access this class until the world has been loaded
* These methods should be called from INEIConfig implementors
*/
public class API
{
/**
* Register a new Crafting Recipe handler;
*
* @param handler The handler to register
*/
public static void registerRecipeHandler(ICraftingHandler handler) {
GuiCraftingRecipe.registerRecipeHandler(handler);
}
/**
* Register a new Usage Recipe handler;
*
* @param handler The handler to register
*/
public static void registerUsageHandler(IUsageHandler handler) {
GuiUsageRecipe.registerUsageHandler(handler);
}
/**
* Add a gui to the default overlay renderer with the default position
*
* @param classz The class of your gui
* @param ident The identification string, currently
* {crafting, crafting2x2, smelting, fuel, brewing}
*/
public static void registerGuiOverlay(Class<? extends GuiContainer> classz, String ident) {
registerGuiOverlay(classz, ident, 5, 11);
}
/**
* Add a gui to the default overlay renderer with an offset
*
* @param classz The class of your gui
* @param ident The identification string, currently
* {crafting, crafting2x2, smelting, fuel, brewing}
* @param x x-offset
* @param y y-offset
*/
public static void registerGuiOverlay(Class<? extends GuiContainer> classz, String ident, int x, int y) {
registerGuiOverlay(classz, ident, new OffsetPositioner(x, y));
}
/**
* Add a gui to the default overlay renderer
*
* @param classz The class of your gui
* @param ident The identification string, currently
* {crafting, crafting2x2, smelting, fuel, brewing}
* @param positioner A Stack Repositioner for moving the items to the right place
*/
public static void registerGuiOverlay(Class<? extends GuiContainer> classz, String ident, IStackPositioner positioner) {
RecipeInfo.registerGuiOverlay(classz, ident, positioner);
}
/**
* @param classz The class of your gui
* @param handler The handler to register
* @param ident The recipe identification string
*/
public static void registerGuiOverlayHandler(Class<? extends GuiContainer> classz, IOverlayHandler handler, String ident) {
RecipeInfo.registerOverlayHandler(classz, handler, ident);
}
/**
* Set the offset to be added to items to translate them into recipe coords on the actual gui, default is 5, 11. Primarily RecipeTransferRects
*
* @param classz The class of your gui
* @param x
* @param y
*/
public static void setGuiOffset(Class<? extends GuiContainer> classz, int x, int y) {
RecipeInfo.setGuiOffset(classz, x, y);
}
public static void registerNEIGuiHandler(INEIGuiHandler handler) {
try {
GuiInfo.writeLock.lock();
GuiInfo.guiHandlers.add(handler);
} finally {
GuiInfo.writeLock.unlock();
}
}
/**
* Hide an item from the item panel
* Damage values of OreDictionary.WILDCARD_VALUE and ItemStackMap.WILDCARD_TAG tags function as wildcards for their respective variables
*/
public static void hideItem(ItemStack item) {
ItemInfo.hiddenItems.add(item);
LayoutManager.markItemsDirty();
}
/**
* Add or replace the name normally shown on the item tooltip
*/
public static void setOverrideName(ItemStack item, String name) {
ItemInfo.nameOverrides.put(item, name);
LayoutManager.markItemsDirty();
}
/**
* Adds an item to the item panel. Any items added using this function will override the default search pattern.
* @param item an item with data
*/
public static void addItemListEntry(ItemStack item) {
ItemInfo.itemOverrides.put(item.getItem(), item);
LayoutManager.markItemsDirty();
}
/**
* Sets the item variants to appear in the item panel, overriding the default search pattern for a given item
*/
public static void setItemListEntries(Item item, Iterable<ItemStack> items) {
if(items == null)
items = Collections.emptyList();
ItemInfo.itemOverrides.replaceValues(item, items);
LayoutManager.markItemsDirty();
}
/**
* Add a custom KeyBinding to be configured in the Controls menu.
* @param ident An identifier for your key, eg "shoot"
* @param defaultKey The default value, commonly obtained from {@link Keyboard}
*/
public static void addKeyBind(String ident, int defaultKey) {
NEIClientConfig.setDefaultKeyBinding(ident, defaultKey);
KeyManager.keyStates.put(ident, new KeyState());
addOption(new OptionKeyBind(ident));
}
public static void addOption(Option option) {
NEIClientConfig.getOptionList().addOption(option);
}
/**
* Add a new Layout Style for the NEI interface
* @param styleID The Unique ID to be used for storing your style in the config and cycling through avaliable styles
* @param style The style to add.
*/
public static void addLayoutStyle(int styleID, LayoutStyle style) {
LayoutManager.layoutStyles.put(styleID, style);
}
/**
* Registers a new Infinite Item Handler.
* @param handler The handler to be registered.
*/
public static void addInfiniteItemHandler(IInfiniteItemHandler handler) {
ItemInfo.infiniteHandlers.addFirst(handler);
}
/**
* Registers a new Infinite Item Handler.
* @param block The block to handle, null for all.
* @param handler The handler to be registered.
*/
public static void registerHighlightIdentifier(Block block, IHighlightHandler handler) {
ItemInfo.highlightIdentifiers.put(block, handler);
}
/**
* Tells NEI not to perform any Fast Transfer operations on slots of a particular class
* @param slotClass The class of slot to be exempted
*/
public static void addFastTransferExemptSlot(Class<? extends Slot> slotClass) {
ItemInfo.fastTransferExemptions.add(slotClass);
}
/**
* Register a new text handler for the block highlight tooltip with a layout specification (HEADER, BODY or FOOTER).
* @param handler The handler to be registered.
* @param layout A HUDAugmenterRegistry.Layout entry. HEADER is displayed before BODY which is displayed before FOOTER.
*/
public static void registerHighlightHandler(IHighlightHandler handler, ItemInfo.Layout... layout) {
ItemInfo.registerHighlightHandler(handler, layout);
}
/**
* Register a mode handler for overriding NEI recipe/utility/cheat mode settings.
* @param handler The handler to be registered.
*/
public static void registerModeHandler(INEIModeHandler handler) {
NEIInfo.modeHandlers.add(handler);
}
/**
* Register a filter provider for the item panel.
* @param filterProvider The filter provider to be registered.
*/
public static void addItemFilter(ItemFilterProvider filterProvider) {
synchronized (ItemList.itemFilterers) {
ItemList.itemFilterers.add(filterProvider);
}
}
/**
* Adds a new tag to the item subset dropdown.
* @param name The fully qualified name, Eg Blocks.MobSpawners. NOT case sensitive
* @param filter A filter for matching items that fit in this subset
*/
public static void addSubset(String name, ItemFilter filter) {
addSubset(new SubsetTag(name, filter));
}
/**
* Adds a new tag to the item subset dropdown.
* @param name The fully qualified name, Eg Blocks.MobSpawners. NOT case sensitive
* @param items An iterable of itemstacks to be added as a subset
*/
public static void addSubset(String name, Iterable<ItemStack> items) {
ItemStackSet filter = new ItemStackSet();
for(ItemStack item : items)
filter.add(item);
addSubset(new SubsetTag(name, filter));
}
/**
* Adds a new tag to the item subset dropdown.
*/
public static void addSubset(SubsetTag tag) {
SubsetWidget.addTag(tag);
}
/**
* Adds a new search provider to the search field
*/
public static void addSearchProvider(ISearchProvider provider) {
SearchField.searchProviders.add(provider);
}
/**
* Adds a new sorting option to the item panel sort menu
* @param name A unique id for this sort option. Will be used in the config for saving and translated in the options gui. Note that if the translation key name.tip exists, it will be used for a tooltip
*/
public static void addSortOption(String name, Comparator<ItemStack> comparator) {
ItemSorter.add(name, comparator);
}
/**
* Adds an additional item list entry for an item, sorted after the rest of the items are found through the normal process
* @param item The item to add the variant for
* @param variant The stack to appear in the item panel
*/
public static void addItemVariant(Item item, ItemStack variant) {
ItemInfo.itemVariants.put(item, variant);
LayoutManager.markItemsDirty();
}
}
@@ -0,0 +1,44 @@
package codechicken.nei.api;
import codechicken.nei.PositionedStack;
import codechicken.nei.guihook.GuiContainerManager;
import net.minecraft.inventory.Slot;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
import java.util.List;
public class DefaultOverlayRenderer implements IRecipeOverlayRenderer
{
public DefaultOverlayRenderer(List<PositionedStack> ai, IStackPositioner positioner)
{
positioner = this.positioner = positioner;
ingreds = new ArrayList<>();
for(PositionedStack stack : ai)
ingreds.add(stack.copy());
ingreds = positioner.positionStacks(ingreds);
}
@Override
public void renderOverlay(GuiContainerManager gui, Slot slot)
{
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(770, 1);
GL11.glColor4d(0.6, 0.6, 0.6, 0.7);
GuiContainerManager.setColouredItemRender(true);
for(PositionedStack stack : ingreds)
{
if(stack.relx == slot.xDisplayPosition && stack.rely == slot.yDisplayPosition)
GuiContainerManager.drawItem(stack.relx, stack.rely, stack.item);
}
GuiContainerManager.setColouredItemRender(false);
GL11.glColor4f(1, 1, 1, 1);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_LIGHTING);
}
final IStackPositioner positioner;
ArrayList<PositionedStack> ingreds;
}
@@ -0,0 +1,42 @@
package codechicken.nei.api;
import codechicken.nei.NEIChestGuiHandler;
import codechicken.nei.NEICreativeGuiHandler;
import codechicken.nei.NEIDummySlotHandler;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
public class GuiInfo {
public static final LinkedList<INEIGuiHandler> guiHandlers = new LinkedList<>();
public static final HashSet<Class<? extends GuiContainer>> customSlotGuis = new HashSet<>();
public static ReentrantReadWriteLock guiHandlersLock = new ReentrantReadWriteLock();
public static Lock writeLock = guiHandlersLock.writeLock();
public static Lock readLock = guiHandlersLock.readLock();
public static void load() {
API.registerNEIGuiHandler(new NEICreativeGuiHandler());
API.registerNEIGuiHandler(new NEIChestGuiHandler());
API.registerNEIGuiHandler(new NEIDummySlotHandler());
customSlotGuis.add(GuiContainerCreative.class);
}
public static void clearGuiHandlers() {
try {
GuiInfo.writeLock.lock();
guiHandlers.removeIf(ineiGuiHandler -> ineiGuiHandler instanceof GuiContainer);
} finally {
GuiInfo.writeLock.unlock();
}
}
public static boolean hasCustomSlots(GuiContainer gui) {
return customSlotGuis.contains(gui.getClass());
}
}
@@ -0,0 +1,13 @@
package codechicken.nei.api;
/**
* An nei configuration entry point should implement this class and have name "NEI<someting>Config"
* loadConfig will only be called when NEI is installed.
*/
public interface IConfigureNEI
{
public void loadConfig();
public String getName();
public String getVersion();
}
@@ -0,0 +1,8 @@
package codechicken.nei.api;
import net.minecraft.client.gui.inventory.GuiContainer;
public interface IGuiContainerOverlay
{
public GuiContainer getFirstScreen();
}
@@ -0,0 +1,15 @@
package codechicken.nei.api;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import java.util.List;
public interface IHighlightHandler
{
public ItemStack identifyHighlight(World world, EntityPlayer player, MovingObjectPosition mop);
public List<String> handleTextData(ItemStack itemStack, World world, EntityPlayer player, MovingObjectPosition mop, List<String> currenttip, ItemInfo.Layout layout);
}
@@ -0,0 +1,16 @@
package codechicken.nei.api;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
public interface IInfiniteItemHandler
{
void onPickup(ItemStack heldItem);
void onPlaceInfinite(ItemStack heldItem);
boolean canHandleItem(ItemStack stack);
boolean isItemInfinite(ItemStack stack);
public void replenishInfiniteStack(InventoryPlayer inventory, int slotNo);
public ItemStack getInfiniteItem(ItemStack typeStack);
}
@@ -0,0 +1,43 @@
package codechicken.nei.api;
import codechicken.nei.VisiblityData;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import java.util.Collections;
import java.util.List;
/**
* Lets you just override those things you want to
*/
public class INEIGuiAdapter implements INEIGuiHandler
{
@Override
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility)
{
return currentVisibility;
}
@Override
public Iterable<Integer> getItemSpawnSlots(GuiContainer gui, ItemStack item) {
return Collections.emptyList();
}
@Override
public List<TaggedInventoryArea> getInventoryAreas(GuiContainer gui)
{
return null;
}
@Override
public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button)
{
return false;
}
@Override
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h)
{
return false;
}
}
@@ -0,0 +1,49 @@
package codechicken.nei.api;
import codechicken.nei.VisiblityData;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import java.util.List;
/**
* If this is implemented on a gui, it will be automatically registered
*/
public interface INEIGuiHandler
{
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility);
/**
* NEI will give the specified item to the InventoryRange returned if the player's inventory is full.
* Should not return null, just an empty list
*/
public Iterable<Integer> getItemSpawnSlots(GuiContainer gui, ItemStack item);
/**
* @return A list of TaggedInventoryAreas that will be used with the savestates.
*/
public List<TaggedInventoryArea> getInventoryAreas(GuiContainer gui);
/**
* Handles clicks while an itemstack has been dragged from the item panel. Use this to set configurable slots and the like.
* Changes made to the stackSize of the dragged stack will be kept
* @param gui The current gui instance
* @param mousex The x position of the mouse
* @param mousey The y position of the mouse
* @param draggedStack The stack being dragged from the item panel
* @param button The button presed
* @return True if the drag n drop was handled. False to resume processing through other routes. The held stack will be deleted if draggedStack.stackSize == 0
*/
public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button);
/**
* Used to prevent the item panel from drawing on top of other gui elements.
* This function will also be called with a 1x1 size rectangle on the mouse position for determining if the given coordinate should override item panel functions such as scrolling
* @param x The x coordinate of the rectangle bounding the slot
* @param y The y coordinate of the rectangle bounding the slot
* @param w The w coordinate of the rectangle bounding the slot
* @param h The h coordinate of the rectangle bounding the slot
* @return true if the item panel slot within the specified rectangle should not be rendered.
*/
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h);
}
@@ -0,0 +1,6 @@
package codechicken.nei.api;
public interface INEIModeHandler
{
public boolean isModeValid(int mode);
}
@@ -0,0 +1,9 @@
package codechicken.nei.api;
import codechicken.nei.recipe.IRecipeHandler;
import net.minecraft.client.gui.inventory.GuiContainer;
public interface IOverlayHandler
{
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift);
}
@@ -0,0 +1,9 @@
package codechicken.nei.api;
import codechicken.nei.guihook.GuiContainerManager;
import net.minecraft.inventory.Slot;
public interface IRecipeOverlayRenderer
{
public void renderOverlay(GuiContainerManager gui, Slot slot);
}
@@ -0,0 +1,14 @@
package codechicken.nei.api;
import codechicken.nei.PositionedStack;
import java.util.ArrayList;
/**
* For repositioning recipes in overlay renderers.
*
*/
public interface IStackPositioner
{
public ArrayList<PositionedStack> positionStacks(ArrayList<PositionedStack> ai);
}
@@ -0,0 +1,16 @@
package codechicken.nei.api;
import net.minecraft.item.ItemStack;
public interface ItemFilter
{
/**
* Provides an item filter. May be called from any thread. Returned filter should only reference objects with immutable state.
*/
public static interface ItemFilterProvider
{
public ItemFilter getFilter();
}
public boolean matches(ItemStack item);
}
@@ -0,0 +1,527 @@
package codechicken.nei.api;
import codechicken.core.featurehack.GameDataManipulator;
import codechicken.nei.InfiniteStackSizeHandler;
import codechicken.nei.InfiniteToolHandler;
import codechicken.nei.ItemList;
import codechicken.nei.ItemMobSpawner;
import codechicken.nei.ItemStackMap;
import codechicken.nei.ItemStackSet;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.PopupInputHandler;
import codechicken.nei.config.ArrayDumper;
import codechicken.nei.config.HandlerDumper;
import codechicken.nei.config.ItemPanelDumper;
import codechicken.nei.config.RegistryDumper;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.BrewingRecipeHandler;
import codechicken.nei.recipe.RecipeItemInputHandler;
import com.google.common.collect.ArrayListMultimap;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
import net.minecraft.block.Block;
import net.minecraft.client.resources.I18n;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityList.EntityEggInfo;
import net.minecraft.entity.monster.EntityIronGolem;
import net.minecraft.entity.monster.EntitySnowman;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemSpade;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.potion.Potion;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.RegistryNamespaced;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.oredict.OreDictionary;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
/**
* This is an internal class for storing information about items, to be accessed by the API
*/
public class ItemInfo
{
public static enum Layout
{
HEADER, BODY, FOOTER
}
public static final ArrayListMultimap<Layout, IHighlightHandler> highlightHandlers = ArrayListMultimap.create();
public static final ItemStackMap<String> nameOverrides = new ItemStackMap<>();
public static final ItemStackSet hiddenItems = new ItemStackSet();
public static final ItemStackSet finiteItems = new ItemStackSet();
public static final ArrayListMultimap<Item, ItemStack> itemOverrides = ArrayListMultimap.create();
public static final ArrayListMultimap<Item, ItemStack> itemVariants = ArrayListMultimap.create();
public static final LinkedList<IInfiniteItemHandler> infiniteHandlers = new LinkedList<>();
public static final ArrayListMultimap<Block, IHighlightHandler> highlightIdentifiers = ArrayListMultimap.create();
public static final HashSet<Class<? extends Slot>> fastTransferExemptions = new HashSet<>();
public static final HashMap<Item, String> itemOwners = new HashMap<>();
//lookup optimisation
public static final HashMap<ItemStack, String> itemSearchNames = new HashMap<>();
public static boolean isHidden(ItemStack stack) {
return hiddenItems.contains(stack);
}
public static boolean isHidden(Item item) {
return hiddenItems.containsAll(item);
}
public static String getNameOverride(ItemStack stack) {
return nameOverrides.get(stack);
}
public static boolean canBeInfinite(ItemStack stack) {
return !finiteItems.contains(stack);
}
/**
* @deprecated
* Use field directly
*/
@Deprecated
public static List<ItemStack> getItemOverrides(Item item) {
return itemOverrides.get(item);
}
public static void preInit() {
addMobSpawnerItem();
}
public static void load(World world) {
addVanillaBlockProperties();
addDefaultDropDowns();
searchItems();
parseModItems();
ItemMobSpawner.loadSpawners(world);
addSpawnEggs();
addInfiniteHandlers();
addInputHandlers();
addIDDumps();
addHiddenItemFilter();
addSearchOptimisation();
}
private static void addSearchOptimisation() {
ItemList.loadCallbacks.add(itemSearchNames::clear);
}
private static void addHiddenItemFilter() {
API.addItemFilter(() -> item -> !hiddenItems.contains(item));
}
private static void addIDDumps() {
API.addOption(new RegistryDumper<Item>("tools.dump.item")
{
@Override
public String[] header() {
return new String[]{"Name", "ID", "Has Block", "Mod", "Class"};
}
@Override
public String[] dump(Item item, int id, String name) {
return new String[]{
name,
Integer.toString(id),
Boolean.toString(Block.getBlockFromItem(item) != Blocks.air),
ItemInfo.itemOwners.get(item),
item.getClass().getCanonicalName()
};
}
@Override
public RegistryNamespaced registry() {
return Item.itemRegistry;
}
});
API.addOption(new RegistryDumper<Block>("tools.dump.block")
{
@Override
public String[] header() {
return new String[]{"Name", "ID", "Has Item", "Mod", "Class"};
}
@Override
public String[] dump(Block item, int id, String name) {
return new String[]{
name,
Integer.toString(id),
Boolean.toString(Item.getItemFromBlock(item) != null),
ItemInfo.itemOwners.get(item),
item.getClass().getCanonicalName()
};
}
@Override
public RegistryNamespaced registry() {
return Block.blockRegistry;
}
});
API.addOption(new ArrayDumper<Potion>("tools.dump.potion")
{
public String[] header() {
return new String[]{"ID", "Unlocalised name", "Class"};
}
@Override
public String[] dump(Potion potion, int id) {
return new String[]{
Integer.toString(id),
potion.getName(),
potion.getClass().getCanonicalName()
};
}
@Override
public Potion[] array() {
return Potion.potionTypes;
}
});
API.addOption(new ArrayDumper<Enchantment>("tools.dump.enchantment")
{
public String[] header() {
return new String[]{"ID", "Unlocalised name", "Type", "Min Level", "Max Level", "Class"};
}
@Override
public String[] dump(Enchantment ench, int id) {
return new String[]{
Integer.toString(id),
ench.getName(),
ench.type.toString(),
Integer.toString(ench.getMinLevel()),
Integer.toString(ench.getMaxLevel()),
ench.getClass().getCanonicalName()
};
}
@Override
public Enchantment[] array() {
return Enchantment.enchantmentsList;
}
});
API.addOption(new ArrayDumper<BiomeGenBase>("tools.dump.biome")
{
@Override
public String[] header() {
return new String[]{"ID", "Name", "Temperature", "Rainfall", "Spawn Chance", "Root Height", "Height Variation", "Types", "Class"};
}
@Override
public String[] dump(BiomeGenBase biome, int id) {
BiomeDictionary.Type[] types = BiomeDictionary.getTypesForBiome(biome);
StringBuilder s_types = new StringBuilder();
for (BiomeDictionary.Type t : types) {
if (s_types.length() > 0)
s_types.append(", ");
s_types.append(t.name());
}
return new String[]{
Integer.toString(id),
biome.biomeName,
Float.toString(biome.getFloatTemperature(0, 0, 0)),
Float.toString(biome.getFloatRainfall()),
Float.toString(biome.getSpawningChance()),
Float.toString(biome.rootHeight),
Float.toString(biome.heightVariation),
s_types.toString(),
biome.getClass().getCanonicalName()
};
}
@Override
public BiomeGenBase[] array() {
return BiomeGenBase.getBiomeGenArray();
}
});
API.addOption(new ItemPanelDumper("tools.dump.itempanel"));
API.addOption(new HandlerDumper("tools.dump.handlers"));
}
@SuppressWarnings("unchecked")
private static void parseModItems() {
HashMap<String, ItemStackSet> modSubsets = new HashMap<>();
for (Item item : (Iterable<Item>) Item.itemRegistry) {
UniqueIdentifier ident = null;
try {
ident = GameRegistry.findUniqueIdentifierFor(item);
} catch (Exception ignored) {}
if(ident == null) {
NEIClientConfig.logger.error("Failed to find identifier for: "+item);
continue;
}
String modId = ident.modId;
itemOwners.put(item, modId);
ItemStackSet itemset = modSubsets.get(modId);
if(itemset == null)
modSubsets.put(modId, itemset = new ItemStackSet());
itemset.with(item);
}
API.addSubset("Mod.Minecraft", modSubsets.remove("minecraft"));
for(Entry<String, ItemStackSet> entry : modSubsets.entrySet()) {
ModContainer mc = FMLCommonHandler.instance().findContainerFor(entry.getKey());
if(mc == null)
NEIClientConfig.logger.error("Missing container for "+entry.getKey());
else
API.addSubset("Mod."+mc.getName(), entry.getValue());
}
}
private static void addInputHandlers() {
GuiContainerManager.addInputHandler(new RecipeItemInputHandler());
GuiContainerManager.addInputHandler(new PopupInputHandler());
}
private static void addMobSpawnerItem() {
GameDataManipulator.replaceItem(Block.getIdFromBlock(Blocks.mob_spawner), new ItemMobSpawner());
}
private static void addInfiniteHandlers() {
API.addInfiniteItemHandler(new InfiniteStackSizeHandler());
API.addInfiniteItemHandler(new InfiniteToolHandler());
}
private static void addVanillaBlockProperties() {
API.setOverrideName(new ItemStack(Blocks.flowing_water), "Water Source");
API.setOverrideName(new ItemStack(Blocks.water), "Water Still");
API.setOverrideName(new ItemStack(Blocks.flowing_lava), "Lava Source");
API.setOverrideName(new ItemStack(Blocks.lava), "Lava Still");
API.setOverrideName(new ItemStack(Blocks.end_portal), "End Portal");
API.setOverrideName(new ItemStack(Blocks.end_portal_frame), "End Portal Frame");
API.hideItem(new ItemStack(Blocks.double_stone_slab, 1, OreDictionary.WILDCARD_VALUE));
API.hideItem(new ItemStack(Blocks.double_wooden_slab, 1, OreDictionary.WILDCARD_VALUE));
API.hideItem(new ItemStack(Blocks.carrots));
API.hideItem(new ItemStack(Blocks.potatoes));
API.hideItem(new ItemStack(Blocks.cocoa));
}
private static void addDefaultDropDowns() {
API.addSubset("Items", item -> Block.getBlockFromItem(item.getItem()) == Blocks.air);
API.addSubset("Blocks", item -> Block.getBlockFromItem(item.getItem()) != Blocks.air);
API.addSubset("Blocks.MobSpawners", ItemStackSet.of(Blocks.mob_spawner));
}
@SuppressWarnings("unchecked")
private static void searchItems() {
ItemStackSet tools = new ItemStackSet();
ItemStackSet picks = new ItemStackSet();
ItemStackSet shovels = new ItemStackSet();
ItemStackSet axes = new ItemStackSet();
ItemStackSet hoes = new ItemStackSet();
ItemStackSet swords = new ItemStackSet();
ItemStackSet chest = new ItemStackSet();
ItemStackSet helmets = new ItemStackSet();
ItemStackSet legs = new ItemStackSet();
ItemStackSet boots = new ItemStackSet();
ItemStackSet other = new ItemStackSet();
ItemStackSet ranged = new ItemStackSet();
ItemStackSet food = new ItemStackSet();
ItemStackSet potioningredients = new ItemStackSet();
ArrayList<ItemStackSet> creativeTabRanges = new ArrayList<>(CreativeTabs.creativeTabArray.length);
List<ItemStack> stackList = new LinkedList<>();
for (Item item : (Iterable<Item>) Item.itemRegistry) {
if (item == null)
continue;
for(CreativeTabs itemTab : item.getCreativeTabs()) {
if (itemTab != null) {
while (itemTab.getTabIndex() >= creativeTabRanges.size())
creativeTabRanges.add(null);
ItemStackSet set = creativeTabRanges.get(itemTab.getTabIndex());
if (set == null)
creativeTabRanges.set(itemTab.getTabIndex(), set = new ItemStackSet());
try {
stackList.clear();
item.getSubItems(item, itemTab, stackList);
for(ItemStack stack : stackList)
set.add(stack);
} catch (Exception e) {
NEIClientConfig.logger.error("Error loading sub-items for: "+item+". Tab: "+itemTab.getTabLabel(), e);
}
}
}
if (item.isDamageable()) {
tools.with(item);
if (item instanceof ItemPickaxe)
picks.with(item);
else if (item instanceof ItemSpade)
shovels.with(item);
else if (item instanceof ItemAxe)
axes.with(item);
else if (item instanceof ItemHoe)
hoes.with(item);
else if (item instanceof ItemSword)
swords.with(item);
else if (item instanceof ItemArmor)
switch (((ItemArmor) item).armorType) {
case 0:
helmets.with(item);
break;
case 1:
chest.with(item);
break;
case 2:
legs.with(item);
break;
case 3:
boots.with(item);
break;
}
else if (item == Items.arrow || item == Items.bow)
ranged.with(item);
else if (item == Items.fishing_rod || item == Items.flint_and_steel || item == Items.shears)
other.with(item);
}
if (item instanceof ItemFood)
food.with(item);
try {
LinkedList<ItemStack> subItems = new LinkedList<>();
item.getSubItems(item, null, subItems);
for(ItemStack stack : subItems) {
if (item.isPotionIngredient(stack) && item.getPotionEffect(stack) != null) {
BrewingRecipeHandler.ingredients.add(stack);
potioningredients.add(stack);
}
}
} catch (Exception e) {
NEIClientConfig.logger.error("Error loading brewing ingredients for: "+item, e);
}
}
API.addSubset("Items.Tools.Pickaxes", picks);
API.addSubset("Items.Tools.Shovels", shovels);
API.addSubset("Items.Tools.Axes", axes);
API.addSubset("Items.Tools.Hoes", hoes);
API.addSubset("Items.Tools.Other", other);
API.addSubset("Items.Weapons.Swords", swords);
API.addSubset("Items.Weapons.Ranged", ranged);
API.addSubset("Items.Armor.Chestplates", chest);
API.addSubset("Items.Armor.Leggings", legs);
API.addSubset("Items.Armor.Helmets", helmets);
API.addSubset("Items.Armor.Boots", boots);
API.addSubset("Items.Food", food);
API.addSubset("Items.Potions.Ingredients", potioningredients);
for (CreativeTabs tab : CreativeTabs.creativeTabArray) {
if(tab.getTabIndex() >= creativeTabRanges.size()) continue;
ItemStackSet set = creativeTabRanges.get(tab.getTabIndex());
if (set != null && !set.isEmpty())
API.addSubset("CreativeTabs." + I18n.format(tab.getTranslatedTabLabel()), set);
}
BrewingRecipeHandler.searchPotions();
}
private static void addSpawnEggs()
{
addEntityEgg(EntitySnowman.class, 0xEEFFFF, 0xffa221);
addEntityEgg(EntityIronGolem.class, 0xC5C2C1, 0xffe1cc);
}
@SuppressWarnings("unchecked")
private static void addEntityEgg(Class<?> entity, int i, int j) {
int id = (Integer)EntityList.classToIDMapping.get(entity);
EntityList.entityEggs.put(id, new EntityEggInfo(id, i, j));
}
public static ArrayList<ItemStack> getIdentifierItems(World world, EntityPlayer player, MovingObjectPosition hit) {
int x = hit.blockX;
int y = hit.blockY;
int z = hit.blockZ;
Block mouseoverBlock = world.getBlock(x, y, z);
ArrayList<ItemStack> items = new ArrayList<>();
ArrayList<IHighlightHandler> handlers = new ArrayList<>();
if (highlightIdentifiers.containsKey(null))
handlers.addAll(highlightIdentifiers.get(null));
if (highlightIdentifiers.containsKey(mouseoverBlock))
handlers.addAll(highlightIdentifiers.get(mouseoverBlock));
for (IHighlightHandler ident : handlers) {
ItemStack item = ident.identifyHighlight(world, player, hit);
if (item != null)
items.add(item);
}
if (items.size() > 0)
return items;
ItemStack pick = mouseoverBlock.getPickBlock(hit, world, x, y, z, player);
if (pick != null)
items.add(pick);
try {
items.addAll(mouseoverBlock.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 0));
} catch (Exception ignored) {}
if (mouseoverBlock instanceof IShearable) {
IShearable shearable = (IShearable) mouseoverBlock;
if (shearable.isShearable(new ItemStack(Items.shears), world, x, y, z))
items.addAll(shearable.onSheared(new ItemStack(Items.shears), world, x, y, z, 0));
}
if (items.size() == 0)
items.add(0, new ItemStack(mouseoverBlock, 1, world.getBlockMetadata(x, y, z)));
return items;
}
public static void registerHighlightHandler(IHighlightHandler handler, ItemInfo.Layout... layouts) {
for (ItemInfo.Layout layout : layouts)
ItemInfo.highlightHandlers.get(layout).add(handler);
}
public static List<String> getText(ItemStack itemStack, World world, EntityPlayer player, MovingObjectPosition mop) {
List<String> retString = new ArrayList<>();
for (ItemInfo.Layout layout : ItemInfo.Layout.values())
for (IHighlightHandler handler : ItemInfo.highlightHandlers.get(layout))
retString = handler.handleTextData(itemStack, world, player, mop, retString, layout);
return retString;
}
public static String getSearchName(ItemStack stack) {
String s = itemSearchNames.get(stack);
if(s == null) {
s = EnumChatFormatting.getTextWithoutFormattingCodes(GuiContainerManager.concatenatedDisplayName(stack, true).toLowerCase());
itemSearchNames.put(stack, s);
}
return s;
}
}
@@ -0,0 +1,20 @@
package codechicken.nei.api;
import codechicken.nei.Button;
import codechicken.nei.VisiblityData;
import codechicken.nei.guihook.GuiContainerManager;
import net.minecraft.client.gui.inventory.GuiContainer;
public abstract class LayoutStyle
{
public abstract void init();
public abstract void reset();
public abstract void layout(GuiContainer gui, VisiblityData visibility);
public abstract String getName();
public void drawBackground(GuiContainerManager gui)
{
}
public abstract void drawButton(Button button, int mousex, int mousey);
public abstract void drawSubsetTag(String text, int x, int y, int w, int h, int state, boolean mouseover);
}
@@ -0,0 +1,29 @@
package codechicken.nei.api;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.config.OptionCycled;
import net.minecraft.world.World;
import java.util.LinkedList;
public class NEIInfo
{
public static final LinkedList<INEIModeHandler> modeHandlers = new LinkedList<>();
public static void load(World world) {
OptionCycled modeOption = (OptionCycled) NEIClientConfig.getOptionList().getOption("inventory.cheatmode");
modeOption.parent.synthesizeEnvironment(false);
if(!modeOption.optionValid(modeOption.value())) {
modeOption.copyGlobals();
modeOption.cycle();
}
}
public static boolean isValidMode(int mode) {
for(INEIModeHandler handler : modeHandlers)
if(!handler.isModeValid(mode))
return false;
return true;
}
}
@@ -0,0 +1,48 @@
package codechicken.nei.api;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import java.util.HashSet;
public class TaggedInventoryArea
{
public final HashSet<Integer> slots = new HashSet<>();
public final String tagName;
/**
* Only for player inventories.
*/
private IInventory inventory;
/**
* Other inventories
*/
private final Container container;
public TaggedInventoryArea(InventoryPlayer invPlayer)
{
this("InventoryPlayer", 0, 39, null);
inventory = invPlayer;
}
public TaggedInventoryArea(String name, int first, int last, Container container)
{
this.container = container;
tagName = name;
for(int i = first; i <= last; i++)
slots.add(i);
}
public ItemStack getStackInSlot(int i)
{
if(inventory != null)
return inventory.getStackInSlot(i);
return container.getSlot(i).getStack();
}
public boolean isContainer()
{
return inventory == null;
}
}