mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-22 05:02:30 +00:00
Added support for recipes in the Lexicon.
This commit is contained in:
1 parent
7e8151229e
commit
3cba219f5f
12 files changed
+197
-13
No files matched your search
@@ -65,6 +65,10 @@ public final class BotaniaAPI {
|
||||
*/
|
||||
public static List<IRecipe> getLatestAddedRecipes(int x) {
|
||||
List<IRecipe> list = CraftingManager.getInstance().getRecipeList();
|
||||
return list.subList(list.size() - 1 - x, list.size() - 1);
|
||||
List<IRecipe> newList = new ArrayList();
|
||||
for(int i = (x - 1); i >= 0; i--)
|
||||
newList.add(list.get(list.size() - 1 - i));
|
||||
|
||||
return newList;
|
||||
}
|
||||
}
|
||||
@@ -49,4 +49,9 @@ public interface IGuiLexiconEntry {
|
||||
* Gets the GUI's height
|
||||
*/
|
||||
public int getHeight();
|
||||
|
||||
/**
|
||||
* Gets the GUI's Z level for rendering.
|
||||
*/
|
||||
public float getZLevel();
|
||||
}
|
||||
@@ -29,6 +29,13 @@ public abstract class LexiconPage {
|
||||
*/
|
||||
public abstract void renderScreen(IGuiLexiconEntry gui, int mx, int my);
|
||||
|
||||
/**
|
||||
* Called per update tick.
|
||||
*/
|
||||
public void updateScreen() {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
public String getUnlocalizedName() {
|
||||
return unlocalizedName;
|
||||
}
|
||||
|
||||
@@ -26,9 +26,20 @@ public final class RenderHelper {
|
||||
int color = 0x505000ff;
|
||||
int color2 = 0xf0100010;
|
||||
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
net.minecraft.client.renderer.RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
renderTooltip(x, y, tooltipData, color, color2);
|
||||
}
|
||||
|
||||
public static void renderTooltipGreen(int x, int y, List<String> tooltipData) {
|
||||
int color = 0x00a000ff;
|
||||
int color2 = 0x001e0010;
|
||||
|
||||
renderTooltip(x, y, tooltipData, color, color2);
|
||||
}
|
||||
|
||||
public static void renderTooltip(int x, int y, List<String> tooltipData, int color, int color2) {
|
||||
boolean lighting = GL11.glGetBoolean(GL11.GL_LIGHTING);
|
||||
if(lighting)
|
||||
net.minecraft.client.renderer.RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
if (!tooltipData.isEmpty()) {
|
||||
@@ -65,6 +76,10 @@ public final class RenderHelper {
|
||||
var7 += 10;
|
||||
}
|
||||
}
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
if(!lighting)
|
||||
net.minecraft.client.renderer.RenderHelper.disableStandardItemLighting();
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
}
|
||||
|
||||
public static void drawGradientRect(int par1, int par2, float z, int par3, int par4, int par5, int par6) {
|
||||
@@ -95,5 +110,4 @@ public final class RenderHelper {
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -99,6 +99,12 @@ public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry {
|
||||
LexiconPage page = entry.pages.get(this.page);
|
||||
page.renderScreen(this, par1, par2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
LexiconPage page = entry.pages.get(this.page);
|
||||
page.updateScreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLeft() {
|
||||
@@ -120,4 +126,9 @@ public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry {
|
||||
return guiHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getZLevel() {
|
||||
return zLevel;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,7 @@ public final class LibResources {
|
||||
public static final String EMTPY_TEXTURE = "emptyTexture";
|
||||
|
||||
public static final String GUI_LEXICON = PREFIX_GUI + "lexicon.png";
|
||||
public static final String GUI_CRAFTING_OVERLAY = PREFIX_GUI + "craftingOverlay.png";
|
||||
|
||||
public static final String ENTRY_FLOWERS = PREFIX_ENTRIES + "flowers.png";
|
||||
|
||||
|
||||
@@ -34,13 +34,14 @@ public class CommonProxy {
|
||||
|
||||
ModBlocks.init();
|
||||
ModItems.init();
|
||||
|
||||
ModCrafingRecipes.init();
|
||||
|
||||
LexiconData.init();
|
||||
}
|
||||
|
||||
public void init(FMLInitializationEvent event) {
|
||||
NetworkRegistry.instance().registerGuiHandler(Botania.instance, new GuiHandler());
|
||||
|
||||
ModCrafingRecipes.init();
|
||||
}
|
||||
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
|
||||
@@ -11,18 +11,29 @@
|
||||
*/
|
||||
package vazkii.botania.common.crafting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
public final class ModCrafingRecipes {
|
||||
|
||||
public static List<IRecipe> recipesPetals;
|
||||
public static List<IRecipe> recipesDyes;
|
||||
|
||||
public static final void init() {
|
||||
// Petal/Dye Recipes
|
||||
for(int i = 0; i < 16; i++) {
|
||||
for(int i = 0; i < 16; i++)
|
||||
GameRegistry.addShapelessRecipe(new ItemStack(ModItems.petal, 2, i), new ItemStack(ModBlocks.flower, 1, i));
|
||||
recipesPetals = BotaniaAPI.getLatestAddedRecipes(16);
|
||||
|
||||
for(int i = 0; i < 16; i++)
|
||||
GameRegistry.addShapelessRecipe(new ItemStack(ModItems.dye, 1, i), new ItemStack(ModItems.petal, 1, i));
|
||||
}
|
||||
recipesDyes = BotaniaAPI.getLatestAddedRecipes(16);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.LexiconCategory;
|
||||
import vazkii.botania.api.LexiconEntry;
|
||||
import vazkii.botania.client.lib.LibResources;
|
||||
import vazkii.botania.common.crafting.ModCrafingRecipes;
|
||||
import vazkii.botania.common.lexicon.page.PageCraftingRecipes;
|
||||
import vazkii.botania.common.lexicon.page.PageImage;
|
||||
import vazkii.botania.common.lexicon.page.PageText;
|
||||
import vazkii.botania.common.lib.LibLexicon;
|
||||
@@ -40,7 +42,7 @@ public final class LexiconData {
|
||||
|
||||
// BASICS ENTRIES
|
||||
entry = new BLexiconEntry("world", categoryBasics);
|
||||
entry.setLexiconPages(new PageText("0"), new PageText("1"), new PageImage("2", LibResources.ENTRY_FLOWERS));
|
||||
entry.setLexiconPages(new PageText("0"), new PageText("1"), new PageImage("2", LibResources.ENTRY_FLOWERS), new PageCraftingRecipes("3", ModCrafingRecipes.recipesPetals), new PageCraftingRecipes("4", ModCrafingRecipes.recipesDyes));
|
||||
|
||||
entry = new BLexiconEntry("basicConcepts", categoryBasics);
|
||||
entry.setLexiconPages(new PageText("0"), new PageText("1"));
|
||||
|
||||
@@ -14,14 +14,41 @@ package vazkii.botania.common.lexicon.page;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import vazkii.botania.api.internal.IGuiLexiconEntry;
|
||||
import vazkii.botania.api.page.LexiconPage;
|
||||
import vazkii.botania.client.core.helper.RenderHelper;
|
||||
import vazkii.botania.client.lib.LibResources;
|
||||
|
||||
public class PageCraftingRecipes extends LexiconPage {
|
||||
|
||||
private static final ResourceLocation craftingOverlay = new ResourceLocation(LibResources.GUI_CRAFTING_OVERLAY);
|
||||
|
||||
List<IRecipe> recipes;
|
||||
|
||||
int ticksElapsed = 0;
|
||||
int recipeAt = 0;
|
||||
|
||||
int relativeMouseX, relativeMouseY;
|
||||
|
||||
ItemStack tooltipStack, tooltipContainerStack;
|
||||
|
||||
public PageCraftingRecipes(String unlocalizedName, List<IRecipe> recipes) {
|
||||
super(unlocalizedName);
|
||||
this.recipes = recipes;
|
||||
@@ -30,10 +57,108 @@ public class PageCraftingRecipes extends LexiconPage {
|
||||
public PageCraftingRecipes(String unlocalizedName, IRecipe recipe) {
|
||||
this(unlocalizedName, Arrays.asList(recipe));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void renderScreen(IGuiLexiconEntry gui, int mx, int my) {
|
||||
// TODO
|
||||
relativeMouseX = mx;
|
||||
relativeMouseY = my;
|
||||
|
||||
TextureManager render = Minecraft.getMinecraft().renderEngine;
|
||||
render.bindTexture(craftingOverlay);
|
||||
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
((GuiScreen) gui).drawTexturedModalRect(gui.getLeft(), gui.getTop(), 0, 0, gui.getWidth(), gui.getHeight());
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
|
||||
IRecipe recipe = recipes.get(recipeAt);
|
||||
renderCraftingRecipe(gui, recipe);
|
||||
|
||||
int width = gui.getWidth() - 30;
|
||||
int height = gui.getHeight();
|
||||
int x = gui.getLeft() + 16;
|
||||
int y = gui.getTop() + height - 40;
|
||||
PageText.renderText(x, y, width, height, getUnlocalizedName());
|
||||
|
||||
if(tooltipStack != null) {
|
||||
List<String> tooltipData = tooltipStack.getTooltip(Minecraft.getMinecraft().thePlayer, false);
|
||||
|
||||
RenderHelper.renderTooltip(relativeMouseX, relativeMouseY, tooltipData);
|
||||
if(tooltipContainerStack != null)
|
||||
RenderHelper.renderTooltipGreen(relativeMouseX, relativeMouseY + 8 + tooltipData.size() * 11, Arrays.asList(EnumChatFormatting.AQUA + StatCollector.translateToLocal("botaniamisc.craftingContainer"), tooltipContainerStack.getDisplayName()));
|
||||
}
|
||||
tooltipStack = tooltipContainerStack = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
if(ticksElapsed % 20 == 0) {
|
||||
recipeAt++;
|
||||
|
||||
if(recipeAt == recipes.size())
|
||||
recipeAt = 0;
|
||||
}
|
||||
++ticksElapsed;
|
||||
}
|
||||
|
||||
public void renderCraftingRecipe(IGuiLexiconEntry gui, IRecipe recipe) {
|
||||
if(recipe instanceof ShapedRecipes) {
|
||||
ShapedRecipes shaped = (ShapedRecipes)recipe;
|
||||
|
||||
for(int y = 0; y < shaped.recipeHeight; y++)
|
||||
for(int x = 0; x < shaped.recipeWidth; x++)
|
||||
renderItemAtGridPos(gui, 1 + x, 1 + y, shaped.recipeItems[y * shaped.recipeWidth + x], true);
|
||||
|
||||
} else if(recipe instanceof ShapelessRecipes) {
|
||||
ShapelessRecipes shapeless = (ShapelessRecipes) recipe;
|
||||
|
||||
drawGrid : {
|
||||
for(int y = 0; y < 3; y++)
|
||||
for(int x = 0; x < 3; x++) {
|
||||
int index = y * 3 + x;
|
||||
|
||||
if(index >= shapeless.recipeItems.size())
|
||||
break drawGrid;
|
||||
|
||||
renderItemAtGridPos(gui, 1 + x, 1 + y, (ItemStack) shapeless.recipeItems.get(index), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
renderItemAtGridPos(gui, 2, 0, recipe.getRecipeOutput(), false);
|
||||
}
|
||||
|
||||
public void renderItemAtGridPos(IGuiLexiconEntry gui, int x, int y, ItemStack stack, boolean accountForContainer) {
|
||||
if(stack == null || stack.getItem() == null)
|
||||
return;
|
||||
|
||||
int xPos = gui.getLeft() + x * 29 + 7;
|
||||
int yPos = gui.getTop() + y * 29 + 24 - (y == 0 ? 7 : 0);
|
||||
ItemStack stack1 = stack.copy();
|
||||
if(stack1.getItemDamage() == -1)
|
||||
stack1.setItemDamage(0);
|
||||
|
||||
renderItem(gui, xPos, yPos, stack1, accountForContainer);
|
||||
}
|
||||
|
||||
public void renderItem(IGuiLexiconEntry gui, int xPos, int yPos, ItemStack stack, boolean accountForContainer) {
|
||||
RenderItem render = new RenderItem();
|
||||
TextureManager renderEngine = Minecraft.getMinecraft().renderEngine;
|
||||
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
if(!ForgeHooksClient.renderInventoryItem(new RenderBlocks(), renderEngine, stack, render.renderWithColor, gui.getZLevel(), xPos, yPos))
|
||||
render.renderItemIntoGUI(fontRenderer, renderEngine, stack, xPos, yPos);
|
||||
render.renderItemOverlayIntoGUI(fontRenderer, renderEngine, stack, xPos, yPos);
|
||||
|
||||
if(relativeMouseX >= xPos && relativeMouseY >= yPos && relativeMouseX <= xPos + 16 && relativeMouseY <= yPos + 16) {
|
||||
tooltipStack = stack;
|
||||
ItemStack containerStack = stack.getItem().getContainerItemStack(stack);
|
||||
if(containerStack != null && containerStack.getItem() != null)
|
||||
tooltipContainerStack = containerStack;
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ itemGroup.Botania=Botania
|
||||
botaniamisc.nextPage=Next Page
|
||||
botaniamisc.prevPage=Previous Page
|
||||
botaniamisc.back=Back
|
||||
botaniamisc.craftingContainer=Returns on Crafting
|
||||
|
||||
# BLOCK NAMES
|
||||
tile.botania:flower0.name=Mystical White Flower
|
||||
@@ -75,6 +76,8 @@ botania.entry.world=The World
|
||||
botania.page.world0=The world is fun.<br>This line of text is very long so I can test if line wrap works fine, woo.<br>And this one is kinda long too. &eTesting colors. &cMore colors.
|
||||
botania.page.world1=This is a second page. There will be something here. Eventually.
|
||||
botania.page.world2=Flowers in the wild
|
||||
botania.page.world3=Plucking petals off flowers
|
||||
botania.page.world4=Grinding petals into dye
|
||||
|
||||
# -- BASIC CONCEPTS
|
||||
botania.entry.basicConcepts=Basic Concepts
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
Reference in new issue
Block a user