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

@@ -6,7 +6,9 @@ import de.oliver.fancynpcs.v1_19_4.ReflectionHelper;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.item.DyeColor;
import org.bukkit.entity.EntityType;
import org.checkerframework.checker.units.qual.N;
import java.util.ArrayList;
import java.util.Arrays;
@@ -33,6 +35,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;
}
@@ -61,4 +70,23 @@ public class CatAttributes {
}
}
private static void setCollarColor(Npc npc, String value){
final Cat cat = ReflectionHelper.getEntity(npc);
if (value.equalsIgnoreCase("none") || value.isEmpty()){
cat.setTame(false);
return;
}
try {
DyeColor color = DyeColor.valueOf(value.toUpperCase());
if (!cat.isTame()){
cat.setTame(true);
}
cat.setCollarColor(color);
} catch (IllegalArgumentException e){
System.out.print("Invalid Color: " + value);
}
}
}

View File

@@ -31,10 +31,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;
@@ -57,7 +57,7 @@ public class WolfAttributes {
wolf.setRemainingPersistentAngerTime(angry ? 100 : 0);
}
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()) {

View File

@@ -6,6 +6,7 @@ import de.oliver.fancynpcs.v1_20_1.ReflectionHelper;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.item.DyeColor;
import org.bukkit.entity.EntityType;
import java.util.ArrayList;
@@ -33,6 +34,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;
}
@@ -61,4 +69,23 @@ public class CatAttributes {
}
}
private static void setCollarColor(Npc npc, String value){
final Cat cat = ReflectionHelper.getEntity(npc);
if (value.equalsIgnoreCase("none") || value.isEmpty()){
cat.setTame(false);
return;
}
try {
DyeColor color = DyeColor.valueOf(value.toUpperCase());
if (!cat.isTame()){
cat.setTame(true);
}
cat.setCollarColor(color);
} catch (IllegalArgumentException e){
System.out.print("Invalid Color: " + value);
}
}
}

View File

@@ -30,10 +30,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;
@@ -56,7 +56,7 @@ public class WolfAttributes {
wolf.setRemainingPersistentAngerTime(angry ? 100 : 0);
}
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()) {

View File

@@ -5,6 +5,7 @@ import de.oliver.fancynpcs.api.NpcAttribute;
import de.oliver.fancynpcs.v1_20_2.ReflectionHelper;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.entity.animal.Cat;
import org.bukkit.entity.EntityType;
@@ -33,6 +34,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;
}
@@ -61,4 +69,23 @@ public class CatAttributes {
}
}
private static void setCollarColor(Npc npc, String value){
final Cat cat = ReflectionHelper.getEntity(npc);
if (value.equalsIgnoreCase("none") || value.isEmpty()){
cat.setTame(false);
return;
}
try {
DyeColor color = DyeColor.valueOf(value.toUpperCase());
if (!cat.isTame()){
cat.setTame(true);
}
cat.setCollarColor(color);
} catch (IllegalArgumentException e){
System.out.print("Invalid Color: " + value);
}
}
}

View File

@@ -30,10 +30,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;
@@ -56,7 +56,7 @@ public class WolfAttributes {
wolf.setRemainingPersistentAngerTime(angry ? 100 : 0);
}
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()) {

View File

@@ -6,6 +6,7 @@ import de.oliver.fancynpcs.v1_20_4.ReflectionHelper;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.item.DyeColor;
import org.bukkit.entity.EntityType;
import java.util.ArrayList;
@@ -33,6 +34,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;
}
@@ -61,4 +69,23 @@ public class CatAttributes {
}
}
private static void setCollarColor(Npc npc, String value){
final Cat cat = ReflectionHelper.getEntity(npc);
if (value.equalsIgnoreCase("none") || value.isEmpty()){
cat.setTame(false);
return;
}
try {
DyeColor color = DyeColor.valueOf(value.toUpperCase());
if (!cat.isTame()){
cat.setTame(true);
}
cat.setCollarColor(color);
} catch (IllegalArgumentException e){
System.out.print("Invalid Color: " + value);
}
}
}

View File

@@ -30,10 +30,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;
@@ -56,7 +56,7 @@ public class WolfAttributes {
wolf.setRemainingPersistentAngerTime(angry ? 100 : 0);
}
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()) {

View File

@@ -6,6 +6,7 @@ import de.oliver.fancynpcs.v1_20_6.ReflectionHelper;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.item.DyeColor;
import org.bukkit.entity.EntityType;
import java.util.ArrayList;
@@ -33,6 +34,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;
}
@@ -61,4 +69,23 @@ public class CatAttributes {
}
}
private static void setCollarColor(Npc npc, String value){
final Cat cat = ReflectionHelper.getEntity(npc);
if (value.equalsIgnoreCase("none") || value.isEmpty()){
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.print("Invalid Color: " + value);
}
}
}

View File

@@ -42,10 +42,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;
@@ -86,7 +86,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()) {

View File

@@ -6,6 +6,7 @@ import de.oliver.fancynpcs.v1_21_1.ReflectionHelper;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.item.DyeColor;
import org.bukkit.entity.EntityType;
import java.util.ArrayList;
@@ -30,6 +31,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;
}
@@ -58,4 +66,24 @@ public class CatAttributes {
}
}
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

@@ -43,10 +43,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;
@@ -100,7 +100,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()) {

View File

@@ -6,6 +6,7 @@ import de.oliver.fancynpcs.v1_21_3.ReflectionHelper;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.item.DyeColor;
import org.bukkit.entity.EntityType;
import java.util.ArrayList;
@@ -30,6 +31,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;
}
@@ -58,4 +66,25 @@ public class CatAttributes {
}
}
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

@@ -42,10 +42,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;
@@ -95,7 +95,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()) {

View File

@@ -6,6 +6,7 @@ import de.oliver.fancynpcs.v1_21_4.ReflectionHelper;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.item.DyeColor;
import org.bukkit.entity.EntityType;
import java.util.ArrayList;
@@ -30,6 +31,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;
}
@@ -58,4 +66,24 @@ public class CatAttributes {
}
}
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

@@ -43,10 +43,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;
@@ -96,7 +96,7 @@ public class WolfAttributes {
);
}
public static void setColor(Npc npc, String value) {
public static void setCollarColor(Npc npc, String value) {
Wolf wolf = ReflectionHelper.getEntity(npc); // NMS Wolf
if (value.equalsIgnoreCase("none") || value.isEmpty()) {

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()) {