package com.yolp900.itsjustacharm.common.integration.jei.constructionTable;
import com.yolp900.itsjustacharm.common.integration.jei.IJCPlugin;
import com.yolp900.itsjustacharm.reference.LibModIntegrations;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.recipe.BlankRecipeWrapper;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class RecipeWrapperConstructionTable extends BlankRecipeWrapper {
private ItemStack output;
private List<Object> inputs;
private boolean shapeless;
private final IDrawable shapelessIcon = IJCPlugin.jeiHelpers.getGuiHelper().createDrawable(LibModIntegrations.JEI.Recipes.ConstructionTable.getGui(), 0, 98, 19, 15);
public RecipeWrapperConstructionTable(@Nonnull ItemStack output, Object[] gridInputs, Object[] secInputs, boolean shapeless) {
this.output = output;
this.shapeless = shapeless;
List<Object> inputs = new ArrayList<Object>();
for (int i = 0; i < 9; i++) {
if (i < gridInputs.length) {
if (gridInputs[i] == null) {
inputs.add(null);
} else if (gridInputs[i] instanceof ItemStack) {
inputs.add(gridInputs[i]);
} else if (gridInputs[i] instanceof Item) {
inputs.add(new ItemStack((Item)gridInputs[i]));
} else if (gridInputs[i] instanceof Block) {
inputs.add(new ItemStack((Block)gridInputs[i]));
} else if (gridInputs[i] instanceof String) {
inputs.add(gridInputs[i]);
}
} else {
inputs.add(null);
}
}
for (int i = 0; i < 8; i++) {
if (i < secInputs.length) {
if (secInputs[i] == null) {
inputs.add(null);
} else if (secInputs[i] instanceof ItemStack) {
inputs.add(secInputs[i]);
} else if (secInputs[i] instanceof Item) {
inputs.add(new ItemStack((Item)secInputs[i]));
} else if (secInputs[i] instanceof Block) {
inputs.add(new ItemStack((Block)secInputs[i]));
} else if (secInputs[i] instanceof String) {
inputs.add(secInputs[i]);
}
} else {
inputs.add(null);
}
}
this.inputs = inputs;
}
@Override
@Nonnull
public List getInputs() {
return this.inputs;
}
@Override
@Nonnull
public List getOutputs() {
return Collections.singletonList(this.output);
}
@Override
public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) {
super.drawInfo(minecraft, recipeWidth, recipeHeight, mouseX, mouseY);
if (this.shapeless) {
GlStateManager.pushMatrix();
GlStateManager.scale(0.5, 0.5, 0.5);
GlStateManager.color(1f, 1f, 1f, 1f);
shapelessIcon.draw(minecraft, 204, 127);
GlStateManager.popMatrix();
}
}
@Nullable
@Override
public List<String> getTooltipStrings(int mouseX, int mouseY) {
if (shapeless && mouseX > 100 && mouseX < (102 + (shapelessIcon.getWidth() / 2)) && mouseY > 65 && mouseY < (65 + (shapelessIcon.getHeight() / 2))) {
return Collections.singletonList(LibModIntegrations.JEI.Tooltips.ShapelessGrid.getTooltip());
}
return super.getTooltipStrings(mouseX, mouseY);
}
}