2015-11-15 15:15:32 +01:00
|
|
|
/*
|
|
|
|
* This file ("PageReconstructor.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 Ellpeck
|
|
|
|
*/
|
|
|
|
|
|
|
|
package ellpeck.actuallyadditions.booklet.page;
|
|
|
|
|
|
|
|
import ellpeck.actuallyadditions.blocks.InitBlocks;
|
|
|
|
import ellpeck.actuallyadditions.booklet.GuiBooklet;
|
|
|
|
import ellpeck.actuallyadditions.proxy.ClientProxy;
|
2015-11-15 18:05:58 +01:00
|
|
|
import ellpeck.actuallyadditions.recipe.ReconstructorRecipeHandler;
|
2015-11-15 15:15:32 +01:00
|
|
|
import ellpeck.actuallyadditions.util.ModUtil;
|
|
|
|
import ellpeck.actuallyadditions.util.StringUtil;
|
|
|
|
import ellpeck.actuallyadditions.util.Util;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.EnumChatFormatting;
|
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
|
2015-11-15 18:14:39 +01:00
|
|
|
import java.util.List;
|
2015-11-15 15:15:32 +01:00
|
|
|
|
|
|
|
public class PageReconstructor extends BookletPage{
|
|
|
|
|
|
|
|
private final ItemStack result;
|
|
|
|
private final ItemStack input;
|
|
|
|
|
|
|
|
public PageReconstructor(int id, ItemStack result){
|
|
|
|
this(id, null, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PageReconstructor(int id, ItemStack input, ItemStack result){
|
|
|
|
super(id);
|
|
|
|
this.result = result;
|
|
|
|
this.input = input;
|
|
|
|
this.addToPagesWithItemStackData();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void renderPre(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){
|
|
|
|
if(this.input != null || this.getInputForOutput(this.result) != null){
|
|
|
|
gui.mc.getTextureManager().bindTexture(ClientProxy.bulletForMyValentine ? GuiBooklet.resLocValentine : GuiBooklet.resLoc);
|
|
|
|
gui.drawTexturedModalRect(gui.guiLeft+37, gui.guiTop+20, 188, 154, 60, 60);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public void render(GuiBooklet gui, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){
|
|
|
|
ItemStack input = this.input != null ? this.input : this.getInputForOutput(this.result);
|
|
|
|
if(input == null){
|
|
|
|
gui.mc.fontRenderer.drawSplitString(EnumChatFormatting.DARK_RED+StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".recipeDisabled"), gui.guiLeft+14, gui.guiTop+15, 115, 0);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
String strg = "Atomic Reconstructor";
|
|
|
|
gui.mc.fontRenderer.drawString(strg, gui.guiLeft+gui.xSize/2-gui.mc.fontRenderer.getStringWidth(strg)/2, gui.guiTop+10, 0);
|
2015-11-22 20:23:54 +01:00
|
|
|
|
|
|
|
//Lens
|
|
|
|
strg = this.getRecipeForOutput(this.result).type.name;
|
|
|
|
gui.mc.fontRenderer.drawString(strg, gui.guiLeft+gui.xSize/2-gui.mc.fontRenderer.getStringWidth(strg)/2, gui.guiTop+75, 0);
|
2015-11-15 15:15:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
String text = gui.currentPage.getText();
|
|
|
|
if(text != null && !text.isEmpty()){
|
|
|
|
gui.mc.fontRenderer.drawSplitString(text, gui.guiLeft+14, gui.guiTop+100, 115, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(input != null){
|
2015-11-15 17:50:31 +01:00
|
|
|
renderItem(gui, new ItemStack(InitBlocks.blockAtomicReconstructor), gui.guiLeft+37+22, gui.guiTop+20+21, 1.0F);
|
2015-11-15 15:15:32 +01:00
|
|
|
for(int i = 0; i < 2; i++){
|
|
|
|
for(int x = 0; x < 2; x++){
|
|
|
|
ItemStack stack = x == 0 ? input : this.result;
|
|
|
|
if(stack.getItemDamage() == Util.WILDCARD){
|
|
|
|
stack.setItemDamage(0);
|
|
|
|
}
|
|
|
|
boolean tooltip = i == 1;
|
|
|
|
|
|
|
|
int xShow = gui.guiLeft+37+1+x*42;
|
|
|
|
int yShow = gui.guiTop+20+21;
|
|
|
|
if(!tooltip){
|
|
|
|
renderItem(gui, stack, xShow, yShow, 1.0F);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if(mouseX >= xShow && mouseX <= xShow+16 && mouseY >= yShow && mouseY <= yShow+16){
|
|
|
|
this.renderTooltipAndTransfer(gui, stack, mouseX, mouseY, x == 0, mousePressed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack[] getItemStacksForPage(){
|
|
|
|
return this.result == null ? new ItemStack[0] : new ItemStack[]{this.result};
|
|
|
|
}
|
|
|
|
|
2015-11-22 20:23:54 +01:00
|
|
|
private ReconstructorRecipeHandler.Recipe getRecipeForOutput(ItemStack output){
|
2015-11-15 18:05:58 +01:00
|
|
|
for(ReconstructorRecipeHandler.Recipe recipe : ReconstructorRecipeHandler.recipes){
|
2015-11-15 18:14:39 +01:00
|
|
|
List<ItemStack> stacks = OreDictionary.getOres(recipe.output, false);
|
2015-11-15 15:15:32 +01:00
|
|
|
for(ItemStack stack : stacks){
|
|
|
|
if(output.isItemEqual(stack)){
|
2015-11-22 20:23:54 +01:00
|
|
|
return recipe;
|
2015-11-15 15:15:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2015-11-22 20:23:54 +01:00
|
|
|
|
|
|
|
private ItemStack getInputForOutput(ItemStack output){
|
|
|
|
ReconstructorRecipeHandler.Recipe recipe = this.getRecipeForOutput(output);
|
|
|
|
if(recipe != null){
|
|
|
|
List<ItemStack> inputs = OreDictionary.getOres(recipe.input, false);
|
|
|
|
if(inputs != null && !inputs.isEmpty() && inputs.get(0) != null){
|
|
|
|
ItemStack input = inputs.get(0).copy();
|
|
|
|
input.stackSize = 1;
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2015-11-15 15:15:32 +01:00
|
|
|
}
|