Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #1775 Add basic Compostable recipe category
- Loading branch information
Showing
8 changed files
with
168 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/mezz/jei/plugins/vanilla/compostable/CompostableRecipe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package mezz.jei.plugins.vanilla.compostable; | ||
|
||
import net.minecraft.world.item.ItemStack; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class CompostableRecipe { | ||
private final List<List<ItemStack>> inputs; | ||
private final float chance; | ||
|
||
public CompostableRecipe(ItemStack input, float chance) { | ||
this.inputs = Collections.singletonList(Collections.singletonList(input)); | ||
this.chance = chance; | ||
} | ||
|
||
public List<List<ItemStack>> getInputs() { | ||
return inputs; | ||
} | ||
|
||
public float getChance() { | ||
return chance; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
src/main/java/mezz/jei/plugins/vanilla/compostable/CompostableRecipeCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package mezz.jei.plugins.vanilla.compostable; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import mezz.jei.api.constants.VanillaRecipeCategoryUid; | ||
import mezz.jei.api.constants.VanillaTypes; | ||
import mezz.jei.api.gui.IRecipeLayout; | ||
import mezz.jei.api.gui.drawable.IDrawable; | ||
import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; | ||
import mezz.jei.api.helpers.IGuiHelper; | ||
import mezz.jei.api.ingredients.IIngredients; | ||
import mezz.jei.api.recipe.category.IRecipeCategory; | ||
import mezz.jei.util.Translator; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.Font; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.chat.TranslatableComponent; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.block.Blocks; | ||
|
||
public class CompostableRecipeCategory implements IRecipeCategory<CompostableRecipe> { | ||
private static final int inputSlot = 0; | ||
|
||
public static final int width = 120; | ||
public static final int height = 18; | ||
|
||
private final IDrawable background; | ||
private final IDrawable slot; | ||
private final IDrawable icon; | ||
private final Component localizedName; | ||
|
||
public CompostableRecipeCategory(IGuiHelper guiHelper) { | ||
background = guiHelper.createBlankDrawable(width, height); | ||
slot = guiHelper.getSlotDrawable(); | ||
icon = guiHelper.createDrawableIngredient(new ItemStack(Blocks.COMPOSTER)); | ||
localizedName = new TranslatableComponent("gui.jei.category.compostable"); | ||
} | ||
|
||
@Override | ||
public ResourceLocation getUid() { | ||
return VanillaRecipeCategoryUid.COMPOSTABLE; | ||
} | ||
|
||
@Override | ||
public Class<? extends CompostableRecipe> getRecipeClass() { | ||
return CompostableRecipe.class; | ||
} | ||
|
||
@Override | ||
public Component getTitle() { | ||
return localizedName; | ||
} | ||
|
||
@Override | ||
public IDrawable getBackground() { | ||
return background; | ||
} | ||
|
||
@Override | ||
public IDrawable getIcon() { | ||
return icon; | ||
} | ||
|
||
@Override | ||
public void setIngredients(CompostableRecipe recipe, IIngredients ingredients) { | ||
ingredients.setInputLists(VanillaTypes.ITEM, recipe.getInputs()); | ||
} | ||
|
||
@Override | ||
public void setRecipe(IRecipeLayout recipeLayout, CompostableRecipe recipe, IIngredients ingredients) { | ||
IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks(); | ||
guiItemStacks.init(inputSlot, true, 0, 0); | ||
guiItemStacks.set(ingredients); | ||
} | ||
|
||
@Override | ||
public void draw(CompostableRecipe recipe, PoseStack poseStack, double mouseX, double mouseY) { | ||
slot.draw(poseStack); | ||
|
||
float chance = recipe.getChance(); | ||
int chancePercent = (int) Math.floor(chance * 100); | ||
String text = Translator.translateToLocalFormatted("gui.jei.category.compostable.chance", chancePercent); | ||
|
||
Minecraft minecraft = Minecraft.getInstance(); | ||
Font font = minecraft.font; | ||
font.draw(poseStack, text, 24, 5, 0xFF808080); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/mezz/jei/plugins/vanilla/compostable/CompostableRecipeMaker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package mezz.jei.plugins.vanilla.compostable; | ||
|
||
import it.unimi.dsi.fastutil.objects.Object2FloatMap; | ||
import mezz.jei.api.constants.VanillaTypes; | ||
import mezz.jei.api.runtime.IIngredientManager; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.ItemLike; | ||
import net.minecraft.world.level.block.ComposterBlock; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
public class CompostableRecipeMaker { | ||
public static List<CompostableRecipe> getRecipes(IIngredientManager ingredientManager) { | ||
List<CompostableRecipe> recipes = new ArrayList<>(); | ||
Object2FloatMap<ItemLike> compostables = ComposterBlock.COMPOSTABLES; | ||
Collection<ItemStack> allItemStacks = ingredientManager.getAllIngredients(VanillaTypes.ITEM); | ||
for (ItemStack itemStack : allItemStacks) { | ||
Item item = itemStack.getItem(); | ||
float compostValue = compostables.getOrDefault(item, 0); | ||
if (compostValue > 0) { | ||
CompostableRecipe recipe = new CompostableRecipe(itemStack, compostValue); | ||
recipes.add(recipe); | ||
} | ||
} | ||
recipes.sort(Comparator.comparingDouble(CompostableRecipe::getChance)); | ||
return recipes; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/mezz/jei/plugins/vanilla/compostable/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@ParametersAreNonnullByDefault | ||
@FieldsAndMethodsAreNonnullByDefault | ||
package mezz.jei.plugins.vanilla.compostable; | ||
|
||
import mezz.jei.util.FieldsAndMethodsAreNonnullByDefault; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters