-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
140 additions
and
9 deletions.
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
54 changes: 54 additions & 0 deletions
54
Library/src/main/java/mezz/jei/library/ingredients/NormalizedTypedItemStack.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,54 @@ | ||
package mezz.jei.library.ingredients; | ||
|
||
import com.google.common.base.MoreObjects; | ||
import mezz.jei.api.constants.VanillaTypes; | ||
import mezz.jei.api.ingredients.IIngredientType; | ||
import mezz.jei.api.ingredients.ITypedIngredient; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.core.component.DataComponentPatch; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import java.util.Optional; | ||
|
||
public record NormalizedTypedItemStack( | ||
Holder<Item> itemHolder, | ||
DataComponentPatch dataComponentPatch | ||
) implements ITypedIngredient<ItemStack> { | ||
public static ITypedIngredient<ItemStack> create(ITypedIngredient<ItemStack> typedIngredient) { | ||
if (typedIngredient instanceof NormalizedTypedItemStack normalizedTypedItemStack) { | ||
return normalizedTypedItemStack; | ||
} else if (typedIngredient instanceof TypedItemStack typedItemStack) { | ||
return new NormalizedTypedItemStack(typedItemStack.itemHolder(), typedItemStack.dataComponentPatch()); | ||
} | ||
ItemStack itemStack = typedIngredient.getIngredient(); | ||
return new NormalizedTypedItemStack(itemStack.getItemHolder(), itemStack.getComponentsPatch()); | ||
} | ||
|
||
public static ITypedIngredient<ItemStack> create(ItemStack itemStack) { | ||
return new NormalizedTypedItemStack(itemStack.getItemHolder(), itemStack.getComponentsPatch()); | ||
} | ||
|
||
@Override | ||
public ItemStack getIngredient() { | ||
return new ItemStack(itemHolder, 1, dataComponentPatch); | ||
} | ||
|
||
@Override | ||
public Optional<ItemStack> getItemStack() { | ||
return Optional.of(getIngredient()); | ||
} | ||
|
||
@Override | ||
public IIngredientType<ItemStack> getType() { | ||
return VanillaTypes.ITEM_STACK; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("type", getType().getUid()) | ||
.add("ingredient", getIngredient()) | ||
.toString(); | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
Library/src/main/java/mezz/jei/library/ingredients/TypedItemStack.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,52 @@ | ||
package mezz.jei.library.ingredients; | ||
|
||
import com.google.common.base.MoreObjects; | ||
import mezz.jei.api.constants.VanillaTypes; | ||
import mezz.jei.api.ingredients.IIngredientType; | ||
import mezz.jei.api.ingredients.ITypedIngredient; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.core.component.DataComponentPatch; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import java.util.Optional; | ||
|
||
public record TypedItemStack( | ||
Holder<Item> itemHolder, | ||
DataComponentPatch dataComponentPatch, | ||
int count | ||
) implements ITypedIngredient<ItemStack> { | ||
public static ITypedIngredient<ItemStack> create(ItemStack ingredient) { | ||
if (ingredient.getCount() == 1) { | ||
return NormalizedTypedItemStack.create(ingredient); | ||
} | ||
return new TypedItemStack( | ||
ingredient.getItemHolder(), | ||
ingredient.getComponentsPatch(), | ||
ingredient.getCount() | ||
); | ||
} | ||
|
||
@Override | ||
public ItemStack getIngredient() { | ||
return new ItemStack(itemHolder, count, dataComponentPatch); | ||
} | ||
|
||
@Override | ||
public Optional<ItemStack> getItemStack() { | ||
return Optional.of(getIngredient()); | ||
} | ||
|
||
@Override | ||
public IIngredientType<ItemStack> getType() { | ||
return VanillaTypes.ITEM_STACK; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("type", getType().getUid()) | ||
.add("ingredient", getIngredient()) | ||
.toString(); | ||
} | ||
} |