#Spear Error

1 messages ยท Page 1 of 1 (latest)

hollow coyote
#

When collecting 2 spears that are both about to break, it causes an error and doesn't allow collecting any other spears of that item (as shown in the video, you cannot collect any other wooden spears, even if they are at full durability).

Anyone have an idea for a fix? One idea I have is to not allow charge if it is about to break. Although, I am a little unsure of where to begin.

Error in video:
[Scripting][error]-Error: Invalid damage value '100' set on item 'ti:wooden_spear'. Damage values cannot be greater than maxDurability. at <anonymous> (spear_scripts/spear_pickup.js:26)

hollow coyote
#

bump

brittle gust
#

I think it because your giving it a enchant right?

#

So make it enchant it one at a time

#

I would assume it is that

hollow coyote
#

no the item has no enchant

#

basically the code is meant to give the item to whoever has the corresponding tag

#

and also decrease the durability every time

hollow coyote
#

Ive decided to go with the method of cancelling the event since it is similar to a trident, although I wrote this script and I am not quite sure if it's right:

import { system, world, ItemStack } from '@minecraft/server'

// List of spears
const spearsList = [
  { item: "ti:wooden_spear", tag: "wooden_spear" },
  { item: "ti:stone_spear", tag: "stone_spear" }
  // Add as many items as you like
]

export function pickUpSpear() {
  world.beforeEvents.itemOnUse.subscribe((eventData) => {
    const itemTest = eventData.itemStack

    const matchingSpear = spearsList.find(spear => spear.item === itemTest.typeId)
    let durability = itemTest.getComponent("durability")
    if (matchingSpear && (durability.damage === (durability.maxDurability - 1))) {
      return eventData.cancel = true
    }

  })
  world.afterEvents.itemReleaseUse.subscribe((eventData) => {
    const player = eventData.source
    const thrownSpear = eventData.itemStack
    const inv = player.getComponent("inventory")

    // Check if the thrown spear matches any item in the spearsList
    const matchingSpear = spearsList.find(spear => spear.item === thrownSpear.typeId)

    let tick = system.runInterval(() => {
      if (matchingSpear && player.removeTag(matchingSpear.tag)) {
        const newSpear = thrownSpear.clone()
        let durability = newSpear.getComponent("durability")
        if (durability.damage === (durability.maxDurability - 1))
          inv.container.addItem(new ItemStack("minecraft:air"))
        else {
          durability.damage++
          inv.container.addItem(newSpear)
        }
        system.clearRun(tick)
      }
    })
  })
}```
north harbor
hollow coyote
hollow coyote
#

so it turns out the issue is that i was giving myself a spear with a damage value that was way above the max durability, although i would like to try and fix that. But besides that the script works pretty well

#

changing:

if (durability.damage === (durability.maxDurability - 1))
          inv.container.addItem(new ItemStack("minecraft:air"))
        else {
          durability.damage++
          inv.container.addItem(newSpear)
        }

to:

if (durability.damage >= (durability.maxDurability - 1)) {
          inv.container.addItem(new ItemStack("minecraft:air"))
        } else {
          durability.damage++
          inv.container.addItem(newSpear)
        }```
Will fix this error
north harbor
#

I forgot to tell you that I had figured it out earlier

hollow coyote
north harbor
hollow coyote
#
import { system, world } from '@minecraft/server';
// List of spears
const spearsList = [
  { item: "ti:wooden_spear", tag: "wooden_spear" },
  { item: "ti:stone_spear", tag: "stone_spear" }
  // Add as many items as you like
];
export function pickUpSpear() {
  world.beforeEvents.itemUse.subscribe((eventData) => {
    const usingSpear = eventData.itemStack;
    const durability = usingSpear.getComponent("durability");
    const matchingSpear = spearsList.find(spear => spear.item === usingSpear.typeId);
    if (matchingSpear)
      if (durability.damage >= (durability.maxDurability - 1)) {
        eventData.cancel = true;
      }
  });
  world.afterEvents.itemReleaseUse.subscribe((eventData) => {
    const player = eventData.source;
    const thrownSpear = eventData.itemStack;
    const inv = player.getComponent("inventory");
    // Check if the thrown spear matches any item in the spearsList
    const matchingSpear = spearsList.find(spear => spear.item === thrownSpear.typeId);
    let tick = system.runInterval(() => {
      if (matchingSpear && player.removeTag(matchingSpear.tag)) {
        const newSpear = thrownSpear.clone();
        let durability = newSpear.getComponent("durability");
        durability.damage++;
        inv.container.addItem(newSpear);
        // console.warn(`${durability.damage}/${(durability.maxDurability)}`)
        system.clearRun(tick);
      }
    });
  });
}```
#

this basically works exactly like a trident

#

and it's been tested in multiplayer to work

north harbor
#

Nicee!

#

I'll check it out

#

Later

hollow coyote
#

alright!

north harbor
#

Another thing, does this cancel the throwing component if the durability is at 1?

#

Or is that even possible?

hollow coyote
#

yep!

#

i figured it out luckily

north harbor
#

Nice! I was having trouble with that

hollow coyote
#
world.beforeEvents.itemUse.subscribe((eventData) => {
    const usingSpear = eventData.itemStack;
    const durability = usingSpear.getComponent("durability");
    const matchingSpear = spearsList.find(spear => spear.item === usingSpear.typeId);
    if (matchingSpear)
      if (durability.damage >= (durability.maxDurability - 1)) {
        eventData.cancel = true;
      }
  });```
