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

@@ -134,7 +134,7 @@ public class ClientCommandHandler extends CommandHandler
if (mc.currentScreen instanceof GuiChat)
{
List<String> commands = getTabCompletions(mc.player, leftOfCursor, mc.player.getPosition());
if (commands != null && !commands.isEmpty())
if (!commands.isEmpty())
{
if (leftOfCursor.indexOf(' ') == -1)
{
@@ -24,6 +24,8 @@ import net.minecraft.world.GameType;
import net.minecraft.client.settings.GameSettings.Options;
import net.minecraftforge.common.util.EnumHelper;
import javax.annotation.Nullable;
public class EnumHelperClient extends EnumHelper
{
private static Class<?>[][] clientTypes =
@@ -33,16 +35,19 @@ public class EnumHelperClient extends EnumHelper
{EnumOS.class}
};
@Nullable
public static GameType addGameType(String name, int id, String displayName, String shortName)
{
return addEnum(GameType.class, name, id, displayName, shortName);
}
@Nullable
public static Options addOptions(String name, String langName, boolean isSlider, boolean isToggle)
{
return addEnum(Options.class, name, langName, isSlider, isToggle);
}
@Nullable
public static Options addOptions(String name, String langName, boolean isSlider, boolean isToggle, float valMin, float valMax, float valStep)
{
return addEnum(Options.class, name,
@@ -50,11 +55,13 @@ public class EnumHelperClient extends EnumHelper
langName, isSlider, isToggle, valMin, valMax, valStep);
}
@Nullable
public static EnumOS addOS2(String name)
{
return addEnum(EnumOS.class, name);
}
@Nullable
private static <T extends Enum<? >> T addEnum(Class<T> enumType, String enumName, Object... paramValues)
{
return addEnum(clientTypes, enumType, enumName, paramValues);
@@ -25,6 +25,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.player.PlayerEvent;
import javax.annotation.Nonnull;
public abstract class RenderPlayerEvent extends PlayerEvent
{
private final RenderPlayer renderer;
@@ -99,8 +101,9 @@ public abstract class RenderPlayerEvent extends PlayerEvent
{
private int result = -1;
private final int slot;
@Nonnull
private final ItemStack stack;
public SetArmorModel(EntityPlayer player, RenderPlayer renderer, int slot, float partialTick, ItemStack stack)
public SetArmorModel(EntityPlayer player, RenderPlayer renderer, int slot, float partialTick, @Nonnull ItemStack stack)
{
super(player, renderer, partialTick, 0D, 0D, 0D);
this.slot = slot;
@@ -126,6 +129,7 @@ public abstract class RenderPlayerEvent extends PlayerEvent
return slot;
}
@Nonnull
public ItemStack getStack()
{
return stack;
@@ -6,7 +6,6 @@ import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}
@@ -22,6 +21,7 @@ public class RenderSpecificHandEvent extends Event
private final float interpolatedPitch;
private final float swingProgress;
private final float equipProgress;
@Nonnull
private final ItemStack stack;
public RenderSpecificHandEvent(EnumHand hand, float partialTicks, float interpolatedPitch, float swingProgress, float equipProgress, @Nonnull ItemStack stack)
@@ -4,7 +4,6 @@ import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.item.ItemStack;
@@ -26,6 +25,7 @@ import net.minecraftforge.fml.common.eventhandler.Event;
*/
public abstract class RenderTooltipEvent extends Event
{
@Nonnull
protected final ItemStack stack;
protected final List<String> lines;
protected int x;
@@ -42,7 +42,7 @@ public abstract class RenderTooltipEvent extends Event
}
/**
* @return The stack which the tooltip is being rendered for. As tooltips can be drawn without itemstacks, this return is {@link Nullable}.
* @return The stack which the tooltip is being rendered for. As tooltips can be drawn without itemstacks, this stack may be empty.
*/
@Nonnull
public ItemStack getStack()
@@ -98,7 +98,7 @@ public abstract class RenderTooltipEvent extends Event
private int screenHeight;
private int maxWidth;
public Pre(@Nullable ItemStack stack, @Nonnull List<String> lines, int x, int y, int screenWidth, int screenHeight, int maxWidth, @Nonnull FontRenderer fr)
public Pre(@Nonnull ItemStack stack, @Nonnull List<String> lines, int x, int y, int screenWidth, int screenHeight, int maxWidth, @Nonnull FontRenderer fr)
{
super(stack, lines, x, y, fr);
this.screenWidth = screenWidth;
@@ -181,7 +181,7 @@ public abstract class RenderTooltipEvent extends Event
private final int width;
private final int height;
public Post(@Nullable ItemStack stack, @Nonnull List<String> textLines, int x, int y, @Nonnull FontRenderer fr, int width, int height)
public Post(@Nonnull ItemStack stack, @Nonnull List<String> textLines, int x, int y, @Nonnull FontRenderer fr, int width, int height)
{
super(stack, textLines, x, y, fr);
this.width = width;
@@ -210,7 +210,7 @@ public abstract class RenderTooltipEvent extends Event
*/
public static class PostBackground extends Post
{
public PostBackground(@Nullable ItemStack stack, @Nonnull List<String> textLines, int x, int y, @Nonnull FontRenderer fr, int width, int height)
public PostBackground(@Nonnull ItemStack stack, @Nonnull List<String> textLines, int x, int y, @Nonnull FontRenderer fr, int width, int height)
{ super(stack, textLines, x, y, fr, width, height); }
}
@@ -219,7 +219,7 @@ public abstract class RenderTooltipEvent extends Event
*/
public static class PostText extends Post
{
public PostText(@Nullable ItemStack stack, @Nonnull List<String> textLines, int x, int y, @Nonnull FontRenderer fr, int width, int height)
public PostText(@Nonnull ItemStack stack, @Nonnull List<String> textLines, int x, int y, @Nonnull FontRenderer fr, int width, int height)
{ super(stack, textLines, x, y, fr, width, height); }
}
}
@@ -30,6 +30,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import javax.vecmath.AxisAngle4d;
import javax.vecmath.Matrix4f;
import javax.vecmath.Quat4f;
@@ -218,7 +219,7 @@ public class ForgeBlockStateV1 extends Marker
return ret;
}
private Multimap<String, ForgeBlockStateV1.Variant> getPermutations(List<String> sorted, Map<String, Map<String, ForgeBlockStateV1.Variant>> base, int depth, String prefix, Multimap<String, ForgeBlockStateV1.Variant> ret, ForgeBlockStateV1.Variant parent)
private Multimap<String, ForgeBlockStateV1.Variant> getPermutations(List<String> sorted, Map<String, Map<String, ForgeBlockStateV1.Variant>> base, int depth, String prefix, Multimap<String, ForgeBlockStateV1.Variant> ret, @Nullable ForgeBlockStateV1.Variant parent)
{
if (depth == sorted.size())
{
@@ -24,6 +24,7 @@ import java.util.BitSet;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import javax.vecmath.Vector4f;
@@ -140,7 +141,7 @@ public final class ItemLayerModel implements IRetexturableModel
private final boolean isCulled;
private final ItemOverrideList overrides;
public BakedItemModel(ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, ImmutableMap<TransformType, TRSRTransformation> transforms, ItemOverrideList overrides, IBakedModel otherModel)
public BakedItemModel(ImmutableList<BakedQuad> quads, TextureAtlasSprite particle, ImmutableMap<TransformType, TRSRTransformation> transforms, ItemOverrideList overrides, @Nullable IBakedModel otherModel)
{
this.quads = quads;
this.particle = particle;
@@ -75,10 +75,13 @@ public final class ModelDynBucket implements IModel, IModelCustomData, IRetextur
public static final IModel MODEL = new ModelDynBucket();
@Nullable
private final ResourceLocation baseLocation;
@Nullable
private final ResourceLocation liquidLocation;
@Nullable
private final ResourceLocation coverLocation;
@Nullable
private final Fluid fluid;
private final boolean flipGas;
@@ -87,7 +90,7 @@ public final class ModelDynBucket implements IModel, IModelCustomData, IRetextur
this(null, null, null, null, false);
}
public ModelDynBucket(ResourceLocation baseLocation, ResourceLocation liquidLocation, ResourceLocation coverLocation, Fluid fluid, boolean flipGas)
public ModelDynBucket(@Nullable ResourceLocation baseLocation, @Nullable ResourceLocation liquidLocation, @Nullable ResourceLocation coverLocation, @Nullable Fluid fluid, boolean flipGas)
{
this.baseLocation = baseLocation;
this.liquidLocation = liquidLocation;
@@ -121,6 +121,8 @@ import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Sets;
import javax.annotation.Nonnull;
public final class ModelLoader extends ModelBakery
{
private final Map<ModelResourceLocation, IModel> stateModels = Maps.newHashMap();
@@ -1167,7 +1169,7 @@ public final class ModelLoader extends ModelBakery
ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition()
{
@Override
public ModelResourceLocation getModelLocation(ItemStack stack)
public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack)
{
return ModelDynBucket.LOCATION;
}
@@ -22,6 +22,7 @@ package net.minecraftforge.client.model;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nonnull;
import javax.vecmath.Matrix4f;
import net.minecraft.block.state.IBlockState;
@@ -177,6 +178,7 @@ public final class MultiLayerModel implements IModelCustomData
return builder.build();
}
@Nonnull
@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand)
{
@@ -67,10 +67,10 @@ public final class AnimationItemOverrideList extends ItemOverrideList
@Override
public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity)
{
if(stack.hasCapability(net.minecraftforge.common.model.animation.CapabilityAnimation.ANIMATION_CAPABILITY, null))
IAnimationStateMachine asm = stack.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
if (asm != null)
{
// TODO: caching?
IAnimationStateMachine asm = stack.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
if(world == null && entity != null)
{
world = entity.world;
@@ -44,6 +44,7 @@ import net.minecraftforge.common.animation.IEventHandler;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.animation.CapabilityAnimation;
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
import org.apache.commons.lang3.tuple.Pair;
import org.lwjgl.opengl.GL11;
@@ -67,12 +68,12 @@ public class AnimationModelBase<T extends Entity> extends ModelBase implements I
@Override
public void render(Entity entity, float limbSwing, float limbSwingSpeed, float timeAlive, float yawHead, float rotationPitch, float scale)
{
if(!(entity.hasCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null)))
IAnimationStateMachine capability = entity.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
if (capability == null)
{
return;
}
Pair<IModelState, Iterable<Event>> pair = entity.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null).apply(timeAlive / 20);
Pair<IModelState, Iterable<Event>> pair = capability.apply(timeAlive / 20);
handleEvents((T)entity, timeAlive / 20, pair.getRight());
IModel model = ModelLoaderRegistry.getModelOrMissing(modelLocation);
IBakedModel bakedModel = model.bake(pair.getLeft(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
@@ -32,11 +32,14 @@ import net.minecraftforge.common.animation.Event;
import net.minecraftforge.common.animation.IEventHandler;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.animation.CapabilityAnimation;
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.Properties;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nonnull;
/**
* Generic TileEntitySpecialRenderer that works with the Forge model system and animations.
*/
@@ -44,7 +47,7 @@ public class AnimationTESR<T extends TileEntity> extends FastTESR<T> implements
{
protected static BlockRendererDispatcher blockRenderer;
public void renderTileEntityFast(T te, double x, double y, double z, float partialTick, int breakStage, VertexBuffer renderer)
public void renderTileEntityFast(@Nonnull T te, double x, double y, double z, float partialTick, int breakStage, @Nonnull VertexBuffer renderer)
{
if(!te.hasCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null))
{
@@ -64,16 +67,20 @@ public class AnimationTESR<T extends TileEntity> extends FastTESR<T> implements
if(exState.getUnlistedNames().contains(Properties.AnimationProperty))
{
float time = Animation.getWorldTime(getWorld(), partialTick);
Pair<IModelState, Iterable<Event>> pair = te.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null).apply(time);
handleEvents(te, time, pair.getRight());
IAnimationStateMachine capability = te.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
if (capability != null)
{
Pair<IModelState, Iterable<Event>> pair = capability.apply(time);
handleEvents(te, time, pair.getRight());
// TODO: caching?
IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(exState.getClean());
exState = exState.withProperty(Properties.AnimationProperty, pair.getLeft());
// TODO: caching?
IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(exState.getClean());
exState = exState.withProperty(Properties.AnimationProperty, pair.getLeft());
renderer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
renderer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
blockRenderer.getBlockModelRenderer().renderModel(world, model, exState, pos, renderer, false);
blockRenderer.getBlockModelRenderer().renderModel(world, model, exState, pos, renderer, false);
}
}
}
}
@@ -31,10 +31,12 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.tileentity.TileEntity;
import javax.annotation.Nonnull;
public abstract class FastTESR<T extends TileEntity> extends TileEntitySpecialRenderer<T>
{
@Override
public final void renderTileEntityAt(T te, double x, double y, double z, float partialTicks, int destroyStage)
public final void renderTileEntityAt(@Nonnull T te, double x, double y, double z, float partialTicks, int destroyStage)
{
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer VertexBuffer = tessellator.getBuffer();
@@ -64,5 +66,5 @@ public abstract class FastTESR<T extends TileEntity> extends TileEntitySpecialRe
}
@Override
public abstract void renderTileEntityFast(T te, double x, double y, double z, float partialTicks, int destroyStage, VertexBuffer VertexBuffer);
public abstract void renderTileEntityFast(@Nonnull T te, double x, double y, double z, float partialTicks, int destroyStage, @Nonnull VertexBuffer VertexBuffer);
}
@@ -29,6 +29,7 @@ import java.util.Map;
import java.util.NoSuchElementException;
import java.util.TreeMap;
import javax.annotation.Nullable;
import javax.vecmath.AxisAngle4f;
import javax.vecmath.Matrix4f;
import javax.vecmath.Quat4f;
@@ -515,6 +516,7 @@ public class ModelBlockAnimation
}
}
@Nullable
public TRSRTransformation getPartTransform(IModelState state, BlockPart part, int i)
{
ImmutableCollection<MBJointWeight> infos = getJoint(i);
@@ -30,6 +30,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import javax.vecmath.Vector3f;
@@ -168,6 +169,7 @@ public enum B3DLoader implements ICustomModelLoader
private final int frame;
private final int nextFrame;
private final float progress;
@Nullable
private final IModelState parent;
public B3DState(Animation animation, int frame)
@@ -185,7 +187,7 @@ public enum B3DLoader implements ICustomModelLoader
this(animation, frame, nextFrame, progress, null);
}
public B3DState(Animation animation, int frame, int nextFrame, float progress, IModelState parent)
public B3DState(Animation animation, int frame, int nextFrame, float progress, @Nullable IModelState parent)
{
this.animation = animation;
this.frame = frame;
@@ -194,7 +196,8 @@ public enum B3DLoader implements ICustomModelLoader
this.parent = getParent(parent);
}
private IModelState getParent(IModelState parent)
@Nullable
private IModelState getParent(@Nullable IModelState parent)
{
if (parent == null) return null;
else if (parent instanceof B3DState) return ((B3DState)parent).parent;
@@ -221,6 +224,7 @@ public enum B3DLoader implements ICustomModelLoader
return progress;
}
@Nullable
public IModelState getParent()
{
return parent;
@@ -33,6 +33,7 @@ import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import javax.vecmath.Matrix3f;
import javax.vecmath.Matrix4f;
import javax.vecmath.Vector2f;
@@ -1068,7 +1069,7 @@ public class OBJModel implements IRetexturableModel, IModelCustomData
// public float[] minUVBounds = new float[] {0.0f, 0.0f};
// public float[] maxUVBounds = new float[] {1.0f, 1.0f};
public Group(String name, LinkedHashSet<Face> faces)
public Group(String name, @Nullable LinkedHashSet<Face> faces)
{
this.name = name != null ? name : DEFAULT_NAME;
this.faces = faces == null ? new LinkedHashSet<Face>() : faces;
@@ -1129,6 +1130,7 @@ public class OBJModel implements IRetexturableModel, IModelCustomData
for (String s : visibleGroups) this.visibilityMap.put(s, visibility);
}
@Nullable
public IModelState getParent(IModelState parent)
{
if (parent == null) return null;
@@ -22,6 +22,7 @@ package net.minecraftforge.client.settings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.util.IntHashMap;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
@@ -38,6 +39,7 @@ public class KeyBindingMap
}
}
@Nullable
public KeyBinding lookupActive(int keyCode)
{
KeyModifier activeModifier = KeyModifier.getActiveModifier();
@@ -52,6 +54,7 @@ public class KeyBindingMap
return getBinding(keyCode, KeyModifier.NONE);
}
@Nullable
private KeyBinding getBinding(int keyCode, KeyModifier keyModifier)
{
Collection<KeyBinding> bindings = map.get(keyModifier).lookup(keyCode);