Fix some null warnings

This commit is contained in:
mezz committed 2016-10-20 23:51:14 -07:00
1 parent c6783e573c
commit 3178aa890d
22 files changed
+114 -95

No files matched your search

+1 -4
View File
@@ -174,13 +174,10 @@ public class Botany extends AbstractMod {
if (event.getEntityPlayer() != null && event.getEntityPlayer().getHeldItemMainhand() != null) {
BlockPos down = event.getPos();
Block block = event.getWorld().getBlockState(event.getPos()).getBlock();
if (block == null || !Gardening.isSoil(block)) {
if (!Gardening.isSoil(block)) {
down = down.down();
block = event.getWorld().getBlockState(down).getBlock();
}
if (block == null) {
return;
}
if (Gardening.isSoil(block)) {
final IBlockSoil soil = (IBlockSoil) block;
// if (Gardening.isNutrientFertiliser(event.getEntityPlayer().getHeldItemMainhand()) && soil.getType(event.getWorld(), down) != EnumSoilType.FLOWERBED) {
@@ -140,10 +140,10 @@ public abstract class BreedingSystem implements IItemStackRepresentitive {
for (final IMutation mutation : mutations) {
this.allMutations.add(mutation);
final Set<IAlleleSpecies> participatingSpecies = new LinkedHashSet<>();
if (mutation.getAllele0() instanceof IAlleleSpecies) {
if (mutation.getAllele0() != null) {
participatingSpecies.add(mutation.getAllele0());
}
if (mutation.getAllele1() instanceof IAlleleSpecies) {
if (mutation.getAllele1() != null) {
participatingSpecies.add(mutation.getAllele1());
}
for (final IAlleleSpecies species3 : participatingSpecies) {
@@ -152,9 +152,11 @@ public abstract class BreedingSystem implements IItemStackRepresentitive {
this.furtherMutations.get(species3).add(mutation);
}
}
if (this.resultantMutations.containsKey(mutation.getTemplate()[0])) {
this.allResultantMutations.get(mutation.getTemplate()[0]).add(mutation);
this.resultantMutations.get(mutation.getTemplate()[0]).add(mutation);
IAllele[] template = mutation.getTemplate();
IAlleleSpecies speciesAllele = (IAlleleSpecies) template[0];
if (this.resultantMutations.containsKey(speciesAllele)) {
this.allResultantMutations.get(speciesAllele).add(mutation);
this.resultantMutations.get(speciesAllele).add(mutation);
}
}
}
@@ -1,6 +1,7 @@
package binnie.core.machines;
import binnie.core.BinnieCore;
import binnie.core.util.TileUtil;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyInteger;
@@ -153,11 +154,7 @@ class BlockMachine extends BlockContainer implements IBlockMachine {
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
final TileEntity tileentity = world.getTileEntity(pos);
if (!(tileentity instanceof TileEntityMachine)) {
return;
}
final TileEntityMachine entity = (TileEntityMachine) tileentity;
final TileEntityMachine entity = TileUtil.getTile(world, pos, TileEntityMachine.class);
if (entity != null) {
entity.onBlockDestroy();
}
@@ -23,6 +23,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import javax.annotation.Nullable;
import java.util.*;
public class Machine implements INetworkedEntity, INbtReadable, INbtWritable, INetwork.TilePacketSync, IMachine, INetwork.GuiNBT {
@@ -215,6 +216,7 @@ public class Machine implements INetworkedEntity, INbtReadable, INbtWritable, IN
return null;
}
@Nullable
public static <T> T getInterface(final Class<T> interfac, final Object inventory) {
final IMachine machine = getMachine(inventory);
if (machine != null) {
@@ -37,7 +37,7 @@ public enum Position {
return Position.Bottom;
}
default: {
return null;
throw new IllegalStateException();
}
}
}
@@ -27,10 +27,7 @@ public class ControlBreweryProgress extends ControlProgressBase {
public void onRenderBackground() {
CraftGUI.Render.texture(ControlBreweryProgress.Brewery, new IPoint(0.0f, 0.0f));
final Brewery.ComponentBreweryLogic logic = Machine.getInterface(Brewery.ComponentBreweryLogic.class, Window.get(this).getInventory());
if (logic.currentCrafting == null) {
return;
}
if (logic.currentCrafting.currentInput == null) {
if (logic == null || logic.currentCrafting == null || logic.currentCrafting.currentInput == null) {
return;
}
final int fermentedHeight = (int) (32.0f * logic.getProgress() / 100.0f);
@@ -41,9 +41,12 @@ public class ControlDistilleryProgress extends ControlProgressBase {
@Override
public void onRenderForeground() {
final int level = Machine.getInterface(Distillery.ComponentDistilleryLogic.class, Window.get(this).getInventory()).level;
CraftGUI.Render.texture(ControlDistilleryProgress.Output, new IPoint(47.0f, 14 + level * 15));
CraftGUI.Render.texture(ControlDistilleryProgress.DistilleryOverlay, new IPoint(0.0f, 0.0f));
Distillery.ComponentDistilleryLogic distilleryLogic = Machine.getInterface(Distillery.ComponentDistilleryLogic.class, Window.get(this).getInventory());
if (distilleryLogic != null) {
final int level = distilleryLogic.level;
CraftGUI.Render.texture(ControlDistilleryProgress.Output, new IPoint(47.0f, 14 + level * 15));
CraftGUI.Render.texture(ControlDistilleryProgress.DistilleryOverlay, new IPoint(0.0f, 0.0f));
}
}
protected ControlDistilleryProgress(final IWidget parent, final float x, final float y) {
@@ -11,6 +11,7 @@ import binnie.craftgui.resource.Texture;
import binnie.craftgui.resource.minecraft.StandardTexture;
import binnie.extratrees.core.ExtraTreeTexture;
import binnie.extratrees.machines.Press;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.Fluid;
@@ -23,7 +24,11 @@ public class ControlFruitPressProgress extends ControlProgressBase {
@Override
public void onRenderBackground() {
CraftGUI.Render.texture(ControlFruitPressProgress.PressSlot, new IPoint(3.0f, 52.0f));
final ItemStack input = Window.get(this).getContainer().getSlotFromInventory(Window.get(this).getInventory(), Press.slotCurrent).getStack();
Slot slotFromInventory = Window.get(this).getContainer().getSlotFromInventory(Window.get(this).getInventory(), Press.slotCurrent);
if (slotFromInventory == null) {
return;
}
final ItemStack input = slotFromInventory.getStack();
if (input == null || Press.getOutput(input) == null) {
return;
}
@@ -31,6 +31,9 @@ public class ControlRecipeSlot extends ControlSlotBase {
@Override
public ItemStack getItemStack() {
final IComponentRecipe recipe = Machine.getInterface(IComponentRecipe.class, Window.get(this).getInventory());
return recipe.isRecipe() ? recipe.getProduct() : null;
if (recipe != null && recipe.isRecipe()) {
return recipe.getProduct();
}
return null;
}
}
@@ -160,10 +160,13 @@ public class ContainerCraftGUI extends Container {
if (slotnumber < 0) {
return null;
}
final Slot shiftClickedSlot = (Slot) this.inventorySlots.get(slotnumber);
final Slot shiftClickedSlot = this.inventorySlots.get(slotnumber);
ItemStack itemstack = null;
if (shiftClickedSlot.getHasStack()) {
itemstack = shiftClickedSlot.getStack().copy();
ItemStack shiftClickedStack = shiftClickedSlot.getStack();
if (shiftClickedStack != null) {
itemstack = shiftClickedStack.copy();
}
}
final IInventory playerInventory = player.inventory;
final IInventory containerInventory = this.window.getInventory();
@@ -265,7 +268,7 @@ public class ContainerCraftGUI extends Container {
}
if (shouldSend) {
//TODO INVENTORY
this.crafters.stream().filter(entityPlayer -> entityPlayer instanceof EntityPlayerMP).forEach(entityPlayer -> {
this.crafters.stream().filter(Objects::nonNull).forEach(entityPlayer -> {
System.out.println("send to:" + entityPlayer.getDisplayName().getUnformattedText());
BinnieCore.proxy.sendToPlayer(new MessageContainerUpdate(nbt.getValue()), (EntityPlayerMP) entityPlayer);
});
@@ -68,8 +68,9 @@ public class AlvearyFrame {
}
public IHiveFrame getHiveFrame() {
if (this.getInventory().getStackInSlot(AlvearyFrame.slotFrame) != null) {
return (IHiveFrame) this.getInventory().getStackInSlot(AlvearyFrame.slotFrame).getItem();
ItemStack stackInSlot = this.getInventory().getStackInSlot(AlvearyFrame.slotFrame);
if (stackInSlot != null) {
return (IHiveFrame) stackInSlot.getItem();
}
return null;
}
@@ -26,11 +26,12 @@ public class BeeModelProvider implements IBeeModelProvider {
public void registerModels(Item item, IModelManager manager) {
String beeIconDir = "bees/default/";
EnumBeeType beeType = BeeManager.beeRoot.getType(new ItemStack(item));
String beeTypeNameBase = beeIconDir + beeType.toString().toLowerCase(Locale.ENGLISH);
if (beeType != null) {
String beeTypeNameBase = beeIconDir + beeType.toString().toLowerCase(Locale.ENGLISH);
models[beeType.ordinal()] = getModelLocation("forestry", beeTypeNameBase);
ModelBakery.registerItemVariants(item, new ResourceLocation("forestry:" + beeTypeNameBase));
models[beeType.ordinal()] = getModelLocation("forestry", beeTypeNameBase);
ModelBakery.registerItemVariants(item, new ResourceLocation("forestry:" + beeTypeNameBase));
}
}
@Override
@@ -112,9 +112,6 @@ public enum ExtraBeesFlowers implements IFlowerProvider, IAlleleFlowers, IChromo
public boolean isAcceptedFlower(final World world, final IIndividual individual, final BlockPos pos) {
final Block block = world.getBlockState(pos).getBlock();
if (block == null) {
return false;
}
switch (this) {
case WATER: {
return block == Blocks.WATERLILY;
@@ -220,13 +217,11 @@ public enum ExtraBeesFlowers implements IFlowerProvider, IAlleleFlowers, IChromo
final int z2 = pos.getZ() - tZ + world.rand.nextInt(1 + 2 * tZ);
final BlockPos pos2 = new BlockPos(x2, y2, z2);
final Block block = world.getBlockState(pos2).getBlock();
if (block != null) {
if (block == Mods.Botania.block("flower")) {
final int meta = world.getBlockState(pos2).getBlock().getMetaFromState(world.getBlockState(pos2));
final Item item = Mods.Botania.item("petal");
if (item != null) {
prods.add(new ItemStack(item, 1, meta));
}
if (block == Mods.Botania.block("flower")) {
final int meta = world.getBlockState(pos2).getBlock().getMetaFromState(world.getBlockState(pos2));
final Item item = Mods.Botania.item("petal");
if (item != null) {
prods.add(new ItemStack(item, 1, meta));
}
}
}
@@ -135,23 +135,19 @@ public enum ExtraBeesEffect implements IAlleleBeeEffect {
final double var3 = pos.getZ() + world.rand.nextFloat();
world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, var1, var2, var3, 0.0, 0.0, 0.0);
world.spawnParticle(EnumParticleTypes.FLAME, var1, var2, var3, 0.0, 0.0, 0.0);
final EntityLiving var4 = (EntityLiving) EntityList.createEntityByName(name, world);
if (var4 == null) {
return;
}
final int var5 = world.getEntitiesWithinAABB(var4.getClass(), new AxisAlignedBB(pos, pos.add(1, 1, 1)).expand(8.0, 4.0, 8.0)).size();
if (var5 >= 6) {
return;
}
if (var4 != null) {
final double var6 = pos.getX() + (world.rand.nextDouble() - world.rand.nextDouble()) * 4.0;
final double var7 = pos.getY() + world.rand.nextInt(3) - 1;
final double var8 = pos.getZ() + (world.rand.nextDouble() - world.rand.nextDouble()) * 4.0;
var4.setLocationAndAngles(var6, var7, var8, world.rand.nextFloat() * 360.0f, 0.0f);
if (var4.getCanSpawnHere()) {
world.spawnEntityInWorld(var4);
world.playEvent(2004, pos, 0);//playSFX
var4.spawnExplosionParticle();
final EntityLiving entity = (EntityLiving) EntityList.createEntityByName(name, world);
if (entity != null) {
final int nearbyEntityCount = world.getEntitiesWithinAABB(entity.getClass(), new AxisAlignedBB(pos, pos.add(1, 1, 1)).expand(8.0, 4.0, 8.0)).size();
if (nearbyEntityCount < 6) {
final double var6 = pos.getX() + (world.rand.nextDouble() - world.rand.nextDouble()) * 4.0;
final double var7 = pos.getY() + world.rand.nextInt(3) - 1;
final double var8 = pos.getZ() + (world.rand.nextDouble() - world.rand.nextDouble()) * 4.0;
entity.setLocationAndAngles(var6, var7, var8, world.rand.nextFloat() * 360.0f, 0.0f);
if (entity.getCanSpawnHere()) {
world.spawnEntityInWorld(entity);
world.playEvent(2004, pos, 0);//playSFX
entity.spawnExplosionParticle();
}
}
}
}
@@ -31,7 +31,10 @@ public class ControlBiomes extends Control implements ITooltip {
final int y = (int) (this.getRelativeMousePosition().y() / 16.0f);
final int i = x + y * 8;
if (i < this.tolerated.size()) {
list.add(Biome.getBiome(this.tolerated.get(i)).getBiomeName());
Biome biome = Biome.getBiome(this.tolerated.get(i));
if (biome != null) {
list.add(biome.getBiomeName());
}
}
}
@@ -6,8 +6,9 @@ import net.minecraft.potion.PotionEffect;
public class AlcoholEffect {
public static void makeDrunk(final EntityPlayer player, final float strength) {
final int existingStrength = player.isPotionActive(MobEffects.NAUSEA) ? player.getActivePotionEffect(MobEffects.NAUSEA).getAmplifier() : 0;
final int existingTime = player.isPotionActive(MobEffects.NAUSEA) ? player.getActivePotionEffect(MobEffects.NAUSEA).getDuration() : 0;
PotionEffect potionEffect = player.getActivePotionEffect(MobEffects.NAUSEA);
final int existingStrength = potionEffect != null ? potionEffect.getAmplifier() : 0;
final int existingTime = potionEffect != null ? potionEffect.getDuration() : 0;
int time = (int) (100.0 * Math.sqrt(strength)) + existingTime;
final float intensity = 0.1f * strength + existingStrength + existingTime / 500;
if (time < 5) {
@@ -3,6 +3,7 @@ package binnie.extratrees.carpentry;
import binnie.core.block.BlockMetadata;
import binnie.core.block.IMultipassBlock;
import binnie.core.block.TileEntityMetadata;
import binnie.core.util.TileUtil;
import binnie.extratrees.api.CarpentryManager;
import binnie.extratrees.api.IDesign;
import binnie.extratrees.api.IDesignSystem;
@@ -45,10 +46,12 @@ public abstract class BlockDesign extends BlockMetadata implements IMultipassBlo
return;
}
final DesignBlock block = blockC.getCarpentryBlock(world, pos);
final TileEntityMetadata tile = (TileEntityMetadata) world.getTileEntity(pos);
//block.rotate(event.getFace(), item, player, world, pos);
final int meta = block.getBlockMetadata(blockC.getDesignSystem());
tile.setTileMetadata(meta, true);
final TileEntityMetadata tile = TileUtil.getTile(world, pos, TileEntityMetadata.class);
if (tile != null) {
//block.rotate(event.getFace(), item, player, world, pos);
final int meta = block.getBlockMetadata(blockC.getDesignSystem());
tile.setTileMetadata(meta, true);
}
}
public BlockDesign(final IDesignSystem system, final Material material) {
@@ -25,6 +25,7 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -71,16 +72,13 @@ public class Brewery {
return null;
}
@Nullable
public static FluidStack getOutput(final BreweryCrafting crafting) {
if (crafting.currentInput == null) {
return null;
}
if (crafting.yeast == null) {
return null;
}
for (final IBreweryRecipe recipe : Brewery.recipes) {
if (recipe.getOutput(crafting) != null) {
return recipe.getOutput(crafting);
if (crafting.currentInput != null && crafting.yeast != null) {
for (final IBreweryRecipe recipe : Brewery.recipes) {
if (recipe.getOutput(crafting) != null) {
return recipe.getOutput(crafting);
}
}
}
return null;
@@ -275,9 +273,12 @@ public class Brewery {
@Override
protected void onFinishTask() {
final FluidStack output = Brewery.getOutput(this.currentCrafting).copy();
output.amount = 1000;
this.getUtil().fillTank(Brewery.tankOutput, output);
FluidStack output = Brewery.getOutput(this.currentCrafting);
if (output != null) {
output = output.copy();
output.amount = 1000;
this.getUtil().fillTank(Brewery.tankOutput, output);
}
}
@Override
@@ -317,7 +318,11 @@ public class Brewery {
if (this.currentCrafting == null) {
return "Empty";
}
return "Creating " + Brewery.getOutput(this.currentCrafting).getFluid().getLocalizedName(Brewery.getOutput(this.currentCrafting));
FluidStack output = Brewery.getOutput(this.currentCrafting);
if (output == null) {
return "Empty";
}
return "Creating " + output.getFluid().getLocalizedName(output);
}
}
@@ -44,7 +44,7 @@ public abstract class AnalystPageProduce extends ControlAnalystPage {
final List<ItemStack> products = new ArrayList<>();
for (final ICentrifugeRecipe recipe : RecipeManagers.centrifugeManager.recipes()) {
boolean isRecipe = false;
if (recipe.getInput() instanceof ItemStack && stack.isItemEqual((ItemStack) recipe.getInput())) {
if (recipe.getInput() != null && stack.isItemEqual(recipe.getInput())) {
isRecipe = true;
}
if (isRecipe) {
@@ -68,8 +68,8 @@ public abstract class AnalystPageProduce extends ControlAnalystPage {
}
}
if (isRecipe) {
if (recipe.getRemnants() instanceof ItemStack) {
products.add((ItemStack) recipe.getRemnants());
if (recipe.getRemnants() != null) {
products.add(recipe.getRemnants());
}
}
}
@@ -139,7 +139,7 @@ public abstract class AnalystPageProduce extends ControlAnalystPage {
}
}
if (isRecipe) {
if (recipe.getFluidOutput() instanceof FluidStack) {
if (recipe.getFluidOutput() != null) {
products.add(recipe.getFluidOutput());
}
}
@@ -27,6 +27,7 @@ import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import javax.annotation.Nullable;
import java.util.*;
public class Acclimatiser {
@@ -35,17 +36,17 @@ public class Acclimatiser {
public static final int[] slotAcclimatiser;
public static final int[] slotDone;
private static List<ToleranceSystem> toleranceSystems;
static Map<ItemStack, Float> temperatureItems;
static Map<ItemStack, Float> humidityItems;
private static Map<ItemStack, Float> temperatureItems;
private static Map<ItemStack, Float> humidityItems;
@Nullable
private static ToleranceSystem getToleranceSystem(final ItemStack stack, final ItemStack acclim) {
final ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(stack);
if (root == null) {
return null;
}
for (final ToleranceSystem system : Acclimatiser.toleranceSystems) {
if (root.getUID() == system.uid && system.type.hasEffect(acclim)) {
return system;
if (root != null) {
for (final ToleranceSystem system : Acclimatiser.toleranceSystems) {
if (Objects.equals(root.getUID(), system.uid) && system.type.hasEffect(acclim)) {
return system;
}
}
}
return null;
@@ -135,6 +136,9 @@ public class Acclimatiser {
public static ItemStack acclimatise(final ItemStack stack, final ItemStack acc) {
final ToleranceSystem system = getToleranceSystem(stack, acc);
if (system == null) {
return stack;
}
return system.alter(stack, acc);
}
@@ -201,7 +201,7 @@ public class Analyser {
public ComponentAnalyserFX(final IMachine machine) {
super(machine);
this.dummyEntityItem = new EntityItem((World) null);
this.dummyEntityItem = new EntityItem(machine.getWorld());
}
@SideOnly(Side.CLIENT)
@@ -53,8 +53,9 @@ public abstract class ComponentIndexerInventory<T> extends ComponentInventory im
@Override
public ItemStack decrStackSize(final int index, final int amount) {
if (index >= 0) {
final ItemStack returnStack = this.getStackInSlot(index).copy();
ItemStack stackInSlot = this.getStackInSlot(index);
if (stackInSlot != null) {
final ItemStack returnStack = stackInSlot.copy();
this.setInventorySlotContents(index, null);
return returnStack;
}