mmb.menu.world.craft.RecipeList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multimachinebuilder Show documentation
Show all versions of multimachinebuilder Show documentation
Dependency for the MultiMachineBuilder, a voxel game about building an industrial empire in a finite world.
THIS RELEASE IS NOT PLAYABLE. To play the game, donwload from >ITCH.IO LINK HERE< or >GH releases link here<
/**
*
*/
package mmb.menu.world.craft;
import javax.swing.JScrollPane;
import javax.swing.ListCellRenderer;
import mmb.NN;
import mmb.Nil;
import mmb.engine.craft.Recipe;
import mmb.engine.craft.RecipeGroup;
import mmb.engine.inv.ItemStack;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JList;
/**
* Represents a recipe list for almost anything (but not pickaxes)
* @author oskar
* @param type of the recipes
* @param type of the recipe group
*/
public class RecipeList, G extends RecipeGroup> extends JScrollPane {
private static final long serialVersionUID = 828762086772542204L;
private final RecipeView rv;
/**
* Creates a recipe list for almost anything (but not pickaxes)
* @param group recipe group used for this list
* */
public RecipeList(G group) {
rv = group.createView();
JList> list = new JList<>();
@SuppressWarnings("unchecked")
RecipeEntry[] data = new RecipeEntry[group.recipes().size()];
int i = 0;
for(T recipe: group.recipes()) {
data[i] = new RecipeEntry<>(recipe);
i++;
}
list.setListData(data);
list.setCellRenderer(new CellRenderer());
setViewportView(list);
}
static class RecipeEntry>{
@NN public final T recipe;
@NN public final ItemStack[] stack;
public RecipeEntry(T recipe2) {
this.recipe = recipe2;
stack = VectorUtils.list2arr(recipe2.output());
}
}
class CellRenderer implements ListCellRenderer>{
public CellRenderer() {
setPreferredSize(new Dimension(600, 200));
}
@Override
public Component getListCellRendererComponent(
@SuppressWarnings("null") JList extends RecipeEntry> list,
@Nil RecipeEntry value, int index,
boolean isSelected, boolean cellHasFocus) {
if(value != null) rv.set(value.recipe);
return rv;
}
}
}