Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit c51bee2

Browse files
Fix the wolf variants textures (#251)
* Fix the wolf varient in 1.21.4 being untextured * Fix the wolf variants in 1.20.6 - 1.21.3
1 parent 9d54c1c commit c51bee2

File tree

4 files changed

+77
-16
lines changed

4 files changed

+77
-16
lines changed

implementation_1_20_6/src/main/java/de/oliver/fancynpcs/v1_20_6/attributes/WolfAttributes.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,26 @@ private static void setAngry(Npc npc, String value) {
5656
Wolf wolf = ReflectionHelper.getEntity(npc);
5757

5858
boolean angry = Boolean.parseBoolean(value.toLowerCase());
59-
6059
wolf.setRemainingPersistentAngerTime(angry ? 100 : 0);
6160
}
6261

6362
private static void setVariant(Npc npc, String value) {
6463
Wolf wolf = ReflectionHelper.getEntity(npc);
6564

66-
Registry<WolfVariant> registry = wolf.level().registryAccess().registry(Registries.WOLF_VARIANT).get();
67-
WolfVariant variant = registry.get(ResourceLocation.of(value.toLowerCase(), ':'));
65+
Registry<WolfVariant> registry = (Registry<WolfVariant>) wolf.level().registryAccess().registryOrThrow(Registries.WOLF_VARIANT);
66+
67+
ResourceLocation variantLocation = ResourceLocation.tryParse("minecraft:" + value.toLowerCase());
68+
if (variantLocation == null) {
69+
System.out.println("Invalid variant name: " + value);
70+
return;
71+
}
6872

73+
WolfVariant variant = registry.get(variantLocation);
6974
if (variant != null) {
7075
wolf.setVariant(Holder.direct(variant));
76+
} else {
77+
System.out.println("Wolf variant not found: " + variantLocation);
7178
}
7279
}
80+
7381
}

implementation_1_21_1/src/main/java/de/oliver/fancynpcs/v1_21_1/attributes/WolfAttributes.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import de.oliver.fancynpcs.v1_21_1.ReflectionHelper;
66
import net.minecraft.core.Holder;
77
import net.minecraft.core.Registry;
8+
import net.minecraft.resources.ResourceKey;
89
import net.minecraft.core.registries.Registries;
910
import net.minecraft.resources.ResourceLocation;
1011
import net.minecraft.world.entity.animal.Wolf;
@@ -56,18 +57,38 @@ private static void setAngry(Npc npc, String value) {
5657
Wolf wolf = ReflectionHelper.getEntity(npc);
5758

5859
boolean angry = Boolean.parseBoolean(value.toLowerCase());
59-
6060
wolf.setRemainingPersistentAngerTime(angry ? 100 : 0);
6161
}
6262

6363
private static void setVariant(Npc npc, String value) {
6464
Wolf wolf = ReflectionHelper.getEntity(npc);
6565

66-
Registry<WolfVariant> registry = wolf.level().registryAccess().registry(Registries.WOLF_VARIANT).get();
67-
WolfVariant variant = registry.get(ResourceLocation.parse(value.toLowerCase()));
66+
Registry<?> anyRegistry = wolf.level().registryAccess().registryOrThrow(Registries.WOLF_VARIANT);
67+
Registry<WolfVariant> registry = (Registry<WolfVariant>) anyRegistry;
68+
69+
ResourceLocation variantLocation = ResourceLocation.tryParse("minecraft:" + value.toLowerCase());
70+
if (variantLocation == null) {
71+
System.out.println("Invalid variant name: " + value);
72+
return;
73+
}
6874

69-
if (variant != null) {
70-
wolf.setVariant(Holder.direct(variant));
75+
WolfVariant variant = registry.get(variantLocation);
76+
if (variant == null) {
77+
System.out.println("Wolf variant not found: " + variantLocation);
78+
return;
7179
}
80+
81+
// Try to get the registered key and use it to build a proper reference
82+
registry.getResourceKey(variant).ifPresentOrElse(
83+
key -> {
84+
// Create a bound reference using the registry + key (safe holder)
85+
Holder<WolfVariant> holder = registry.getHolderOrThrow(ResourceKey.create(Registries.WOLF_VARIANT, variantLocation));
86+
wolf.setVariant(holder);
87+
},
88+
() -> {
89+
System.out.println("Wolf variant key not found in registry, using direct holder (may be unsafe)");
90+
wolf.setVariant(Holder.direct(variant));
91+
}
92+
);
7293
}
7394
}

implementation_1_21_3/src/main/java/de/oliver/fancynpcs/v1_21_3/attributes/WolfAttributes.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,34 @@ private static void setAngry(Npc npc, String value) {
5656
Wolf wolf = ReflectionHelper.getEntity(npc);
5757

5858
boolean angry = Boolean.parseBoolean(value.toLowerCase());
59-
6059
wolf.setRemainingPersistentAngerTime(angry ? 100 : 0);
6160
}
6261

6362
private static void setVariant(Npc npc, String value) {
6463
Wolf wolf = ReflectionHelper.getEntity(npc);
6564

6665
Registry<WolfVariant> registry = wolf.level().registryAccess().lookupOrThrow(Registries.WOLF_VARIANT);
67-
WolfVariant variant = registry.getValue(ResourceLocation.parse(value.toLowerCase()));
6866

69-
if (variant != null) {
70-
wolf.setVariant(Holder.direct(variant));
67+
ResourceLocation variantLocation = ResourceLocation.tryParse("minecraft:" + value.toLowerCase());
68+
if (variantLocation == null) {
69+
System.out.println("Invalid variant name: " + value);
70+
return;
71+
}
72+
73+
WolfVariant variant = registry.getOptional(variantLocation).orElse(null);
74+
if (variant == null) {
75+
System.out.println("Wolf variant not found: " + variantLocation);
76+
return;
7177
}
78+
79+
// Get the ResourceKey from the registry
80+
registry.getResourceKey(variant).ifPresentOrElse(
81+
key -> {
82+
// Get the holder from the registry — this is properly bound
83+
Holder<WolfVariant> holder = registry.wrapAsHolder(variant);
84+
wolf.setVariant(holder);
85+
},
86+
() -> System.out.println("Wolf variant not registered: " + variantLocation)
87+
);
7288
}
7389
}

implementation_1_21_4/src/main/java/de/oliver/fancynpcs/v1_21_4/attributes/WolfAttributes.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,34 @@ private static void setAngry(Npc npc, String value) {
5656
Wolf wolf = ReflectionHelper.getEntity(npc);
5757

5858
boolean angry = Boolean.parseBoolean(value.toLowerCase());
59-
6059
wolf.setRemainingPersistentAngerTime(angry ? 100 : 0);
6160
}
6261

6362
private static void setVariant(Npc npc, String value) {
6463
Wolf wolf = ReflectionHelper.getEntity(npc);
6564

6665
Registry<WolfVariant> registry = wolf.level().registryAccess().lookupOrThrow(Registries.WOLF_VARIANT);
67-
WolfVariant variant = registry.getValue(ResourceLocation.parse(value.toLowerCase()));
6866

69-
if (variant != null) {
70-
wolf.setVariant(Holder.direct(variant));
67+
ResourceLocation variantLocation = ResourceLocation.tryParse("minecraft:" + value.toLowerCase());
68+
if (variantLocation == null) {
69+
System.out.println("Invalid variant name: " + value);
70+
return;
71+
}
72+
73+
WolfVariant variant = registry.getOptional(variantLocation).orElse(null);
74+
if (variant == null) {
75+
System.out.println("Wolf variant not found: " + variantLocation);
76+
return;
7177
}
78+
79+
// Get the ResourceKey from the registry
80+
registry.getResourceKey(variant).ifPresentOrElse(
81+
key -> {
82+
// Get the holder from the registry — this is properly bound
83+
Holder<WolfVariant> holder = registry.wrapAsHolder(variant);
84+
wolf.setVariant(holder);
85+
},
86+
() -> System.out.println("Wolf variant not registered: " + variantLocation)
87+
);
7288
}
7389
}

0 commit comments

Comments
 (0)