north harbor
#

Ahh okay ๐Ÿ‘

#

itemUse does that?

hollow coyote
north harbor
#

Ooo

hollow coyote
#

so eating and drawing back bows also do it

#

but i made a list so that it only cancels the spears event

brittle gust
#

@hollow coyote were you ever a builder?

north harbor
north harbor
#

@hollow coyote where can i put the PlayAnimation on here?

north harbor
#

i tried this

      player.playAnimation('animation.player.charge_spear', {
        stopExpression: '!query.is_using_item',
        blendOutTime: 0.2,
      });```
hollow coyote
hollow coyote
hollow coyote
north harbor
#

it should play when the player is using the item and cancel once they're no longer using the item

hollow coyote
#

btw how did u get the model to work? im having a rlly hard time doing so

north harbor
#

something like the trident brandish animation but it's a custom one

north harbor
hollow coyote
#

like my attachables are completely broken and im so unsure how to fix it

hollow coyote
north harbor
#
{
  "format_version": "1.10.0",
  "minecraft:attachable": {
    "description": {
      "identifier": "fs:giant_spear",
      "materials": {
        "default": "entity_alphatest",
        "enchanted": "entity_alphatest_glint"
      },
      "textures": {
        "default": "textures/models/giant_spear",
        "enchanted": "textures/misc/enchanted_item_glint"
      },
      "geometry": {
        "default": "geometry.player.giant_spear"
      },
      "render_controllers": ["controller.render.item_default"],
      "animations": {
        "wield": "controller.animation.trident.wield",
        "wield_first_person": "animation.trident.wield_first_person",
        "wield_first_person_raise": "animation.trident.wield_first_person_raise",
        "wield_first_person_raise_shake": "animation.trident.wield_first_person_raise_shake",
        "wield_first_person_riptide": "animation.trident.wield_first_person_riptide",
        "wield_third_person": "animation.trident.wield_third_person",
        "wield_third_person_raise": "animation.trident.wield_third_person_raise"
      },
      "scripts": {
        "pre_animation": [
          "v.charge_amount = math.clamp((q.main_hand_item_max_duration - (q.main_hand_item_use_duration - q.frame_alpha + 1.0)) / 10.0, 0.0, 1.0f);"
        ],
        "animate": ["wield"]
      }
    }
  }
}```
hollow coyote
hollow coyote
#

it's all janky

north harbor
#

it has to do with your model?

hollow coyote
#

that's what im thinking but im not sure what could be wrong

north harbor
#
{
    "format_version": "1.16.0",
    "minecraft:geometry": [
        {
            "description": {
                "identifier": "geometry.player.giant_spear",
                "texture_width": 176,
                "texture_height": 176,
                "visible_bounds_width": 12,
                "visible_bounds_height": 11,
                "visible_bounds_offset": [0, 1.5, 0]
            },
            "bones": [
                {
                    "name": "pole",
                    "pivot": [-1, 24, 0],
                    "binding": "q.item_slot_to_bone_name(c.item_slot)",
                    "cubes": [
                        {"origin": [0, 36.5, -5.5], "size": [0, 10, 15], "pivot": [0, 41.5, 0], "rotation": [-90, 0, 0], "uv": [0, 3]},
                        {"origin": [0, 36.5, -5.5], "size": [0, 10, 15], "pivot": [0, 41.5, 0], "rotation": [0, 90, 90], "uv": [0, 3]},
                        {"origin": [-1, -44, 15], "size": [2, 2, 66], "pivot": [0, -43, 0], "rotation": [90, 0, 0], "uv": [15, 15]},
                        {"origin": [-3, -28, -4], "size": [6, 0, 7], "pivot": [0, -28, 0], "rotation": [90, 0, 0], "uv": [39, 51]},
                        {"origin": [-3, -28, -4], "size": [6, 0, 7], "pivot": [0, -28, 0], "rotation": [0, 90, -90], "uv": [39, 51]}
                    ]
                }
            ]
        }
    ]
}```
#

make sure you have the binding

hollow coyote
#

yeah i have the binding, maybe it's because i have extra bones inside the pole

north harbor
#

i dont think that should be a problem? Check your version

hollow coyote
north harbor
#

hmmmm

#

can you show me what happens when you use it

hollow coyote
#

yeah i can show u one second let me pull up my minecraft

north harbor
#

like this?

world.beforeEvents.itemUse.subscribe((eventData) => {
  const usingSpear = eventData.itemStack;
  const player = eventData.source;
  const durability = usingSpear.getComponent('durability');
  const matchingSpear = spearsList.find(
    (spear) => spear.item === usingSpear.typeId
  );
  if (matchingSpear)
    if (durability.damage >= durability.maxDurability - 1) {
      player.playAnimation('animation.player.charge_spear', {
        stopExpression: '!query.is_using_item',
        blendOutTime: 0.2,
      });
      eventData.cancel = true;
    }
});```
#

it doesnt play the animation for some reason?

hollow coyote
north harbor
#

i havent tested it any other way

hollow coyote
#

hmm

#

maybe it has to be played after the event is canceled

#

bc when the animation is playing it's still technically is being used

#

doesnt stop use till it reaches the line eventData.cancel = true;

north harbor
#

umm like how?

