2015-08-29 23:01:13 +02: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://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2015-11-02 20:55:19 +01:00
|
|
|
* © 2015 Ellpeck
|
2015-08-29 23:01:13 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package ellpeck.actuallyadditions.booklet.page;
|
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.ReflectionHelper;
|
|
|
|
import ellpeck.actuallyadditions.booklet.GuiBooklet;
|
2015-10-23 23:08:53 +02:00
|
|
|
import ellpeck.actuallyadditions.proxy.ClientProxy;
|
2015-08-29 23:01:13 +02:00
|
|
|
import ellpeck.actuallyadditions.util.ModUtil;
|
|
|
|
import ellpeck.actuallyadditions.util.StringUtil;
|
|
|
|
import ellpeck.actuallyadditions.util.Util;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.crafting.IRecipe;
|
|
|
|
import net.minecraft.item.crafting.ShapedRecipes;
|
|
|
|
import net.minecraft.item.crafting.ShapelessRecipes;
|
2015-09-16 11:58:11 +02:00
|
|
|
import net.minecraft.util.EnumChatFormatting;
|
2015-08-29 23:01:13 +02:00
|
|
|
import net.minecraftforge.oredict.ShapedOreRecipe;
|
|
|
|
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2015-10-03 22:09:53 +02:00
|
|
|
|
2015-08-29 23:01:13 +02:00
|
|
|
public class PageCrafting extends BookletPage{
|
|
|
|
|
2015-09-29 17:42:04 +02:00
|
|
|
private final IRecipe[] recipes;
|
|
|
|
private int recipePos;
|
2015-08-29 23:01:13 +02:00
|
|
|
|
2015-09-29 17:42:04 +02:00
|
|
|
public PageCrafting(int id, ArrayList<IRecipe> recipes){
|
|
|
|
this(id, recipes.toArray(new IRecipe[recipes.size()]));
|
|
|
|
}
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
public PageCrafting(int id, IRecipe... recipes){
|
|
|
|
super(id);
|
|
|
|
this.recipes = recipes;
|
2015-10-30 21:42:14 +01:00
|
|
|
this.addToPagesWithItemStackData();
|
2015-08-29 23:01:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-04 13:21:07 +02:00
|
|
|
public void renderPre(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){
|
2015-09-29 17:42:04 +02:00
|
|
|
if(this.recipes[this.recipePos] != null){
|
2015-10-23 23:08:53 +02:00
|
|
|
gui.mc.getTextureManager().bindTexture(ClientProxy.bulletForMyValentine ? GuiBooklet.resLocValentine : GuiBooklet.resLoc);
|
2015-08-29 23:01:13 +02:00
|
|
|
gui.drawTexturedModalRect(gui.guiLeft+27, gui.guiTop+20, 146, 20, 99, 60);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
2015-10-04 13:21:07 +02:00
|
|
|
public void render(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){
|
2015-09-29 17:42:04 +02:00
|
|
|
IRecipe recipe = this.recipes[this.recipePos];
|
|
|
|
|
|
|
|
if(recipe == null){
|
2015-10-03 19:19:26 +02:00
|
|
|
gui.mc.fontRenderer.drawSplitString(EnumChatFormatting.DARK_RED+StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".recipeDisabled"), gui.guiLeft+14, gui.guiTop+15, 115, 0);
|
2015-08-29 23:01:13 +02:00
|
|
|
}
|
2015-08-31 10:45:05 +02:00
|
|
|
else{
|
|
|
|
String strg = StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+"."+(recipe instanceof ShapedRecipes ? "shapedRecipe" : (recipe instanceof ShapelessRecipes ? "shapelessRecipe" : (recipe instanceof ShapelessOreRecipe ? "shapelessOreRecipe" : "shapedOreRecipe"))));
|
2015-10-03 19:19:26 +02:00
|
|
|
gui.mc.fontRenderer.drawString(strg, gui.guiLeft+gui.xSize/2-gui.mc.fontRenderer.getStringWidth(strg)/2, gui.guiTop+10, 0);
|
2015-08-31 10:45:05 +02:00
|
|
|
}
|
2015-08-29 23:01:13 +02:00
|
|
|
|
2015-08-30 04:02:28 +02:00
|
|
|
String text = gui.currentPage.getText();
|
2015-09-14 11:02:16 +02:00
|
|
|
if(text != null && !text.isEmpty()){
|
2015-10-03 19:19:26 +02:00
|
|
|
gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+90, 115, 0);
|
2015-08-30 04:02:28 +02:00
|
|
|
}
|
2015-08-29 23:01:13 +02:00
|
|
|
|
2015-09-29 17:42:04 +02:00
|
|
|
if(recipe != null){
|
2015-08-29 23:01:13 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else if(recipe instanceof ShapelessRecipes){
|
|
|
|
ShapelessRecipes shapeless = (ShapelessRecipes)recipe;
|
|
|
|
for(int i = 0; i < shapeless.recipeItems.size(); i++){
|
|
|
|
stacks[i] = (ItemStack)shapeless.recipeItems.get(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(recipe instanceof ShapedOreRecipe){
|
|
|
|
ShapedOreRecipe shaped = (ShapedOreRecipe)recipe;
|
|
|
|
width = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, shaped, 4);
|
|
|
|
height = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, shaped, 5);
|
|
|
|
for(int i = 0; i < shaped.getInput().length; i++){
|
|
|
|
Object input = shaped.getInput()[i];
|
|
|
|
if(input != null){
|
2015-11-04 19:39:14 +01:00
|
|
|
stacks[i] = input instanceof ItemStack ? (ItemStack)input : (((ArrayList<ItemStack>)input).isEmpty() ? null : ((ArrayList<ItemStack>)input).get(0));
|
2015-08-29 23:01:13 +02: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);
|
2015-11-04 19:39:14 +01:00
|
|
|
stacks[i] = input instanceof ItemStack ? (ItemStack)input : (((ArrayList<ItemStack>)input).isEmpty() ? null : ((ArrayList<ItemStack>)input).get(0));
|
2015-08-29 23:01:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-30 21:47:44 +02:00
|
|
|
int xShowOutput = gui.guiLeft+27+82;
|
|
|
|
int yShowOutput = gui.guiTop+20+22;
|
2015-09-10 21:25:34 +02:00
|
|
|
renderItem(gui, recipe.getRecipeOutput(), xShowOutput, yShowOutput, 1.0F);
|
2015-08-29 23:01:13 +02:00
|
|
|
for(int i = 0; i < 2; i++){
|
|
|
|
boolean tooltip = i == 1;
|
|
|
|
for(int x = 0; x < width; x++){
|
|
|
|
for(int y = 0; y < height; y++){
|
|
|
|
ItemStack stack = stacks[y*width+x];
|
|
|
|
if(stack != null){
|
2015-10-04 15:24:11 +02:00
|
|
|
stack.stackSize = 1;
|
2015-10-03 10:16:18 +02:00
|
|
|
if(stack.getItemDamage() == Util.WILDCARD){
|
|
|
|
stack.setItemDamage(0);
|
|
|
|
}
|
2015-08-30 21:47:44 +02:00
|
|
|
int xShow = gui.guiLeft+27+4+x*18;
|
|
|
|
int yShow = gui.guiTop+20+4+y*18;
|
2015-08-29 23:01:13 +02:00
|
|
|
if(!tooltip){
|
2015-09-10 21:25:34 +02:00
|
|
|
renderItem(gui, stack, xShow, yShow, 1.0F);
|
2015-08-29 23:01:13 +02:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
if(mouseX >= xShow && mouseX <= xShow+16 && mouseY >= yShow && mouseY <= yShow+16){
|
2015-10-04 13:21:07 +02:00
|
|
|
this.renderTooltipAndTransfer(gui, stack, mouseX, mouseY, true, mousePressed);
|
2015-08-29 23:01:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(mouseX >= xShowOutput && mouseX <= xShowOutput+16 && mouseY >= yShowOutput && mouseY <= yShowOutput+16){
|
2015-10-04 13:21:07 +02:00
|
|
|
this.renderTooltipAndTransfer(gui, recipe.getRecipeOutput(), mouseX, mouseY, false, mousePressed);
|
2015-08-29 23:01:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-03 10:19:40 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateScreen(int ticksElapsed){
|
|
|
|
if(ticksElapsed%30 == 0){
|
|
|
|
if(this.recipePos+1 >= this.recipes.length){
|
|
|
|
this.recipePos = 0;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
this.recipePos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack[] getItemStacksForPage(){
|
2015-10-29 20:54:10 +01:00
|
|
|
if(this.recipes != null && this.recipes.length > 0 && this.recipes[0] != null){
|
2015-10-04 15:24:11 +02:00
|
|
|
return new ItemStack[]{this.recipes[0].getRecipeOutput()};
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
2015-10-04 15:24:11 +02:00
|
|
|
return null;
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
2015-08-29 23:01:13 +02:00
|
|
|
}
|