#Looking for Yarn translation of Mojang: ArmorStandEntity.getArmorSlots()

17 messages · Page 1 of 1 (latest)

fast pawn
slate fractal
fast pawn
#

the link is to the translation from the mojang method to the yarn one

slate fractal
#

oh... right thanks for that! I need to find how to use it now, it seems that IntelliJ doesn't recognize the method when used on ArmorStandEntity

fast pawn
#

What Minecraft version are you using?

slate fractal
#

1.21.4

#

I can send you the repo if you want to take a look at the class

fast pawn
#

should be as simple as calling getArmorItems() on the armor stand instance

slate fractal
#

Maybe it's not an ArmorStand after all, here's the bit of code in question:

Entity entity = state.getData(DataTickets.ENTITY);
// We'll just have ArmorStands always animate, so we can return here
if (entity instanceof ArmorStandEntity)
  return PlayState.CONTINUE;
  // For this example, we only want the animation to play if the entity is   wearing all pieces of the armor
   // Let's collect the armor pieces the entity is currently wearing
   Set<Item> wornArmor = new ObjectOpenHashSet<>();

   for (ItemStack stack : entity.getArmorItems()) {
   // We can stop immediately if any of the slots are empty
   if (stack.isEmpty())
   return PlayState.STOP;

   wornArmor.add(stack.getItem());
            }```
fast pawn
#

okay well in that snippet it's explicitly not an armor stand
but I assume it's a LivingEntity of some kind, yes?

slate fractal
#

I think? The Geckolib documentation presents this class, and from Linkie it appears that it does need to be a LivingEntity to work:

```java

// Let's add our animation controller
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
controllers.add(new AnimationController<>(this, 20, state -> {
// Apply our generic idle animation.
// Whether it plays or not is decided down below.
state.getController().setAnimation(DefaultAnimations.IDLE);

        // Let's gather some data from the state to use below
        // This is the entity that is currently wearing/holding the item
        Entity entity = state.getData(DataTickets.ENTITY);

    // We'll just have ArmorStands always animate, so we can return here
        if (entity instanceof ArmorStand)
            return PlayState.CONTINUE;


        // For this example, we only want the animation to play if the entity is wearing all pieces of the armor
        // Let's collect the armor pieces the entity is currently wearing
        Set<Item> wornArmor = new ObjectOpenHashSet<>();

        for (ItemStack stack : entity.getArmorSlots()) {
            // We can stop immediately if any of the slots are empty
            if (stack.isEmpty())
                return PlayState.STOP;

            wornArmor.add(stack.getItem());
        }
fast pawn
#

okay well right there you just have it be Entity
You need to cast to LivingEntity to use that method, preferably with an instanceof check first to make sure

slate fractal
#

Riiight, I'll try that then, thanks!

#

Unfortunately state.getData(DataTickets.ENTITY); (where entity is defined) needs to be defined as an Entity, not a LivingEntity

fast pawn
#

... yes, so you then cast that to a LivingEntity

#

!!learnjava

ivory basinBOT
#

To start modding Minecraft using Fabric, it's strongly recommended to know Java.
Minecraft, in its codebase, and mods, using Fabric API, use more advanced Java concepts like lambdas, generics and polymorphism.
If you don't know all of these concepts, you may have some difficulties modding.

Here are some online resources that will help learning Java
JetBrains Academy (free online course): https://www.jetbrains.com/academy/
Codecademy (free online course): https://www.codecademy.com/learn/learn-java
University of Helsinki (free online course): https://java-programming.mooc.fi/
Basic Java Tutorials: https://docs.oracle.com/javase/tutorial/
Introduction to Programming using Java by David J. Eck (free online textbook): http://math.hws.edu/javanotes/

After Learning Java
For most mods you will want to make, you will have to use the Spongepowered Mixin Java library.
To learn more about Mixin, you can use the faq/mixin bot tag by typing !!faq/mixin in #bot-posting .