hollow coyote
#
world.beforeEvents.itemUse.subscribe((eventData) => {
  const usingSpear = eventData.itemStack;
  const player = eventData.source;
  const durability = usingSpear.getComponent('durability');
  const matchingSpear = spearsList.find(
    (spear) => spear.item === usingSpear.typeId
  );
  if (matchingSpear)
    if (durability.damage >= durability.maxDurability - 1) {
      eventData.cancel = true;
      player.playAnimation('animation.player.charge_spear', {
        stopExpression: '!query.is_using_item',
        blendOutTime: 0.2,
      });
    }
});```
north harbor
hollow coyote
#

hold on one second i gotta take my dog out but ill be right back and keep researching into ur problem

hollow coyote
north harbor
hollow coyote
north harbor
#

okay

hollow coyote
#

im trying to find the documentation on playAnimation

hollow coyote
#

yeah that's what i was looking at, im just wondering it can be used after source

north harbor
#

oh that might be why :/

#

but i cant find more information on the documentation

hollow coyote
#

yeah, the only thing i can see after player that can be used is playSound and playMusic

hollow coyote
#

maybe u could run the /playanimation command using runCommand

north harbor
#

RIP

#

okay ill try that out then

hollow coyote
#

alright, let me know how that goes! im down to help out!

north harbor
#

wait how do i use runCommand?

#

is that a system thing?

hollow coyote
#
player.runCommand('/playanimation')```
north harbor
#

oh okay

hollow coyote
#

oh i found out about the playanimation thing more, it probably can be used on a player

#

wait i think i have a different idea

north harbor
#

oh okay let me know

hollow coyote
#

i think u should try and do system.runInterval for the animation

north harbor
#

oh have it run a loop

#

could work

hollow coyote
#

yeah that's what im thinking

#

u can clear the run too later if needed

#

btw i changed the pivot, it's just behind me now, but i think im getting somwhere for sure

north harbor
#

i did this typescript world.beforeEvents.itemUse.subscribe((eventData) => { const usingSpear = eventData.itemStack; const player = eventData.source; const durability = usingSpear.getComponent('durability'); const matchingSpear = spearsList.find( (spear) => spear.item === usingSpear.typeId ); if (matchingSpear) if (durability.damage >= durability.maxDurability - 1) { eventData.cancel = true; let animTick = system.runInterval(() => { player.playAnimation('animation.player.charge_spear', { stopExpression: '!query.is_using_item', blendOutTime: 0.2, }); system.clearRun(animTick); }, 20); } });

#

doesnt work still

hollow coyote
#

maybe trying removing the stopExpression

#

since technically the item has already stopped so u dont need to specify for it to play when it stops

north harbor
#

i cleared the stopExpression and blendOutTime. No luck :/

hollow coyote
#

what is ur manifest version for scripting?

#

bc apparently from what im reading is that playAnimation() might be experimental

#

so if that doesnt work u can still use runCommand(), but i would use runCommandAsync()

north harbor
#
    {
      "module_name": "@minecraft/server",
      "version": "1.10.0-beta"
    }```
hollow coyote
#

yeah then my guess is that is not the problem

#

is it an animation for the item?

north harbor
#

no, player animation

hollow coyote
#

hmm

#

maybe see if u can play a different animation

#

to narrow down if the line is even working

north harbor
#

it doesnt even work with the runcommand

#

maybe it's the placement

hollow coyote
#

maybe although the code looks fine

#

how does ur animation work?

#

idk if this would help but i would try and specify the players that can see the animation

north harbor
#

nothing special with it

#

i ran the command in game, i can see the animation

hollow coyote
north harbor
#

no

#

i think we have to use an afterEvent of itemUse

#

right?

hollow coyote
#

maybe, that could be it

#

i dont know y it wouldnt work with before, especially since ur using system.runInterval but it's worth a try

north harbor
#

i gtg, ill be back later to continue testing. If you figure something out with the animation please let me know

north harbor
#

also my model is standing up like this.

north harbor
hollow coyote
#

oooh okay yeah mines is sideways, maybe i need to put it like that ๐Ÿ˜‚

#

okay will try it out

north harbor
#

yeah maybe

#

try it out lmk

hollow coyote
#

okay

hollow coyote
#

okay i tested it out, unfortunately it is still broken

#

possibly might have to do with one of my scripts in the attachable

#

no it does not seem any of those are the problem so i genuinely have no idea

#

okay so i think it is definetly something to do with my model because i tested out the animations with the trident model and it worked perfectly

#

except the charging animation was bugged so that is good to know that can be ruled out as something to do with my model

#

okay i think i figured out the problem with my spear but now i have to do a remodel ๐Ÿ˜ข but it's okay, it's going to turn out great!

north harbor
#

Lol

#

You should do a player animation and see if you can get it to trigger

hollow coyote
#

yeah that's what i tried, it didnt work

#

i think bc my blocks had random pivots in it, so im remodeling it to get rid of the pivots

north harbor
#

Oh okay

#

Yeah I noticed that on your model

hollow coyote
#

yeah, i think that's the problem, it happened bc i was using global instead of local

#

its okay tho bc i got an epic idea i can do

#

hey is it okay if i can see the code for ur script that ur trying to use to animate? i think i might be able to figure it out if i can see what the latest version is

hollow coyote
#

nice! I got my spear working after like an hour! Only thing broken is charging animation and the entity rotation

hollow coyote
#

anyways i plan on doing research into ur problem more tmr, tbh im very uncertain y it wont work but im sure we will figure it out

north harbor
#

I'm omw home I'll see what I can do

north harbor
#

@hollow coyote looks like we can only use it in an afterEvent

#
import { system, world } from '@minecraft/server';
// List of spears
const spearsList = [
  { item: 'fs:giant_spear', tag: 'giant_spear' },
  // Add as many items as you like
];

world.beforeEvents.itemUse.subscribe((eventData) => {
  const usingSpear = eventData.itemStack;
  const durability = usingSpear.getComponent('durability');
  const matchingSpear = spearsList.find(
    (spear) => spear.item === usingSpear.typeId
  );
  if (matchingSpear && durability.damage >= durability.maxDurability - 1) {
    eventData.cancel = true;
  }
});

world.afterEvents.itemUse.subscribe((eventData) => {
  const player = eventData.source;
  const spearsList = eventData.itemStack;
  if (spearsList.typeId !== 'fs:giant_spear') return;
  player.playAnimation('animation.player.charge_spear', {
    stopExpression:
      '!(math.clamp((query.main_hand_item_max_duration - (query.main_hand_item_use_duration - query.frame_alpha + 1.0)) / 10.0, 0.0, 1.0f))',
  });
});

world.afterEvents.itemReleaseUse.subscribe((eventData) => {
  const player = eventData.source;
  const thrownSpear = eventData.itemStack;
  const inv = player.getComponent('inventory');
  // Check if the thrown spear matches any item in the spearsList
  const matchingSpear = spearsList.find(
    (spear) => spear.item === thrownSpear.typeId
  );
  let tick = system.runInterval(() => {
    if (matchingSpear && player.removeTag(matchingSpear.tag)) {
      const newSpear = thrownSpear.clone();
      let durability = newSpear.getComponent('durability');
      durability.damage++;
      inv.container.addItem(newSpear);
      // console.warn(`${durability.damage}/${(durability.maxDurability)}`)
      system.clearRun(tick);
    }
  });
});```
#

