93 lines
2.3 KiB
Java
93 lines
2.3 KiB
Java
package projectzombie.menu;
|
|
|
|
import gl_engine.matrix.Matrix4;
|
|
import gl_engine.vec.Vec2d;
|
|
import projectzombie.Main;
|
|
import projectzombie.init.Items;
|
|
import projectzombie.init.Models;
|
|
import projectzombie.init.Recipies;
|
|
import projectzombie.inventory.Crafting;
|
|
import projectzombie.inventory.Inventory;
|
|
import projectzombie.inventory.recipe.Recipe;
|
|
import projectzombie.menu.gui.GUIContainerSlider;
|
|
import projectzombie.menu.gui.GUIItemSlot;
|
|
import projectzombie.menu.gui.GUIItemSlotGetter;
|
|
import projectzombie.util.math.ItemStack;
|
|
|
|
public class MenuInventoryBasic extends MenuInventory
|
|
{
|
|
private GUIContainerSlider slider;
|
|
private Inventory inventory;
|
|
private Crafting tool;
|
|
|
|
public MenuInventoryBasic(Menu parent, Crafting tool) {
|
|
super(parent);
|
|
|
|
this.tool = tool;
|
|
|
|
Recipe[] recipies = Recipies.getCraftableRecipies(tool);
|
|
inventory = Main.player.getInventory();
|
|
|
|
slider = new GUIContainerSlider(new Vec2d(
|
|
Models.UI_INVENTORY.getWidth() * 21 / 256.0,
|
|
-Models.UI_INVENTORY.getHeight() * 127 / 256.0), new Vec2d(
|
|
Models.UI_INVENTORY.getWidth() * 234 / 256.0,
|
|
Models.UI_INVENTORY.getHeight() * 254 / 256.0), 100);
|
|
|
|
for(int i=0;i<recipies.length;i++)
|
|
{
|
|
Recipe recipe = recipies[i];
|
|
|
|
GUIItemSlot slot = new GUIItemSlot(1.5, true, new GUIItemSlotGetter()
|
|
{
|
|
@Override
|
|
public void setItemStack(ItemStack stack) {
|
|
}
|
|
|
|
@Override
|
|
public boolean isAllowed(ItemStack stack) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getItemStack() {
|
|
return (recipe.canCraft(tool) &&
|
|
recipe.hasResourcesToCraft(inventory)) ?
|
|
recipe.getResult().copy() :
|
|
ItemStack.getEmpty();
|
|
}
|
|
|
|
@Override
|
|
public boolean mustTakeAll() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void onRemoveItemStack() {
|
|
if(recipe.canCraft(tool) && recipe.hasResourcesToCraft(inventory)) {
|
|
recipe.craftResult(inventory);
|
|
}
|
|
}
|
|
});
|
|
|
|
slot.setPos(new Vec2d(4, i*1.5));
|
|
|
|
slider.add(slot);
|
|
}
|
|
|
|
gui.add(slider);
|
|
}
|
|
|
|
@Override
|
|
public void render()
|
|
{
|
|
Matrix4 matrix = Matrix4.translate(0, -Models.UI_INVENTORY.getHeight() / 2, 0);
|
|
|
|
// Render the inventory gui
|
|
Models.UI_SELECTION_BOX_BIG.setModel(matrix);
|
|
Models.UI_SELECTION_BOX_BIG.render();
|
|
|
|
super.render();
|
|
}
|
|
}
|