Skip to content

Commit e104173

Browse files
committed
Merge pull request #468 from hilburn/master
A load of null checking for keys
2 parents 376e9d0 + d76e478 commit e104173

22 files changed

+72
-131
lines changed

src/main/java/minechem/MinechemRecipes.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -3140,11 +3140,7 @@ public boolean shouldCreateSynthesis(ItemStack item)
31403140
public boolean shouldCreateSynthesis(ItemBlock block)
31413141
{
31423142
// check if the block is an oreBlock
3143-
if (block.field_150939_a instanceof BlockOre)
3144-
{
3145-
return false;
3146-
}
3147-
return true;
3143+
return !(block.field_150939_a instanceof BlockOre);
31483144
}
31493145

31503146
private ArrayList<OreDictionaryHandler> oreDictionaryHandlers;

src/main/java/minechem/computercraft/ChemicalTurtlePeripheral.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ public String[] getDetails() {
832832
}
833833

834834
protected boolean addStackToKnown(ItemStack add) {
835-
MapKey addString = DecomposerRecipe.getKey(add);
835+
MapKey addString = MapKey.getKey(add);
836836
for (MapKey key:known)
837837
{
838838
if (key.equals(addString)) return false;
@@ -847,7 +847,7 @@ private ArrayList<MapKey> stackListToKeys(List<ItemStack> stacks)
847847
ArrayList<MapKey> result = new ArrayList<MapKey>();
848848
for (ItemStack stack:stacks)
849849
if (stack!=null)
850-
result.add(DecomposerRecipe.getKey(stack));
850+
result.add(MapKey.getKey(stack));
851851
return result;
852852
}
853853

@@ -925,8 +925,7 @@ private ItemStack getJournal(int slot)
925925

926926
private boolean validateInteger(Integer input, int max)
927927
{
928-
if (input==null) return false;
929-
if (input>=max) return false;
928+
if (input==null || input>=max) return false;
930929
return true;
931930
}
932931

src/main/java/minechem/container/ContainerWithFakeSlots.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ private void addStackToSlot(ItemStack stackOnMouse, Slot slot, int amount)
7373
ItemStack stackInSlot = slot.inventory.getStackInSlot(slot.slotNumber);
7474
if (stackInSlot != null)
7575
{
76-
int newStackSize = Math.min(stackInSlot.stackSize + amount, slot.inventory.getInventoryStackLimit());
77-
stackInSlot.stackSize = newStackSize;
76+
stackInSlot.stackSize = Math.min(stackInSlot.stackSize + amount, slot.inventory.getInventoryStackLimit());
7877
} else
7978
{
8079
ItemStack copyStack = stackOnMouse.copy();

src/main/java/minechem/gui/GuiContainerTabbed.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public abstract class GuiContainerTabbed extends GuiMinechemContainer implements
2424

2525
protected static enum SlotColor
2626
{
27-
BLUE, RED, YELLOW, ORANGE, GREEN, PURPLE;
27+
BLUE, RED, YELLOW, ORANGE, GREEN, PURPLE
2828
}
2929

3030
protected static enum SlotType

src/main/java/minechem/item/molecule/Molecule.java

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ public PotionChemical copy()
1919
return new Molecule(molecule, amount);
2020
}
2121

22-
;
23-
2422
public Molecule(MoleculeEnum molecule)
2523
{
2624
super(1);

src/main/java/minechem/oredictionary/OreDictionaryDefaultHandler.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ public String[] parseOreName(String oreName)
5757
@Override
5858
public boolean canHandle(String oreName)
5959
{
60-
if (this.parseOreName(oreName) != null)
61-
{
62-
return true;
63-
}
64-
return false;
60+
return this.parseOreName(oreName) != null;
6561
}
6662

6763
@Override
@@ -161,11 +157,7 @@ private PotionChemical[] scaleFloor(PotionChemical[] composition, double factor)
161157

162158
private boolean haveSeen(OreDictionaryBaseOreEnum ore, EnumOrePrefix prefix)
163159
{
164-
if (this.seenOres.containsKey(ore) && this.seenOres.get(ore).contains(prefix))
165-
{
166-
return true;
167-
}
168-
return false;
160+
return this.seenOres.containsKey(ore) && this.seenOres.get(ore).contains(prefix);
169161
}
170162

171163
private void seen(OreDictionaryBaseOreEnum ore, EnumOrePrefix prefix)

src/main/java/minechem/oredictionary/OreDictionaryMineFactoryReloadedHandler.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ public class OreDictionaryMineFactoryReloadedHandler implements
1414
@Override
1515
public boolean canHandle(String oreName)
1616
{
17-
if (oreName.equals("itemRawRubber") || oreName.equals("itemRubber") || oreName.equals("fertilizerOrganic"))
18-
{
19-
return true;
20-
} else
21-
{
22-
return false;
23-
}
17+
return oreName.equals("itemRawRubber") || oreName.equals("itemRubber") || oreName.equals("fertilizerOrganic");
2418
}
2519

2620
@Override

src/main/java/minechem/potion/PotionMineral.java

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ public PotionChemical copy()
1616
return new PotionMineral(mineral, amount);
1717
}
1818

19-
;
20-
2119
public PotionMineral(PotionMineralEnum mineral)
2220
{
2321
super(1);

src/main/java/minechem/tileentity/blueprintprojector/BlueprintProjectorBlock.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer e
5454
private ItemStack takeBlueprintFromProjector(BlueprintProjectorTileEntity projector)
5555
{
5656
MinechemBlueprint blueprint = projector.takeBlueprint();
57-
ItemStack blueprintItem = ItemBlueprint.createItemStackFromBlueprint(blueprint);
58-
return blueprintItem;
57+
return ItemBlueprint.createItemStackFromBlueprint(blueprint);
5958
}
6059

6160
@Override

src/main/java/minechem/tileentity/blueprintprojector/BlueprintProjectorGui.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3)
3333
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
3434

3535
this.mc.renderEngine.bindTexture(Resources.Gui.PROJECTOR);
36-
;
36+
3737
int x = (width - xSize) / 2;
3838
int y = (height - ySize) / 2;
3939
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);

src/main/java/minechem/tileentity/decomposer/DecomposerRecipe.java

+11-30
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,14 @@ public static DecomposerRecipe add(DecomposerRecipe recipe)
2929
{
3030
return null;
3131
}
32-
recipes.put(getKey(recipe.input), recipe);
32+
recipes.put(MapKey.getKey(recipe.input), recipe);
3333
} else if (recipe instanceof DecomposerFluidRecipe && ((DecomposerFluidRecipe) recipe).inputFluid != null)
3434
{
35-
recipes.put(getKey(((DecomposerFluidRecipe) recipe).inputFluid), recipe);
35+
recipes.put(MapKey.getKey(((DecomposerFluidRecipe) recipe).inputFluid), recipe);
3636
}
3737
return recipe;
3838
}
3939

40-
public static DecomposerRecipe get(String string)
41-
{
42-
return recipes.get(string);
43-
}
44-
4540
public static DecomposerRecipe remove(String string)
4641
{
4742
if (recipes.containsKey(string))
@@ -53,9 +48,10 @@ public static DecomposerRecipe remove(String string)
5348

5449
public static DecomposerRecipe remove(ItemStack itemStack)
5550
{
56-
if (recipes.containsKey(getKey(itemStack)))
51+
MapKey key = MapKey.getKey(itemStack);
52+
if (key!=null&&recipes.containsKey(key))
5753
{
58-
return recipes.remove(getKey(itemStack));
54+
return recipes.remove(key);
5955
}
6056
return null;
6157
}
@@ -65,24 +61,16 @@ public static DecomposerRecipe remove(MapKey key)
6561
return recipes.remove(key);
6662
}
6763

68-
public static MapKey getKey(ItemStack itemStack)
69-
{
70-
return new MapKey(itemStack);
71-
}
72-
73-
public static MapKey getKey(FluidStack fluidStack)
64+
public static DecomposerRecipe get(ItemStack itemStack)
7465
{
75-
return new MapKey(fluidStack);
66+
if (itemStack==null || itemStack.getItem()==null) return null;
67+
return get(MapKey.getKey(itemStack));
7668
}
7769

