add slightly hacky way of showing planned assembly table recipes
This commit is contained in:
parent
0997e97604
commit
3cdb0342ec
2 changed files with 56 additions and 4 deletions
|
@ -8,9 +8,12 @@
|
|||
*/
|
||||
package buildcraft.silicon;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import buildcraft.api.recipes.IFlexibleRecipeViewable;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
@ -40,6 +43,7 @@ import buildcraft.core.recipes.AssemblyRecipeManager;
|
|||
public class TileAssemblyTable extends TileLaserTableBase implements IInventory, IFlexibleCrafter, ICommandReceiver {
|
||||
public String currentRecipeId = "";
|
||||
public IFlexibleRecipe<ItemStack> currentRecipe;
|
||||
public HashMap<String, CraftingResult<ItemStack>> plannedOutputIcons = new HashMap<String, CraftingResult<ItemStack>>();
|
||||
private HashSet<String> plannedOutput = new HashSet<String>();
|
||||
private boolean queuedNetworkUpdate = false;
|
||||
|
||||
|
@ -153,9 +157,37 @@ public class TileAssemblyTable extends TileLaserTableBase implements IInventory,
|
|||
plannedOutput.add(NetworkUtils.readUTF(stream));
|
||||
}
|
||||
|
||||
// Update plannedOutputIcons
|
||||
generatePlannedOutputIcons();
|
||||
|
||||
currentRecipe = AssemblyRecipeManager.INSTANCE.getRecipe(currentRecipeId);
|
||||
}
|
||||
|
||||
private void generatePlannedOutputIcons() {
|
||||
for (String s : plannedOutput) {
|
||||
IFlexibleRecipe<ItemStack> recipe = AssemblyRecipeManager.INSTANCE.getRecipe(s);
|
||||
CraftingResult<ItemStack> result = recipe.craft(this, true);
|
||||
if (result != null && result.usedItems != null && result.usedItems.size() > 0) {
|
||||
plannedOutputIcons.put(s, result);
|
||||
} else if (recipe instanceof IFlexibleRecipeViewable) {
|
||||
// !! HACK !! TODO !! HACK !!
|
||||
Object out = ((IFlexibleRecipeViewable) recipe).getOutput();
|
||||
if (out instanceof ItemStack) {
|
||||
result = new CraftingResult<ItemStack>();
|
||||
result.crafted = (ItemStack) out;
|
||||
result.recipe = recipe;
|
||||
plannedOutputIcons.put(s, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String s : plannedOutputIcons.keySet().toArray(new String[plannedOutputIcons.size()])) {
|
||||
if (!(plannedOutput.contains(s))) {
|
||||
plannedOutputIcons.remove(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(ByteBuf stream) {
|
||||
super.writeData(stream);
|
||||
|
@ -226,6 +258,9 @@ public class TileAssemblyTable extends TileLaserTableBase implements IInventory,
|
|||
currentRecipeId = "";
|
||||
}
|
||||
|
||||
// Update plannedOutputIcons
|
||||
generatePlannedOutputIcons();
|
||||
|
||||
if (worldObj != null && !worldObj.isRemote) {
|
||||
queueNetworkUpdate();
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
*/
|
||||
package buildcraft.silicon.gui;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
|
@ -72,6 +72,7 @@ public class GuiAssemblyTable extends GuiAdvancedInterface {
|
|||
|
||||
class RecipeSlot extends AdvancedSlot {
|
||||
public CraftingResult<ItemStack> crafting;
|
||||
public boolean craftable;
|
||||
|
||||
public RecipeSlot(int x, int y) {
|
||||
super(GuiAssemblyTable.this, x, y);
|
||||
|
@ -104,14 +105,28 @@ public class GuiAssemblyTable extends GuiAdvancedInterface {
|
|||
}
|
||||
|
||||
public void updateRecipes() {
|
||||
Set<String> addedRecipes = new HashSet<String>();
|
||||
List<CraftingResult<ItemStack>> potentialRecipes = table.getPotentialOutputs();
|
||||
Iterator<CraftingResult<ItemStack>> cur = potentialRecipes.iterator();
|
||||
Collection<String> plannedIcons = table.plannedOutputIcons.keySet();
|
||||
Iterator<String> cur2 = plannedIcons.iterator();
|
||||
|
||||
for (AdvancedSlot s : slots) {
|
||||
if (cur.hasNext()) {
|
||||
((RecipeSlot) s).crafting = cur.next();
|
||||
((RecipeSlot) s).craftable = true;
|
||||
addedRecipes.add(((RecipeSlot) s).crafting.recipe.getId());
|
||||
} else {
|
||||
((RecipeSlot) s).crafting = null;
|
||||
String recipe = null;
|
||||
while (cur2.hasNext() && (recipe == null || addedRecipes.contains(recipe))) {
|
||||
recipe = cur2.next();
|
||||
}
|
||||
if (recipe != null && !addedRecipes.contains(recipe)) {
|
||||
((RecipeSlot) s).crafting = table.plannedOutputIcons.get(recipe);
|
||||
((RecipeSlot) s).craftable = false;
|
||||
} else {
|
||||
((RecipeSlot) s).crafting = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +152,9 @@ public class GuiAssemblyTable extends GuiAdvancedInterface {
|
|||
RecipeSlot slot = (RecipeSlot) slot2;
|
||||
|
||||
if (slot.crafting != null) {
|
||||
if (table.isAssembling(slot.crafting.recipe)) {
|
||||
if (!slot.craftable) {
|
||||
drawTexturedModalRect(guiLeft + slot.x, guiTop + slot.y, 215, 1, 16, 16);
|
||||
} else if (table.isAssembling(slot.crafting.recipe)) {
|
||||
drawTexturedModalRect(guiLeft + slot.x, guiTop + slot.y, 196, 1, 16, 16);
|
||||
} else if (table.isPlanned(slot.crafting.recipe)) {
|
||||
drawTexturedModalRect(guiLeft + slot.x, guiTop + slot.y, 177, 1, 16, 16);
|
||||
|
|
Loading…
Reference in a new issue