#How can I set the variant and collar color of a WolfEntity?

28 messages · Page 1 of 1 (latest)

hushed whale
#

Hey! I'm trying to set the variant of a WolfEntity, and I don't know how to get the RegistryEntry<WolfVariant> that it's asking for.
I have been able to get the RegistryKey<WolfVariant> from the WolfVariants class, such as WolfVariants.ASHEN, but I don't know how to then use that to get a the RegistryEntry<WolfVariant> I need.
I've tried looking through the code of RegistryKey and RegistryEntry, but I didn't find anything.

I also tried to set the collar color of the Wolf, but it said that .setCollarColor() has private access, so I can't use that. Is there any other method I can use to do this, or is there no way to set the collar color of the Wolf with code?

Please see the images attached for further info.
Thanks so much!

#

Also, for some reason, there is a Registries.CAT_VARIANT and Registries.FROG_VARIANT, but no WOLF_VARIANT. I'm sure there's a reason for this, I'm just unsure.

barren ferry
#

you'll need to query the dynamic registry to get RegistryEntry<WolfVariant>

#

see net.minecraft.entity.passive.WolfVariants#fromBiome

hushed whale
hushed whale
hushed whale
#

i think the problem is I don't want to get the wolf variant based on the biome the player is in; i just want to set the wolf to a particular variant, no matter what biome the player is in

solemn swift
solemn swift
hushed whale
solemn swift
#

(RegistryKeys.<registry>)

hushed whale
solemn swift
#

yes, look at the methods Optional has

hushed whale
#

i think i fixed it

solemn swift
#

-# i would use ifPresentOrElse and log a warning if its not present but that will probably work in 99% of cases

hushed whale
#

btw do you know of any way to set the collar color of the wolf using code? .setCollarColor() is private

solemn swift
#

!!accessor

waxen salmonBOT
#

io/github/mymod/mixin/MyClassAccess

@Mixin(MyClass.class)
public interface MyClassAccess {
  @Invoker void callAccess();
  @Accessor int getMyField();
}

to use it

public class Container {
  public void slapHaykam(MyClass instance) {
     ((MyClassAccess)instance).callAccess();
  }
}
hushed whale
#

is that a dependency you need to add to build.gradle?

hushed whale
# solemn swift -# i would use ifPresentOrElse and log a warning if its not present but that wil...

also I added that now, prob a good idea

DynamicRegistryManager registryManager = world.getRegistryManager();
Optional<RegistryEntry.Reference<WolfVariant>> wolfVariant = registryManager.getOrThrow(RegistryKeys.WOLF_VARIANT).getEntry(rndmElem2.getValue());

wolfVariant.ifPresentOrElse(value -> wolf.setVariant(wolfVariant.get()),
    () -> BlazinBlazeTwitchMod.LOGGER.info("WolfVariant not found!"));
#

wait nvm i just realized i have an ExampleMixin class 🤦

solemn swift
#

fabric depends on mixin and mixin extras so you have access to it too

#

if you don't know how mixins work, then read the pinned message in #mod-dev-mixin (#mod-dev-mixin message)

hushed whale
#

So I'm assuming I would replace MyClass with the class I'm trying to get access to

#

it won't let me put those methods in though without errors