mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
fancynpcs: Add collar colors (#19)
Co-authored-by: Clove Twilight <admin@mazeymoos.com>
This commit is contained in:
@@ -4,6 +4,8 @@ import de.oliver.fancynpcs.api.Npc;
|
|||||||
import de.oliver.fancynpcs.api.NpcAttribute;
|
import de.oliver.fancynpcs.api.NpcAttribute;
|
||||||
import de.oliver.fancynpcs.v1_19_4.ReflectionHelper;
|
import de.oliver.fancynpcs.v1_19_4.ReflectionHelper;
|
||||||
import net.minecraft.world.entity.animal.Wolf;
|
import net.minecraft.world.entity.animal.Wolf;
|
||||||
|
import org.apache.commons.io.IOExceptionList;
|
||||||
|
import net.minecraft.world.item.DyeColor;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -28,6 +30,13 @@ public class WolfAttributes {
|
|||||||
WolfAttributes::setAngry
|
WolfAttributes::setAngry
|
||||||
));
|
));
|
||||||
|
|
||||||
|
attributes.add(new NpcAttribute(
|
||||||
|
"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
|
||||||
|
));
|
||||||
|
|
||||||
return attributes;
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,4 +56,24 @@ public class WolfAttributes {
|
|||||||
|
|
||||||
wolf.setRemainingPersistentAngerTime(angry ? 100 : 0);
|
wolf.setRemainingPersistentAngerTime(angry ? 100 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setColor(Npc npc, String value) {
|
||||||
|
Wolf wolf = ReflectionHelper.getEntity(npc);
|
||||||
|
|
||||||
|
if (value.equalsIgnoreCase("none") || value.isEmpty()) {
|
||||||
|
// Reset to no collar
|
||||||
|
wolf.setTame(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DyeColor color = DyeColor.valueOf(value.toUpperCase());
|
||||||
|
if (!wolf.isTame()){
|
||||||
|
wolf.setTame(true);
|
||||||
|
}
|
||||||
|
wolf.setCollarColor(color);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.out.println("Invalid wolf collar color: " + value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import de.oliver.fancynpcs.api.Npc;
|
|||||||
import de.oliver.fancynpcs.api.NpcAttribute;
|
import de.oliver.fancynpcs.api.NpcAttribute;
|
||||||
import de.oliver.fancynpcs.v1_20_1.ReflectionHelper;
|
import de.oliver.fancynpcs.v1_20_1.ReflectionHelper;
|
||||||
import net.minecraft.world.entity.animal.Wolf;
|
import net.minecraft.world.entity.animal.Wolf;
|
||||||
|
import net.minecraft.world.item.DyeColor;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -28,6 +29,13 @@ public class WolfAttributes {
|
|||||||
WolfAttributes::setAngry
|
WolfAttributes::setAngry
|
||||||
));
|
));
|
||||||
|
|
||||||
|
attributes.add(new NpcAttribute(
|
||||||
|
"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
|
||||||
|
));
|
||||||
|
|
||||||
return attributes;
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,4 +55,24 @@ public class WolfAttributes {
|
|||||||
|
|
||||||
wolf.setRemainingPersistentAngerTime(angry ? 100 : 0);
|
wolf.setRemainingPersistentAngerTime(angry ? 100 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setColor(Npc npc, String value) {
|
||||||
|
Wolf wolf = ReflectionHelper.getEntity(npc);
|
||||||
|
|
||||||
|
if (value.equalsIgnoreCase("none") || value.isEmpty()) {
|
||||||
|
// Reset to no collar
|
||||||
|
wolf.setTame(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DyeColor color = DyeColor.valueOf(value.toUpperCase());
|
||||||
|
if (!wolf.isTame()){
|
||||||
|
wolf.setTame(true);
|
||||||
|
}
|
||||||
|
wolf.setCollarColor(color);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.out.println("Invalid wolf collar color: " + value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import de.oliver.fancynpcs.api.Npc;
|
|||||||
import de.oliver.fancynpcs.api.NpcAttribute;
|
import de.oliver.fancynpcs.api.NpcAttribute;
|
||||||
import de.oliver.fancynpcs.v1_20_2.ReflectionHelper;
|
import de.oliver.fancynpcs.v1_20_2.ReflectionHelper;
|
||||||
import net.minecraft.world.entity.animal.Wolf;
|
import net.minecraft.world.entity.animal.Wolf;
|
||||||
|
import net.minecraft.world.item.DyeColor;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -28,6 +29,13 @@ public class WolfAttributes {
|
|||||||
WolfAttributes::setAngry
|
WolfAttributes::setAngry
|
||||||
));
|
));
|
||||||
|
|
||||||
|
attributes.add(new NpcAttribute(
|
||||||
|
"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
|
||||||
|
));
|
||||||
|
|
||||||
return attributes;
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,4 +55,24 @@ public class WolfAttributes {
|
|||||||
|
|
||||||
wolf.setRemainingPersistentAngerTime(angry ? 100 : 0);
|
wolf.setRemainingPersistentAngerTime(angry ? 100 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setColor(Npc npc, String value) {
|
||||||
|
Wolf wolf = ReflectionHelper.getEntity(npc);
|
||||||
|
|
||||||
|
if (value.equalsIgnoreCase("none") || value.isEmpty()) {
|
||||||
|
// Reset to no collar
|
||||||
|
wolf.setTame(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DyeColor color = DyeColor.valueOf(value.toUpperCase());
|
||||||
|
if (!wolf.isTame()){
|
||||||
|
wolf.setTame(true);
|
||||||
|
}
|
||||||
|
wolf.setCollarColor(color);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.out.println("Invalid wolf collar color: " + value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import de.oliver.fancynpcs.api.Npc;
|
|||||||
import de.oliver.fancynpcs.api.NpcAttribute;
|
import de.oliver.fancynpcs.api.NpcAttribute;
|
||||||
import de.oliver.fancynpcs.v1_20_4.ReflectionHelper;
|
import de.oliver.fancynpcs.v1_20_4.ReflectionHelper;
|
||||||
import net.minecraft.world.entity.animal.Wolf;
|
import net.minecraft.world.entity.animal.Wolf;
|
||||||
|
import net.minecraft.world.item.DyeColor;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -28,6 +29,13 @@ public class WolfAttributes {
|
|||||||
WolfAttributes::setAngry
|
WolfAttributes::setAngry
|
||||||
));
|
));
|
||||||
|
|
||||||
|
attributes.add(new NpcAttribute(
|
||||||
|
"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
|
||||||
|
));
|
||||||
|
|
||||||
return attributes;
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,4 +55,24 @@ public class WolfAttributes {
|
|||||||
|
|
||||||
wolf.setRemainingPersistentAngerTime(angry ? 100 : 0);
|
wolf.setRemainingPersistentAngerTime(angry ? 100 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setColor(Npc npc, String value) {
|
||||||
|
Wolf wolf = ReflectionHelper.getEntity(npc);
|
||||||
|
|
||||||
|
if (value.equalsIgnoreCase("none") || value.isEmpty()) {
|
||||||
|
// Reset to no collar
|
||||||
|
wolf.setTame(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DyeColor color = DyeColor.valueOf(value.toUpperCase());
|
||||||
|
if (!wolf.isTame()){
|
||||||
|
wolf.setTame(true);
|
||||||
|
}
|
||||||
|
wolf.setCollarColor(color);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.out.println("Invalid wolf collar color: " + value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import net.minecraft.core.registries.Registries;
|
|||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.animal.Wolf;
|
import net.minecraft.world.entity.animal.Wolf;
|
||||||
import net.minecraft.world.entity.animal.WolfVariant;
|
import net.minecraft.world.entity.animal.WolfVariant;
|
||||||
|
import net.minecraft.world.item.DyeColor;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -40,6 +41,13 @@ public class WolfAttributes {
|
|||||||
WolfAttributes::setVariant
|
WolfAttributes::setVariant
|
||||||
));
|
));
|
||||||
|
|
||||||
|
attributes.add(new NpcAttribute(
|
||||||
|
"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
|
||||||
|
));
|
||||||
|
|
||||||
return attributes;
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,4 +86,24 @@ public class WolfAttributes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setColor(Npc npc, String value) {
|
||||||
|
Wolf wolf = ReflectionHelper.getEntity(npc);
|
||||||
|
|
||||||
|
if (value.equalsIgnoreCase("none") || value.isEmpty()) {
|
||||||
|
// Reset to no collar
|
||||||
|
wolf.setTame(false, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DyeColor color = DyeColor.valueOf(value.toUpperCase());
|
||||||
|
if (!wolf.isTame()){
|
||||||
|
wolf.setTame(true, false);
|
||||||
|
}
|
||||||
|
wolf.setCollarColor(color);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.out.println("Invalid wolf collar color: " + value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import net.minecraft.core.registries.Registries;
|
|||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.animal.Wolf;
|
import net.minecraft.world.entity.animal.Wolf;
|
||||||
import net.minecraft.world.entity.animal.WolfVariant;
|
import net.minecraft.world.entity.animal.WolfVariant;
|
||||||
|
import net.minecraft.world.item.DyeColor;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -41,6 +42,13 @@ public class WolfAttributes {
|
|||||||
WolfAttributes::setVariant
|
WolfAttributes::setVariant
|
||||||
));
|
));
|
||||||
|
|
||||||
|
attributes.add(new NpcAttribute(
|
||||||
|
"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
|
||||||
|
));
|
||||||
|
|
||||||
return attributes;
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,4 +99,24 @@ public class WolfAttributes {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setColor(Npc npc, String value) {
|
||||||
|
Wolf wolf = ReflectionHelper.getEntity(npc);
|
||||||
|
|
||||||
|
if (value.equalsIgnoreCase("none") || value.isEmpty()) {
|
||||||
|
// Reset to no collar
|
||||||
|
wolf.setTame(false, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DyeColor color = DyeColor.valueOf(value.toUpperCase());
|
||||||
|
if (!wolf.isTame()){
|
||||||
|
wolf.setTame(true, false);
|
||||||
|
}
|
||||||
|
wolf.setCollarColor(color);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.out.println("Invalid wolf collar color: " + value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package de.oliver.fancynpcs.v1_21_3.attributes;
|
|||||||
import de.oliver.fancynpcs.api.Npc;
|
import de.oliver.fancynpcs.api.Npc;
|
||||||
import de.oliver.fancynpcs.api.NpcAttribute;
|
import de.oliver.fancynpcs.api.NpcAttribute;
|
||||||
import de.oliver.fancynpcs.v1_21_3.ReflectionHelper;
|
import de.oliver.fancynpcs.v1_21_3.ReflectionHelper;
|
||||||
|
import net.minecraft.world.item.DyeColor;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
@@ -40,6 +41,13 @@ public class WolfAttributes {
|
|||||||
WolfAttributes::setVariant
|
WolfAttributes::setVariant
|
||||||
));
|
));
|
||||||
|
|
||||||
|
attributes.add(new NpcAttribute(
|
||||||
|
"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
|
||||||
|
));
|
||||||
|
|
||||||
return attributes;
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,4 +94,24 @@ public class WolfAttributes {
|
|||||||
() -> System.out.println("Wolf variant not registered: " + variantLocation)
|
() -> System.out.println("Wolf variant not registered: " + variantLocation)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setColor(Npc npc, String value) {
|
||||||
|
Wolf wolf = ReflectionHelper.getEntity(npc);
|
||||||
|
|
||||||
|
if (value.equalsIgnoreCase("none") || value.isEmpty()) {
|
||||||
|
// Reset to no collar
|
||||||
|
wolf.setTame(false, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DyeColor color = DyeColor.valueOf(value.toUpperCase());
|
||||||
|
if (!wolf.isTame()){
|
||||||
|
wolf.setTame(true, false);
|
||||||
|
}
|
||||||
|
wolf.setCollarColor(color);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.out.println("Invalid wolf collar color: " + value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,11 @@ import net.minecraft.core.Holder;
|
|||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.entity.Relative;
|
||||||
import net.minecraft.world.entity.animal.Wolf;
|
import net.minecraft.world.entity.animal.Wolf;
|
||||||
import net.minecraft.world.entity.animal.WolfVariant;
|
import net.minecraft.world.entity.animal.WolfVariant;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import net.minecraft.world.item.DyeColor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -40,6 +42,13 @@ public class WolfAttributes {
|
|||||||
WolfAttributes::setVariant
|
WolfAttributes::setVariant
|
||||||
));
|
));
|
||||||
|
|
||||||
|
attributes.add(new NpcAttribute(
|
||||||
|
"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
|
||||||
|
));
|
||||||
|
|
||||||
return attributes;
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,4 +95,22 @@ public class WolfAttributes {
|
|||||||
() -> System.out.println("Wolf variant not registered: " + variantLocation)
|
() -> System.out.println("Wolf variant not registered: " + variantLocation)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setColor(Npc npc, String value) {
|
||||||
|
Wolf wolf = ReflectionHelper.getEntity(npc); // NMS Wolf
|
||||||
|
|
||||||
|
if (value.equalsIgnoreCase("none") || value.isEmpty()) {
|
||||||
|
// Untame to remove collar
|
||||||
|
wolf.setTame(false, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DyeColor color = DyeColor.valueOf(value.toUpperCase()); // NMS enum
|
||||||
|
wolf.setTame(true, false); // Wolves need to be tamed for collar color to show
|
||||||
|
wolf.setCollarColor(color);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.out.println("Invalid color for wolf collar: " + value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,10 @@ import de.oliver.fancynpcs.api.NpcAttribute;
|
|||||||
import de.oliver.fancynpcs.v1_21_5.ReflectionHelper;
|
import de.oliver.fancynpcs.v1_21_5.ReflectionHelper;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.core.HolderLookup;
|
import net.minecraft.core.HolderLookup;
|
||||||
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.data.registries.VanillaRegistries;
|
import net.minecraft.data.registries.VanillaRegistries;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.world.item.DyeColor;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.animal.wolf.Wolf;
|
import net.minecraft.world.entity.animal.wolf.Wolf;
|
||||||
import net.minecraft.world.entity.animal.wolf.WolfVariant;
|
import net.minecraft.world.entity.animal.wolf.WolfVariant;
|
||||||
@@ -45,6 +46,13 @@ public class WolfAttributes {
|
|||||||
WolfAttributes::setVariant
|
WolfAttributes::setVariant
|
||||||
));
|
));
|
||||||
|
|
||||||
|
attributes.add(new NpcAttribute(
|
||||||
|
"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
|
||||||
|
));
|
||||||
|
|
||||||
return attributes;
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,14 +76,49 @@ public class WolfAttributes {
|
|||||||
private static void setVariant(Npc npc, String value) {
|
private static void setVariant(Npc npc, String value) {
|
||||||
Wolf wolf = ReflectionHelper.getEntity(npc);
|
Wolf wolf = ReflectionHelper.getEntity(npc);
|
||||||
|
|
||||||
Holder<WolfVariant> variant = getWolfVariantRegistry()
|
Registry<WolfVariant> registry = wolf.level().registryAccess().lookupOrThrow(Registries.WOLF_VARIANT);
|
||||||
.get(ResourceKey.create(
|
|
||||||
Registries.WOLF_VARIANT,
|
|
||||||
ResourceLocation.withDefaultNamespace(value.toLowerCase())
|
|
||||||
))
|
|
||||||
.orElseThrow();
|
|
||||||
|
|
||||||
wolf.setVariant(variant);
|
ResourceLocation variantLocation = ResourceLocation.tryParse("minecraft:" + value.toLowerCase());
|
||||||
|
if (variantLocation == null) {
|
||||||
|
System.out.println("Invalid variant name: " + value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
WolfVariant variant = registry.getOptional(variantLocation).orElse(null);
|
||||||
|
if (variant == null) {
|
||||||
|
System.out.println("Wolf variant not found: " + variantLocation);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the ResourceKey from the registry
|
||||||
|
registry.getResourceKey(variant).ifPresentOrElse(
|
||||||
|
key -> {
|
||||||
|
// Get the holder from the registry — this is properly bound
|
||||||
|
Holder<WolfVariant> holder = registry.wrapAsHolder(variant);
|
||||||
|
wolf.setVariant(holder);
|
||||||
|
},
|
||||||
|
() -> System.out.println("Wolf variant not registered: " + variantLocation)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setColor(Npc npc, String value) {
|
||||||
|
Wolf wolf = ReflectionHelper.getEntity(npc);
|
||||||
|
|
||||||
|
if (value.equalsIgnoreCase("none") || value.isEmpty()) {
|
||||||
|
// Reset to no collar
|
||||||
|
wolf.setTame(false, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DyeColor color = DyeColor.valueOf(value.toUpperCase());
|
||||||
|
if (!wolf.isTame()){
|
||||||
|
wolf.setTame(true, false);
|
||||||
|
}
|
||||||
|
wolf.setCollarColor(color);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.out.println("Invalid wolf collar color: " + value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HolderLookup.RegistryLookup<WolfVariant> getWolfVariantRegistry() {
|
private static HolderLookup.RegistryLookup<WolfVariant> getWolfVariantRegistry() {
|
||||||
|
|||||||
Reference in New Issue
Block a user