now i just need to figure out the melee attack animation :/

hollow coyote
hollow coyote
#

i think i would use the resource pack queries to play the attacking animation instead of scripting, bc there is a is_attacking query

hollow coyote
#

also do yk how i could fix the charge animation and the rotation?

north harbor
#

like change it or?

#

what is the issue?

hollow coyote
hollow coyote
north harbor
hollow coyote
#

ahh okay cool!

north harbor
#

the trident animations should fix that for you

hollow coyote
north harbor
#

i changed the animation of my charge

hollow coyote
#

yeah i am using the trident animation for the charge but it is still not working

hollow coyote
north harbor
#

i need to fix the first person animation tho

hollow coyote
#

yeah, that is a little broken but im sure ull get there

hollow coyote
#

basically

#

here ill show u

#
{
    "format_version": "1.10.0",
    "minecraft:attachable": {
        "description": {
            "identifier": "ti:wooden_spear",
            "render_controllers": [
                "controller.render.item_default"
            ],
            "materials": {
                "default": "entity_alphatest",
                "enchanted": "entity_alphatest_glint"
            },
            "textures": {
                "default": "textures/entity/attachables/spears/wooden_spear",
                "enchanted": "textures/misc/enchanted_item_glint"
            },
            "geometry": {
                "default": "geometry.spear"
            },
            "animations": {
                "wield": "controller.animation.trident.wield",
                "wield_first_person": "animation.trident.wield_first_person",
                "wield_first_person_raise": "animation.trident.wield_first_person_raise",
                "wield_first_person_raise_shake": "animation.trident.wield_first_person_raise_shake",
                "wield_first_person_riptide": "animation.trident.wield_first_person_riptide",
                "wield_third_person": "animation.trident.wield_third_person",
                "wield_third_person_raise": "animation.trident.wield_third_person_raise"
            },
            "scripts": {
                "pre_animation": [
                    "variable.charge_amount = math.clamp((query.main_hand_item_max_duration - (query.main_hand_item_use_duration - query.frame_alpha + 1.0)) / 10.0, 0.0, 1.0f);"
                ],
                "animate": [
                    "wield"
                ]
            }
        }
    }
}```
north harbor
#

yeah everything looks correct

hollow coyote
#

do u think it's something with my model?

north harbor
#

what about your projectile entity? you have to use a different model

hollow coyote
#

ooooh okay that's probably what is wrong with the entity then

north harbor
#

my projectile entity is laid down like this

#

facing north

hollow coyote
#

yeah, mines is using the same one ๐Ÿ˜…

north harbor
#

oh lol

hollow coyote
#

but that doesnt explain y the charge is not working

north harbor
#

just name it like thrown_spear or something like that

north harbor
#

im not exactly sure tbh

hollow coyote
hollow coyote
north harbor
hollow coyote
north harbor
#

this is what i have ```json

  "minecraft:use_modifiers": {
    "use_duration": 3600
  },```
hollow coyote
#

i think that might be it, i never added that component before

north harbor
#

yeah by default i think it's like 1

#

that's why it's giving you that 'eat' animation

#

i had that same issue when i was testing my spear before adding the script

hollow coyote
#

yep it works perfectly now! tysm!

#

what's the pivot that u use for the entity?

north harbor
#

i did this to detect melee but it doesnt work

world.afterEvents.entityHitEntity.subscribe((ev) => {
  const source = ev.damagingEntity;
  const getInv = source.getComponent('equippable').getEquipment('Mainhand');
  if (source.typeId == 'minecraft:player' && getInv == 'fs:giant_spear') {
    source.playAnimation('animation.player.spear_melee', {
      blendOutTime: 0.2,
    });
  }
});```
north harbor
hollow coyote
hollow coyote
hollow coyote
#

i figured it out, i had to rotate the z to 0

#

but imma see if there is a way to keep it at 90 bc i like it the other way better

north harbor
#

    "animation.spear.thrown": {
      "loop": true,
      "bones": {
        "giant_spear": {
          "rotation": ["-q.target_x_rotation", "-q.body_y_rotation", 0]
        }
      }
    }```
hollow coyote
#

yeah that's what i have for my animation:

{
    "format_version": "1.10.0",
    "animations": {
        "animation.spear.default_thrown": {
            "loop": true,
            "bones": {
                "pole": {
                    "rotation": [
                        "-q.target_x_rotation",
                        "-q.body_y_rotation",
                        0
                    ]
                }
            }
        }
    }
}```
north harbor
#

oh

#

hmmm

hollow coyote
#

yeah it is most strange

#

btw how is ur animation going?

north harbor
#

i cant figure it out ๐Ÿ˜ข

hollow coyote
north harbor
#

i scrapped it xD

#

im trying to rewrite it again

hollow coyote
#

oh ๐Ÿ’€

#

well i wish u good luck

#

although i think u should take a look into animations through the resource pack instead of scripts

#

at least for this animation

north harbor
#

i have this

world.afterEvents.entityHitEntity.subscribe((ev) => {
  const source = ev.damagingEntity;
  if (!(source instanceof Player)) return;
  if (
    source.getComponent('equippable')?.getEquipment(EquipmentSlot.Mainhand)
      .typeId == 'fs:giant_spear'
  ) {
    source.playAnimation('animation.player.spear_melee');
  }
});```
hollow coyote
#

did it work?

north harbor
#

no

hollow coyote
north harbor
#

none

hollow coyote
#

i think bc it's detecting the player and since ur returning it on the player if, it's just ending the function

north harbor
#

i got it to work

import { world, Player, EquipmentSlot } from '@minecraft/server';
world.afterEvents.entityHitEntity.subscribe((ev) => {
  const source = ev.damagingEntity;
  if (!(source instanceof Player)) return;
  const equipComp = source
    .getComponent('equippable')
    ?.getEquipment(EquipmentSlot.Mainhand);
  if (equipComp.typeId == 'fs:giant_spear') {
    source.playAnimation('animation.player.spear_melee', {
      blendOutTime: 0.2,
    });
  }
});```
hollow coyote
#

that is actually really interesting that's how it worked out, smart to use instanceof

north harbor
#

i wasnt testing it to hit an entity xD

#

i was hitting the air

#

so it was working this whole time just wasnt testing it right

hollow coyote
#

ooooh ๐Ÿ˜‚

#

have u figured out what was wrong with mine?

#

and also the throwing animation in 3rd person is also broken for me, it just turns reversed

north harbor
north harbor
hollow coyote
#

ohh like the one u were working on?

hollow coyote
north harbor
hollow coyote
north harbor
#

yes but that the attachable animations, not player

hollow coyote
#

oooh yeah that makes sense

#

do u think copying the player.json will work?

north harbor
#

copy what?

hollow coyote
#

like taking the vanilla player.json and putting it in my pack will fix the issue

north harbor
#

oh, that wont fix it

#

the player.json file is already in the game

#

if you put it in your pack and edit it, it will overwrite the one in game

hollow coyote
#

ohh yeah ๐Ÿคฆโ€โ™‚๏ธ

#

is there a built in player animation i can use?

north harbor
#

        "animation.player.charge_spear": {
            "loop": "hold_on_last_frame",
            "animation_length": 0.25,
            "override_previous_animation": true,
            "bones": {
                "rightArm": {
                    "relative_to": {
                        "rotation": "entity"
                    },
                    "rotation": {
                        "0.0": [0, 0, 0.01],
                        "0.1667": [177.5, 0, 0]
                    },
                    "position": [0, 0, 0]
                },
                "body": {
                    "rotation": {
                        "0.0": [0, 0, 0],
                        "0.25": [0, 25, 0]
                    },
                    "position": [0, 0, 0]
                },
                "leftArm": {
                    "rotation": {
                        "0.0": [0, 0, 0],
                        "0.25": [-106.46212, 8.17155, 3.06337]
                    }
                }
            }
        },```
#

use this one

hollow coyote
#

okay tysm! srry i feel bad just taking it

north harbor
#

and this script

world.afterEvents.itemUse.subscribe((eventData) => {
  const player = eventData.source;
  const usingSpear = eventData.itemStack;
  if (usingSpear.typeId !== 'fs:giant_spear') return;
  player.playAnimation('animation.player.charge_spear', {
    blendOutTime: 0.2,
    stopExpression:
      '!(math.clamp((query.main_hand_item_max_duration - (query.main_hand_item_use_duration - query.frame_alpha + 1.0)) / 10.0, 0.0, 1.0f))',
  });
});```
hollow coyote
#

okay ty, i really apprieciate it fr

north harbor
#

but remember that if we change the player position we have to do the same for first person animation

#

ill have to work on that later

hollow coyote
north harbor
#

im having a hard time running an animation when the player is holding a specific item

