A bunch more null check \o/

This commit is contained in:
modmuss50 2016-12-06 18:22:18 +00:00
parent 97e5fcc032
commit 5dff31d937
19 changed files with 33 additions and 29 deletions

View file

@ -13,7 +13,7 @@ public class AchievementTriggerer {
@SubscribeEvent
public void onItemPickedUp(ItemPickupEvent event) {
ItemStack stack = event.pickedUp.getEntityItem();
if (stack != null && stack.getItem() instanceof IPickupAchievement) {
if (stack != ItemStack.EMPTY && stack.getItem() instanceof IPickupAchievement) {
Achievement achievement = ((IPickupAchievement) stack.getItem()).getAchievementOnPickup(stack, event.player,
event.pickedUp);
if (achievement != null)
@ -23,7 +23,7 @@ public class AchievementTriggerer {
@SubscribeEvent
public void onItemCrafted(ItemCraftedEvent event) {
if (event.crafting != null && event.crafting.getItem() instanceof ICraftAchievement) {
if (event.crafting != ItemStack.EMPTY && event.crafting.getItem() instanceof ICraftAchievement) {
Achievement achievement = ((ICraftAchievement) event.crafting.getItem())
.getAchievementOnCraft(event.crafting, event.player, event.craftMatrix);
if (achievement != null)

View file

@ -150,7 +150,7 @@ public class BlockRubberLog extends Block implements ITexturedBlock {
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
if (stack != null)
if (stack != ItemStack.EMPTY)
if ((stack.getItem() instanceof ItemElectricTreetap && PoweredItem.canUseEnergy(20, stack)) || stack.getItem() instanceof ItemTreeTap)
if (state.getValue(HAS_SAP)) {
if (state.getValue(SAP_SIDE) == side) {

View file

@ -116,10 +116,10 @@ public abstract class BlockTransformer extends BaseTileBlock implements IRotatio
for (int i = 0; i < inventory.getSizeInventory(); i++) {
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack == null) {
if (itemStack == ItemStack.EMPTY) {
continue;
}
if (itemStack != null && itemStack.getCount() > 0) {
if (itemStack != ItemStack.EMPTY && itemStack.getCount() > 0) {
if (itemStack.getItem() instanceof ItemBlock) {
if (((ItemBlock) itemStack.getItem()).block instanceof BlockFluidBase
|| ((ItemBlock) itemStack.getItem()).block instanceof BlockStaticLiquid

View file

@ -3,6 +3,7 @@ package techreborn.client.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n;
import techreborn.client.container.ContainerDigitalChest;
@ -38,10 +39,10 @@ public class GuiDigitalChest extends GuiContainer {
this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory", new Object[0]), 8,
this.ySize - 96 + 2, 4210752);
this.fontRendererObj.drawString("Amount", 10, 20, 16448255);
if (tile.storedItem != null && tile.getStackInSlot(1) != null)
if (tile.storedItem != ItemStack.EMPTY && tile.getStackInSlot(1) != null)
this.fontRendererObj.drawString(tile.storedItem.getCount() + tile.getStackInSlot(1).getCount() + "", 10, 30,
16448255);
if (tile.storedItem == null && tile.getStackInSlot(1) != null)
if (tile.storedItem == ItemStack.EMPTY && tile.getStackInSlot(1) != null)
this.fontRendererObj.drawString(tile.getStackInSlot(1).getCount() + "", 10, 30, 16448255);
}
}

View file

@ -3,6 +3,7 @@ package techreborn.client.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n;
import techreborn.client.container.ContainerQuantumChest;
@ -38,10 +39,10 @@ public class GuiQuantumChest extends GuiContainer {
this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory", new Object[0]), 8,
this.ySize - 96 + 2, 4210752);
this.fontRendererObj.drawString("Amount", 10, 20, 16448255);
if (tile.storedItem != null && tile.getStackInSlot(1) != null)
if (tile.storedItem != ItemStack.EMPTY && tile.getStackInSlot(1) != null)
this.fontRendererObj.drawString(tile.storedItem.getCount() + tile.getStackInSlot(1).getCount() + "", 10, 30,
16448255);
if (tile.storedItem == null && tile.getStackInSlot(1) != null)
if (tile.storedItem == ItemStack.EMPTY && tile.getStackInSlot(1) != null)
this.fontRendererObj.drawString(tile.getStackInSlot(1).getCount() + "", 10, 30, 16448255);
}
}

View file

@ -50,7 +50,7 @@ public class ChargeHud {
int y = 5;
if (armorstack != null && ConfigTechReborn.ShowChargeHud
if (armorstack != ItemStack.EMPTY && ConfigTechReborn.ShowChargeHud
&& armorstack.getItem() instanceof IEnergyInterfaceItem) {
double MaxCharge = ((IEnergyInterfaceItem) armorstack.getItem()).getMaxPower(armorstack);
double CurrentCharge = ((IEnergyInterfaceItem) armorstack.getItem()).getEnergy(armorstack);
@ -76,7 +76,7 @@ public class ChargeHud {
}
if (showHud) {
if (offHandstack != null && offHandstack.getItem() instanceof IEnergyInterfaceItem) {
if (offHandstack != ItemStack.EMPTY && offHandstack.getItem() instanceof IEnergyInterfaceItem) {
double MaxCharge = ((IEnergyInterfaceItem) offHandstack.getItem()).getMaxPower(offHandstack);
double CurrentCharge = ((IEnergyInterfaceItem) offHandstack.getItem()).getEnergy(offHandstack);
if (MaxCharge != 0) {
@ -99,7 +99,7 @@ public class ChargeHud {
y += 20;
}
}
if (stack != null && stack.getItem() instanceof IEnergyInterfaceItem) {
if (stack != ItemStack.EMPTY && stack.getItem() instanceof IEnergyInterfaceItem) {
double MaxCharge = ((IEnergyInterfaceItem) stack.getItem()).getMaxPower(stack);
double CurrentCharge = ((IEnergyInterfaceItem) stack.getItem()).getEnergy(stack);
Color color = Color.GREEN;

View file

@ -7,6 +7,7 @@ import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
@ -74,7 +75,7 @@ public class TechRebornDevCommand extends CommandBase {
}
} else if ("getname".equals(args[0])) {
EntityPlayer player = (EntityPlayer) sender;
if (player.getHeldItem(EnumHand.MAIN_HAND) != null) {
if (player.getHeldItem(EnumHand.MAIN_HAND) != ItemStack.EMPTY) {
sender.sendMessage(new TextComponentString(player.getHeldItem(EnumHand.MAIN_HAND).getItem().getRegistryName() + ":" + player.getHeldItem(EnumHand.MAIN_HAND).getItemDamage()));
} else {
sender.sendMessage(new TextComponentString("hold an item!"));

View file

@ -4,6 +4,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@ -18,7 +19,7 @@ public class TRTickHandler {
@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
public void onPlayerTick(TickEvent.PlayerTickEvent e) {
EntityPlayer player = e.player;
Item chestslot = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST) != null
Item chestslot = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST) != ItemStack.EMPTY
? player.getItemStackFromSlot(EntityEquipmentSlot.CHEST).getItem() : null;
if (previouslyWearing != chestslot && previouslyWearing == ModItems.cloakingDevice && player.isInvisible()

View file

@ -29,7 +29,7 @@ public class ItemBlockAesu extends ItemBlock {
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
if (stack != null && stack.hasTagCompound()) {
if (stack != ItemStack.EMPTY && stack.hasTagCompound()) {
if (stack.getTagCompound().getCompoundTag("tileEntity") != null)
list.add(PowerSystem
.getLocaliszedPower(stack.getTagCompound().getCompoundTag("tileEntity").getInteger("energy")));
@ -47,7 +47,7 @@ public class ItemBlockAesu extends ItemBlock {
// world.getBlockState(pos).getBlock().onPostBlockPlaced(world, x,
// y, z, metadata);
}
if (stack != null && stack.hasTagCompound()) {
if (stack != ItemStack.EMPTY && stack.hasTagCompound()) {
((TileAesu) world.getTileEntity(pos))
.readFromNBTWithoutCoords(stack.getTagCompound().getCompoundTag("tileEntity"));
}

View file

@ -24,7 +24,7 @@ public class ItemBlockDigitalChest extends ItemBlock {
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
if (stack != null && stack.hasTagCompound()) {
if (stack != ItemStack.EMPTY && stack.hasTagCompound()) {
if (stack.getTagCompound().getCompoundTag("tileEntity") != null)
list.add(stack.getTagCompound().getCompoundTag("tileEntity").getInteger("storedQuantity") + " items");
}
@ -41,7 +41,7 @@ public class ItemBlockDigitalChest extends ItemBlock {
// world.getBlockState(pos).getBlock().onPostBlockPlaced(world, x,
// y, z, metadata);
}
if (stack != null && stack.hasTagCompound()) {
if (stack != ItemStack.EMPTY && stack.hasTagCompound()) {
((TileDigitalChest) world.getTileEntity(pos))
.readFromNBTWithoutCoords(stack.getTagCompound().getCompoundTag("tileEntity"));
}

View file

@ -24,7 +24,7 @@ public class ItemBlockQuantumChest extends ItemBlock {
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
if (stack != null && stack.hasTagCompound()) {
if (stack != ItemStack.EMPTY && stack.hasTagCompound()) {
if (stack.getTagCompound().getCompoundTag("tileEntity") != null)
list.add(stack.getTagCompound().getCompoundTag("tileEntity").getInteger("storedQuantity") + " items");
}
@ -41,7 +41,7 @@ public class ItemBlockQuantumChest extends ItemBlock {
// world.getBlockState(pos).getBlock().onPostBlockPlaced(world, x,
// y, z, metadata);
}
if (stack != null && stack.hasTagCompound()) {
if (stack != ItemStack.EMPTY && stack.hasTagCompound()) {
((TileQuantumChest) world.getTileEntity(pos))
.readFromNBTWithoutCoords(stack.getTagCompound().getCompoundTag("tileEntity"));
}

View file

@ -27,7 +27,7 @@ public class ItemBlockQuantumTank extends ItemBlock {
// world.getBlockState(pos).getBlock().onPostBlockPlaced(world, x,
// y, z, metadata);
}
if (stack != null && stack.hasTagCompound()) {
if (stack != ItemStack.EMPTY && stack.hasTagCompound()) {
((TileQuantumTank) world.getTileEntity(pos))
.readFromNBTWithoutCoords(stack.getTagCompound().getCompoundTag("tileEntity"));
}

View file

@ -39,7 +39,7 @@ public class ItemBattery extends ItemTRNoDestroy implements IEnergyItemInfo {
World worldIn,
@Nullable
EntityLivingBase entityIn) {
if (stack != null && PoweredItem.getEnergy(stack) == 0.0) {
if (stack != ItemStack.EMPTY && PoweredItem.getEnergy(stack) == 0.0) {
return 1.0F;
}
return 0.0F;

View file

@ -240,7 +240,7 @@ public class CraftingInfoPage extends TitledPage {
continue;
ItemStack result = recipe.getRecipeOutput();
if (result == null || !result.isItemEqual(resultingItem))
if (result == ItemStack.EMPTY || !result.isItemEqual(resultingItem))
continue;
Object[] input = getRecipeInput(recipe);

View file

@ -116,7 +116,7 @@ public class TileIronFurnace extends TileLegacyMachineBase implements IInventory
public ItemStack getResultFor(ItemStack stack) {
ItemStack result = FurnaceRecipes.instance().getSmeltingResult(stack);
if (result != null) {
if (result != ItemStack.EMPTY) {
return result.copy();
}
return null;

View file

@ -130,7 +130,7 @@ public class TileGasTurbine extends TilePowerAcceptor implements IWrenchable, II
if (tank.getFluidType() != null && getStackInSlot(2) == ItemStack.EMPTY) {
inventory.setInventorySlotContents(2, new ItemStack(tank.getFluidType().getBlock()));
} else if (tank.getFluidType() == null && getStackInSlot(2) != ItemStack.EMPTY) {
setInventorySlotContents(2, null);
setInventorySlotContents(2, ItemStack.EMPTY);
}
}

View file

@ -127,7 +127,7 @@ public class TileThermalGenerator extends TilePowerAcceptor implements IWrenchab
// inventory.setInventorySlotContents(2, new ItemStack(tank
// .getFluidType().getBlock()));
} else if (tank.getFluidType() == null && getStackInSlot(2) != ItemStack.EMPTY) {
setInventorySlotContents(2, null);
setInventorySlotContents(2, ItemStack.EMPTY);
}
}

View file

@ -76,7 +76,7 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl
if (getStackInSlot(input1).getCount() > 1) {
this.decrStackSize(input1, 1);
} else {
setInventorySlotContents(input1, null);
setInventorySlotContents(input1, ItemStack.EMPTY);
}
}
}
@ -86,7 +86,7 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl
return false;
} else {
ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1));
if (itemstack == null)
if (itemstack == ItemStack.EMPTY)
return false;
if (getStackInSlot(output) == ItemStack.EMPTY)
return true;

View file

@ -88,7 +88,7 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv
this.decrStackSize(input1, 1);
} else {
useEnergy(cost);
setInventorySlotContents(input1, null);
setInventorySlotContents(input1, ItemStack.EMPTY);
}
}
}