-
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
7 changed files
with
200 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
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
34 changes: 34 additions & 0 deletions
34
Library/src/main/java/mezz/jei/library/ingredients/itemStacks/NormalizedTypedItem.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,34 @@ | ||
package mezz.jei.library.ingredients.itemStacks; | ||
|
||
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.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import java.util.Optional; | ||
|
||
record NormalizedTypedItem(Holder<Item> itemHolder) implements ITypedIngredient<ItemStack> { | ||
@Override | ||
public ItemStack getIngredient() { | ||
return new ItemStack(itemHolder); | ||
} | ||
|
||
@Override | ||
public Optional<ItemStack> getItemStack() { | ||
return Optional.of(getIngredient()); | ||
} | ||
|
||
@Override | ||
public IIngredientType<ItemStack> getType() { | ||
return VanillaTypes.ITEM_STACK; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SimpleItemStack{" + | ||
"itemHolder=" + itemHolder + | ||
'}'; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
Library/src/main/java/mezz/jei/library/ingredients/itemStacks/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,71 @@ | ||
package mezz.jei.library.ingredients.itemStacks; | ||
|
||
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> normalize(ITypedIngredient<ItemStack> typedIngredient) { | ||
switch (typedIngredient) { | ||
case NormalizedTypedItemStack normalized -> { | ||
return normalized; | ||
} | ||
case NormalizedTypedItem normalized -> { | ||
return normalized; | ||
} | ||
case TypedItemStack typedItemStack -> { | ||
return create(typedItemStack.itemHolder(), typedItemStack.dataComponentPatch()); | ||
} | ||
default -> { | ||
ItemStack itemStack = typedIngredient.getIngredient(); | ||
return create(itemStack.getItemHolder(), itemStack.getComponentsPatch()); | ||
} | ||
} | ||
} | ||
|
||
public static ITypedIngredient<ItemStack> create(Holder<Item> itemHolder, DataComponentPatch dataComponentPatch) { | ||
if (dataComponentPatch.isEmpty()) { | ||
return new NormalizedTypedItem(itemHolder); | ||
} | ||
return new NormalizedTypedItemStack(itemHolder, dataComponentPatch); | ||
} | ||
|
||
public static ITypedIngredient<ItemStack> create(ItemStack itemStack) { | ||
return create( | ||
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 "NormalizedTypedItemStack{" + | ||
"itemHolder=" + itemHolder + | ||
", dataComponentPatch=" + dataComponentPatch + | ||
'}'; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
Library/src/main/java/mezz/jei/library/ingredients/itemStacks/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.itemStacks; | ||
|
||
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 "TypedItemStack{" + | ||
"itemHolder=" + itemHolder + | ||
", dataComponentPatch=" + dataComponentPatch + | ||
", count=" + count + | ||
'}'; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
Library/src/main/java/mezz/jei/library/ingredients/itemStacks/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 | ||
@MethodsReturnNonnullByDefault | ||
package mezz.jei.library.ingredients.itemStacks; | ||
|
||
import net.minecraft.MethodsReturnNonnullByDefault; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |