Skip to content

Commit d3a3b53

Browse files
fancynpcs: Fix cat variant attribute for 1.21.5
1 parent 4a3d030 commit d3a3b53

1 file changed

Lines changed: 22 additions & 17 deletions

File tree

  • plugins/fancynpcs/implementation_1_21_5/src/main/java/de/oliver/fancynpcs/v1_21_5/attributes

plugins/fancynpcs/implementation_1_21_5/src/main/java/de/oliver/fancynpcs/v1_21_5/attributes/CatAttributes.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import net.minecraft.core.Holder;
77
import net.minecraft.core.HolderLookup;
88
import net.minecraft.core.registries.Registries;
9-
import net.minecraft.data.registries.VanillaRegistries;
109
import net.minecraft.resources.ResourceKey;
1110
import net.minecraft.resources.ResourceLocation;
1211
import net.minecraft.world.entity.animal.Cat;
1312
import net.minecraft.world.entity.animal.CatVariant;
1413
import net.minecraft.world.item.DyeColor;
14+
import net.minecraft.world.level.Level;
1515
import org.bukkit.entity.EntityType;
1616

1717
import java.util.ArrayList;
@@ -24,10 +24,19 @@ public static List<NpcAttribute> getAllAttributes() {
2424

2525
attributes.add(new NpcAttribute(
2626
"variant",
27-
getCatVariantRegistry()
28-
.listElementIds()
29-
.map(id -> id.location().getPath())
30-
.toList(),
27+
List.of(
28+
"tabby",
29+
"black",
30+
"red",
31+
"siamese",
32+
"british_shorthair",
33+
"calico",
34+
"persian",
35+
"ragdoll",
36+
"white",
37+
"jellie",
38+
"all_black"
39+
),
3140
List.of(EntityType.CAT),
3241
CatAttributes::setVariant
3342
));
@@ -52,12 +61,11 @@ public static List<NpcAttribute> getAllAttributes() {
5261
private static void setVariant(Npc npc, String value) {
5362
final Cat cat = ReflectionHelper.getEntity(npc);
5463

55-
Holder<CatVariant> variant = getCatVariantRegistry()
56-
.get(ResourceKey.create(
57-
Registries.CAT_VARIANT,
58-
ResourceLocation.withDefaultNamespace(value.toLowerCase())
59-
))
60-
.orElseThrow();
64+
HolderLookup.RegistryLookup<CatVariant> registry = getCatVariantRegistry(cat.level());
65+
Holder.Reference<CatVariant> variant = registry.get(ResourceKey.create(
66+
Registries.CAT_VARIANT,
67+
ResourceLocation.withDefaultNamespace(value.toLowerCase())
68+
)).orElseThrow();
6169

6270
cat.setVariant(variant);
6371
}
@@ -81,11 +89,8 @@ private static void setPose(Npc npc, String value) {
8189
}
8290
}
8391

84-
private static HolderLookup.RegistryLookup<CatVariant> getCatVariantRegistry() {
85-
return VanillaRegistries
86-
.createLookup()
87-
.lookup(Registries.CAT_VARIANT)
88-
.orElseThrow();
92+
private static HolderLookup.RegistryLookup<CatVariant> getCatVariantRegistry(Level world) {
93+
return world.registryAccess().lookup(Registries.CAT_VARIANT).orElseThrow();
8994
}
9095

9196
private static void setCollarColor(Npc npc, String value) {
@@ -99,7 +104,7 @@ private static void setCollarColor(Npc npc, String value) {
99104

100105
try {
101106
DyeColor color = DyeColor.valueOf(value.toUpperCase());
102-
if (!cat.isTame()){
107+
if (!cat.isTame()) {
103108
cat.setTame(true, false);
104109
}
105110
cat.setCollarColor(color);

0 commit comments

Comments
 (0)