All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mmb.engine.recipe.RecipeList Maven / Gradle / Ivy

Go to download

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<

The newest version!
/**
 * 
 */
package mmb.engine.recipe;

import javax.swing.JScrollPane;
import javax.swing.ListCellRenderer;

import mmb.NN;
import mmb.Nil;

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> list,
						@Nil RecipeEntry value, int index,
				boolean isSelected, boolean cellHasFocus) {
			if(value != null) rv.set(value.recipe);
			return rv;
		} 
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy