#Making the spawned mob have nbt data

1 messages · Page 1 of 1 (latest)

pure quail
#

I am trying to make a custom entity from a mod to spawn in a structure
I tried doing so using jigsaw blocks, but they keep the exact same details each time, causing some issues
I want to know if the issue can be avoided by using a script, that will generate the entity each time the structure spawns
Also I don't really know how scripts work so might need some help with that

hasty blade
#

What details do you mean are the same

thick osprey
#

Like their NBT

hasty blade
#

Structure blocks copy the exact entity

thick osprey
#

or the items they have

hasty blade
#

Yeah but what details need to be changed

pure quail
#

nbt

bold harbor
#

Also Java doesn't have scripts

pure quail
#

so I made this pack for the cobblemon mod
and the entity(the pokemon) I made always had the same ID
meaning that they are considered dupes and are removed upon relogging

bold harbor
#

Youmean UUID?

pure quail
pure quail
thick osprey
#

you can use the jigsaw blocks to spawn a marker and then use a function to summon the entity at that position whilst killing the marker.

bold harbor
bold harbor
pure quail
#

oh for real?

thick osprey
hasty blade
#

Possibly

pure quail
#

I thought it was intended behavior

pure quail
hasty blade
#

Probably to avoid duped cobblemon

bold harbor
thick osprey
pure quail
#

how would I go about doing that?

thick osprey
#

Have you ever used functions?

pure quail
#

and will it work in a world where commands are turned off?

thick osprey
#

yea

pure quail
mighty oracleBOT
hasty blade
#

Oop wrong reply

thick osprey
#

I recommend checking out the beginners guide

pure quail
#

can the functions also call commands who are specific to the mod?

hasty blade
#

Yes

pure quail
#

because cobblemon doesn't use the normal summon command

thick osprey
#

yea most of the time, thats no problem, I'm pretty sure it works for cobblemon

pure quail
#

I assume the way I make this not accessible by just renaming the armor stand is making it invisible and maybe even giving it an effect?

pure quail
#

ok this is strange
It spawns my entity wrong
could this be tied to the fect my datapck only loads after a world is made?

#

ok yeah /place works fine

#

any way around this?

bold harbor
#

You're gonna need to be more specific

pure quail
#

so what my datapack does is add a form for the pokemon eldegoss
the way it handles forms is by giving them a tag
when the world is made(a completely new one)
normal eldegoss spawn on the trees despite having the datapck

bold harbor
#

Shouldn't have anything to do with load order, the data pack is loaded when those entities get spawned since you're spawning them with functions.

pure quail
#

then why are they loaded as normal?
When I use /place my version shows up

bold harbor
#

I don't know

pure quail
#

is there a way to make it so my command only works while the player is close to the structure?

thick osprey
#

yea use execute if entity @a[distance=..50] for example

pure quail
#

won't replace them at all now, did I get something wrong?

bold harbor
#

You're checking if the player is exactly 300 blocks away

#

Blackswitch's example included .. for a reason, they indicate a range/greater than or equal to/less than or equal to

pure quail
#

oh my bad

#

so this just checks if the player is close enough to my armorstand?

bold harbor
#

Is that what you think it does?

pure quail
#

no

bold harbor
#

What do you think it does?

pure quail
#

I just think I got something wrong
I believe the part that checks where the player is and the detection of the armorstand should be seprate

bold harbor
#

Correct

pure quail
#

like @a is to check where the palyer is
and @e is to located the armor stand

bold harbor
#

Right now you have it checking if there is a player within ranger that is an armor stand, which of course will never be true

pure quail
#

so right after my if should be an as statement?

#

execute if entity @a[distance=..300] as @e[type=armor_stand,name="Spawn"] at @s run pokespawn eldegoss end status=sleep
something like this

bold harbor
#

You want to switch your as @e at @s and the if entity

#

Think about it logically. First the function needs to know who it's running as and from where, before it can accurately check who is near it

pure quail
#

oh so the if just comes right at the end?

#

ok no still confused

#

in the first part, I tell it who to run the command on
shouldn't the second part check if a player is nearby?

#

so like @e as then if entity @a and then @s

pure quail
#

this didn't work either

#

Could I get another explanation as to how this works?

pure quail
#

I believe I'm still doing something wrong, the entity is spawning but I don't think my distance has anything to do with it

hasty blade
#

What would you like more clarification for

pure quail
#

how does the if condition works

#

