fn: Add Cat Collars (#20)

* Add Collar Colors!

* fancynpcs: Add cat collar colors *meow*

* fancynpcs: Add issue with color not existing on 1.20.6

* fancynpcs: Fixed Color - CollarColor for clarity and consistancy!

* fancynpcs: Fix missed 1.21.1 change

---------

Co-authored-by: Clove Twilight <admin@mazeymoos.com>
This commit is contained in:
Clove Twilight
2025-04-01 19:10:46 +01:00
committed by GitHub
parent f093f125d5
commit 8303c89c36
18 changed files with 276 additions and 27 deletions

View File

@@ -11,6 +11,7 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.entity.animal.CatVariant;
import net.minecraft.world.item.DyeColor;
import org.bukkit.entity.EntityType;
import java.util.ArrayList;
@@ -38,6 +39,13 @@ public class CatAttributes {
CatAttributes::setPose
));
attributes.add(new NpcAttribute(
"collar_color",
List.of("RED", "BLUE", "YELLOW", "GREEN", "PURPLE", "ORANGE", "LIME", "MAGENTA", "BROWN", "WHITE", "GRAY", "LIGHT_GRAY", "LIGHT_BLUE", "BLACK", "CYAN", "PINK", "NONE"),
List.of(EntityType.CAT),
CatAttributes::setCollarColor
));
return attributes;
}
@@ -79,4 +87,24 @@ public class CatAttributes {
.lookup(Registries.CAT_VARIANT)
.orElseThrow();
}
private static void setCollarColor(Npc npc, String value) {
Cat cat = ReflectionHelper.getEntity(npc);
if (value.equalsIgnoreCase("none") || value.isEmpty()) {
// Reset to no collar
cat.setTame(false, false);
return;
}
try {
DyeColor color = DyeColor.valueOf(value.toUpperCase());
if (!cat.isTame()){
cat.setTame(true, false);
}
cat.setCollarColor(color);
} catch (IllegalArgumentException e) {
System.out.println("Invalid cat collar color: " + value);
}
}
}

View File

@@ -47,10 +47,10 @@ public class WolfAttributes {
));
attributes.add(new NpcAttribute(
"color",
"collar_color",
List.of("RED", "BLUE", "YELLOW", "GREEN", "PURPLE", "ORANGE", "LIME", "MAGENTA", "BROWN", "WHITE", "GRAY", "LIGHT_GRAY", "LIGHT_BLUE", "BLACK", "CYAN", "PINK", "NONE"),
List.of(EntityType.WOLF),
WolfAttributes::setColor
WolfAttributes::setCollarColor
));
return attributes;
@@ -101,7 +101,7 @@ public class WolfAttributes {
);
}
private static void setColor(Npc npc, String value) {
private static void setCollarColor(Npc npc, String value) {
Wolf wolf = ReflectionHelper.getEntity(npc);
if (value.equalsIgnoreCase("none") || value.isEmpty()) {