Skip to content

Commit

Permalink
improve: show the conditions for catalysts (Snownee#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
SettingDust committed Mar 27, 2024
1 parent 6db02e2 commit c1a3e13
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/main/java/snownee/lychee/compat/rei/REICompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.ItemLike;

import org.jetbrains.annotations.NotNull;

import snownee.lychee.Lychee;
import snownee.lychee.LycheeTags;
import snownee.lychee.RecipeTypes;
Expand Down Expand Up @@ -274,7 +277,7 @@ public Rectangle getBounds() {
}

@Override
public List<? extends GuiEventListener> children() {
public @NotNull List<? extends GuiEventListener> children() {
return Collections.emptyList();
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/snownee/lychee/core/post/input/DamageItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -109,16 +110,18 @@ public boolean canRepeat() {

@Override
public void validate(ILycheeRecipe<?> recipe, ILycheeRecipe.NBTPatchContext patchContext) {
Preconditions.checkArgument(recipe.getItemIndexes(target).size() > 0, "No target found for %s", target);
Preconditions.checkArgument(!recipe.getItemIndexes(target).isEmpty(), "No target found for %s", target);
}

@Override
public void loadCatalystsInfo(ILycheeRecipe<?> recipe, List<IngredientInfo> ingredients) {
String key = CommonProxy.makeDescriptionId("postAction", getType().getRegistryName());
Component component = Component.translatable(key, damage).withStyle(ChatFormatting.YELLOW);
Minecraft mc = Minecraft.getInstance();
recipe.getItemIndexes(target).forEach(i -> {
IngredientInfo info = ingredients.get(i);
info.addTooltip(component);
getConditionTooltips(info.tooltips, 0, mc.level, mc.player);
info.isCatalyst = true;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.google.gson.JsonObject;

import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf;
import snownee.lychee.PostActionTypes;
import snownee.lychee.compat.IngredientInfo;
Expand Down Expand Up @@ -39,13 +40,13 @@ public boolean isHidden() {
@Override
public void loadCatalystsInfo(ILycheeRecipe<?> recipe, List<IngredientInfo> ingredients) {
if (recipe instanceof LycheeRecipe<?> lycheeRecipe && lycheeRecipe.getType().canPreventConsumeInputs) {
Minecraft mc = Minecraft.getInstance();
for (var ingredient : ingredients) {
if (!ingredient.tooltips.isEmpty()) {
continue;
}
if (getConditions().isEmpty()) {
ingredient.addTooltip(lycheeRecipe.getType().getPreventDefaultDescription(lycheeRecipe));
}
ingredient.addTooltip(lycheeRecipe.getType().getPreventDefaultDescription(lycheeRecipe));
getConditionTooltips(ingredient.tooltips, 0, mc.level, mc.player);
ingredient.isCatalyst = true;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/data/lychee/recipes/damage_item.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
"post": [
{
"type": "damage_item",
"target": "/item_in/0"
"target": "/item_in/0",
"contextual": {
"type": "chance",
"chance": 0.5
}
},
{
"type": "set_item",
Expand Down

0 comments on commit c1a3e13

Please sign in to comment.