hollow coyote
north harbor
#

yes

#

that only plays the third person animation

hollow coyote
#

okay, i think i should be able to figure that out

north harbor
#

i think the first person animation would have to be done through the attachable file

hollow coyote
#

yeah, probably but idt that should be too bad

hollow coyote
#

like the animation

#

oh wait no im dumb forget i said that ๐Ÿ’€

north harbor
#

lol

#

its okay

hollow coyote
# north harbor and this script ```typescript world.afterEvents.itemUse.subscribe((eventData) =>...

okay i put in the script but for some reason i couldnt get it to work:

import { world } from '@minecraft/server';

const spearsList = [
    "ti:wooden_spear",
    "ti:stone_spear"
    // Add as many items as you like
];

export function spearAnimations() {
    world.afterEvents.itemUse.subscribe((eventData) => {
        const player = eventData.source;
        const usingSpear = eventData.itemStack;

        const matchingSpear = spearsList.includes(usingSpear.typeId)

        if (matchingSpear) return;
        player.playAnimation('animation.player.charge_spear', {
            blendOutTime: 0.2,
            stopExpression:
                '!(math.clamp((query.main_hand_item_max_duration - (query.main_hand_item_use_duration - query.frame_alpha + 1.0)) / 10.0, 0.0, 1.0f))',
        });
    });
}```
north harbor
#

hmmm

#

why are you exporting it?

hollow coyote
#

i do that to keep it cleaner, so i can have different scripts in different files

north harbor
#

can i see how you're exporting it?

hollow coyote
#

this is my main.js:

// Spear Script Imports
import { pickUpSpear } from './spear_scripts/spear_pickup.js';
import { spearAnimations } from './spear_scripts/spear_animations.js'

// Tool Scripts Imports
import { toolDurability } from './tool_scripts/tool_durability.js';

pickUpSpear();
toolDurability();
spearAnimations();```
north harbor
#

oh my code is in typescript, idk if that has something to do with it

#

although they should technically both work?

hollow coyote
#

yeah they do, i see no use of the typescripting in the script so

#

also ig it does work?

#

but not for my spear, but it does for the trident ๐Ÿ’€

north harbor
#

wait really?

hollow coyote
#

yeah

#

idk y tho

#

actually, maybe i do

north harbor
#

wait the trident has an animation already

hollow coyote
#

yeah, im unsure y

#

but the script is affecting the trident

north harbor
#

this animation will only work on those items you listed

north harbor
hollow coyote
#

one second brb

north harbor
#

wait let me check this

#

mine doesnt affect the trident?

hollow coyote
#

weird, i wonder y it did it for me

#

oh i fixed it

#

i just removed the return statement

#
import { world } from '@minecraft/server';

const spearsList = [
    "ti:wooden_spear",
    "ti:stone_spear"
    // Add as many items as you like
];

export function spearAnimations() {
    world.afterEvents.itemUse.subscribe((eventData) => {
        const player = eventData.source;
        const usingSpear = eventData.itemStack;

        const matchingSpear = spearsList.includes(usingSpear.typeId)

        if (matchingSpear) {
            player.playAnimation('animation.player.charge_spear', {
                blendOutTime: 0.2,
                stopExpression:
                    '!(math.clamp((query.main_hand_item_max_duration - (query.main_hand_item_use_duration - query.frame_alpha + 1.0)) / 10.0, 0.0, 1.0f))',
            });
        }
    });
};```
#

it appears the animation is kinda still broken tho

#

does the animation still happen when u switch over to another item after using the spear?

#

like the trident?

#

and also the animation does not stop if the item is still selected on the use

#

okay, i figured out a way to do it without needing scripts

hollow coyote
#

yep! i got the animation to work perfectly

#

@north harbor

#

im using a different animation bc it matches more towards what i wanted

#

but it should work for ur animation too

#

i can test it out if u want

north harbor
#

Yeah test it out

hollow coyote
north harbor
hollow coyote
#

i added a tag to the item your_identifier:is_spear

#

in the behavior packs

#
"components": {
            "minecraft:tags": {
                "tags": [
                    "ti:is_spear"
                ]
            }
        }```
#

then after i created a new animation controller:

{
    "format_version": "1.10.0",
    "animation_controllers": {
        "controller.animation.player.spear": {
            "initial_state": "default",
            "states": {
                "default": {
                    "transitions": [
                        {
                            "spear": "query.equipped_item_any_tag('slot.weapon.mainhand','ti:is_spear')&&query.is_using_item&&!variable.is_first_person"
                        }
                    ]
                },
                "spear": {
                    "animations": [
                        "charge_spear"
                    ],
                    "transitions": [
                        {
                            "default": "!query.equipped_item_any_tag('slot.weapon.mainhand','ti:is_spear')||!query.is_using_item||variable.is_first_person"
                        }
                    ]
                }
            }
        }
    }
}```
#

then i used the player.entity.json

#

id just take the one from the vanilla files and modify it but basically in the animations:

"animations": {
                "charge_spear": "animation.player.charge_spear",
                "spear_controller": "controller.animation.player.spear"
            }```
#

then in animate:

