mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user