Show the recipe in the autocrafting gui
This commit is contained in:
parent
0e9c61bd60
commit
a3c4b9f3ed
1 changed files with 59 additions and 4 deletions
|
@ -2,6 +2,7 @@ package techreborn.client.gui.autocrafting;
|
|||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButtonImage;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.RenderItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -11,6 +12,10 @@ import net.minecraft.inventory.InventoryCrafting;
|
|||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import reborncore.common.network.NetworkManager;
|
||||
import techreborn.client.gui.GuiBase;
|
||||
|
@ -19,6 +24,7 @@ import techreborn.packets.PacketSetRecipe;
|
|||
import techreborn.tiles.TileAutoCraftingTable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import static net.minecraft.item.ItemStack.EMPTY;
|
||||
|
||||
|
@ -27,6 +33,7 @@ import static net.minecraft.item.ItemStack.EMPTY;
|
|||
*/
|
||||
public class GuiAutoCrafting extends GuiBase {
|
||||
|
||||
static final ResourceLocation RECIPE_BOOK_TEXTURE = new ResourceLocation("textures/gui/recipe_book.png");
|
||||
GuiAutoCraftingRecipeSlector recipeSlector = new GuiAutoCraftingRecipeSlector();
|
||||
private GuiButtonImage recipeButton;
|
||||
boolean showGui = true;
|
||||
|
@ -61,25 +68,74 @@ public class GuiAutoCrafting extends GuiBase {
|
|||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
IRecipe recipe = tileAutoCraftingTable.getIRecipe();
|
||||
if(recipe != null){
|
||||
if (recipe != null) {
|
||||
renderItemStack(recipe.getRecipeOutput(), 95, 42);
|
||||
|
||||
int x = mouseX -= getGuiLeft();
|
||||
int y = mouseY -= getGuiTop();
|
||||
renderRecipe(recipe, 91, 66);
|
||||
}
|
||||
final Layer layer = Layer.FOREGROUND;
|
||||
this.builder.drawMultiEnergyBar(this, 9, 26, (int) this.tileAutoCraftingTable.getEnergy(), (int) this.tileAutoCraftingTable.getMaxPower(), mouseX, mouseY, 0, layer);
|
||||
this.builder.drawProgressBar(this, 50, 100, 120, 44, mouseX, mouseY, TRBuilder.ProgressDirection.RIGHT, layer);
|
||||
}
|
||||
|
||||
//Based of vanilla code
|
||||
public void renderRecipe(IRecipe recipe, int x, int y) {
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GlStateManager.enableAlpha();
|
||||
mc.getTextureManager().bindTexture(RECIPE_BOOK_TEXTURE);
|
||||
|
||||
this.drawTexturedModalRect(x, y, 152, 78, 24, 24);
|
||||
|
||||
int recipeWidth = 3;
|
||||
int recipeHeight = 3;
|
||||
if (recipe instanceof ShapedRecipes) {
|
||||
ShapedRecipes shapedrecipes = (ShapedRecipes) recipe;
|
||||
recipeWidth = shapedrecipes.getWidth();
|
||||
recipeHeight = shapedrecipes.getHeight();
|
||||
}
|
||||
if (recipe instanceof ShapedOreRecipe) {
|
||||
ShapedOreRecipe shapedrecipes = (ShapedOreRecipe) recipe;
|
||||
recipeWidth = shapedrecipes.getWidth();
|
||||
recipeHeight = shapedrecipes.getHeight();
|
||||
}
|
||||
Iterator<Ingredient> ingredients = recipe.getIngredients().iterator();
|
||||
for (int rHeight = 0; rHeight < recipeHeight; ++rHeight) {
|
||||
int j1 = 3 + rHeight * 7;
|
||||
for (int rWidth = 0; rWidth < recipeWidth; ++rWidth) {
|
||||
if (ingredients.hasNext()) {
|
||||
ItemStack[] aitemstack = ingredients.next().getMatchingStacks();
|
||||
if (aitemstack.length != 0) {
|
||||
int l1 = 3 + rWidth * 7;
|
||||
GlStateManager.pushMatrix();
|
||||
int i2 = (int) ((float) (x + l1) / 0.42F - 3.0F);
|
||||
int j2 = (int) ((float) (y + j1) / 0.42F - 3.0F);
|
||||
GlStateManager.scale(0.42F, 0.42F, 1.0F);
|
||||
GlStateManager.enableLighting();
|
||||
mc.getRenderItem().renderItemAndEffectIntoGUI(aitemstack[0], i2, j2);
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GlStateManager.disableAlpha();
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(final float f, final int mouseX, final int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
|
||||
final Layer layer = Layer.BACKGROUND;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
drawSlot(28 + (i *18), 25 + (j * 18), layer);
|
||||
drawSlot(28 + (i * 18), 25 + (j * 18), layer);
|
||||
}
|
||||
}
|
||||
drawOutputSlot(145, 42, layer);
|
||||
drawOutputSlot(95, 42, layer);
|
||||
drawString("Inventory", 8, 82, 4210752, layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -136,10 +192,9 @@ public class GuiAutoCrafting extends GuiBase {
|
|||
super.onGuiClosed();
|
||||
}
|
||||
|
||||
public void setRecipe(IRecipe recipe){
|
||||
public void setRecipe(IRecipe recipe) {
|
||||
tileAutoCraftingTable.setCurrentRecipe(recipe.getRegistryName());
|
||||
NetworkManager.sendToServer(new PacketSetRecipe(tileAutoCraftingTable, recipe.getRegistryName()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue