Skip to content

Commit

Permalink
Merge pull request #468 from hilburn/master
Browse files Browse the repository at this point in the history
A load of null checking for keys
  • Loading branch information
jakimfett committed Nov 19, 2014
2 parents 376e9d0 + d76e478 commit e104173
Show file tree
Hide file tree
Showing 22 changed files with 72 additions and 131 deletions.
6 changes: 1 addition & 5 deletions src/main/java/minechem/MinechemRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -3140,11 +3140,7 @@ public boolean shouldCreateSynthesis(ItemStack item)
public boolean shouldCreateSynthesis(ItemBlock block)
{
// check if the block is an oreBlock
if (block.field_150939_a instanceof BlockOre)
{
return false;
}
return true;
return !(block.field_150939_a instanceof BlockOre);
}

private ArrayList<OreDictionaryHandler> oreDictionaryHandlers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ public String[] getDetails() {
}

protected boolean addStackToKnown(ItemStack add) {
MapKey addString = DecomposerRecipe.getKey(add);
MapKey addString = MapKey.getKey(add);
for (MapKey key:known)
{
if (key.equals(addString)) return false;
Expand All @@ -847,7 +847,7 @@ private ArrayList<MapKey> stackListToKeys(List<ItemStack> stacks)
ArrayList<MapKey> result = new ArrayList<MapKey>();
for (ItemStack stack:stacks)
if (stack!=null)
result.add(DecomposerRecipe.getKey(stack));
result.add(MapKey.getKey(stack));
return result;
}

Expand Down Expand Up @@ -925,8 +925,7 @@ private ItemStack getJournal(int slot)

private boolean validateInteger(Integer input, int max)
{
if (input==null) return false;
if (input>=max) return false;
if (input==null || input>=max) return false;
return true;
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/minechem/container/ContainerWithFakeSlots.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ private void addStackToSlot(ItemStack stackOnMouse, Slot slot, int amount)
ItemStack stackInSlot = slot.inventory.getStackInSlot(slot.slotNumber);
if (stackInSlot != null)
{
int newStackSize = Math.min(stackInSlot.stackSize + amount, slot.inventory.getInventoryStackLimit());
stackInSlot.stackSize = newStackSize;
stackInSlot.stackSize = Math.min(stackInSlot.stackSize + amount, slot.inventory.getInventoryStackLimit());
} else
{
ItemStack copyStack = stackOnMouse.copy();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/minechem/gui/GuiContainerTabbed.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class GuiContainerTabbed extends GuiMinechemContainer implements

protected static enum SlotColor
{
BLUE, RED, YELLOW, ORANGE, GREEN, PURPLE;
BLUE, RED, YELLOW, ORANGE, GREEN, PURPLE
}

protected static enum SlotType
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/minechem/item/molecule/Molecule.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public PotionChemical copy()
return new Molecule(molecule, amount);
}

;

public Molecule(MoleculeEnum molecule)
{
super(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ public String[] parseOreName(String oreName)
@Override
public boolean canHandle(String oreName)
{
if (this.parseOreName(oreName) != null)
{
return true;
}
return false;
return this.parseOreName(oreName) != null;
}

@Override
Expand Down Expand Up @@ -161,11 +157,7 @@ private PotionChemical[] scaleFloor(PotionChemical[] composition, double factor)

private boolean haveSeen(OreDictionaryBaseOreEnum ore, EnumOrePrefix prefix)
{
if (this.seenOres.containsKey(ore) && this.seenOres.get(ore).contains(prefix))
{
return true;
}
return false;
return this.seenOres.containsKey(ore) && this.seenOres.get(ore).contains(prefix);
}

private void seen(OreDictionaryBaseOreEnum ore, EnumOrePrefix prefix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ public class OreDictionaryMineFactoryReloadedHandler implements
@Override
public boolean canHandle(String oreName)
{
if (oreName.equals("itemRawRubber") || oreName.equals("itemRubber") || oreName.equals("fertilizerOrganic"))
{
return true;
} else
{
return false;
}
return oreName.equals("itemRawRubber") || oreName.equals("itemRubber") || oreName.equals("fertilizerOrganic");
}

@Override
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/minechem/potion/PotionMineral.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public PotionChemical copy()
return new PotionMineral(mineral, amount);
}

;

public PotionMineral(PotionMineralEnum mineral)
{
super(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer e
private ItemStack takeBlueprintFromProjector(BlueprintProjectorTileEntity projector)
{
MinechemBlueprint blueprint = projector.takeBlueprint();
ItemStack blueprintItem = ItemBlueprint.createItemStackFromBlueprint(blueprint);
return blueprintItem;
return ItemBlueprint.createItemStackFromBlueprint(blueprint);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3)
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

this.mc.renderEngine.bindTexture(Resources.Gui.PROJECTOR);
;

int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
Expand Down
41 changes: 11 additions & 30 deletions src/main/java/minechem/tileentity/decomposer/DecomposerRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,14 @@ public static DecomposerRecipe add(DecomposerRecipe recipe)
{
return null;
}
recipes.put(getKey(recipe.input), recipe);
recipes.put(MapKey.getKey(recipe.input), recipe);
} else if (recipe instanceof DecomposerFluidRecipe && ((DecomposerFluidRecipe) recipe).inputFluid != null)
{
recipes.put(getKey(((DecomposerFluidRecipe) recipe).inputFluid), recipe);
recipes.put(MapKey.getKey(((DecomposerFluidRecipe) recipe).inputFluid), recipe);
}
return recipe;
}

public static DecomposerRecipe get(String string)
{
return recipes.get(string);
}

public static DecomposerRecipe remove(String string)
{
if (recipes.containsKey(string))
Expand All @@ -53,9 +48,10 @@ public static DecomposerRecipe remove(String string)

public static DecomposerRecipe remove(ItemStack itemStack)
{
if (recipes.containsKey(getKey(itemStack)))
MapKey key = MapKey.getKey(itemStack);
if (key!=null&&recipes.containsKey(key))
{
return recipes.remove(getKey(itemStack));
return recipes.remove(key);
}
return null;
}
Expand All @@ -65,24 +61,16 @@ public static DecomposerRecipe remove(MapKey key)
return recipes.remove(key);
}

public static MapKey getKey(ItemStack itemStack)
{
return new MapKey(itemStack);
}

public static MapKey getKey(FluidStack fluidStack)
public static DecomposerRecipe get(ItemStack itemStack)
{
return new MapKey(fluidStack);
if (itemStack==null || itemStack.getItem()==null) return null;
return get(MapKey.getKey(itemStack));
}

public static DecomposerRecipe get(ItemStack item)
public static DecomposerRecipe get(FluidStack fluidStack)
{
return get(getKey(item));
}

public static DecomposerRecipe get(FluidStack item)
{
return get(getKey(item));
if (fluidStack==null) return null;
return get(MapKey.getKey(fluidStack));
}

public static DecomposerRecipe get(MapKey key)
Expand Down Expand Up @@ -157,13 +145,6 @@ public ArrayList<PotionChemical> getOutput()
return result;
}

public static PotionChemical getPotionKey(PotionChemical potion)
{
PotionChemical key = potion.copy();
key.amount = 1;
return key;
}

public ArrayList<PotionChemical> getOutputRaw()
{
ArrayList<PotionChemical> result = new ArrayList<PotionChemical>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public ArrayList<ItemStack> getRecipeOutputForInput(ItemStack input)
DecomposerRecipe recipe = getRecipe(input);
if (recipe != null)
{
ArrayList<ItemStack> stacks = MinechemUtil.convertChemicalsIntoItemStacks(recipe.getOutput());
return stacks;
return MinechemUtil.convertChemicalsIntoItemStacks(recipe.getOutput());
}
return null;
}
Expand All @@ -76,9 +75,7 @@ public ArrayList<ItemStack> getRecipeOutputForFluidInput(FluidStack input)
DecomposerFluidRecipe fluidRecipe = (DecomposerFluidRecipe) DecomposerRecipe.get(input);
if (fluidRecipe != null)
{

ArrayList<ItemStack> stacks = MinechemUtil.convertChemicalsIntoItemStacks(fluidRecipe.getOutput());
return stacks;
return MinechemUtil.convertChemicalsIntoItemStacks(fluidRecipe.getOutput());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ public DecomposerRecipeSuper(ItemStack input, ItemStack[] components, int level)

private void addDecompRecipe(DecomposerRecipe decompRecipe, double d)
{
MapKey key = DecomposerRecipe.getKey(decompRecipe.input);
Double current = recipes.put(key, d);
if (current != null)
{
recipes.put(key, d + current);
MapKey key = MapKey.getKey(decompRecipe.input);
if (key!=null) {
Double current = recipes.put(key, d);
if (current != null) {
recipes.put(key, d + current);
}
}
}

Expand Down Expand Up @@ -146,11 +147,7 @@ public ArrayList<PotionChemical> getGuaranteedOutput()
@Override
public boolean isNull()
{
if (super.getOutput() == null && this.recipes == null)
{
return true;
}
return false;
return (super.getOutput() == null || this.recipes == null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,7 @@ else if (tank != null)

private boolean energyToDecompose()
{
if (this.getEnergyStored() >= Settings.costDecomposition || !Settings.powerUseEnabled)
{
return true;
}
return false;
return this.getEnergyStored() >= Settings.costDecomposition || !Settings.powerUseEnabled;
}

@Override
Expand Down Expand Up @@ -210,8 +206,7 @@ public boolean canInsertItem(int i, ItemStack itemstack, int j)
return false;
} else
{
boolean hasRecipe = DecomposerRecipeHandler.instance.getRecipe(itemstack) != null;
return hasRecipe;
return DecomposerRecipeHandler.instance.getRecipe(itemstack) != null;
}
}

Expand Down
14 changes: 2 additions & 12 deletions src/main/java/minechem/tileentity/prefab/TileEntityProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,25 +235,15 @@ public int[] getAccessibleSlotsFromSide(int var1)
public boolean canInsertItem(int slot, ItemStack itemstack, int side)
{
// Cannot insert items into reactor with automation disabled.
if (Settings.AllowAutomation && isItemValidForSlot(slot, itemstack))
{
return true;
} else
{
return false;
}
return Settings.AllowAutomation && isItemValidForSlot(slot, itemstack);
}

@Override
public boolean canExtractItem(int slot, ItemStack itemstack, int side)
{
// Cannot extract items from reactor with automation disabled.
// Can only extract from the bottom.
if (Settings.AllowAutomation && side == 0 && slot == 2)
{
return true;
}
return false;
return Settings.AllowAutomation && side == 0 && slot == 2;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ private void armVertical(float timer, float start, float end, float yStart, floa
{
float time = end - start;
float verticalTimer = timer - start;
float newY = MinechemUtil.translateValue(verticalTimer, 0.0F, time, yStart, yEnd);
bottomarm.rotationPointY = newY;
bottomarm.rotationPointY = MinechemUtil.translateValue(verticalTimer, 0.0F, time, yStart, yEnd);
}
}

Expand Down
14 changes: 4 additions & 10 deletions src/main/java/minechem/tileentity/synthesis/SynthesisRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import minechem.Settings;
import minechem.potion.PotionChemical;
import minechem.utils.LogHelper;
import minechem.utils.MapKey;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;

Expand All @@ -30,7 +28,8 @@ public static SynthesisRecipe add(SynthesisRecipe recipe)
{
return null;
}
recipes.put(new MapKey(recipe.output), recipe);
MapKey key = MapKey.getKey(recipe.output);
if (key!=null) recipes.put(key, recipe);
}

return recipe;
Expand All @@ -50,7 +49,7 @@ public static void remove(ItemStack itemStack)

for (SynthesisRecipe recipe : recipes)
{
SynthesisRecipe.recipes.remove(getKey(recipe.output));
SynthesisRecipe.recipes.remove(MapKey.getKey(recipe.output));
}
}

Expand Down Expand Up @@ -87,11 +86,6 @@ public static ArrayList<SynthesisRecipe> search(ItemStack itemStack)

}

public static MapKey getKey(ItemStack itemStack)
{
return new MapKey(itemStack);
}

public SynthesisRecipe(ItemStack output, boolean isShaped, int energyCost, PotionChemical... recipe)
{
this.output = output;
Expand Down Expand Up @@ -138,7 +132,7 @@ public PotionChemical[] getShapedRecipe()

public PotionChemical[] getShapelessRecipe()
{
return this.unshapedRecipe.toArray(new PotionChemical[0]);
return this.unshapedRecipe.toArray(new PotionChemical[unshapedRecipe.size()]);
}

public int getIngredientCount()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import minechem.potion.PotionChemical;
import minechem.utils.Compare;
import minechem.utils.MapKey;
import minechem.utils.MinechemUtil;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
Expand All @@ -21,7 +22,9 @@ public SynthesisRecipeHandler()

public SynthesisRecipe getRecipeFromOutput(ItemStack output)
{
return SynthesisRecipe.recipes.get(SynthesisRecipe.getKey(output));
MapKey key = MapKey.getKey(output);
if (key==null) return null;
return SynthesisRecipe.recipes.get(key);
}

public SynthesisRecipe getRecipeFromInput(ItemStack[] input)
Expand Down
Loading

0 comments on commit e104173

Please sign in to comment.