Clean up null issues, add more annotations (#3590)

This commit is contained in:
James Mitchell authored and LexManos committed 2017-01-11 15:17:56 -08:00
1 parent 43efa3cfc4
commit c545b8ecd4
130 files changed
+629 -262

No files matched your search

@@ -135,6 +135,8 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import javax.annotation.Nullable;
/**
* Handles primary communication from hooked code into the system
@@ -512,7 +514,7 @@ public class FMLClientHandler implements IFMLSidedHandler
}
@Override
public void showGuiScreen(Object clientGuiElement)
public void showGuiScreen(@Nullable Object clientGuiElement)
{
GuiScreen gui = (GuiScreen) clientGuiElement;
client.displayGuiScreen(gui);
@@ -813,6 +815,7 @@ public class FMLClientHandler implements IFMLSidedHandler
private static final ResourceLocation iconSheet = new ResourceLocation("fml:textures/gui/icons.png");
private static final CountDownLatch startupConnectionData = new CountDownLatch(1);
@Nullable
public String enhanceServerListEntry(ServerListEntryNormal serverListEntry, ServerData serverEntry, int x, int width, int y, int relativeMouseX, int relativeMouseY)
{
String tooltip;
@@ -29,6 +29,7 @@ import java.util.Comparator;
import java.util.List;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import net.minecraft.client.Minecraft;
@@ -84,6 +85,7 @@ public class GuiModList extends GuiScreen
this.buttonID = buttonID;
}
@Nullable
public static SortType getTypeForButton(GuiButton button)
{
for (SortType t : values())
@@ -468,11 +470,12 @@ public class GuiModList extends GuiScreen
private class Info extends GuiScrollingList
{
@Nullable
private ResourceLocation logoPath;
private Dimension logoDims;
private List<ITextComponent> lines = null;
public Info(int width, List<String> lines, ResourceLocation logoPath, Dimension logoDims)
public Info(int width, List<String> lines, @Nullable ResourceLocation logoPath, Dimension logoDims)
{
super(GuiModList.this.getMinecraftInstance(),
width,
@@ -25,6 +25,8 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;
import javax.annotation.Nullable;
public interface IModGuiFactory {
/**
* Called when instantiated to initialize with the active minecraft instance.
@@ -85,6 +87,7 @@ public interface IModGuiFactory {
* @param element The element we wish to paint for
* @return The Handler for painting it
*/
@Nullable
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element);
/**
@@ -38,6 +38,8 @@ import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
@@ -731,12 +733,12 @@ public class SplashProgress
private final int frames;
private final int size;
public Texture(ResourceLocation location, ResourceLocation fallback)
public Texture(ResourceLocation location, @Nullable ResourceLocation fallback)
{
this(location, fallback, true);
}
public Texture(ResourceLocation location, ResourceLocation fallback, boolean allowRP)
public Texture(ResourceLocation location, @Nullable ResourceLocation fallback, boolean allowRP)
{
InputStream s = null;
try
@@ -881,14 +883,15 @@ public class SplashProgress
}
@Override
protected void bindTexture(ResourceLocation location)
protected void bindTexture(@Nonnull ResourceLocation location)
{
if(location != locationFontTexture) throw new IllegalArgumentException();
fontTexture.bind();
}
@Nonnull
@Override
protected IResource getResource(ResourceLocation location) throws IOException
protected IResource getResource(@Nonnull ResourceLocation location) throws IOException
{
DefaultResourcePack pack = Minecraft.getMinecraft().mcDefaultResourcePack;
return new SimpleResource(pack.getPackName(), location, pack.getInputStream(location), null, null);
@@ -920,7 +923,7 @@ public class SplashProgress
}
}
private static InputStream open(ResourceLocation loc, ResourceLocation fallback, boolean allowRP) throws IOException
private static InputStream open(ResourceLocation loc, @Nullable ResourceLocation fallback, boolean allowRP) throws IOException
{
if (!allowRP)
return mcPack.getInputStream(loc);
@@ -28,6 +28,8 @@ import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.client.config.GuiConfigEntries.IConfigEntry;
import net.minecraftforge.fml.client.config.GuiEditArrayEntries.IArrayEntry;
import javax.annotation.Nullable;
/**
* This class's main purpose is to provide the necessary objects for a sample Config GUI for FML, although
@@ -56,6 +58,7 @@ public class DummyConfigElement implements IConfigElement
protected boolean isListFixedLength = false;
protected int maxListLength = -1;
protected List<IConfigElement> childElements;
@Nullable
protected Class<? extends IConfigEntry> configEntryClass;
protected Class<? extends IArrayEntry> arrayEntryClass;
@@ -75,7 +78,7 @@ public class DummyConfigElement implements IConfigElement
this(name, langKey, new ArrayList<IConfigElement>(), customListEntryClass);
}
public DummyCategoryElement(String name, String langKey, List<IConfigElement> childElements, Class<? extends IConfigEntry> customListEntryClass)
public DummyCategoryElement(String name, String langKey, List<IConfigElement> childElements, @Nullable Class<? extends IConfigEntry> customListEntryClass)
{
super(name, null, ConfigGuiType.CONFIG_CATEGORY, langKey);
this.childElements = childElements;
@@ -89,7 +92,7 @@ public class DummyConfigElement implements IConfigElement
*/
public static class DummyListElement extends DummyConfigElement
{
public DummyListElement(String name, Object[] defaultValues, ConfigGuiType type, String langKey, boolean isListFixedLength, int maxListLength, Pattern validStringPattern, Object minValue, Object maxValue)
public DummyListElement(String name, Object[] defaultValues, ConfigGuiType type, String langKey, boolean isListFixedLength, int maxListLength, @Nullable Pattern validStringPattern, @Nullable Object minValue, @Nullable Object maxValue)
{
super(name, null, type, langKey, minValue, maxValue);
this.defaultValues = defaultValues;
@@ -42,6 +42,8 @@ import net.minecraftforge.fml.common.eventhandler.Event.Result;
import org.lwjgl.input.Keyboard;
import javax.annotation.Nullable;
/**
* This class is the base GuiScreen for all config GUI screens. It can be extended by mods to provide the top-level config screen
* that will be called when the Config button is clicked from the Main Menu Mods list.
@@ -55,6 +57,7 @@ public class GuiConfig extends GuiScreen
*/
public final GuiScreen parentScreen;
public String title = "Config GUI";
@Nullable
public String titleLine2;
public final List<IConfigElement> configElements;
public final List<IConfigEntry> initEntries;
@@ -68,6 +71,7 @@ public class GuiConfig extends GuiScreen
* if any configElements were changed (includes child screens). If not defined, the events will be posted if the parent gui is null
* or if the parent gui is not an instance of GuiConfig.
*/
@Nullable
public final String configID;
public final boolean isWorldRunning;
public final boolean allRequireWorldRestart;
@@ -154,8 +158,8 @@ public class GuiConfig extends GuiScreen
* @param titleLine2 the desired title second line for this screen. Typically this is used to send the category name of the category
* currently being edited.
*/
public GuiConfig(GuiScreen parentScreen, List<IConfigElement> configElements, String modID, String configID,
boolean allRequireWorldRestart, boolean allRequireMcRestart, String title, String titleLine2)
public GuiConfig(GuiScreen parentScreen, List<IConfigElement> configElements, String modID, @Nullable String configID,
boolean allRequireWorldRestart, boolean allRequireMcRestart, String title, @Nullable String titleLine2)
{
this.mc = Minecraft.getMinecraft();
this.parentScreen = parentScreen;
@@ -20,16 +20,17 @@
package net.minecraftforge.fml.client.config;
import net.minecraft.client.gui.GuiDisconnected;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.text.ITextComponent;
import javax.annotation.Nullable;
public class GuiMessageDialog extends GuiDisconnected
{
protected String buttonText;
public GuiMessageDialog(GuiScreen nextScreen, String title, ITextComponent message, String buttonText)
public GuiMessageDialog(@Nullable GuiScreen nextScreen, String title, ITextComponent message, String buttonText)
{
super(nextScreen, title, message);
this.buttonText = buttonText;
@@ -22,6 +22,8 @@ package net.minecraftforge.fml.client.config;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import javax.annotation.Nullable;
/**
* This class is blatantly stolen from iChunUtils with permission.
*
@@ -42,6 +44,7 @@ public class GuiSlider extends GuiButtonExt
public double maxValue = 5.0D;
public int precision = 1;
@Nullable
public ISlider parent = null;
public String suffix = "";
@@ -53,7 +56,7 @@ public class GuiSlider extends GuiButtonExt
this(id, xPos, yPos, width, height, prefix, suf, minVal, maxVal, currentVal, showDec, drawStr, null);
}
public GuiSlider(int id, int xPos, int yPos, int width, int height, String prefix, String suf, double minVal, double maxVal, double currentVal, boolean showDec, boolean drawStr, ISlider par)
public GuiSlider(int id, int xPos, int yPos, int width, int height, String prefix, String suf, double minVal, double maxVal, double currentVal, boolean showDec, boolean drawStr, @Nullable ISlider par)
{
super(id, xPos, yPos, width, height, prefix);
minValue = minVal;
@@ -36,7 +36,7 @@ import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import javax.annotation.Nonnull;
/**
* This class provides several methods and constants used by the Config GUI classes.
@@ -210,14 +210,15 @@ public class GuiUtils
tessellator.draw();
}
private static ItemStack cachedTooltipStack;
@Nonnull
private static ItemStack cachedTooltipStack = ItemStack.EMPTY;
/**
* Must be called from {@code GuiScreen.renderToolTip} before {@code GuiScreen.drawHoveringText} is called.
*
* @param stack The stack for which a tooltip is about to be drawn.
*/
public static void preItemToolTip(ItemStack stack)
public static void preItemToolTip(@Nonnull ItemStack stack)
{
cachedTooltipStack = stack;
}
@@ -227,7 +228,7 @@ public class GuiUtils
*/
public static void postItemToolTip()
{
cachedTooltipStack = null;
cachedTooltipStack = ItemStack.EMPTY;
}
/**
@@ -255,8 +256,7 @@ public class GuiUtils
*
* @see #drawHoveringText(List, int, int, int, int, int, FontRenderer)
*/
public static void drawHoveringText(@Nullable final ItemStack stack, List<String> textLines, int mouseX, int mouseY, int screenWidth, int screenHeight,
int maxTextWidth, FontRenderer font)
public static void drawHoveringText(@Nonnull final ItemStack stack, List<String> textLines, int mouseX, int mouseY, int screenWidth, int screenHeight, int maxTextWidth, FontRenderer font)
{
if (!textLines.isEmpty())
{
@@ -22,6 +22,8 @@ package net.minecraftforge.fml.client.event;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
import javax.annotation.Nullable;
/**
* These events are posted from the GuiConfig screen when the done button is pressed. The events are only posted
* if the parent screen is not an instance of GuiConfig or if the configID field has been set for
@@ -39,9 +41,10 @@ public class ConfigChangedEvent extends Event
private final String modID;
private final boolean isWorldRunning;
private final boolean requiresMcRestart;
@Nullable
private final String configID;
public ConfigChangedEvent(String modID, String configID, boolean isWorldRunning, boolean requiresMcRestart)
public ConfigChangedEvent(String modID, @Nullable String configID, boolean isWorldRunning, boolean requiresMcRestart)
{
this.modID = modID;
this.configID = configID;
@@ -76,6 +79,7 @@ public class ConfigChangedEvent extends Event
/**
* A String identifier for this ConfigChangedEvent.
*/
@Nullable
public String getConfigID()
{
return configID;
@@ -92,7 +96,7 @@ public class ConfigChangedEvent extends Event
*/
public static class OnConfigChangedEvent extends ConfigChangedEvent
{
public OnConfigChangedEvent(String modID, String configID, boolean isWorldRunning, boolean requiresMcRestart)
public OnConfigChangedEvent(String modID, @Nullable String configID, boolean isWorldRunning, boolean requiresMcRestart)
{
super(modID, configID, isWorldRunning, requiresMcRestart);
}
@@ -104,7 +108,7 @@ public class ConfigChangedEvent extends Event
*/
public static class PostConfigChangedEvent extends ConfigChangedEvent
{
public PostConfigChangedEvent(String modID, String configID, boolean isWorldRunning, boolean requiresMcRestart)
public PostConfigChangedEvent(String modID, @Nullable String configID, boolean isWorldRunning, boolean requiresMcRestart)
{
super(modID, configID, isWorldRunning, requiresMcRestart);
}
@@ -43,7 +43,7 @@ public class CertificateHelper {
}
catch (Exception e)
{
return null;
return "CERTIFICATE FINGERPRINT EXCEPTION";
}
}
@@ -58,7 +58,7 @@ public class CertificateHelper {
}
catch (Exception e)
{
return null;
return "CERTIFICATE FINGERPRINT EXCEPTION";
}
}
@@ -34,6 +34,8 @@ import net.minecraftforge.fml.common.versioning.VersionRange;
import com.google.common.collect.ImmutableList;
import com.google.common.eventbus.EventBus;
import javax.annotation.Nullable;
public class DummyModContainer implements ModContainer
{
private ModMetadata md;
@@ -164,6 +166,7 @@ public class DummyModContainer implements ModContainer
}
@Override
@Nullable
public Certificate getSigningCertificate()
{
return null;
@@ -81,6 +81,8 @@ import com.google.common.collect.MapMaker;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import javax.annotation.Nullable;
/**
* The main class for non-obfuscated hook handling code
@@ -709,6 +711,7 @@ public class FMLCommonHandler
* @param inputstream Input stream containing the lang file.
* @return A new InputStream that vanilla uses to load normal Lang files, Null if this is a 'enhanced' file and loading is done.
*/
@Nullable
public InputStream loadLanguage(Map<String, String> table, InputStream inputstream) throws IOException
{
byte[] data = IOUtils.toByteArray(inputstream);
@@ -52,6 +52,8 @@ import org.apache.logging.log4j.Level;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import javax.annotation.Nullable;
/**
* @author cpw
*
@@ -343,6 +345,7 @@ public final class FMLContainer extends DummyModContainer implements WorldAccess
@Override
@Nullable
public Certificate getSigningCertificate()
{
Certificate[] certificates = getClass().getProtectionDomain().getCodeSource().getCertificates();
@@ -77,6 +77,8 @@ import com.google.common.collect.Sets;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import javax.annotation.Nullable;
public class FMLModContainer implements ModContainer
{
private Object modInstance;
@@ -280,6 +282,7 @@ public class FMLModContainer implements ModContainer
}
}
@Nullable
public Properties searchForVersionProperties()
{
try
@@ -391,6 +394,7 @@ public class FMLModContainer implements ModContainer
}
}
@Nullable
@SuppressWarnings("unchecked")
private Method gatherAnnotations(Class<?> clazz) throws Exception
{
@@ -31,6 +31,8 @@ import net.minecraftforge.fml.common.versioning.VersionRange;
import com.google.common.eventbus.EventBus;
import javax.annotation.Nullable;
public class InjectedModContainer implements ModContainer
{
private File source;
@@ -150,6 +152,7 @@ public class InjectedModContainer implements ModContainer
return wrappedContainer.acceptableMinecraftVersionRange();
}
@Nullable
public WorldAccessContainer getWrappedWorldAccessContainer()
{
if (wrappedContainer instanceof WorldAccessContainer)
@@ -163,6 +166,7 @@ public class InjectedModContainer implements ModContainer
}
@Override
@Nullable
public Certificate getSigningCertificate()
{
return wrappedContainer.getSigningCertificate();
@@ -55,6 +55,8 @@ import com.google.common.eventbus.Subscribe;
import com.google.common.eventbus.SubscriberExceptionHandler;
import com.google.common.eventbus.SubscriberExceptionContext;
import javax.annotation.Nullable;
public class LoadController
{
private Loader loader;
@@ -198,12 +200,13 @@ public class LoadController
}
@Nullable
public ModContainer activeContainer()
{
return activeContainer != null ? activeContainer : findActiveContainerFromStack();
}
void forceActiveContainer(ModContainer container)
void forceActiveContainer(@Nullable ModContainer container)
{
activeContainer = container;
}
@@ -237,7 +240,7 @@ public class LoadController
}
}
activeContainer = mc;
stateEvent.applyModContainer(activeContainer());
stateEvent.applyModContainer(mc);
ThreadContext.put("mod", modId);
FMLLog.log(modId, Level.TRACE, "Sending event %s to mod %s", stateEvent.getEventType(), modId);
eventChannels.get(modId).post(stateEvent);
@@ -358,6 +361,7 @@ public class LoadController
this.state = newState;
}
@Nullable
private ModContainer findActiveContainerFromStack()
{
for (Class<?> c : getCallingStack())
@@ -90,6 +90,8 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import javax.annotation.Nullable;
/**
* The loader class performs the actual loading of the mod code from disk.
*
@@ -887,6 +889,7 @@ public class Loader
return getModObjectList().inverse();
}
@Nullable
public ModContainer activeModContainer()
{
return modController != null ? modController.activeContainer() : null;
@@ -1162,7 +1165,7 @@ public class Loader
return modController != null ? modController.getState() : LoaderState.NOINIT;
}
public void setActiveModContainer(ModContainer container)
public void setActiveModContainer(@Nullable ModContainer container)
{
this.modController.forceActiveContainer(container);
}
@@ -41,13 +41,15 @@ import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import javax.annotation.Nullable;
public class MetadataCollection
{
private String modListVersion;
private ModMetadata[] modList;
private Map<String, ModMetadata> metadatas = Maps.newHashMap();
public static MetadataCollection from(InputStream inputStream, String sourceName)
public static MetadataCollection from(@Nullable InputStream inputStream, String sourceName)
{
if (inputStream == null)
{
@@ -28,6 +28,8 @@ import net.minecraftforge.fml.common.versioning.VersionRange;
import net.minecraftforge.fml.relauncher.FMLLaunchHandler;
import net.minecraftforge.fml.relauncher.Side;
import javax.annotation.Nullable;
public class MinecraftDummyContainer extends DummyModContainer
{
@@ -65,6 +67,7 @@ public class MinecraftDummyContainer extends DummyModContainer
}
@Override
@Nullable
public Certificate getSigningCertificate()
{
if (FMLLaunchHandler.side() != Side.CLIENT)
@@ -76,7 +79,7 @@ public class MinecraftDummyContainer extends DummyModContainer
Certificate[] certificates = cbr.getProtectionDomain().getCodeSource().getCertificates();
return certificates != null ? certificates[0] : null;
}
catch (Exception e){} // Errors don't matter just return null.
catch (Exception ignored){} // Errors don't matter just return null.
return null;
}
}
@@ -32,6 +32,8 @@ import net.minecraftforge.fml.common.versioning.VersionRange;
import com.google.common.collect.ImmutableMap;
import com.google.common.eventbus.EventBus;
import javax.annotation.Nullable;
/**
* The container that wraps around mods in the system.
* <p>
@@ -141,6 +143,7 @@ public interface ModContainer
VersionRange acceptableMinecraftVersionRange();
@Nullable
Certificate getSigningCertificate();
public static final Map<String,String> EMPTY_PROPERTIES = ImmutableMap.of();
@@ -34,6 +34,8 @@ import org.objectweb.asm.Type;
import com.google.common.base.Throwables;
import com.google.common.collect.Maps;
import javax.annotation.Nullable;
public class ModContainerFactory
{
public static Map<Type, Constructor<? extends ModContainer>> modTypes = Maps.newHashMap();
@@ -58,6 +60,8 @@ public class ModContainerFactory
Throwables.propagate(e);
}
}
@Nullable
public ModContainer build(ASMModParser modParser, File modSource, ModCandidate container)
{
String className = modParser.getASMType().getClassName();
@@ -24,6 +24,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
import net.minecraft.server.MinecraftServer;
import javax.annotation.Nullable;
public class StartupQuery {
// internal class/functionality, do not use
@@ -80,12 +82,13 @@ public class StartupQuery {
private static volatile boolean aborted = false;
private StartupQuery(String text, AtomicBoolean result)
private StartupQuery(String text, @Nullable AtomicBoolean result)
{
this.text = text;
this.result = result;
}
@Nullable
public Boolean getResult()
{
return result == null ? null : result.get();
@@ -159,6 +162,7 @@ public class StartupQuery {
}
private String text;
@Nullable
private AtomicBoolean result;
private CountDownLatch signal = new CountDownLatch(1);
private volatile boolean synchronous;
@@ -47,6 +47,8 @@ import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Maps;
import javax.annotation.Nullable;
public class ASMTransformerWrapper
{
private static final Map<String, String> wrapperModMap = Maps.newHashMap();
@@ -80,6 +82,7 @@ public class ASMTransformerWrapper
private static class ASMGenHandler extends URLStreamHandler
{
@Nullable
protected URLConnection openConnection(URL url) throws IOException
{
String file = url.getFile();
@@ -125,6 +128,7 @@ public class ASMTransformerWrapper
}
@Override
@Nullable
public Permission getPermission()
{
return null;
@@ -54,6 +54,8 @@ import com.google.common.collect.Sets;
import com.google.common.io.CharSource;
import com.google.common.io.Files;
import javax.annotation.Nullable;
public class FMLDeobfuscatingRemapper extends Remapper {
public static final FMLDeobfuscatingRemapper INSTANCE = new FMLDeobfuscatingRemapper();
@@ -198,12 +200,13 @@ public class FMLDeobfuscatingRemapper extends Remapper {
/*
* Cache the field descriptions for classes so we don't repeatedly reload the same data again and again
*/
private Map<String,Map<String,String>> fieldDescriptions = Maps.newHashMap();
private final Map<String,Map<String,String>> fieldDescriptions = Maps.newHashMap();
// Cache null values so we don't waste time trying to recompute classes with no field or method maps
private Set<String> negativeCacheMethods = Sets.newHashSet();
private Set<String> negativeCacheFields = Sets.newHashSet();
@Nullable
private String getFieldType(String owner, String name)
{
if (fieldDescriptions.containsKey(owner))
@@ -283,12 +286,12 @@ public class FMLDeobfuscatingRemapper extends Remapper {
}
@Override
public String mapFieldName(String owner, String name, String desc)
public String mapFieldName(String owner, String name, @Nullable String desc)
{
return mapFieldName(owner, name, desc, false);
}
String mapFieldName(String owner, String name, String desc, boolean raw)
String mapFieldName(String owner, String name, @Nullable String desc, boolean raw)
{
if (classNameBiMap == null || classNameBiMap.isEmpty())
{
@@ -350,6 +353,7 @@ public class FMLDeobfuscatingRemapper extends Remapper {
}
@Override
@Nullable
public String mapSignature(String signature, boolean typeSignature)
{
// JDT decorates some lambdas with this and SignatureReader chokes on it
@@ -430,7 +434,7 @@ public class FMLDeobfuscatingRemapper extends Remapper {
e.printStackTrace();
}
}
public void mergeSuperMaps(String name, String superName, String[] interfaces)
public void mergeSuperMaps(String name, @Nullable String superName, String[] interfaces)
{
// System.out.printf("Computing super maps for %s: %s %s\n", name, superName, Arrays.asList(interfaces));
if (classNameBiMap == null || classNameBiMap.isEmpty())
@@ -483,6 +487,7 @@ public class FMLDeobfuscatingRemapper extends Remapper {
return ImmutableSet.copyOf(classNameBiMap.keySet());
}
@Nullable
public String getStaticFieldType(String oldType, String oldName, String newType, String newName)
{
String fType = getFieldType(newType, newName);
@@ -35,6 +35,8 @@ import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.SetMultimap;
import javax.annotation.Nullable;
public class ASMDataTable
{
public final static class ASMData implements Cloneable
@@ -45,7 +47,7 @@ public class ASMDataTable
private String objectName;
private int classVersion;
private Map<String,Object> annotationInfo;
public ASMData(ModCandidate candidate, String annotationName, String className, String objectName, Map<String,Object> info)
public ASMData(ModCandidate candidate, String annotationName, String className, @Nullable String objectName, @Nullable Map<String,Object> info)
{
this.candidate = candidate;
this.annotationName = annotationName;
@@ -128,7 +130,7 @@ public class ASMDataTable
return globalAnnotationData.get(annotation);
}
public void addASMData(ModCandidate candidate, String annotation, String className, String objectName, Map<String,Object> annotationInfo)
public void addASMData(ModCandidate candidate, String annotation, String className, @Nullable String objectName, @Nullable Map<String,Object> annotationInfo)
{
globalAnnotationData.put(annotation, new ASMData(candidate, annotation, className, objectName, annotationInfo));
}
@@ -148,6 +150,7 @@ public class ASMDataTable
return this.packageMap.get(pkg);
}
@Nullable
public static String getOwnerModID(Set<ASMData> mods, ASMData targ)
{
if (mods.size() == 1) {
@@ -39,6 +39,8 @@ import org.apache.logging.log4j.Level;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import javax.annotation.Nullable;
public class DirectoryDiscoverer implements ITypeDiscoverer
{
private class ClassFilter implements FileFilter
@@ -66,7 +68,7 @@ public class DirectoryDiscoverer implements ITypeDiscoverer
return found;
}
public void exploreFileSystem(String path, File modDir, List<ModContainer> harvestedMods, ModCandidate candidate, MetadataCollection mc)
public void exploreFileSystem(String path, File modDir, List<ModContainer> harvestedMods, ModCandidate candidate, @Nullable MetadataCollection mc)
{
if (path.length() == 0)
{
@@ -35,6 +35,8 @@ import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList;
import org.apache.logging.log4j.Level;
import javax.annotation.Nonnull;
/**
* Simple intermod communications to receive simple messages directed at you
* from other mods
@@ -91,20 +93,22 @@ public class FMLInterModComms {
/**
* This field, and {@link #value} are both at the mod's discretion
*/
@Nonnull
public final String key;
/**
* This field, and {@link #key} are both at the mod's discretion
*/
@Nonnull
private final Object value;
private IMCMessage(String key, Object value)
private IMCMessage(@Nonnull String key, @Nonnull Object value)
{
this.key = key;
this.value = value;
this.isFunction = false;
}
private IMCMessage(String key, String value, boolean isFunction) {
private IMCMessage(@Nonnull String key, @Nonnull String value, boolean isFunction) {
this.key = key;
this.value = value;
this.isFunction = isFunction;
@@ -164,6 +168,7 @@ public class FMLInterModComms {
* @throws ClassCastException if this message doesn't contain an Itemstack value
* @return The Itemstack value
*/
@Nonnull
public ItemStack getItemStackValue()
{
return (ItemStack) value;
@@ -70,14 +70,14 @@ public class FMLPostInitializationEvent extends FMLStateEvent
@Nullable
@Override
public Class<?> apply(@Nullable Object input) {
return input.getClass();
return input == null ? null : input.getClass();
}
}).toArray(new Class[0]);
try
{
Class<?> clz = Class.forName(className,true,Loader.instance().getModClassLoader());
Constructor<?> ct = clz.getConstructor(args);
return Optional.fromNullable(ct.newInstance(arguments));
return Optional.of(ct.newInstance(arguments));
}
catch (Exception e)
{
@@ -33,6 +33,8 @@ import net.minecraftforge.fml.common.discovery.ASMDataTable;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
/**
* Called before {@link FMLInitializationEvent} during mod startup.
*
@@ -132,6 +134,7 @@ public class FMLPreInitializationEvent extends FMLStateEvent
* such as a unique version number from a properties file shipped as part of the distributable.
* @return A properties object if one exists, else null
*/
@Nullable
public Properties getVersionProperties()
{
if (this.modContainer instanceof FMLModContainer)
@@ -153,7 +153,7 @@ public class Event
public void setPhase(@Nonnull EventPriority value)
{
Preconditions.checkArgument(value != null, "setPhase argument must not be null");
Preconditions.checkNotNull(value, "setPhase argument must not be null");
int prev = phase == null ? -1 : phase.ordinal();
Preconditions.checkArgument(prev < value.ordinal(), "Attempted to set event phase to %s when already %s", value, phase);
phase = value;
@@ -59,7 +59,7 @@ public class EventBus implements IEventExceptionHandler
public EventBus(@Nonnull IEventExceptionHandler handler)
{
this();
Preconditions.checkArgument(handler != null, "EventBus exception handler can not be null");
Preconditions.checkNotNull(handler, "EventBus exception handler can not be null");
exceptionHandler = handler;
}
@@ -23,12 +23,15 @@ import java.util.*;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import javax.annotation.Nullable;
public class ListenerList
{
private static ImmutableList<ListenerList> allLists = ImmutableList.of();
private static int maxSize = 0;
@Nullable
private ListenerList parent;
private ListenerListInst[] lists = new ListenerListInst[0];
@@ -37,7 +40,7 @@ public class ListenerList
this(null);
}
public ListenerList(ListenerList parent)
public ListenerList(@Nullable ListenerList parent)
{
// parent needs to be set before resize !
this.parent = parent;
@@ -30,6 +30,8 @@ import com.google.common.base.Throwables;
import io.netty.buffer.ByteBuf;
import javax.annotation.Nullable;
/**
* Utilities for interacting with {@link ByteBuf}.
* @author cpw
@@ -203,6 +205,7 @@ public class ByteBufUtils {
* @param from The buffer to read from
* @return The read tag
*/
@Nullable
public static NBTTagCompound readTag(ByteBuf from)
{
PacketBuffer pb = new PacketBuffer(from);
@@ -31,6 +31,8 @@ import net.minecraftforge.fml.common.network.FMLOutboundHandler.OutboundTarget;
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
import net.minecraftforge.fml.relauncher.Side;
import javax.annotation.Nullable;
/**
* Utility wrapper around {@link EmbeddedChannel}. Provides some convenience methods
* associated with the specific needs of FML network handling.
@@ -72,6 +74,7 @@ public class FMLEmbeddedChannel extends EmbeddedChannel {
return pkt;
}
@Nullable
public String findChannelHandlerNameForType(Class<? extends ChannelHandler> type)
{
String targetName = null;
@@ -33,6 +33,8 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
import net.minecraftforge.fml.relauncher.Side;
import javax.annotation.Nullable;
/**
* An event driven network channel, using {@link FMLNetworkEvent.CustomPacketEvent} and {@link FMLNetworkEvent.CustomNetworkEvent}
* to deliver messages to an event listener. There is one "bus" for each channel, due to the
@@ -57,6 +59,7 @@ public class FMLEventChannel {
SERVER()
{
@Override
@Nullable
FMLNetworkEvent.CustomPacketEvent<?> make(FMLProxyPacket msg)
{
FMLNetworkEvent.CustomPacketEvent<?> event = null;
@@ -71,6 +74,7 @@ public class FMLEventChannel {
CLIENT()
{
@Override
@Nullable
FMLNetworkEvent.CustomPacketEvent<?> make(FMLProxyPacket msg)
{
FMLNetworkEvent.CustomPacketEvent<?> event = null;
@@ -87,6 +91,7 @@ public class FMLEventChannel {
return event;
}
};
@Nullable
abstract FMLNetworkEvent.CustomPacketEvent<?> make(FMLProxyPacket msg);
}
@@ -40,6 +40,8 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import javax.annotation.Nullable;
public class FMLOutboundHandler extends ChannelOutboundHandlerAdapter {
public static final AttributeKey<OutboundTarget> FML_MESSAGETARGET = AttributeKey.valueOf("fml:outboundTarget");
public static final AttributeKey<Object> FML_MESSAGETARGETARGS = AttributeKey.valueOf("fml:outboundTargetArgs");
@@ -59,6 +61,7 @@ public class FMLOutboundHandler extends ChannelOutboundHandlerAdapter {
}
@Override
@Nullable
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
return null;
@@ -253,6 +256,7 @@ public class FMLOutboundHandler extends ChannelOutboundHandlerAdapter {
}
public final ImmutableSet<Side> allowed;
public abstract void validateArgs(Object args);
@Nullable
public abstract List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet);
}
@@ -50,6 +50,8 @@ import net.minecraftforge.fml.relauncher.Side;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import javax.annotation.Nullable;
/**
* @author cpw
*
@@ -242,6 +244,7 @@ public enum NetworkRegistry
* @param z Z coord
* @return The server side GUI object (An instance of {@link Container})
*/
@Nullable
public Container getRemoteGuiContainer(ModContainer mc, EntityPlayerMP player, int modGuiId, World world, int x, int y, int z)
{
IGuiHandler handler = serverGuiHandlers.get(mc);
@@ -267,6 +270,7 @@ public enum NetworkRegistry
* @param z Z coord
* @return The client side GUI object (An instance of {@link net.minecraft.client.gui.Gui})
*/
@Nullable
public Object getLocalGuiContainer(ModContainer mc, EntityPlayer player, int modGuiId, World world, int x, int y, int z)
{
IGuiHandler handler = clientGuiHandlers.get(mc);
@@ -291,7 +295,7 @@ public enum NetworkRegistry
* @param remoteVersionRange the acceptable remote range
* @param asmHarvestedData internal data
*/
public void register(ModContainer fmlModContainer, Class<?> clazz, String remoteVersionRange, ASMDataTable asmHarvestedData)
public void register(ModContainer fmlModContainer, Class<?> clazz, @Nullable String remoteVersionRange, ASMDataTable asmHarvestedData)
{
NetworkModHolder networkModHolder = new NetworkModHolder(fmlModContainer, clazz, remoteVersionRange, asmHarvestedData);
registry.put(fmlModContainer, networkModHolder);
@@ -21,6 +21,8 @@ package net.minecraftforge.fml.common.network.handshake;
import io.netty.channel.ChannelHandlerContext;
import javax.annotation.Nullable;
public interface IHandshakeState<S> {
S accept(ChannelHandlerContext ctx, FMLHandshakeMessage msg);
S accept(ChannelHandlerContext ctx, @Nullable FMLHandshakeMessage msg);
}
@@ -60,6 +60,8 @@ import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import javax.annotation.Nullable;
public class FMLNetworkHandler
{
public static final int READ_TIMEOUT = Integers.parseInt(System.getProperty("fml.readTimeout","30"),30);
@@ -117,6 +119,7 @@ public class FMLNetworkHandler
}
@Nullable
public static Packet<?> getEntitySpawningPacket(Entity entity)
{
EntityRegistration er = EntityRegistry.instance().lookupModSpawn(entity.getClass(), false);
@@ -132,11 +135,14 @@ public class FMLNetworkHandler
return channelPair.get(Side.SERVER).generatePacketFrom(new FMLMessage.EntitySpawnMessage(er, entity, er.getContainer()));
}
@Nullable
public static String checkModList(FMLHandshakeMessage.ModList modListPacket, Side side)
{
Map<String,String> modList = modListPacket.modList();
return checkModList(modList, side);
}
@Nullable
public static String checkModList(Map<String,String> listData, Side side)
{
List<ModContainer> rejects = Lists.newArrayList();
@@ -49,6 +49,8 @@ import com.google.common.collect.Multiset;
import com.google.common.collect.Multiset.Entry;
import com.google.common.collect.Multisets;
import javax.annotation.Nullable;
public class FMLProxyPacket implements Packet<INetHandler> {
final String channel;
private Side target;
@@ -192,6 +194,7 @@ public class FMLProxyPacket implements Packet<INetHandler> {
this.dispatcher = networkDispatcher;
}
@Nullable
public NetworkManager getOrigin()
{
return this.dispatcher != null ? this.dispatcher.manager : null;
@@ -41,6 +41,8 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.SetMultimap;
import javax.annotation.Nullable;
public class NetworkModHolder
{
public abstract class NetworkChecker {
@@ -118,7 +120,7 @@ public class NetworkModHolder
this.checker = Preconditions.checkNotNull(checker);
FMLLog.fine("The mod %s is using a custom checker %s", container.getModId(), checker.getClass().getName());
}
public NetworkModHolder(ModContainer container, Class<?> modClass, String acceptableVersionRange, ASMDataTable table)
public NetworkModHolder(ModContainer container, Class<?> modClass, @Nullable String acceptableVersionRange, ASMDataTable table)
{
this(container);
SetMultimap<String, ASMData> annotationTable = table.getAnnotationsFor(container);
@@ -42,6 +42,8 @@ import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ListMultimap;
import javax.annotation.Nullable;
public class EntityRegistry
{
public class EntityRegistration
@@ -312,6 +314,7 @@ public class EntityRegistry
}
}
@Nullable
public EntityRegistration lookupModSpawn(Class<? extends Entity> clazz, boolean keepLooking)
{
Class<?> localClazz = clazz;
@@ -331,6 +334,7 @@ public class EntityRegistry
return null;
}
@Nullable
public EntityRegistration lookupModSpawn(ModContainer mc, int modEntityId)
{
for (EntityRegistration er : entityRegistrations.get(mc))
@@ -356,6 +360,7 @@ public class EntityRegistry
}
//Helper function
@Nullable
public static EntityEntry getEntry(Class<? extends Entity> entry)
{
//TODO: Slave map for faster lookup?
@@ -30,6 +30,7 @@ import java.util.Map.Entry;
import java.util.Set;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Iterators;
@@ -47,12 +48,17 @@ import net.minecraftforge.fml.common.functions.GenericIterableFactory;
import net.minecraftforge.fml.common.registry.RegistryDelegate.Delegate;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> extends RegistryNamespacedDefaultedByKey<ResourceLocation, I> implements IForgeRegistry<I>
{
public static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("fml.debugRegistryEntries", "false"));
private final Class<I> superType;
private final boolean isDelegated;
@Nullable
private ResourceLocation optionalDefaultKey;
@Nullable
private I optionalDefaultObject;
private int maxId;
private int minId;
@@ -83,16 +89,16 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
private final BitSet availabilityMap;
private final Map<ResourceLocation,?> slaves = Maps.newHashMap();
@Nullable
private final AddCallback<I> addCallback;
@Nullable
private final ClearCallback<I> clearCallback;
@Nullable
private final CreateCallback<I> createCallback;
@Nullable
private final SubstitutionCallback<I> substitutionCallback;
FMLControlledNamespacedRegistry(ResourceLocation defaultKey, int minIdValue, int maxIdValue, Class<I> type, BiMap<ResourceLocation, ? extends IForgeRegistry<?>> registries, AddCallback<I> addCallback, ClearCallback<I> clearCallback, CreateCallback<I> createCallback, SubstitutionCallback<I> substitutionCallback)
FMLControlledNamespacedRegistry(@Nullable ResourceLocation defaultKey, int minIdValue, int maxIdValue, Class<I> type, BiMap<ResourceLocation, ? extends IForgeRegistry<?>> registries, @Nullable AddCallback<I> addCallback, @Nullable ClearCallback<I> clearCallback, @Nullable CreateCallback<I> createCallback, @Nullable SubstitutionCallback<I> substitutionCallback)
{
super(defaultKey);
this.superType = type;
@@ -220,7 +226,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
*/
@Override
@Deprecated
public void register(int id, ResourceLocation name, I thing)
public void register(int id, @Nonnull ResourceLocation name, @Nonnull I thing)
{
add(id, name, thing);
}
@@ -232,17 +238,10 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
*/
@Override
@Deprecated
public void putObject(ResourceLocation name, I thing)
public void putObject(@Nonnull ResourceLocation name, @Nonnull I thing)
{
if (name == null)
{
throw new NullPointerException("Can't use a null-name for the registry.");
}
if (thing == null)
{
throw new NullPointerException("Can't add null-object to the registry.");
}
Preconditions.checkNotNull(name, "Can't use a null-name for the registry.");
Preconditions.checkNotNull(thing, "Can't add null-object to the registry.");
ResourceLocation existingName = getNameForObject(thing);
@@ -269,6 +268,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
* @param name Unique name identifying the object.
* @return Registered object of the default object if it wasn't found-
*/
@Nullable
@Override
public I getObject(ResourceLocation name)
{
@@ -284,6 +284,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
* @param id ID identifying the object.
* @return Registered object of the default object if it wasn't found-
*/
@Nullable
@Override
public I getObjectById(int id)
{
@@ -302,7 +303,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
* @param thing Block/Item object.
* @return Block/Item id or -1 if it wasn't found.
*/
public int getId(I thing)
public int getId(@Nullable I thing)
{
return getIDForObjectBypass(thing);
}
@@ -313,6 +314,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
* @param id Block/Item id.
* @return Block/Item object or null if it wasn't found.
*/
@Nullable
public I getRaw(int id)
{
return super.getObjectById(id);
@@ -324,6 +326,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
* @param name Block/Item name.
* @return Block/Item object or null if it wasn't found.
*/
@Nullable
private I getRaw(ResourceLocation name)
{
I ret = super.getObject(name);
@@ -350,7 +353,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
* @return true if a matching entry was found.
*/
@Override
public boolean containsKey(ResourceLocation name)
public boolean containsKey(@Nonnull ResourceLocation name)
{
boolean ret = super.containsKey(name);
@@ -430,16 +433,11 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
* @param thing Object to add.
* @return ID eventually allocated.
*/
int add(int id, ResourceLocation name, I thing)
int add(int id, @Nonnull ResourceLocation name, @Nonnull I thing)
{
if (name == null)
{
throw new NullPointerException(String.format("Can't use a null-name for the registry, object %s.", thing));
}
if (thing == null)
{
throw new NullPointerException(String.format("Can't add null-object to the registry, name %s.", name));
}
Preconditions.checkNotNull(name, "Can't use a null-name for the registry, object %s.", thing);
Preconditions.checkNotNull(thing, "Can't add null-object to the registry, name %s.", name);
if (optionalDefaultKey != null && optionalDefaultKey.equals(name) && this.optionalDefaultObject == null)
{
this.optionalDefaultObject = thing;
@@ -573,18 +571,9 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
*/
private void addObjectRaw(int id, ResourceLocation name, I thing)
{
if (name == null)
{
throw new NullPointerException("The name to be added to the registry is null. This can only happen with a corrupted registry state. Reflection/ASM hackery? Registry bug?");
}
if (thing == null)
{
throw new NullPointerException("The object to be added to the registry is null. This can only happen with a corrupted registry state. Reflection/ASM hackery? Registry bug?");
}
if (!superType.isInstance(thing))
{
throw new IllegalArgumentException("The object to be added to the registry is not of the right type. Reflection/ASM hackery? Registry bug?");
}
Preconditions.checkNotNull(name, "The name to be added to the registry is null. This can only happen with a corrupted registry state. Reflection/ASM hackery? Registry bug?");
Preconditions.checkNotNull(thing, "The object to be added to the registry is null. This can only happen with a corrupted registry state. Reflection/ASM hackery? Registry bug?");
Preconditions.checkState(superType.isInstance(thing), "The object to be added to the registry is not of the right type. Reflection/ASM hackery? Registry bug?");
underlyingIntegerMap.put(thing, id); // obj <-> id
super.putObject(name, thing); // name <-> obj
@@ -595,6 +584,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
}
}
@Nullable
public I getDefaultValue()
{
return optionalDefaultObject;
@@ -606,6 +596,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
}
@SuppressWarnings("unchecked")
@Nonnull
private Delegate<I> getExistingDelegate(I thing)
{
if (isDelegated)
@@ -614,10 +605,11 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
}
else
{
return null;
throw new IllegalStateException("Tried to get existing delegate from registry that is not delegated.");
}
}
@Nullable
I activateSubstitution(ResourceLocation nameToReplace)
{
if (getPersistentSubstitutions().containsKey(nameToReplace))
@@ -682,6 +674,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
* This iterator is used by some regular MC methods to visit all blocks, we need to include substitutions
* Compare #typeSafeIterable()
*/
@Nonnull
@Override
public Iterator<I> iterator()
{
@@ -777,6 +770,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
remappedIds.put(itemName, new Integer[] {currId, newId});
}
I obj = currentRegistry.getRaw(itemName);
Preconditions.checkState(obj != null, "objectKey has an ID but no object. Reflection/ASM hackery? Registry bug?");
I sub = obj;
// If we have an object in the originals set, we use that for initial adding - substitute activation will readd the substitute if neceessary later
if (currentRegistry.substitutionOriginals.containsKey(itemName))
@@ -808,7 +802,8 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
}
@Override
public ResourceLocation getNameForObject(I p_177774_1_)
@Nullable
public ResourceLocation getNameForObject(@Nonnull I p_177774_1_)
{
ResourceLocation rl = super.getNameForObjectBypass(p_177774_1_);
if (rl == null)
@@ -828,7 +823,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
// IForgeRegistry: Modders should only interfaces with these methods
@Override
public void register(I value)
public void register(@Nonnull I value)
{
ResourceLocation key = value.getRegistryName();
if (key == null)
@@ -847,7 +842,7 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
}
}
@Override
public boolean containsValue(I value)
public boolean containsValue(@Nonnull I value)
{
return getKey(value) != null;
}
@@ -859,11 +854,13 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
}
@Override
@Nullable
public ResourceLocation getKey(I value)
{
return getNameForObject(value);
}
@Nonnull
@Override //Bouncer for OBF, as the super class's function is NotchCode and gets obfed. This plus the SRG lines prevents a AbstractMethodException
public Set<ResourceLocation> getKeys()
{
@@ -871,12 +868,14 @@ public class FMLControlledNamespacedRegistry<I extends IForgeRegistryEntry<I>> e
}
@Override
@Nonnull
public List<I> getValues()
{
return Lists.newArrayList(this.iterator());
}
@Override
@Nonnull
public Set<Entry<ResourceLocation, I>> getEntries()
{
return Sets.newHashSet(new Iterator<Entry<ResourceLocation, I>>()
@@ -21,6 +21,7 @@ package net.minecraftforge.fml.common.registry;
import com.google.common.base.Throwables;
import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -50,7 +51,7 @@ class FinalFieldHelper
}
static void setField(Field field, Object instance, Object thing) throws Exception
static void setField(Field field, @Nullable Object instance, Object thing) throws Exception
{
Object fieldAccessor = newFieldAccessor.invoke(reflectionFactory, field, false);
fieldAccessorSet.invoke(fieldAccessor, instance, thing);
@@ -27,6 +27,9 @@ import java.util.Set;
import com.google.common.collect.BiMap;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* Main interface for the registry system. Use this to query the registry system.
*
@@ -44,12 +47,12 @@ public interface IForgeRegistry<V extends IForgeRegistryEntry<V>> extends Iterab
boolean containsKey(ResourceLocation key);
boolean containsValue(V value);
V getValue(ResourceLocation key);
ResourceLocation getKey(V value);
@Nullable V getValue(ResourceLocation key);
@Nullable ResourceLocation getKey(V value);
Set<ResourceLocation> getKeys();
List<V> getValues();
Set<Entry<ResourceLocation, V>> getEntries();
@Nonnull Set<ResourceLocation> getKeys();
@Nonnull List<V> getValues();
@Nonnull Set<Entry<ResourceLocation, V>> getEntries();
/**
* Retrieve the slave map of type T from the registry.
@@ -28,6 +28,8 @@ import net.minecraftforge.fml.common.InjectedModContainer;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import javax.annotation.Nullable;
public interface IForgeRegistryEntry<V>
{
/**
@@ -54,6 +56,7 @@ public interface IForgeRegistryEntry<V>
*
* @return Unique identifier or null.
*/
@Nullable
ResourceLocation getRegistryName();
Class<? super V> getRegistryType();
@@ -89,6 +92,7 @@ public interface IForgeRegistryEntry<V>
//Helper functions
public final T setRegistryName(ResourceLocation name){ return setRegistryName(name.toString()); }
public final T setRegistryName(String modID, String name){ return setRegistryName(modID + ":" + name); }
@Nullable
public final ResourceLocation getRegistryName()
{
if (delegate.name() != null) return delegate.name();
@@ -33,6 +33,8 @@ import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
import net.minecraftforge.fml.common.registry.PersistentRegistryManager.PersistentRegistry;
import javax.annotation.Nullable;
/**
* Internal class used in tracking {@link ObjectHolder} references
@@ -100,6 +102,7 @@ class ObjectHolderRef {
}
@SuppressWarnings("unchecked")
@Nullable
private FMLControlledNamespacedRegistry<?> getRegistryForType(Field field)
{
Queue<Class<?>> typesToExamine = new LinkedList<Class<?>>();
@@ -35,6 +35,8 @@ import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import javax.annotation.Nullable;
/**
* Internal registry for tracking {@link ObjectHolder} references
* @author cpw
@@ -78,7 +80,7 @@ public enum ObjectHolderRegistry {
FMLLog.info("Found %d ObjectHolder annotations", objectHolders.size());
}
private void scanTarget(Map<String, String> classModIds, Map<String, Class<?>> classCache, String className, String annotationTarget, String value, boolean isClass, boolean extractFromValue)
private void scanTarget(Map<String, String> classModIds, Map<String, Class<?>> classCache, String className, @Nullable String annotationTarget, String value, boolean isClass, boolean extractFromValue)
{
Class<?> clazz;
if (classCache.containsKey(className))
@@ -57,6 +57,8 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.collect.Sets.SetView;
import javax.annotation.Nullable;
/**
* Persistent registry manager. Manages the registries loading from disk, and from network. Handles staging
* registry data before loading uniformly into the active registry, and keeps a frozen registry instance
@@ -112,7 +114,7 @@ public class PersistentRegistryManager
}
@SuppressWarnings("unchecked")
private <T extends IForgeRegistryEntry<T>> FMLControlledNamespacedRegistry<T> getRegistry(ResourceLocation key, @SuppressWarnings("UnusedParameters") Class<T> regType)
private <T extends IForgeRegistryEntry<T>> FMLControlledNamespacedRegistry<T> getRegistry(ResourceLocation key, @SuppressWarnings("UnusedParameters") @Nullable Class<T> regType)
{
return (FMLControlledNamespacedRegistry<T>)registries.get(key);
}
@@ -127,7 +129,7 @@ public class PersistentRegistryManager
return getRegistry(key, regType);
}
private <T extends IForgeRegistryEntry<T>> FMLControlledNamespacedRegistry<T> createRegistry(ResourceLocation registryName, Class<T> type, ResourceLocation defaultObjectKey, int minId, int maxId, IForgeRegistry.AddCallback<T> addCallback, IForgeRegistry.ClearCallback<T> clearCallback, IForgeRegistry.CreateCallback<T> createCallback, IForgeRegistry.SubstitutionCallback<T> substitutionCallback)
private <T extends IForgeRegistryEntry<T>> FMLControlledNamespacedRegistry<T> createRegistry(ResourceLocation registryName, Class<T> type, ResourceLocation defaultObjectKey, int minId, int maxId, @Nullable IForgeRegistry.AddCallback<T> addCallback, @Nullable IForgeRegistry.ClearCallback<T> clearCallback, @Nullable IForgeRegistry.CreateCallback<T> createCallback, @Nullable IForgeRegistry.SubstitutionCallback<T> substitutionCallback)
{
Set<Class<?>> parents = Sets.newHashSet();
findSuperTypes(type, parents);
@@ -196,21 +198,21 @@ public class PersistentRegistryManager
public static <T extends IForgeRegistryEntry<T>> FMLControlledNamespacedRegistry<T> createRegistry(
ResourceLocation registryName, Class<T> registryType, ResourceLocation optionalDefaultKey,
int minId, int maxId, boolean hasDelegates,
IForgeRegistry.AddCallback<T> addCallback,
IForgeRegistry.ClearCallback<T> clearCallback,
IForgeRegistry.CreateCallback<T> createCallback)
@Nullable IForgeRegistry.AddCallback<T> addCallback,
@Nullable IForgeRegistry.ClearCallback<T> clearCallback,
@Nullable IForgeRegistry.CreateCallback<T> createCallback)
{
return PersistentRegistry.ACTIVE.createRegistry(registryName, registryType, optionalDefaultKey, minId, maxId,
getLegacyAdd(addCallback), getLegacyClear(clearCallback), getLegacyCreate(createCallback), null);
}
@Deprecated //Use RegistryBuilder TODO: Remove in 1.11 {Make package private so only builder can use it}
public static <T extends IForgeRegistryEntry<T>> FMLControlledNamespacedRegistry<T> createRegistry(
ResourceLocation registryName, Class<T> registryType, ResourceLocation optionalDefaultKey,
ResourceLocation registryName, Class<T> registryType, @Nullable ResourceLocation optionalDefaultKey,
int minId, int maxId, boolean hasDelegates,
IForgeRegistry.AddCallback<T> addCallback,
IForgeRegistry.ClearCallback<T> clearCallback,
IForgeRegistry.CreateCallback<T> createCallback,
IForgeRegistry.SubstitutionCallback<T> substitutionCallback)
@Nullable IForgeRegistry.AddCallback<T> addCallback,
@Nullable IForgeRegistry.ClearCallback<T> clearCallback,
@Nullable IForgeRegistry.CreateCallback<T> createCallback,
@Nullable IForgeRegistry.SubstitutionCallback<T> substitutionCallback)
{
return PersistentRegistry.ACTIVE.createRegistry(registryName, registryType, optionalDefaultKey, minId, maxId,
addCallback, clearCallback, createCallback, substitutionCallback);
@@ -766,7 +768,8 @@ public class PersistentRegistryManager
//TODO: Remove in 1.11, creates wrappers for API breakage cpw did in registry re-work.
private static <T extends IForgeRegistryEntry<T>> IForgeRegistry.ClearCallback<T> getLegacyClear(final IForgeRegistry.ClearCallback<T> cb)
@Nullable
private static <T extends IForgeRegistryEntry<T>> IForgeRegistry.ClearCallback<T> getLegacyClear(@Nullable final IForgeRegistry.ClearCallback<T> cb)
{
if (cb == null)
return null;
@@ -790,13 +793,13 @@ public class PersistentRegistryManager
return cb; //Assume they are ussing modern API
} catch (SecurityException e) {
e.printStackTrace();
Throwables.propagate(e);
throw Throwables.propagate(e);
}
return null; //Will never get here unless things go wonkey...
}
//TODO: Remove in 1.11, creates wrappers for API breakage cpw did in registry re-work.
private static <T extends IForgeRegistryEntry<T>> IForgeRegistry.CreateCallback<T> getLegacyCreate(final IForgeRegistry.CreateCallback<T> cb)
@Nullable
private static <T extends IForgeRegistryEntry<T>> IForgeRegistry.CreateCallback<T> getLegacyCreate(@Nullable final IForgeRegistry.CreateCallback<T> cb)
{
if (cb == null)
return null;
@@ -820,13 +823,13 @@ public class PersistentRegistryManager
return cb; //Assume they are ussing modern API
} catch (SecurityException e) {
e.printStackTrace();
Throwables.propagate(e);
throw Throwables.propagate(e);
}
return null; //Will never get here unless things go wonkey...
}
//TODO: Remove in 1.11, creates wrappers for API breakage cpw did in registry re-work.
private static <T extends IForgeRegistryEntry<T>> IForgeRegistry.AddCallback<T> getLegacyAdd(final IForgeRegistry.AddCallback<T> cb)
@Nullable
private static <T extends IForgeRegistryEntry<T>> IForgeRegistry.AddCallback<T> getLegacyAdd(@Nullable final IForgeRegistry.AddCallback<T> cb)
{
if (cb == null)
return null;
@@ -850,8 +853,7 @@ public class PersistentRegistryManager
return cb; //Assume they are ussing modern API
} catch (SecurityException e) {
e.printStackTrace();
Throwables.propagate(e);
throw Throwables.propagate(e);
}
return null; //Will never get here unless things go wonkey...
}
}
@@ -28,6 +28,8 @@ import com.google.common.collect.Lists;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.IForgeRegistry.*;
import javax.annotation.Nullable;
public class RegistryBuilder<T extends IForgeRegistryEntry<T>>
{
private ResourceLocation registryName;
@@ -104,6 +106,7 @@ public class RegistryBuilder<T extends IForgeRegistryEntry<T>>
getAdd(), getClear(), getCreate(), getSubstitution());
}
@Nullable
private AddCallback<T> getAdd()
{
if (this.addCallback.isEmpty())
@@ -121,6 +124,8 @@ public class RegistryBuilder<T extends IForgeRegistryEntry<T>>
}
};
}
@Nullable
private ClearCallback<T> getClear()
{
if (this.clearCallback.isEmpty())
@@ -138,6 +143,8 @@ public class RegistryBuilder<T extends IForgeRegistryEntry<T>>
}
};
}
@Nullable
private CreateCallback<T> getCreate()
{
if (this.createCallback.isEmpty())
@@ -155,6 +162,8 @@ public class RegistryBuilder<T extends IForgeRegistryEntry<T>>
}
};
}
@Nullable
private SubstitutionCallback<T> getSubstitution()
{
if (this.substitutionCallback.isEmpty())
@@ -37,6 +37,9 @@ import net.minecraft.world.gen.structure.StructureComponent;
import net.minecraft.world.gen.structure.StructureVillagePieces;
import net.minecraft.world.gen.structure.StructureVillagePieces.PieceWeight;
import net.minecraft.world.gen.structure.StructureVillagePieces.Village;
import javax.annotation.Nullable;
/**
* Registry for villager trading control
*/
@@ -284,7 +287,7 @@ public class VillagerRegistry
return this;
}
@Nullable
public List<ITradeList> getTrades(int level)
{
return level >= 0 && level < this.trades.size() ? Collections.unmodifiableList(this.trades.get(level)) : null;
@@ -357,7 +360,7 @@ public class VillagerRegistry
}
@Deprecated public static VillagerProfession getById(int network){ return INSTANCE.professions.getObjectById(network); }
@Deprecated public static int getId(VillagerProfession prof){ return INSTANCE.professions.getId(prof); }
@Deprecated public static int getId(@Nullable VillagerProfession prof){ return INSTANCE.professions.getId(prof); }
//TODO: Figure out a good generic system for this. Put on hold for Patches.
@@ -21,6 +21,8 @@ package net.minecraftforge.fml.common.versioning;
import net.minecraft.client.resources.I18n;
import javax.annotation.Nullable;
/**
* Describes a restriction in versioning.
*
@@ -38,8 +40,8 @@ public class Restriction
public static final Restriction EVERYTHING = new Restriction( null, false, null, false );
public Restriction( ArtifactVersion lowerBound, boolean lowerBoundInclusive, ArtifactVersion upperBound,
boolean upperBoundInclusive )
public Restriction( @Nullable ArtifactVersion lowerBound, boolean lowerBoundInclusive, @Nullable ArtifactVersion upperBound,
boolean upperBoundInclusive )
{
this.lowerBound = lowerBound;
this.lowerBoundInclusive = lowerBoundInclusive;
@@ -47,6 +49,7 @@ public class Restriction
this.upperBoundInclusive = upperBoundInclusive;
}
@Nullable
public ArtifactVersion getLowerBound()
{
return lowerBound;
@@ -57,6 +60,7 @@ public class Restriction
return lowerBoundInclusive;
}
@Nullable
public ArtifactVersion getUpperBound()
{
return upperBound;
@@ -29,6 +29,8 @@ import java.util.List;
import com.google.common.base.Joiner;
import javax.annotation.Nullable;
/**
* Construct a version range from a specification.
*
@@ -101,7 +103,7 @@ public class VersionRange
* @throws InvalidVersionSpecificationException
*
*/
public static VersionRange createFromVersionSpec( String spec )
public static VersionRange createFromVersionSpec( @Nullable String spec )
throws InvalidVersionSpecificationException
{
if ( spec == null )
@@ -19,6 +19,7 @@
package net.minecraftforge.fml.relauncher;
import javax.annotation.Nullable;
import java.io.File;
import java.io.FilenameFilter;
import java.util.Arrays;
@@ -40,7 +41,7 @@ public final class FileListHelper {
Arrays.sort(files, CaseInsensitiveFileComparator.INSTANCE);
return files;
}
public static File[] sortFileList(File dir, FilenameFilter filter)
public static File[] sortFileList(File dir, @Nullable FilenameFilter filter)
{
File[] files = dir.listFiles(filter);
return sortFileList(files);
@@ -19,6 +19,7 @@
package net.minecraftforge.fml.relauncher;
import javax.annotation.Nullable;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -60,6 +61,7 @@ public interface IFMLLoadingPlugin
* minecraft class loading
* TODO: implement crash ;)
*/
@Nullable
String getSetupClass();
/**
@@ -33,6 +33,8 @@ import com.google.common.io.Files;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import javax.annotation.Nullable;
public class ModListHelper {
public static class JsonModList {
public String repositoryRoot;
@@ -148,7 +150,7 @@ public class ModListHelper {
tryAddFile(fileName.toString(), repoRoot, genericName.toString());
}
}
private static void tryAddFile(String modFileName, File repoRoot, String descriptor) {
private static void tryAddFile(String modFileName, @Nullable File repoRoot, String descriptor) {
File modFile = repoRoot != null ? new File(repoRoot,modFileName) : new File(mcDirectory, modFileName);
if (!modFile.exists())
{
@@ -18,6 +18,7 @@
*/
package net.minecraftforge.fml.relauncher;
import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
@@ -46,7 +47,7 @@ public class ReflectionHelper
private static final long serialVersionUID = 1L;
//private String[] classNames;
public UnableToFindClassException(String[] classNames, Exception err)
public UnableToFindClassException(String[] classNames, @Nullable Exception err)
{
super(err);
//this.classNames = classNames;
@@ -97,7 +98,7 @@ public class ReflectionHelper
}
@SuppressWarnings("unchecked")
public static <T, E> T getPrivateValue(Class <? super E > classToAccess, E instance, int fieldIndex)
public static <T, E> T getPrivateValue(Class <? super E > classToAccess, @Nullable E instance, int fieldIndex)
{
try
{