CraftTweaker

CraftTweaker

151M Downloads

Allow usage of == on IIngredient

freopt opened this issue ยท 1 comments

commented

Describe the feature you'd like

Doing something like

if (item == <minecraft:stone>) {}

gives an "operator not supported" error
I'm probably missing something

Describe alternatives you've considered

I tried to see if there was a toString function or something but I couldn't find anything

Additional context

No response

Minecraft version

1.12

Modloader

Forge

commented

You should be using matches to compare stacks

if <minecraft:stone>.matches(item) {}

That will check if the given item matches the first item using it as a template, so the ordering matters.

For example

var first = <minecraft:dirt>;
var second = <minecraft:dirt>.withTag({custom: "thing"});
var third = <minecraft:dirt> * 2;

print(first.matches(second)); // true because it checks with partial nbt (doesn't need to be exact, useful for renamed items).
print(first.matches(third)); // true because it checks if third's stacksize is more than first's.
print(third.matches(first)); // false because first's stacksize is smaller than third's
print(second.matches(first)); // false because first doesn't have any nbt.

first matches third because first has a stack size of 1, but third doesn't match first because third has a stack size of 2