78-
public static DecomposerRecipe get(ItemStack item)
70+
public static DecomposerRecipe get(FluidStack fluidStack)
7971
{
80-
return get(getKey(item));
81-
}
82-
83-
public static DecomposerRecipe get(FluidStack item)
84-
{
85-
return get(getKey(item));
72+
if (fluidStack==null) return null;
73+
return get(MapKey.getKey(fluidStack));
8674
}
8775

8876
public static DecomposerRecipe get(MapKey key)
@@ -157,13 +145,6 @@ public ArrayList<PotionChemical> getOutput()
157145
return result;
158146
}
159147

160-
public static PotionChemical getPotionKey(PotionChemical potion)
161-
{
162-
PotionChemical key = potion.copy();
163-
key.amount = 1;
164-
return key;
165-
}
166-
167148
public ArrayList<PotionChemical> getOutputRaw()
168149
{
169150
ArrayList<PotionChemical> result = new ArrayList<PotionChemical>();

src/main/java/minechem/tileentity/decomposer/DecomposerRecipeHandler.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ public ArrayList<ItemStack> getRecipeOutputForInput(ItemStack input)
6565
DecomposerRecipe recipe = getRecipe(input);
6666
if (recipe != null)
6767
{
68-
ArrayList<ItemStack> stacks = MinechemUtil.convertChemicalsIntoItemStacks(recipe.getOutput());
69-
return stacks;
68+
return MinechemUtil.convertChemicalsIntoItemStacks(recipe.getOutput());
7069
}
7170
return null;
7271
}
@@ -76,9 +75,7 @@ public ArrayList<ItemStack> getRecipeOutputForFluidInput(FluidStack input)
7675
DecomposerFluidRecipe fluidRecipe = (DecomposerFluidRecipe) DecomposerRecipe.get(input);
7776
if (fluidRecipe != null)
7877
{
79-
80-
ArrayList<ItemStack> stacks = MinechemUtil.convertChemicalsIntoItemStacks(fluidRecipe.getOutput());
81-
return stacks;
78+
return MinechemUtil.convertChemicalsIntoItemStacks(fluidRecipe.getOutput());
8279
}
8380
return null;
8481
}

src/main/java/minechem/tileentity/decomposer/DecomposerRecipeSuper.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ public DecomposerRecipeSuper(ItemStack input, ItemStack[] components, int level)
5151

5252
private void addDecompRecipe(DecomposerRecipe decompRecipe, double d)
5353
{
54-
MapKey key = DecomposerRecipe.getKey(decompRecipe.input);
55-
Double current = recipes.put(key, d);
56-
if (current != null)
57-
{
58-
recipes.put(key, d + current);
54+
MapKey key = MapKey.getKey(decompRecipe.input);
55+
if (key!=null) {
56+
Double current = recipes.put(key, d);
57+
if (current != null) {
58+
recipes.put(key, d + current);
59+
}
5960
}
6061
}
6162

@@ -146,11 +147,7 @@ public ArrayList<PotionChemical> getGuaranteedOutput()
146147
@Override
147148
public boolean isNull()
148149
{
149-
if (super.getOutput() == null && this.recipes == null)
150-
{
151-
return true;
152-
}
153-
return false;
150+
return (super.getOutput() == null || this.recipes == null);
154151
}
155152

156153
@Override

src/main/java/minechem/tileentity/decomposer/DecomposerTileEntity.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,7 @@ else if (tank != null)
177177

178178
private boolean energyToDecompose()
179179
{
180-
if (this.getEnergyStored() >= Settings.costDecomposition || !Settings.powerUseEnabled)
181-
{
182-
return true;
183-
}
184-
return false;
180+
return this.getEnergyStored() >= Settings.costDecomposition || !Settings.powerUseEnabled;
185181
}
186182

187183
@Override
@@ -210,8 +206,7 @@ public boolean canInsertItem(int i, ItemStack itemstack, int j)
210206
return false;
211207
} else
212208
{
213-
boolean hasRecipe = DecomposerRecipeHandler.instance.getRecipe(itemstack) != null;
214-
return hasRecipe;
209+
return DecomposerRecipeHandler.instance.getRecipe(itemstack) != null;
215210
}
216211
}
217212

src/main/java/minechem/tileentity/prefab/TileEntityProxy.java