"animate": [
                    "root",
                    "spear_controller"
                ]```
north harbor
hollow coyote
#

hmm, i see

#

i got an idea

#

wait nvm idt that idea will work

#

i honestly have no idea how it could be fixed without using the file

#

idk if it is completely possible

#

but ill keep looking into it

north harbor
#

it just has to do with the custom animation.

hollow coyote
#

i think that should work

#

but first put a tag on ur item

#

also i realized my script has a bug where it gives the durability of the other players if it's picked up by them

#

just fixed it:

world.afterEvents.itemReleaseUse.subscribe((eventData) => {
    for (const player of world.getPlayers()) {
      const thrownSpear = eventData.itemStack;
      const inv = player.getComponent("inventory");
      // Check if the thrown spear matches any item in the spearsList
      const matchingSpear = spearsList.find(spear => spear.item === thrownSpear.typeId);
      let tick = system.runInterval(() => {
        if (matchingSpear && player.removeTag(matchingSpear.tag)) {
          const newSpear = thrownSpear.clone();
          let durability = newSpear.getComponent("durability");
          durability.damage++;
          inv.container.addItem(newSpear);
          // console.warn(`${durability.damage}/${(durability.maxDurability)}`)
          system.clearRun(tick);
        }
      });
    }```
north harbor
#
system.runInterval(() => {
  world.getPlayers().forEach((player) => {
    const equipComp = player
      .getComponent('equippable')
      ?.getEquipment(EquipmentSlot.Mainhand);
    if (equipComp && equipComp.typeId === 'fs:giant_spear') {
      player.playAnimation('animation.player.giant_spear_wield', {
        blendOutTime: 0.2,
        stopExpression:
          "!query.is_item_name_any('slot.weapon.mainhand','fs:giant_spear') || v.attack_time || (math.clamp((query.main_hand_item_max_duration - (query.main_hand_item_use_duration - query.frame_alpha + 1.0)) / 10.0, 0.0, 1.0f))",
      });
    }
  });
});```

do you know how i can fix this?
#

it should hold the last frame but it the interval is running non stop

hollow coyote
#

assign it to a variable then clear the run

#
let e = system.runInterval(() => {
  world.getPlayers().forEach((player) => {
    const equipComp = player
      .getComponent('equippable')
      ?.getEquipment(EquipmentSlot.Mainhand);
    if (equipComp && equipComp.typeId === 'fs:giant_spear') {
      player.playAnimation('animation.player.giant_spear_wield', {
        blendOutTime: 0.2,
        stopExpression:
          "!query.is_item_name_any('slot.weapon.mainhand','fs:giant_spear') || v.attack_time || (math.clamp((query.main_hand_item_max_duration - (query.main_hand_item_use_duration - query.frame_alpha + 1.0)) / 10.0, 0.0, 1.0f))",
      });
    }
  });
  system.clearRun(e)
});```
north harbor
# hollow coyote ```js let e = system.runInterval(() => { world.getPlayers().forEach((player) =...
let itemWield = system.runInterval(() => {
  world.getPlayers().forEach((player) => {
    const equipComp = player.getComponent('equippable');
    const getEquip = equipComp.getEquipment(EquipmentSlot.Mainhand);
    if (getEquip && getEquip.typeId !== 'fs:giant_spear') {
      return;
    } else {
      beforeGiantSpearUse(); //Only for fs:giant_spear
      player.playAnimation('animation.player.giant_spear_wield', {
        blendOutTime: 0.2,
      });
      afterSpearMelee();
      afterUseSpear();
      afterReleaseSpear();
    }
    system.clearRun(itemWield);
  });
});```
north harbor
#

So no, it should technically hold the animation in place

#

I exported my world events like you did

hollow coyote
north harbor
hollow coyote
#

or ig ts for u

north harbor
#

this is the customSpear.ts file

north harbor
north harbor
hollow coyote
#

is ur animation set to be hold_on_last_frame?

north harbor
#

yes

hollow coyote
#

tbh im unsure

#

it was holding the last frame before right?

#

wait i kinda see the problem, maybe bc it's clearing the run, so it should only clear the run when u finish using the item

#

try exporting itemWield so then u can play it anywhere, and then in the item release after events, u can clear the run

#

btw, add this to ur picking up spear code:

 world.beforeEvents.playerLeave.subscribe((eventData) => {
    const player = eventData.player;
    for (const spear of spearsList) {
      player.removeTag(spear.tag);
    }
  });```
#

i noticed i was getting errors when a player had one of the tags but then left the game, it would throw constant errors

north harbor
#

I was not getting errors but I did see that issue

hollow coyote
#

yeah, luckily i have a guy that just messes around with all my addons and just finds random bugs ๐Ÿ’€

hollow coyote
north harbor
#

Lmao

hollow coyote
#

but he also comes up with some great ideas

north harbor
#

Oh damn wait so are you sending him the pack every time?

#

Or through GitHub?

#

I have like 3 different guys helping me come up with ideas so this is how I got into the spear stuff ๐Ÿคฃ

hollow coyote
#

but i tell him to delete the cache data everytime i make a new update so he can see it

#

he has basically gotten used to the process now

hollow coyote
north harbor
#

True

north harbor
hollow coyote
#

alright no worries, just let me know whenever u get it done

north harbor
#

im using a tag system instead

