}
//If the number is within the bounds of the list
if(blueprintNumber < DriveableType.types.size())
{
//Draw the driveable item
DriveableType type = DriveableType.types.get(blueprintNumber);
drawSlotInventory(new ItemStack(type.item), guiOriginX + 8 + n * 18, guiOriginY + 18 + m * 18);
}
}
}
//Increment the spinner to spin the driveable. Wheeee!
spinner++;
//Return if the selectedBlueprint is invalid
if(selectedBlueprint >= DriveableType.types.size())
{
return;
}
//Make this true and then set it back to false as soon as a problem occurs in finding the required parts
canCraft = true;
//Get the currently selected driveable type and check its not null
DriveableType selectedType = DriveableType.types.get(selectedBlueprint);
if(selectedType != null)
{
//Render rotating driveable model
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glTranslatef(w / 2 - 46, h /2 - 10, 100);
if(selectedType instanceof MechaType)
GL11.glTranslatef(0, 15, 0);
GL11.glScalef(-50F * selectedType.modelScale / selectedType.cameraDistance, 50F * selectedType.modelScale / selectedType.cameraDistance, 50F * selectedType.modelScale / selectedType.cameraDistance);
GL11.glRotatef(180F, 0F, 0F, 1F);
GL11.glRotatef(30F, 1F, 0F, 0F);
GL11.glRotatef(spinner / 5F, 0F, 1F, 0F);
mc.renderEngine.bindTexture(FlansModResourceHandler.getTexture(selectedType));
selectedType.model.render(selectedType);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glPopMatrix();
recipeName = selectedType.name;
if (recipeName.length() > 16)
recipeName = recipeName.substring(0, 15) + "...";
//Render the info text alongside the driveable
drawString(fontRendererObj, recipeName , guiOriginX + 82, guiOriginY + 64, 0xffffff);
drawString(fontRendererObj, "Cargo Slots : " + selectedType.numCargoSlots, guiOriginX + 82, guiOriginY + 74, 0xffffff);
drawString(fontRendererObj, "Bomb Slots : " + selectedType.numBombSlots, guiOriginX + 82, guiOriginY + 84, 0xffffff);
drawString(fontRendererObj, "Passengers : " + selectedType.numPassengers, guiOriginX + 82, guiOriginY + 94, 0xffffff);
drawString(fontRendererObj, "Guns : " + (selectedType.ammoSlots()), guiOriginX + 82, guiOriginY + 104, 0xffffff);
drawString(fontRendererObj, selectedType.numEngines() + "x", guiOriginX + 100, guiOriginY + 141, 0xffffff);
//Create a temporary copy of the player inventory in order to work out whether the player has each of the itemstacks required
InventoryPlayer temporaryInventory = new InventoryPlayer(null);
temporaryInventory.copyInventory(inventory);
//Draw the recipe items
//Iterate over rows then columns
for(int r = 0; r < 3; r++)
{
for(int c = 0; c < 4; c++)
{
//Work out what recipe item this is
int recipeItemNumber = recipeScroll * 4 + r * 4 + c;
//If this is actually a valid recipe item
if(recipeItemNumber < selectedType.recipe.size())
{
//Get the itemstack required by the recipe
ItemStack recipeStack = selectedType.recipe.get(recipeItemNumber);
//The total amount of items found that match this recipe stack
int totalAmountFound = 0;
//Iterate over the temporary inventory
for(int n = 0; n < temporaryInventory.getSizeInventory(); n++)
{
//Get the stack in each slot
ItemStack stackInSlot = temporaryInventory.getStackInSlot(n);
//If the stack is what we want
if(stackInSlot != null && stackInSlot.getItem() == recipeStack.getItem() && stackInSlot.getItemDamage() == recipeStack.getItemDamage())
{
//Work out the amount to take from the stack
int amountFound = Math.min(stackInSlot.stackSize, recipeStack.stackSize - totalAmountFound);
//Take it
stackInSlot.stackSize -= amountFound;
//Check for empty stacks
if(stackInSlot.stackSize <= 0)
stackInSlot = null;
//Put the modified stack back in the inventory
temporaryInventory.setInventorySlotContents(n, stackInSlot);
//Increase the amount found counter
totalAmountFound += amountFound;
//If we have enough, stop looking
if(totalAmountFound == recipeStack.stackSize)
break;
}
}
//If we didn't find enough, give the stack a red outline
if(totalAmountFound < recipeStack.stackSize)
{
mc.renderEngine.bindTexture(texture);
drawTexturedModalRect(guiOriginX + 8 + c * 18, guiOriginY + 138 + r * 18, 195, 11, 16, 16);
canCraft = false;
}
//Draw the actual item we want
drawSlotInventory(recipeStack, guiOriginX + 8 + c * 18, guiOriginY + 138 + r * 18);
}
}
}
//Collect up all the engines into neat and tidy stacks so we can find if any of them are big enough and which of those stacks are best
HashMap<PartType, ItemStack> engines = new HashMap<PartType, ItemStack>();
//Find some suitable engines
for(int n = 0; n < temporaryInventory.getSizeInventory(); n++)
{
//Get the stack in each slot
ItemStack stackInSlot = temporaryInventory.getStackInSlot(n);
//Check to see if its a part
if(stackInSlot != null && stackInSlot.getItem() instanceof ItemPart)
{
PartType partType = ((ItemPart)stackInSlot.getItem()).type;
//Check its an engine that we can use
if(partType.category == 2 && partType.worksWith.contains(EnumType.getFromObject(selectedType)))
{
//If we already have engines of this type, add these ones to the stack
if(engines.containsKey(partType))
{
engines.get(partType).stackSize += stackInSlot.stackSize;
}
//Else, make this the first stack
else engines.put(partType, stackInSlot);
}
}
}
//Find the stack of engines that is fastest but which also has enough for this driveable
float bestEngineSpeed = -1F;
ItemStack bestEngineStack = null;
for(PartType part : engines.keySet())
{
//If this engine outperforms the currently selected best one and there are enough of them, swap
if(part.engineSpeed > bestEngineSpeed && engines.get(part).stackSize >= selectedType.numEngines())
{
bestEngineSpeed = part.engineSpeed;
bestEngineStack = engines.get(part);
}
}