because I believe I'm using it wrong

hasty blade
#

Yeah that makes sure that every player is within 50 blocks

#

..50 is the same as <(or equal to)50

pure quail
hasty blade
#

Assuming your goal is that every player needs to be within 50 blocks then yes

pure quail
#

oh wait no

#

I'm good with just 1

#

but even with 1 it doesn't seem to work

hasty blade
#

Then probably add sort=nearest and limit=1

hasty blade
pure quail
#

if I'm more then 50 blocks away, I would still not see the armor stands I placed

hasty blade
#

That might be a thing with armour stands

#

Place an armour stand then go 50 blocks away and just test it

pure quail
#

disappears immdietly without spawning anything

#

I might have understood why

#

I'm killing them on loop

#

so even if they don't spawn anything they would still be replaced

hasty blade
#

That would be it

pure quail
#

what can I do about it?

#

add a condition to the killing as well?

hasty blade
pure quail
#

oh wait

hasty blade
#

It kills before you get close enough

pure quail
#

maybe?

hasty blade
#

That should be tested

pure quail
#

even if I place it down it disappeares instantly

#

how can I make it so it only kills it when replaced

hasty blade
#

Make the check run a function that summons eldegoss and kills the stand

pure quail
#

I can run 2 commands at once?

hasty blade
#

Not in the execute

#

In another function, yes

pure quail
#

ohhhhh so basicaly make a file that has the command and call it by saying run function name

hasty blade
#

It would have 2 commands but yeah

hasty blade
pure quail
#

ok so I can now see the armor stand

#

first time placing the structure went fine

#

second time they won't spawn the mob

#

and I am close to them

hasty blade
#

So now the issue is it only spawns the armour stands?

pure quail
#

yes

#

it swapped them well the first time

#

but now it won't

hasty blade
#

Ok send the functions

#

(in text after typing ``` before and after the test)

pure quail
#
execute as @e[type=armor_stand,name="Spawn_shiny"] if entity @a[distance=..10,sort=nearest,limit=1] at @s run function endegoss:eldegoss_shiny_spawn```
#
kill @e[type=armor_stand,name="Spawn"]```
#
kill @e[type=armor_stand,name="Spawn_shiny"]```
hasty blade
#

so it spawns once, but when you /place it again it doesnt?

pure quail
#

yeah

hasty blade
#

but it spawns the armour stand?

#

how close are you /placing them

pure quail
pure quail
hasty blade
#

try a bit further away and see if it changes

pure quail
#

went 10000 block away, same result

#

could it be the limit in the @a section?

hasty blade
#

alright that is weird

hasty blade
#

when are these functions even running

pure quail
#

wdym?

#

wait

pure quail
#

tick.json

hasty blade
#

alright

pure quail
#
    "values": ["endegoss:loop"]
} ```
#

this works only at spawn chunk

#

I think

hasty blade
#

oh?

#

try it in a forceloaded chunk

pure quail
#

how do I force load?

#

I'm on 1.21.1

hasty blade
pure quail
#

ok I loaded the chunk it's in but nothing changed

hasty blade
#

and it works in spawn chunks?

pure quail
#

no stopped working there as well

hasty blade
#

ok

pure quail
#

it does work well for a while after /kill @e

hasty blade
#

thats incredibly weird

hasty blade
#

since it already runs as the armour stand

pure quail
#

still spawns armor stands

hasty blade
#

how are you applying these changes btw

pure quail
#

wdym?

hasty blade
#

/reload or relogging the world

pure quail
#

tried both

hasty blade
#

alrighty

#

so unfortunately I do have to go for a bit, but another helper might be able to help you fix your issue

pure quail
#

no problem
thanks for the help!

pure quail
#

ok so my problem is defiantly related to the player distance check

#

removing it solved everything

#

also I think I might not need it

hasty blade
#

Well

#

If this is for a server then you will need something similar

pure quail
#

what I do need to know is if there is a way to do a /reload automatically on load

pure quail
#

why is that?

hasty blade
#

Because @a is every player

#

Wait no

#

Mb

pure quail
#

I removed the @a part entirely

hasty blade
#

This will just do it if everyone exists

#

Yeah

pure quail
#

it just runs

#

but upon loading it for the first time it still has an issue which causes it to spawn the wrong version of the entity

#

but running a /reload before entering the end solves that

#

so is it possiable to run /reload as soon as my pack is loaded?

#

and will it have a negative impact on other packs?

hasty blade
#

Probably won't

#

Just add reload to a load function

pure quail
#

load function?

#

I don't have one

hasty blade
#

Like tick.json but load.json

pure quail
#

oh

#

and will it run each time it's loaded?

hasty blade
#

it might cause a loop of reloads

#

so I would add a scoreboard that checks if it has been ran before

pure quail
#

ohhh never done that before

#

so basicaly I make it run it once, up the scoreboard, and then it won't run again becasue the scoreboard says it already did

#

kinda like a flag

hasty blade
#

yeah exactly

pure quail
#

oh ok

#

gonna go read on the website how to work with scoreboards

hasty blade
#

alright

pure quail
#

but the main function should be called from load.json

hasty blade
#

no?

pure quail
#

oh
so it's not like tick.json

#

or should I add it to tick.json

hasty blade
#

no, it automatically runs once when your datapack is loaded

#

so when a server starts or a singleplayer worlds gets made/joined

pure quail
#

this is about load.json?

hasty blade
#

yes

pure quail
#

and inside will be a call to the function that does a /reload when it is the first ever time being loaded

#

which I will know by setting a scoreboard

pure quail
#

where do I generate the scoreboard
asumming it's supposed to happen once

hasty blade
#

just in in the load

#

it wont reset unless you do that in the load aswell

pure quail
#
    "values": ["endegoss:reloader"]
}```
this is how this looks now
#