system.runInterval(() => {
  world.getPlayers().forEach((player) => {
    const equipComp = player.getComponent('equippable');
    const getEquip = equipComp?.getEquipment(EquipmentSlot.Mainhand);

    if (getEquip && getEquip.typeId === 'fs:giant_spear') {
      if (player.hasTag('useSpear')) {
        player.playAnimation('animation.player.charge_spear', {
          blendOutTime: 0.2,
          stopExpression:
            '!(math.clamp((query.main_hand_item_max_duration - (query.main_hand_item_use_duration - query.frame_alpha + 1.0)) / 10.0, 0.0, 1.0f))',
        });
      } else if (player.hasTag('meleeSpearAttack')) {
        player.playAnimation('animation.player.spear_melee', {
          blendOutTime: 0.2,
          stopExpression: 'q.any_animation_finished',
        });
      } else {
        player.playAnimation('animation.player.giant_spear_wield', {
          blendOutTime: 0.2,
          stopExpression: `q.is_item_name_any('slot.weapon.mainhand', 0, '${getEquip.typeId}') == 0.0`,
        });
      }
    } else {
      player.removeTag('meleeSpearAttack');
      player.removeTag('useSpear');
    }
  });
});```
hollow coyote
#

but that throw animation is definetly weird

#

idk if this would work, but i was thinking that maybe this molang expression:

'!(math.clamp((query.main_hand_item_max_duration - (query.main_hand_item_use_duration - query.frame_alpha + 1.0)) / 10.0, 0.0, 1.0f))'```
#

could be changed to include if they are not using the weapon

north harbor
hollow coyote
north harbor
#

And since it's a running interval, the animations that are not static will continue playing

#

That's why the charge animation was going crazy ๐Ÿ˜…

hollow coyote
#

oooh okay yeah

#

i wonder if u could put a system inside a system

#

idk if that's a bad idea, but u could clear the run later but still clear the run within the run so that way the animation works theoretically

#

although im not exactly sure tbh

north harbor
#

I was thinking that too but idk tbh ๐Ÿคฃ

hollow coyote
#

ig it's worth a try, if it doesnt work u can luckily just control z

hollow coyote
north harbor
#
system.runInterval(() => {
  world.getPlayers().forEach((player) => {
    const equipComp = player.getComponent('equippable');
    const getEquip = equipComp?.getEquipment(EquipmentSlot.Mainhand);
    if (getEquip && getEquip.typeId === 'fs:giant_spear') {
      if (player.hasTag('meleeSpearAttack')) {
        player.removeTag('useSpear');
        player.playAnimation('animation.player.spear_melee', {
          blendOutTime: 0.2,
          stopExpression: 'q.any_animation_finished',
        });
      } else if (
        !player.hasTag('meleeSpearAttack') &&
        !player.hasTag('useSpear')
      ) {
        player.playAnimation('animation.player.giant_spear_wield', {
          blendOutTime: 0.2,
          stopExpression: `q.is_item_name_any('slot.weapon.mainhand', 0, '${getEquip.typeId}') == 0.0`,
        });
      }
    } else {
      player.removeTag('meleeSpearAttack');
      player.removeTag('useSpear');
    }
  });
});```
#
world.afterEvents.itemUse.subscribe((spearUseAnim) => {
  const { source } = spearUseAnim;
  const spearType = spearUseAnim.itemStack;
  let tick = system.runInterval(() => {
    if (spearType && spearType.typeId !== 'fs:giant_spear') {
      return;
    } else {
      source.removeTag('meleeSpearAttack');
      source.addTag('useSpear');
      source.playAnimation('animation.player.charge_spear', {
        blendOutTime: 0.2,
        stopExpression: '!query.is_using_item',
      });
    }
    system.clearRun(tick);
  });
});

world.afterEvents.itemReleaseUse.subscribe((thrownItem) => {
  for (const player of world.getPlayers()) {
    const thrownSpear = thrownItem.itemStack;
    const inv = player.getComponent('inventory');
    // Check if the thrown spear matches any item in the spearsList
    const matchingSpear = spearsList.find(
      (spear) => spear.item === thrownSpear.typeId
    );
    let tick = system.runInterval(() => {
      if (matchingSpear && player.removeTag(matchingSpear.tag)) {
        const newSpear = thrownSpear.clone();
        let durability = newSpear.getComponent('durability');
        durability.damage++;
        inv.container.addItem(newSpear);
        // console.warn(`${durability.damage}/${(durability.maxDurability)}`)
        system.clearRun(tick);
      }
    });
  }
});```
north harbor
hollow coyote
#

does it work for first person?

north harbor
#

uh i need to make the first person animations

#

and the first person animations is through the attachable

hollow coyote
#

oooh yeah after that tho im sure it will work great!

north harbor
#

Yes ๐Ÿ™‚

hollow coyote
#

also the textures and stuff look cool! same with the mammoth in the background

#

how did u make it?

north harbor
#

i have a friend that made it

#

i have like a little team going

#

We're adding a dragon too

#

i need to start working on the flight mechanics

hollow coyote
#

oh sick! ngl i wish i had a friend that could model

north harbor
#

you want to join our team?

hollow coyote
#

im horrendous at modeling

north harbor
#

we need developers

hollow coyote
#

that would be sick! but i feel im too inexperienced and dont exactly have enough time

#

a lot of the addons i make r mostly passion projects

north harbor
#

i never have time either :/

hollow coyote
#

yeah it's spring break for me so that's how ive been able to get on so much

north harbor
#

Our team works whenever we can, no deadline. Just want to make something for the community

hollow coyote
#

that sounds fun!

#

ill think about it and there is a project ive had in mind for a while too so idk if ud guys be up for it or not

#

okay ill join and look into it