-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathItemCost.java
78 lines (64 loc) · 3.07 KB
/
ItemCost.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package net.minecraft.world.item.trading;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import java.util.Optional;
import java.util.function.UnaryOperator;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponentHolder;
import net.minecraft.core.component.DataComponentPredicate;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.util.ExtraCodecs;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ItemLike;
public record ItemCost(Holder<Item> item, int count, DataComponentPredicate components, ItemStack itemStack) {
public static final Codec<ItemCost> CODEC = RecordCodecBuilder.create((var0) -> {
return var0.group(ItemStack.ITEM_NON_AIR_CODEC.fieldOf("id").forGetter(ItemCost::item), ExtraCodecs.POSITIVE_INT.fieldOf("count").orElse(1).forGetter(ItemCost::count), DataComponentPredicate.CODEC.optionalFieldOf("components", DataComponentPredicate.EMPTY).forGetter(ItemCost::components)).apply(var0, ItemCost::new);
});
public static final StreamCodec<RegistryFriendlyByteBuf, ItemCost> STREAM_CODEC;
public static final StreamCodec<RegistryFriendlyByteBuf, Optional<ItemCost>> OPTIONAL_STREAM_CODEC;
public ItemCost(ItemLike var1) {
this(var1, 1);
}
public ItemCost(ItemLike var1, int var2) {
this(var1.asItem().builtInRegistryHolder(), var2, DataComponentPredicate.EMPTY);
}
public ItemCost(Holder<Item> var1, int var2, DataComponentPredicate var3) {
this(var1, var2, var3, createStack(var1, var2, var3));
}
public ItemCost(Holder<Item> item, int count, DataComponentPredicate components, ItemStack itemStack) {
super();
this.item = item;
this.count = count;
this.components = components;
this.itemStack = itemStack;
}
public ItemCost withComponents(UnaryOperator<DataComponentPredicate.Builder> var1) {
return new ItemCost(this.item, this.count, ((DataComponentPredicate.Builder)var1.apply(DataComponentPredicate.builder())).build());
}
private static ItemStack createStack(Holder<Item> var0, int var1, DataComponentPredicate var2) {
return new ItemStack(var0, var1, var2.asPatch());
}
public boolean test(ItemStack var1) {
return var1.is(this.item) && this.components.test((DataComponentHolder)var1);
}
public Holder<Item> item() {
return this.item;
}
public int count() {
return this.count;
}
public DataComponentPredicate components() {
return this.components;
}
public ItemStack itemStack() {
return this.itemStack;
}
static {
STREAM_CODEC = StreamCodec.composite(ByteBufCodecs.holderRegistry(Registries.ITEM), ItemCost::item, ByteBufCodecs.VAR_INT, ItemCost::count, DataComponentPredicate.STREAM_CODEC, ItemCost::components, ItemCost::new);
OPTIONAL_STREAM_CODEC = STREAM_CODEC.apply(ByteBufCodecs::optional);
}
}