2015-10-02 19:58:03 +02:00
|
|
|
/*
|
2015-12-30 22:02:15 +01:00
|
|
|
* This file ("NEICrusherRecipe.java") is part of the Actually Additions Mod for Minecraft.
|
2015-10-02 19:58:03 +02:00
|
|
|
* 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-10-02 19:58:03 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-01-03 16:05:51 +01:00
|
|
|
* © 2016 Ellpeck
|
2015-10-02 19:58:03 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.nei;
|
2015-10-02 19:58:03 +02:00
|
|
|
|
|
|
|
import codechicken.lib.gui.GuiDraw;
|
|
|
|
import codechicken.nei.PositionedStack;
|
|
|
|
import codechicken.nei.recipe.RecipeInfo;
|
|
|
|
import codechicken.nei.recipe.TemplateRecipeHandler;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
2016-01-05 14:57:50 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.BookletPage;
|
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.INEIRecipeHandler;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.booklet.BookletUtils;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiGrinder;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2015-10-02 19:58:03 +02:00
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-11-27 15:22:44 +01:00
|
|
|
public class NEICrusherRecipe extends TemplateRecipeHandler implements INEIRecipeHandler{
|
2015-10-02 19:58:03 +02:00
|
|
|
|
2015-11-27 15:22:44 +01:00
|
|
|
public NEICrusherRecipe(){
|
2015-10-02 19:58:03 +02:00
|
|
|
RecipeInfo.setGuiOffset(this.getGuiClass(), 0, 0);
|
|
|
|
}
|
|
|
|
|
2015-10-03 10:16:18 +02:00
|
|
|
@Override
|
2015-11-27 16:44:39 +01:00
|
|
|
public BookletPage getPageForInfo(int page){
|
|
|
|
return BookletUtils.getFirstPageForStack(new ItemStack(InitBlocks.blockGrinder));
|
2015-10-02 19:58:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadTransferRects(){
|
2015-12-03 20:15:07 +01:00
|
|
|
transferRects.add(new RecipeTransferRect(new Rectangle(80, 40, 24, 22), this.getBaseName()));
|
2015-10-02 19:58:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadCraftingRecipes(String outputId, Object... results){
|
2015-12-03 20:15:07 +01:00
|
|
|
if(outputId.equals(this.getBaseName()) && (getClass() == NEICrusherRecipe.class || getClass() == Double.class)){
|
2016-01-05 04:47:35 +01:00
|
|
|
for(CrusherRecipe recipe : ActuallyAdditionsAPI.crusherRecipes){
|
2015-10-03 21:56:22 +02:00
|
|
|
arecipes.add(new CachedCrush(recipe.getRecipeInputs(), recipe.getRecipeOutputOnes(), recipe.getRecipeOutputTwos(), recipe.outputTwoChance, this));
|
2015-10-02 19:58:03 +02:00
|
|
|
}
|
|
|
|
}
|
2015-10-03 10:16:18 +02:00
|
|
|
else{
|
|
|
|
super.loadCraftingRecipes(outputId, results);
|
|
|
|
}
|
2015-10-02 19:58:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadCraftingRecipes(ItemStack result){
|
2016-01-05 04:47:35 +01:00
|
|
|
for(CrusherRecipe recipe : ActuallyAdditionsAPI.crusherRecipes){
|
2015-10-03 21:56:22 +02:00
|
|
|
if(ItemUtil.contains(recipe.getRecipeOutputOnes(), result, true) || ItemUtil.contains(recipe.getRecipeOutputTwos(), result, true)){
|
|
|
|
arecipes.add(new CachedCrush(recipe.getRecipeInputs(), recipe.getRecipeOutputOnes(), recipe.getRecipeOutputTwos(), recipe.outputTwoChance, this));
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
2015-10-02 19:58:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadUsageRecipes(ItemStack ingredient){
|
2016-01-05 04:47:35 +01:00
|
|
|
for(CrusherRecipe recipe : ActuallyAdditionsAPI.crusherRecipes){
|
2015-10-03 21:56:22 +02:00
|
|
|
if(ItemUtil.contains(recipe.getRecipeInputs(), ingredient, true)){
|
|
|
|
CachedCrush theRecipe = new CachedCrush(recipe.getRecipeInputs(), recipe.getRecipeOutputOnes(), recipe.getRecipeOutputTwos(), recipe.outputTwoChance, this);
|
2015-10-02 19:58:03 +02:00
|
|
|
theRecipe.setIngredientPermutation(Collections.singletonList(theRecipe.ingredient), ingredient);
|
|
|
|
arecipes.add(theRecipe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getGuiTexture(){
|
|
|
|
return ModUtil.MOD_ID_LOWER+":textures/gui/guiGrinder.png";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-03 10:19:40 +02:00
|
|
|
public String getOverlayIdentifier(){
|
2015-12-03 20:15:07 +01:00
|
|
|
return this.getBaseName();
|
2015-10-02 19:58:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawExtras(int recipe){
|
|
|
|
drawProgressBar(80, 40, 176, 0, 24, 23, 48, 1);
|
|
|
|
this.drawChanceString(118, 73, recipe);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-03 10:19:40 +02:00
|
|
|
public Class<? extends GuiContainer> getGuiClass(){
|
|
|
|
return GuiGrinder.class;
|
2015-10-02 19:58:03 +02:00
|
|
|
}
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
|
|
|
public void drawBackground(int recipeIndex){
|
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
GuiDraw.changeTexture(getGuiTexture());
|
|
|
|
GuiDraw.drawTexturedModalRect(60, 13, 60, 13, 56, 79);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int recipiesPerPage(){
|
|
|
|
return 1;
|
2015-10-02 19:58:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void drawChanceString(int x, int y, int recipe){
|
|
|
|
CachedCrush crush = (CachedCrush)this.arecipes.get(recipe);
|
|
|
|
if(crush.resultTwo != null){
|
|
|
|
int secondChance = crush.secondChance;
|
|
|
|
String secondString = secondChance+"%";
|
|
|
|
GuiDraw.drawString(secondString, x, y, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false);
|
|
|
|
}
|
|
|
|
}
|
2015-10-03 10:16:18 +02:00
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
protected String getBaseName(){
|
2015-11-27 15:22:44 +01:00
|
|
|
return "actuallyadditions."+(this instanceof Double ? "crushingDouble" : "crushing");
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getRecipeName(){
|
2015-12-03 20:15:07 +01:00
|
|
|
return StringUtil.localize("container.nei."+this.getBaseName()+".name");
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
2015-11-27 15:22:44 +01:00
|
|
|
public static class Double extends NEICrusherRecipe{
|
2015-10-03 10:16:18 +02:00
|
|
|
|
|
|
|
@Override
|
2015-11-27 16:44:39 +01:00
|
|
|
public BookletPage getPageForInfo(int page){
|
|
|
|
return BookletUtils.getFirstPageForStack(new ItemStack(InitBlocks.blockGrinderDouble));
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadTransferRects(){
|
2015-12-03 20:15:07 +01:00
|
|
|
transferRects.add(new RecipeTransferRect(new Rectangle(51, 40, 24, 22), this.getBaseName()));
|
|
|
|
transferRects.add(new RecipeTransferRect(new Rectangle(101, 40, 24, 22), this.getBaseName()));
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
2015-10-03 22:13:57 +02:00
|
|
|
public String getGuiTexture(){
|
|
|
|
return ModUtil.MOD_ID_LOWER+":textures/gui/guiGrinderDouble.png";
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
2015-10-03 10:16:18 +02:00
|
|
|
@Override
|
2015-10-03 22:13:57 +02:00
|
|
|
public void drawExtras(int recipe){
|
|
|
|
drawProgressBar(51, 40, 176, 0, 24, 23, 48, 1);
|
|
|
|
this.drawChanceString(66, 93, recipe);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<? extends GuiContainer> getGuiClass(){
|
|
|
|
return GuiGrinder.GuiGrinderDouble.class;
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawBackground(int recipeIndex){
|
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
GuiDraw.changeTexture(getGuiTexture());
|
|
|
|
GuiDraw.drawTexturedModalRect(33, 20, 33, 20, 110, 70);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class CachedCrush extends CachedRecipe{
|
|
|
|
|
|
|
|
public PositionedStack ingredient;
|
|
|
|
public PositionedStack resultOne;
|
|
|
|
public PositionedStack resultTwo;
|
|
|
|
public int secondChance;
|
|
|
|
|
2015-11-27 15:22:44 +01:00
|
|
|
public CachedCrush(List<ItemStack> in, List<ItemStack> outOne, List<ItemStack> outTwo, int secondChance, NEICrusherRecipe handler){
|
|
|
|
boolean isDouble = handler instanceof Double;
|
2015-10-03 10:16:18 +02:00
|
|
|
this.ingredient = new PositionedStack(in, isDouble ? 51 : 80, 21);
|
2015-10-03 21:56:22 +02:00
|
|
|
this.resultOne = new PositionedStack(outOne, isDouble ? 38 : 66, 69);
|
|
|
|
if(outTwo != null && !outTwo.isEmpty()){
|
|
|
|
this.resultTwo = new PositionedStack(outTwo, isDouble ? 63 : 94, 69);
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
|
|
|
this.secondChance = secondChance;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-03 10:19:40 +02:00
|
|
|
public PositionedStack getResult(){
|
2015-10-03 21:56:22 +02:00
|
|
|
return null;
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-03 10:19:40 +02:00
|
|
|
public List<PositionedStack> getIngredients(){
|
2015-10-03 21:56:22 +02:00
|
|
|
return this.getCycledIngredients(cycleticks/48, Collections.singletonList(this.ingredient));
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<PositionedStack> getOtherStacks(){
|
|
|
|
ArrayList<PositionedStack> list = new ArrayList<PositionedStack>();
|
2015-10-03 21:56:22 +02:00
|
|
|
list.addAll(this.getCycledIngredients(cycleticks/48, Collections.singletonList(this.resultOne)));
|
2015-10-03 10:16:18 +02:00
|
|
|
if(this.resultTwo != null){
|
2015-10-03 21:56:22 +02:00
|
|
|
list.addAll(this.getCycledIngredients(cycleticks/48, Collections.singletonList(this.resultTwo)));
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|
2015-10-02 19:58:03 +02:00
|
|
|
}
|