+2-12
Original file line numberDiff line numberDiff line change
@@ -235,25 +235,15 @@ public int[] getAccessibleSlotsFromSide(int var1)
235235
public boolean canInsertItem(int slot, ItemStack itemstack, int side)
236236
{
237237
// Cannot insert items into reactor with automation disabled.
238-
if (Settings.AllowAutomation && isItemValidForSlot(slot, itemstack))
239-
{
240-
return true;
241-
} else
242-
{
243-
return false;
244-
}
238+
return Settings.AllowAutomation && isItemValidForSlot(slot, itemstack);
245239
}
246240

247241
@Override
248242
public boolean canExtractItem(int slot, ItemStack itemstack, int side)
249243
{
250244
// Cannot extract items from reactor with automation disabled.
251245
// Can only extract from the bottom.
252-
if (Settings.AllowAutomation && side == 0 && slot == 2)
253-
{
254-
return true;
255-
}
256-
return false;
246+
return Settings.AllowAutomation && side == 0 && slot == 2;
257247
}
258248

259249
@Override

src/main/java/minechem/tileentity/synthesis/SynthesisModel.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ private void armVertical(float timer, float start, float end, float yStart, floa
172172
{
173173
float time = end - start;
174174
float verticalTimer = timer - start;
175-
float newY = MinechemUtil.translateValue(verticalTimer, 0.0F, time, yStart, yEnd);
176-
bottomarm.rotationPointY = newY;
175+
bottomarm.rotationPointY = MinechemUtil.translateValue(verticalTimer, 0.0F, time, yStart, yEnd);
177176
}
178177
}
179178

src/main/java/minechem/tileentity/synthesis/SynthesisRecipe.java

+4-10
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import minechem.Settings;
44
import minechem.potion.PotionChemical;
5-
import minechem.utils.LogHelper;
65
import minechem.utils.MapKey;
7-
import net.minecraft.item.Item;
86
import net.minecraft.item.ItemStack;
97
import net.minecraftforge.oredict.OreDictionary;
108

@@ -30,7 +28,8 @@ public static SynthesisRecipe add(SynthesisRecipe recipe)
3028
{
3129
return null;
3230
}
33-
recipes.put(new MapKey(recipe.output), recipe);
31+
MapKey key = MapKey.getKey(recipe.output);
32+
if (key!=null) recipes.put(key, recipe);
3433
}
3534

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

5150
for (SynthesisRecipe recipe : recipes)
5251
{
53-
SynthesisRecipe.recipes.remove(getKey(recipe.output));
52+
SynthesisRecipe.recipes.remove(MapKey.getKey(recipe.output));
5453
}
5554
}
5655

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

8887
}
8988

90-
public static MapKey getKey(ItemStack itemStack)
91-
{
92-
return new MapKey(itemStack);
93-
}
94-
9589
public SynthesisRecipe(ItemStack output, boolean isShaped, int energyCost, PotionChemical... recipe)
9690
{
9791
this.output = output;
@@ -138,7 +132,7 @@ public PotionChemical[] getShapedRecipe()
138132

139133
public PotionChemical[] getShapelessRecipe()
140134
{
141-
return this.unshapedRecipe.toArray(new PotionChemical[0]);
135+
return this.unshapedRecipe.toArray(new PotionChemical[unshapedRecipe.size()]);
142136
}
143137

144138
public int getIngredientCount()

src/main/java/minechem/tileentity/synthesis/SynthesisRecipeHandler.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import minechem.potion.PotionChemical;
44
import minechem.utils.Compare;
5+
import minechem.utils.MapKey;
56
import minechem.utils.MinechemUtil;
67
import net.minecraft.inventory.IInventory;
78
import net.minecraft.item.ItemStack;
@@ -21,7 +22,9 @@ public SynthesisRecipeHandler()
2122

2223
public SynthesisRecipe getRecipeFromOutput(ItemStack output)
2324
{
24-
return SynthesisRecipe.recipes.get(SynthesisRecipe.getKey(output));
25+
MapKey key = MapKey.getKey(output);
26+
if (key==null) return null;
27+
return SynthesisRecipe.recipes.get(key);
2528
}
2629

2730
public SynthesisRecipe getRecipeFromInput(ItemStack[] input)

0 commit comments

Comments
 (0)