ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageFurnace.java

111 lines
4.4 KiB
Java
Raw Normal View History

2015-08-29 23:01:13 +02:00
/*
* This file ("PageFurnace.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
2016-01-03 16:05:51 +01:00
* http://ellpeck.de/actaddlicense/
2015-08-29 23:01:13 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-01-03 16:05:51 +01:00
* © 2016 Ellpeck
2015-08-29 23:01:13 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.booklet.page;
2015-08-29 23:01:13 +02:00
2016-01-05 14:57:50 +01:00
import de.ellpeck.actuallyadditions.api.internal.IBookletGui;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.booklet.GuiBooklet;
import de.ellpeck.actuallyadditions.mod.proxy.ClientProxy;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
2016-01-05 14:57:50 +01:00
import net.minecraft.client.Minecraft;
2015-08-29 23:01:13 +02:00
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.util.EnumChatFormatting;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-08-29 23:01:13 +02:00
import java.util.Map;
2016-01-05 14:57:50 +01:00
public class PageFurnace extends BookletPageAA{
2015-08-29 23:01:13 +02:00
private final ItemStack result;
private final ItemStack input;
2015-08-29 23:01:13 +02:00
2015-10-03 10:19:40 +02:00
public PageFurnace(int id, ItemStack result){
this(id, null, result);
}
public PageFurnace(int id, ItemStack input, ItemStack result){
2015-08-29 23:01:13 +02:00
super(id);
this.result = result;
this.input = input;
2015-10-30 21:42:14 +01:00
this.addToPagesWithItemStackData();
2015-08-29 23:01:13 +02:00
}
2015-10-02 16:48:01 +02:00
2015-12-01 19:48:09 +01:00
@Override
public ItemStack[] getItemStacksForPage(){
return this.result == null ? new ItemStack[0] : new ItemStack[]{this.result};
}
2015-08-29 23:01:13 +02:00
@Override
@SideOnly(Side.CLIENT)
2016-01-05 14:57:50 +01:00
public void renderPre(IBookletGui gui, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){
if(this.input != null || this.getInputForOutput(this.result) != null){
2016-01-05 14:57:50 +01:00
Minecraft.getMinecraft().getTextureManager().bindTexture(ClientProxy.bulletForMyValentine ? GuiBooklet.resLocValentine : GuiBooklet.resLoc);
gui.drawRect(gui.getGuiLeft()+37, gui.getGuiTop()+20, 0, 180, 60, 60);
2015-08-29 23:01:13 +02:00
}
}
@SuppressWarnings("unchecked")
@Override
@SideOnly(Side.CLIENT)
2016-01-05 14:57:50 +01:00
public void render(IBookletGui gui, int mouseX, int mouseY, int ticksElapsed, boolean mousePressed){
ItemStack input = this.input != null ? this.input : this.getInputForOutput(this.result);
2015-08-29 23:01:13 +02:00
if(input == null){
2016-01-05 14:57:50 +01:00
StringUtil.drawSplitString(Minecraft.getMinecraft().fontRenderer, EnumChatFormatting.DARK_RED+StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".recipeDisabled"), gui.getGuiLeft()+14, gui.getGuiTop()+15, 115, 0, false);
2015-08-29 23:01:13 +02:00
}
2015-08-31 11:48:15 +02:00
else{
String strg = "Furnace Recipe";
2016-01-05 14:57:50 +01:00
Minecraft.getMinecraft().fontRenderer.drawString(strg, gui.getGuiLeft()+gui.getXSize()/2-Minecraft.getMinecraft().fontRenderer.getStringWidth(strg)/2, gui.getGuiTop()+10, 0);
2015-08-31 11:48:15 +02:00
}
2015-08-29 23:01:13 +02:00
2016-01-05 14:57:50 +01:00
String text = gui.getCurrentEntrySet().page.getText();
if(text != null && !text.isEmpty()){
2016-01-05 14:57:50 +01:00
StringUtil.drawSplitString(Minecraft.getMinecraft().fontRenderer, text, gui.getGuiLeft()+14, gui.getGuiTop()+100, 115, 0, false);
2015-08-30 04:02:28 +02:00
}
2015-08-29 23:01:13 +02:00
if(input != null){
for(int i = 0; i < 2; i++){
for(int x = 0; x < 2; x++){
ItemStack stack = x == 0 ? input : this.result;
2015-10-03 10:16:18 +02:00
if(stack.getItemDamage() == Util.WILDCARD){
stack.setItemDamage(0);
}
2015-08-29 23:01:13 +02:00
boolean tooltip = i == 1;
2016-01-05 14:57:50 +01:00
int xShow = gui.getGuiLeft()+37+1+x*42;
int yShow = gui.getGuiTop()+20+21;
2015-08-29 23:01:13 +02:00
if(!tooltip){
2015-12-22 14:55:10 +01:00
AssetUtil.renderStackToGui(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){
2016-01-05 14:57:50 +01:00
gui.renderTooltipAndTransferButton(this, stack, mouseX, mouseY, x == 0, mousePressed);
2015-08-29 23:01:13 +02:00
}
}
}
}
}
}
private ItemStack getInputForOutput(ItemStack output){
for(Object o : FurnaceRecipes.smelting().getSmeltingList().entrySet()){
ItemStack stack = (ItemStack)((Map.Entry)o).getValue();
2015-10-03 10:16:18 +02:00
if(stack.isItemEqual(output)){
return (ItemStack)((Map.Entry)o).getKey();
}
2015-08-29 23:01:13 +02:00
}
return null;
}
}