2016-11-10 21:07:15 +01:00
|
|
|
/*
|
|
|
|
* This file ("PageCrafting.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
|
|
|
|
*
|
|
|
|
* © 2015-2016 Ellpeck
|
|
|
|
*/
|
|
|
|
|
|
|
|
package de.ellpeck.actuallyadditions.mod.booklet.page;
|
|
|
|
|
2016-11-10 23:37:40 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
|
2016-11-11 16:37:45 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet;
|
2016-11-10 23:37:40 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
2016-11-16 16:59:00 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2016-11-11 16:37:45 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2016-11-10 23:37:40 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-11-10 21:07:15 +01:00
|
|
|
import net.minecraft.item.crafting.IRecipe;
|
2016-11-10 23:37:40 +01:00
|
|
|
import net.minecraft.item.crafting.ShapedRecipes;
|
|
|
|
import net.minecraft.item.crafting.ShapelessRecipes;
|
2016-11-11 16:37:45 +01:00
|
|
|
import net.minecraftforge.fml.client.config.GuiUtils;
|
2016-11-10 23:37:40 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
2016-11-11 16:37:45 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2016-11-10 23:37:40 +01:00
|
|
|
import net.minecraftforge.oredict.ShapedOreRecipe;
|
|
|
|
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
2016-11-10 21:07:15 +01:00
|
|
|
|
2016-11-10 23:37:40 +01:00
|
|
|
import java.util.Arrays;
|
2016-11-10 21:07:15 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class PageCrafting extends BookletPage{
|
|
|
|
|
2016-11-16 20:31:16 +01:00
|
|
|
private final List<IRecipe> recipes;
|
2016-11-11 18:55:32 +01:00
|
|
|
private int recipeAt;
|
2016-11-11 16:37:45 +01:00
|
|
|
private String recipeTypeLocKey;
|
2016-11-10 23:37:40 +01:00
|
|
|
private boolean isWildcard;
|
|
|
|
|
2016-11-22 22:54:35 +01:00
|
|
|
public PageCrafting(int localizationKey, int priority, List<IRecipe> recipes){
|
|
|
|
super(localizationKey, priority);
|
2016-11-10 23:37:40 +01:00
|
|
|
this.recipes = recipes;
|
2016-11-10 21:07:15 +01:00
|
|
|
}
|
|
|
|
|
2016-11-22 22:54:35 +01:00
|
|
|
public PageCrafting(int localizationKey, List<IRecipe> recipes){
|
|
|
|
this(localizationKey, 0, recipes);
|
|
|
|
}
|
|
|
|
|
2016-11-10 21:07:15 +01:00
|
|
|
public PageCrafting(int localizationKey, IRecipe... recipes){
|
2016-11-22 22:54:35 +01:00
|
|
|
this(localizationKey, 0, recipes);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public PageCrafting(int localizationKey, int priority, IRecipe... recipes){
|
|
|
|
this(localizationKey, priority, Arrays.asList(recipes));
|
2016-11-10 21:07:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public BookletPage setWildcard(){
|
2016-11-10 23:37:40 +01:00
|
|
|
this.isWildcard = true;
|
2016-11-10 21:07:15 +01:00
|
|
|
return this;
|
|
|
|
}
|
2016-11-10 23:37:40 +01:00
|
|
|
|
2016-11-11 16:37:45 +01:00
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void drawScreenPre(GuiBookletBase gui, int startX, int startY, int mouseX, int mouseY, float partialTicks){
|
|
|
|
super.drawScreenPre(gui, startX, startY, mouseX, mouseY, partialTicks);
|
|
|
|
|
|
|
|
gui.mc.getTextureManager().bindTexture(GuiBooklet.RES_LOC_GADGETS);
|
|
|
|
GuiUtils.drawTexturedModalRect(startX+5, startY+6, 20, 0, 116, 54, 0);
|
|
|
|
|
|
|
|
gui.renderScaledAsciiString("("+StringUtil.localize(this.recipeTypeLocKey)+")", startX+6, startY+65, 0, false, 0.65F);
|
|
|
|
|
|
|
|
PageTextOnly.renderTextToPage(gui, this, startX+6, startY+80);
|
|
|
|
}
|
|
|
|
|
2016-11-10 23:37:40 +01:00
|
|
|
@Override
|
2016-11-11 18:55:32 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void updateScreen(GuiBookletBase gui, int startX, int startY, int pageTimer){
|
|
|
|
super.updateScreen(gui, startX, startY, pageTimer);
|
2016-11-10 23:37:40 +01:00
|
|
|
|
2016-11-11 18:55:32 +01:00
|
|
|
if(pageTimer%20 == 0){
|
|
|
|
this.findRecipe(gui, startX, startY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void findRecipe(GuiBookletBase gui, int startX, int startY){
|
2016-11-10 23:37:40 +01:00
|
|
|
if(!this.recipes.isEmpty()){
|
2016-11-11 18:55:32 +01:00
|
|
|
IRecipe recipe = this.recipes.get(this.recipeAt);
|
2016-11-10 23:37:40 +01:00
|
|
|
if(recipe != null){
|
|
|
|
this.setupRecipe(gui, recipe, startX, startY);
|
|
|
|
}
|
2016-11-11 18:55:32 +01:00
|
|
|
|
|
|
|
this.recipeAt++;
|
|
|
|
if(this.recipeAt >= this.recipes.size()){
|
|
|
|
this.recipeAt = 0;
|
|
|
|
}
|
2016-11-10 23:37:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-11-11 18:55:32 +01:00
|
|
|
public void initGui(GuiBookletBase gui, int startX, int startY){
|
|
|
|
super.initGui(gui, startX, startY);
|
|
|
|
this.findRecipe(gui, startX, startY);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void getItemStacksForPage(List<ItemStack> list){
|
|
|
|
super.getItemStacksForPage(list);
|
2016-11-10 23:37:40 +01:00
|
|
|
|
|
|
|
if(!this.recipes.isEmpty()){
|
|
|
|
for(IRecipe recipe : this.recipes){
|
|
|
|
if(recipe != null){
|
|
|
|
ItemStack output = recipe.getRecipeOutput();
|
2016-11-16 20:31:16 +01:00
|
|
|
if(StackUtil.isValid(output)){
|
2016-11-10 23:37:40 +01:00
|
|
|
ItemStack copy = output.copy();
|
|
|
|
if(this.isWildcard){
|
|
|
|
copy.setItemDamage(Util.WILDCARD);
|
|
|
|
}
|
2016-11-11 18:55:32 +01:00
|
|
|
list.add(copy);
|
2016-11-10 23:37:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setupRecipe(GuiBookletBase gui, IRecipe recipe, int startX, int startY){
|
|
|
|
ItemStack[] stacks = new ItemStack[9];
|
|
|
|
int width = 3;
|
|
|
|
int height = 3;
|
|
|
|
|
|
|
|
if(recipe instanceof ShapedRecipes){
|
|
|
|
ShapedRecipes shaped = (ShapedRecipes)recipe;
|
|
|
|
width = shaped.recipeWidth;
|
|
|
|
height = shaped.recipeHeight;
|
|
|
|
stacks = shaped.recipeItems;
|
2016-11-11 16:37:45 +01:00
|
|
|
this.recipeTypeLocKey = "booklet."+ModUtil.MOD_ID+".shapedRecipe";
|
2016-11-10 23:37:40 +01:00
|
|
|
}
|
|
|
|
else if(recipe instanceof ShapelessRecipes){
|
|
|
|
ShapelessRecipes shapeless = (ShapelessRecipes)recipe;
|
|
|
|
for(int i = 0; i < shapeless.recipeItems.size(); i++){
|
|
|
|
stacks[i] = shapeless.recipeItems.get(i);
|
|
|
|
}
|
2016-11-11 16:37:45 +01:00
|
|
|
this.recipeTypeLocKey = "booklet."+ModUtil.MOD_ID+".shapelessRecipe";
|
2016-11-10 23:37:40 +01:00
|
|
|
}
|
|
|
|
else if(recipe instanceof ShapedOreRecipe){
|
|
|
|
ShapedOreRecipe shaped = (ShapedOreRecipe)recipe;
|
|
|
|
try{
|
|
|
|
width = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, shaped, 4);
|
|
|
|
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++){
|
|
|
|
Object input = shaped.getInput()[i];
|
|
|
|
if(input != null){
|
2016-11-16 20:31:16 +01:00
|
|
|
stacks[i] = input instanceof ItemStack ? (ItemStack)input : (((List<ItemStack>)input).isEmpty() ? StackUtil.getNull() : ((List<ItemStack>)input).get(0));
|
2016-11-10 23:37:40 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-11 16:37:45 +01:00
|
|
|
this.recipeTypeLocKey = "booklet."+ModUtil.MOD_ID+".shapedOreRecipe";
|
2016-11-10 23:37:40 +01:00
|
|
|
}
|
|
|
|
else if(recipe instanceof ShapelessOreRecipe){
|
|
|
|
ShapelessOreRecipe shapeless = (ShapelessOreRecipe)recipe;
|
|
|
|
for(int i = 0; i < shapeless.getInput().size(); i++){
|
|
|
|
Object input = shapeless.getInput().get(i);
|
2016-11-16 20:31:16 +01:00
|
|
|
stacks[i] = input instanceof ItemStack ? (ItemStack)input : (((List<ItemStack>)input).isEmpty() ? StackUtil.getNull() : ((List<ItemStack>)input).get(0));
|
2016-11-10 23:37:40 +01:00
|
|
|
}
|
2016-11-11 16:37:45 +01:00
|
|
|
this.recipeTypeLocKey = "booklet."+ModUtil.MOD_ID+".shapelessOreRecipe";
|
2016-11-10 23:37:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for(int x = 0; x < width; x++){
|
|
|
|
for(int y = 0; y < height; y++){
|
|
|
|
ItemStack stack = stacks[y*width+x];
|
2016-11-16 16:59:00 +01:00
|
|
|
if(StackUtil.isValid(stack)){
|
2016-11-10 23:37:40 +01:00
|
|
|
ItemStack copy = stack.copy();
|
2016-11-16 16:59:00 +01:00
|
|
|
copy = StackUtil.setStackSize(copy, 1);
|
2016-11-10 23:37:40 +01:00
|
|
|
if(copy.getItemDamage() == Util.WILDCARD){
|
|
|
|
copy.setItemDamage(0);
|
|
|
|
}
|
|
|
|
|
2016-11-11 18:55:32 +01:00
|
|
|
gui.addOrModifyItemRenderer(copy, startX+6+x*18, startY+7+y*18, 1F, true);
|
2016-11-10 23:37:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-11 18:55:32 +01:00
|
|
|
gui.addOrModifyItemRenderer(recipe.getRecipeOutput(), startX+100, startY+25, 1F, false);
|
2016-11-10 23:37:40 +01:00
|
|
|
}
|
2016-11-10 21:07:15 +01:00
|
|
|
}
|