Started JEI Implementation.

This commit is contained in:
Ellpeck 2016-01-16 20:06:25 +01:00
parent 07c24cf8dc
commit 3397632e87
8 changed files with 275 additions and 7 deletions

View file

@ -17,11 +17,12 @@ group = "de.ellpeck.actuallyadditions"
archivesBaseName = "ActuallyAdditions" archivesBaseName = "ActuallyAdditions"
minecraft { minecraft {
version = "1.8.9-11.15.0.1684" version = "1.8.9-11.15.0.1697"
runDir = "idea" runDir = "idea"
mappings = "stable_20" mappings = "stable_20"
makeObfSourceJar = false makeObfSourceJar = false
useDepAts = true
replaceIn "ModUtil.java" replaceIn "ModUtil.java"
replace "@VERSION@", project.version.toString() replace "@VERSION@", project.version.toString()
@ -31,12 +32,17 @@ repositories {
maven { maven {
url "http://chickenbones.net/maven/" url "http://chickenbones.net/maven/"
} }
maven {
url "http://dvs1.progwml6.com/files/maven"
}
} }
dependencies { dependencies {
compile "codechicken:CodeChickenLib:1.8-1.1.2.139:dev" compile "codechicken:CodeChickenLib:1.8-1.1.2.139:dev"
compile "codechicken:CodeChickenCore:1.8-1.0.5.36:dev" compile "codechicken:CodeChickenCore:1.8-1.0.5.36:dev"
compile "codechicken:NotEnoughItems:1.8-1.0.5.104:dev" compile "codechicken:NotEnoughItems:1.8-1.0.5.104:dev"
deobfCompile "mezz.jei:jei_1.8.9:2.18.1.88"
} }
processResources { processResources {

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.booklet; package de.ellpeck.actuallyadditions.mod.booklet;
import de.ellpeck.actuallyadditions.mod.achievement.InitAchievements; import de.ellpeck.actuallyadditions.mod.achievement.InitAchievements;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.achievement.GuiAchievements; import net.minecraft.client.gui.achievement.GuiAchievements;
import net.minecraft.stats.StatFileWriter; import net.minecraft.stats.StatFileWriter;
@ -23,8 +24,13 @@ public class GuiAAAchievements extends GuiAchievements{
public GuiAAAchievements(GuiScreen screen, StatFileWriter writer){ public GuiAAAchievements(GuiScreen screen, StatFileWriter writer){
super(screen, writer); super(screen, writer);
try{
ReflectionHelper.setPrivateValue(GuiAchievements.class, this, InitAchievements.pageNumber, 20); ReflectionHelper.setPrivateValue(GuiAchievements.class, this, InitAchievements.pageNumber, 20);
} }
catch(Exception e){
ModUtil.LOGGER.error("Something went wrong trying to open the Achievements GUI!", e);
}
}
@Override @Override
public void initGui(){ public void initGui(){

View file

@ -120,8 +120,13 @@ public class PageCrafting extends BookletPageAA{
} }
else if(recipe instanceof ShapedOreRecipe){ else if(recipe instanceof ShapedOreRecipe){
ShapedOreRecipe shaped = (ShapedOreRecipe)recipe; ShapedOreRecipe shaped = (ShapedOreRecipe)recipe;
try{
width = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, shaped, 4); width = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, shaped, 4);
height = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, shaped, 5); height = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, shaped, 5);
}
catch(Exception e){
ModUtil.LOGGER.error("Something went wrong trying to get the Crafting Recipe in the booklet to display!", e);
}
for(int i = 0; i < shaped.getInput().length; i++){ for(int i = 0; i < shaped.getInput().length; i++){
Object input = shaped.getInput()[i]; Object input = shaped.getInput()[i];
if(input != null){ if(input != null){

View file

@ -0,0 +1,50 @@
/*
* This file ("JEIActuallyAdditionsPlugin.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense/
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.jei;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.mod.jei.booklet.BookletRecipeCategory;
import de.ellpeck.actuallyadditions.mod.jei.booklet.BookletRecipeHandler;
import mezz.jei.api.*;
@JEIPlugin
public class JEIActuallyAdditionsPlugin implements IModPlugin{
private IJeiHelpers helpers;
@Override
public void onJeiHelpersAvailable(IJeiHelpers jeiHelpers){
this.helpers = jeiHelpers;
}
@Override
public void onItemRegistryAvailable(IItemRegistry itemRegistry){
}
@Override
public void register(IModRegistry registry){
registry.addRecipeCategories(
new BookletRecipeCategory(this.helpers.getGuiHelper())
);
registry.addRecipeHandlers(
new BookletRecipeHandler()
);
registry.addRecipes(ActuallyAdditionsAPI.bookletPagesWithItemStackData);
}
@Override
public void onRecipeRegistryAvailable(IRecipeRegistry recipeRegistry){
}
}

View file

@ -0,0 +1,70 @@
/*
* This file ("BookletRecipeCategory.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense/
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.jei.booklet;
import de.ellpeck.actuallyadditions.mod.nei.NEIBookletRecipe;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import mezz.jei.api.IGuiHelper;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.client.Minecraft;
import javax.annotation.Nonnull;
import java.util.Arrays;
public class BookletRecipeCategory implements IRecipeCategory{
private IDrawable background;
public BookletRecipeCategory(IGuiHelper helper){
this.background = helper.createBlankDrawable(150, 256);
}
@Nonnull
@Override
public String getUid(){
return NEIBookletRecipe.NAME;
}
@Nonnull
@Override
public String getTitle(){
return StringUtil.localize("container.nei."+NEIBookletRecipe.NAME+".name");
}
@Nonnull
@Override
public IDrawable getBackground(){
return this.background;
}
@Override
public void drawExtras(Minecraft minecraft){
}
@Override
public void drawAnimations(Minecraft minecraft){
}
@Override
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull IRecipeWrapper recipeWrapper){
if(recipeWrapper instanceof BookletRecipeWrapper){
BookletRecipeWrapper wrapper = (BookletRecipeWrapper)recipeWrapper;
recipeLayout.getItemStacks().init(0, true, 62, 23);
recipeLayout.getItemStacks().set(0, Arrays.asList(wrapper.thePage.getItemStacksForPage()));
}
}
}

View file

@ -0,0 +1,44 @@
/*
* This file ("BookletRecipeHandler.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense/
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.jei.booklet;
import de.ellpeck.actuallyadditions.api.booklet.BookletPage;
import de.ellpeck.actuallyadditions.mod.nei.NEIBookletRecipe;
import mezz.jei.api.recipe.IRecipeHandler;
import mezz.jei.api.recipe.IRecipeWrapper;
import javax.annotation.Nonnull;
public class BookletRecipeHandler implements IRecipeHandler<BookletPage>{
@Nonnull
@Override
public Class getRecipeClass(){
return BookletPage.class;
}
@Nonnull
@Override
public String getRecipeCategoryUid(){
return NEIBookletRecipe.NAME;
}
@Nonnull
@Override
public IRecipeWrapper getRecipeWrapper(@Nonnull BookletPage recipe){
return new BookletRecipeWrapper(recipe);
}
@Override
public boolean isRecipeValid(@Nonnull BookletPage recipe){
return true;
}
}

View file

@ -0,0 +1,87 @@
/*
* This file ("BookletRecipeWrapper.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense/
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.jei.booklet;
import com.google.common.collect.ImmutableList;
import de.ellpeck.actuallyadditions.api.booklet.BookletPage;
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
import de.ellpeck.actuallyadditions.mod.booklet.page.PagePicture;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.client.Minecraft;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
public class BookletRecipeWrapper implements IRecipeWrapper{
public BookletPage thePage;
public BookletRecipeWrapper(BookletPage page){
this.thePage = page;
}
@Override
public List getInputs(){
return Arrays.asList(this.thePage.getItemStacksForPage());
}
@Override
public List getOutputs(){
return Arrays.asList(this.thePage.getItemStacksForPage());
}
@Override
public List<FluidStack> getFluidInputs(){
return ImmutableList.of();
}
@Override
public List<FluidStack> getFluidOutputs(){
return ImmutableList.of();
}
@Override
public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight){
int yOffset = 30;
List header = minecraft.fontRendererObj.listFormattedStringToWidth(StringUtil.localize("container.nei."+ModUtil.MOD_ID_LOWER+".booklet.header").replaceAll("<item>", EnumChatFormatting.BLUE+"").replaceAll("<r>", EnumChatFormatting.BLACK+""), 150);
for(int i = 0; i < header.size(); i++){
minecraft.fontRendererObj.drawString((String)header.get(i), 0, yOffset+18+i*(minecraft.fontRendererObj.FONT_HEIGHT+1), 0, false);
}
int maxLines = 5;
IBookletChapter chapter = this.thePage.getChapter();
String aText = (chapter.getPages()[0] instanceof PagePicture && chapter.getPages().length > 1 ? chapter.getPages()[1] : chapter.getPages()[0]).getText();
List text = minecraft.fontRendererObj.listFormattedStringToWidth(aText != null ? aText : EnumChatFormatting.DARK_RED+StringUtil.localize("container.nei."+ModUtil.MOD_ID_LOWER+".booklet.noText"), 150);
for(int i = 0; i < Math.min(maxLines, text.size()); i++){
minecraft.fontRendererObj.drawString(text.get(i)+(i == maxLines-1 && text.size() > maxLines ? EnumChatFormatting.RESET+""+EnumChatFormatting.BLACK+"..." : ""), 0, yOffset+18+25+i*(minecraft.fontRendererObj.FONT_HEIGHT+1), 0, false);
}
minecraft.fontRendererObj.drawString(EnumChatFormatting.ITALIC+chapter.getLocalizedName(), 0, yOffset+97, 0, false);
minecraft.fontRendererObj.drawString(EnumChatFormatting.ITALIC+"Page "+this.thePage.getID(), 0, yOffset+107, 0, false);
}
@Override
public void drawAnimations(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight){
}
@Nullable
@Override
public List<String> getTooltipStrings(int mouseX, int mouseY){
return null;
}
}

View file

@ -33,8 +33,6 @@ public class NEIScreenEvents{
@SubscribeEvent @SubscribeEvent
public void onInitGuiForNEI(GuiScreenEvent.InitGuiEvent event){ public void onInitGuiForNEI(GuiScreenEvent.InitGuiEvent event){
if(event.gui instanceof GuiRecipe){ if(event.gui instanceof GuiRecipe){
GuiRecipe theGui = (GuiRecipe)event.gui;
int xSize = 176; int xSize = 176;
int ySize = 166; int ySize = 166;
int guiLeft = (event.gui.width-xSize)/2; int guiLeft = (event.gui.width-xSize)/2;
@ -50,8 +48,10 @@ public class NEIScreenEvents{
} }
} }
}; };
event.buttonList.add(this.neiButton); event.buttonList.add(this.neiButton);
GuiRecipe theGui = (GuiRecipe)event.gui;
IRecipeHandler handler = theGui.getCurrentRecipeHandlers().get(theGui.recipetype); IRecipeHandler handler = theGui.getCurrentRecipeHandlers().get(theGui.recipetype);
this.neiButton.visible = handler instanceof INEIRecipeHandler && ((INEIRecipeHandler)handler).getPageForInfo(theGui.page) != null; this.neiButton.visible = handler instanceof INEIRecipeHandler && ((INEIRecipeHandler)handler).getPageForInfo(theGui.page) != null;
} }