reloader just has reload command in

#

and it in fect just spammed it like you said

#

so do I add a function here that makes a scoreboard?

hasty blade
#

Not a separate function

pure quail
#

So just in load.json?

#

Won't it make it run in a loop

#

Or remake the same scoreboard over and over again?

pure quail
#

Gonna be honest kinda lost here

#

how can I use scorboards as a flag?

#

like I get how you set one up it's just
how do I add something to it to act as my flag

bold harbor
#

You don't need to do anything special, there is no "flag" setting

#

You just set it to 1 or 0, or whatever value(s) you care about to determine the status of whatever it represents

pure quail
#
scoreboard players set #reload reload 0```
like this?
bold harbor
#

Sure

pure quail
#

because what I'm trying to do is to make my datapack run the /reload command on the first time it's loaded in

bold harbor
#

That seems redundant

#

It's just gonna loop /reloads

pure quail
#

yeah but if you don't reload right as the pack is added it spawns my entity wrong

bold harbor
#

That's how all packs work

#

All users should be reloading when they add a pack

pure quail
#

from the create world screen

bold harbor
#

Then you need to reasses what is in your load function

#

Cause that shouldn't be the case

pure quail
#

what I wanted it to do is to check the scoreboard and see what the value is
if 0, then run a reload and set the value to 1

#

then every time it will open in the future, it won't force a reload

bold harbor
#

But what is in your load function right now that isn't running correctly when the world actually loads?

pure quail
#

oh I didn't have a load function

#

I just added it

#

I had a tick.json file just running my spawn command

bold harbor
#

I see

pure quail
bold harbor
#

OK, well I guess you can try it

#

What you have so far is fine

pure quail
bold harbor
#

It will technically work, but it's bad practice and solves a problem the cause of which isn't well-understood

pure quail
#

yeah I do get that part of it but I fr don't get what the problem is
It spawn correctly after I use /reload or log out

#

it just that I want everyone to be able to just use it without having to run a command or relog

bold harbor
#

Naturally

pure quail
#

but I don't know how you check things in a scoreboard

#

is it another execute if

bold harbor
#

Yep

pure quail
#

also, is the load.json file running every single tick as well?

bold harbor
#

Nope

#

Just when the pack is loaded upon server startup, and when /reloaded

pure quail
bold harbor
#

Well it won't remake the scoreboard, but yes it will reset it to 0

pure quail
#

so condition for the second line as well

bold harbor
#

Or instead, you don't have to set the score to 0 at all

#

And you can just do execute unless score ... to see if the score has already been set to 1, and if it hasn't, set the score to 1 then reload

pure quail
#
scoreboard players set #reload reload
execute unless reload=1 ```
Is this right? still trying to get the hang of it
bold harbor
#

No

#

Try writing commands in-game to see the syntax

pure quail
#
scoreboard players set #reload reload
execute unless score #reload reload = 1```
bold harbor
#

Line 2 is incorrect syntax and will fail to validate. You also don't need it

pure quail
#

do I not have to add the player?

bold harbor
#

Shouldn't need to

