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

133 lines
5.7 KiB
Java
Raw Normal View History

2015-08-29 23:01:13 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("PageCrusherRecipe.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 23:01:13 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-08-29 23:01:13 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015-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.api.recipe.CrusherRecipe;
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;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.text.TextFormatting;
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
2015-11-15 18:14:39 +01:00
import java.util.List;
2015-10-03 22:09:53 +02:00
2016-01-05 14:57:50 +01:00
public class PageCrusherRecipe extends BookletPageAA{
2015-08-29 23:01:13 +02:00
2016-05-19 20:05:12 +02:00
public final CrusherRecipe recipe;
2015-08-29 23:01:13 +02:00
2015-11-10 21:26:28 +01:00
private int recipePos;
2016-01-05 04:47:35 +01:00
public PageCrusherRecipe(int id, CrusherRecipe recipe){
2015-08-29 23:01:13 +02:00
super(id);
this.recipe = recipe;
2015-10-30 21:42:14 +01:00
this.addToPagesWithItemStackData();
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){
2016-05-02 17:46:53 +02:00
if(this.recipe != 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, 60, 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){
2016-05-02 17:46:53 +02:00
if(this.recipe == null){
2016-04-20 21:39:03 +02:00
StringUtil.drawSplitString(Minecraft.getMinecraft().fontRendererObj, TextFormatting.DARK_RED+StringUtil.localize("booklet."+ModUtil.MOD_ID+".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 = "Crusher Recipe";
Minecraft.getMinecraft().fontRendererObj.drawString(strg, gui.getGuiLeft()+gui.getXSize()/2-Minecraft.getMinecraft().fontRendererObj.getStringWidth(strg)/2, gui.getGuiTop()+10, 0);
2015-08-31 11:48:15 +02:00
}
2015-08-29 23:01:13 +02:00
2016-05-14 13:51:18 +02:00
String text = gui.getCurrentEntrySet().getCurrentPage().getText();
if(text != null && !text.isEmpty()){
StringUtil.drawSplitString(Minecraft.getMinecraft().fontRendererObj, 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
2016-05-02 17:46:53 +02:00
if(this.recipe != null){
if(this.recipe.outputTwoChance > 0){
Minecraft.getMinecraft().fontRendererObj.drawString(this.recipe.outputTwoChance+"%", gui.getGuiLeft()+37+62, gui.getGuiTop()+20+33, 0);
}
2015-08-29 23:01:13 +02:00
2016-05-02 17:46:53 +02:00
if(this.recipe.getRecipeOutputOnes() != null){
for(int i = 0; i < 2; i++){
for(int j = 0; j < 3; j++){
ItemStack stack;
switch(j){
case 0:
2015-11-10 21:26:28 +01:00
stack = this.recipe.getRecipeInputs().get(Math.min(this.recipe.getRecipeInputs().size()-1, this.recipePos));
break;
case 1:
2015-11-10 21:26:28 +01:00
stack = this.recipe.getRecipeOutputOnes().get(Math.min(this.recipe.getRecipeOutputOnes().size()-1, this.recipePos));
break;
default:
2015-11-15 18:14:39 +01:00
List<ItemStack> outputTwos = this.recipe.getRecipeOutputTwos();
2015-11-10 21:26:28 +01:00
stack = outputTwos == null ? null : outputTwos.get(Math.min(outputTwos.size()-1, this.recipePos));
break;
2015-10-03 10:16:18 +02:00
}
if(stack != null){
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+(j == 0 ? 1 : (j == 1 ? 43 : (j == 2 ? 43 : 0)));
int yShow = gui.getGuiTop()+20+(j == 0 ? 21 : (j == 1 ? 11 : (j == 2 ? 29 : 0)));
if(!tooltip){
AssetUtil.renderStackToGui(stack, xShow, yShow, 1.0F);
}
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, j == 0, mousePressed);
}
2015-08-29 23:01:13 +02:00
}
}
}
}
}
}
}
2015-10-03 10:19:40 +02:00
2015-10-03 22:13:57 +02:00
@Override
@SideOnly(Side.CLIENT)
2015-10-03 22:13:57 +02:00
public void updateScreen(int ticksElapsed){
if(ticksElapsed%10 == 0){
2015-11-15 18:14:39 +01:00
List<ItemStack> outputTwos = this.recipe.getRecipeOutputTwos();
2015-11-10 21:26:28 +01:00
if(this.recipePos+1 >= Math.max(this.recipe.getRecipeInputs().size(), Math.max(this.recipe.getRecipeOutputOnes().size(), outputTwos == null ? 0 : outputTwos.size()))){
this.recipePos = 0;
2015-10-03 22:13:57 +02:00
}
else{
2015-11-10 21:26:28 +01:00
this.recipePos++;
2015-10-03 22:13:57 +02:00
}
}
}
2016-02-01 17:49:55 +01:00
@Override
public ItemStack[] getItemStacksForPage(){
return this.recipe == null ? new ItemStack[0] : this.recipe.getRecipeOutputOnes().toArray(new ItemStack[this.recipe.getRecipeOutputOnes().size()]);
}
2015-08-29 23:01:13 +02:00
}