Skip to content

Commit a33ac93

Browse files
Add Item.of(item, components) and Item.of(item, count, components)
...i could swear those used to be a thing
1 parent a9d47a1 commit a33ac93

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/main/java/dev/latvian/mods/kubejs/fluid/FluidWrapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,24 @@ static SizedFluidIngredient wrapSizedIngredient(Context cx, Object from) {
149149
.source(SourceLine.of(cx)));
150150
}
151151

152+
@Info("Returns a FluidStack of the input")
152153
static FluidStack of(FluidStack o) {
153154
return o;
154155
}
155156

157+
@Info("Returns a FluidStack of the input, with the specified amount")
156158
static FluidStack of(FluidStack o, int amount) {
157159
o.setAmount(amount);
158160
return o;
159161
}
160162

163+
@Info("Returns a FluidStack of the input, with the specified data components")
161164
static FluidStack of(FluidStack o, DataComponentMap components) {
162165
o.applyComponents(components);
163166
return o;
164167
}
165168

169+
@Info("Returns a FluidStack of the input, with the specified amount and data components")
166170
static FluidStack of(FluidStack o, int amount, DataComponentMap components) {
167171
o.setAmount(amount);
168172
o.applyComponents(components);

src/main/java/dev/latvian/mods/kubejs/plugin/builtin/wrapper/ItemWrapper.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import dev.latvian.mods.rhino.util.HideFromJS;
2727
import net.minecraft.Util;
2828
import net.minecraft.core.Holder;
29+
import net.minecraft.core.component.DataComponentMap;
2930
import net.minecraft.core.component.DataComponents;
3031
import net.minecraft.core.registries.BuiltInRegistries;
3132
import net.minecraft.nbt.StringTag;
@@ -102,11 +103,24 @@ static ItemStack of(ItemStack in) {
102103
return in;
103104
}
104105

106+
@Info("Returns an ItemStack of the input, with the specified data components")
107+
static ItemStack of(ItemStack in, DataComponentMap components) {
108+
in.applyComponents(components);
109+
return in;
110+
}
111+
105112
@Info("Returns an ItemStack of the input, with the specified count")
106113
static ItemStack of(ItemStack in, int count) {
107114
return in.kjs$withCount(count);
108115
}
109116

117+
@Info("Returns an ItemStack of the input, with the specified count and data components")
118+
static ItemStack of(ItemStack in, int count, DataComponentMap components) {
119+
in.setCount(count);
120+
in.applyComponents(components);
121+
return in;
122+
}
123+
110124
@HideFromJS
111125
private static ItemStack wrapTrivial(Context cx, @Nullable Object from) {
112126
while (from instanceof Wrapper w) {

0 commit comments

Comments
 (0)