#

Line 3 is also incorrect syntax and will fail to validate. Rather than using an = here, you instead need to use matches

pure quail
#

oh in game it was =

bold harbor
#

Writing either of those in-game would have shown as errors

#

= is acceptable in that command but you're using it wrong

#

It's used to compare two scores of one or more entities. If you're comparing to a specific value, you use matches

pure quail
#

oh I see it now

#

ok

#

and after this one all I should do is run the command for a reload and up the score for #reload to 1

bold harbor
#

Yes. You'll need to do both of those in a new function that gets run by that command

pure quail
#
execute unless score #reload reload matches 1 run function reload_updater```
reload_updater
```reload 
scoreboard players set #reload reload 1```
bold harbor
#

You have a logical error in reload_updater, can you see it?

pure quail
#

maybe reload after updating becasue if I do it before it all gets reset and then it will not work

bold harbor
#

Yep

pure quail
#

ok so either what I did didn't solve the problem or it just stright up didn't work

#
say reloading!!!!
say reloading!!!!
reload```
I placed this to see if it actually worked or not, is this a valid way to check, becasue I didn't see anything
bold harbor
#

It is a valid way to check, but it may be sending the say commands before the player enters the world

pure quail
#

logs then

bold harbor
#

Mhm

pure quail
#

nothing in the logs

#

that means it's not calling it

#

also when I check the scoreboard, it's empty

bold harbor
#

In that case, try adding a new line 2 with scoreboard players add #reload reload 0

pure quail
#

won't it reset every time then?

bold harbor
#

add, not set

#

If it's empty, it'll make it 0. If it's 1, it'll stay 1

pure quail
#

oh right

#

list still empty

#

and logs show no sign of my message

#

it's like I can't even add a dummy player to the list

bold harbor
#

The load function must not be running period

#

You made a load.json?

pure quail
#

when I try it ingame, it does say it worked but won't show at all

pure quail
pure quail
#

it does make the scoreboard named reload

pure quail
#

it says that it did that, but nothing shows up on the sidebar ingame

#

works fine when I add myself

bold harbor
pure quail
#

oh

#

that would explain why it won't show up

bold harbor
#

Mhm

pure quail
#

do they not react to the get command as well?

bold harbor
#

They do.

pure quail
#

oh it worked this time

#

the value is 0

#

no the problem is still here I'm afride

#

it's the get command that worked

#

if it reloads, the value should be 1

#

yet it's zero

bold harbor
#

Yes I understand that

#

What happens if you personally /reload?

pure quail
#

you mean the problem with the reloader or the one with the entity

#

because the entity problem is solved when I /reload

bold harbor
#

...Yes, I know that, which means I must be talking about the reloader, huh?

pure quail
#

sorry I get confused easily sometimes

#

the scoreboard is still 0, even after reloading

bold harbor
#

What happens if you run /execute unless score #reload reload matches 1 in chat?

pure quail
#

nothing

#

and scoreboard still is the same

bold harbor
#

Well we weren't changing it

bold harbor
pure quail
#

no output at all

bold harbor
#

It should at least tell you if the test passed or failed

#

Turn on sendCommandFeedback?

pure quail
#

passed

bold harbor
#

So that's working fine

pure quail
#

but with the run command attached to it it doesn't say anything

bold harbor
#

Can you run reload_updater from chat?

pure quail
#

yes

#

it reloaded and sent the output

bold harbor
#

idk then

pure quail
#

execute unless score #reload reload matches 1 run function reload_updater

#

this is the way I call for it

bold harbor
#

Mhm

pure quail
#

so everything is correct yet it still won't work

bold harbor
#

Seems like it

pure quail
#

welp

#

don't know what to do now

bold harbor
#

For now you can wait and see if another helper can spot something I missed

pure quail
#

k
thanks for the help!

pure quail
#

welp through trial and error, I believe it now works as intended

pure quail
#

ok so new problem
I want my entity to not despawn at all
but cobblemon made it difficult
is there a way for me to run the /data merge command with {PersistanceRequired:1b} but only on the entity that spawns on the armor stand?

#

like maybe by executing a command using @n for near entities

#
execute as @e[type=armor_stand,name="Spawn"] at @s run data marge @n {PersistenceRequired:1b}
kill @s[type=armor_stand,name="Spawn"]```
I did this but I it didn't work
#

I think my logic is wrong somewhere

pure quail
#

Making the spawned mob have nbt data