Jump to content

[SOLVED][1.19.2] ListTag nbtpos how to store a pos value as int[] array in a nbt listtag


perromercenary00

Recommended Posts

hello good days 

i need to store block Positions as nbtdata in the same way minecrafts structure_block does save its capture structures 

that looks like this 

	    { "pos"  : list<TAG_Int>[3] [
        0,
        0,
        2
      ],  <-- this looks like an array inside a listtag 
      "state": 0
    },
	

 

if a use the alredy avaliable method

 nbtpos = NbtUtils.writeBlockPos( bpos );

it end looking like this

	    { "pos"  : {
        "X": 1,
        "Y": 2,
        "Z": 1
      }, <---- but the mine is an object whit keys in a regular tag 
      "state": 1
    },
	

Mi code nor the structure_block cannot read this values 

made a test item and put in some experimental code

	// ########## ########## ########## ##########
	@Override
	public InteractionResultHolder<ItemStack> use(Level warudo, Player pe, InteractionHand hand) {
	if(!warudo.isClientSide){
	int [] apos = {0,0,0};
	int index = 2;
	ListTag nbtpos = new ListTag();
	BlockPos bpos = new BlockPos( 6,7,8 );
	apos[0] = bpos.getX();
	apos[1] = bpos.getY();
	apos[2] = bpos.getZ();
	 
	//nbtpos.getIntArray(index); //<---- whats the opossite of this 
	nbtpos.????( apos ); <-- the missing part where i store the data as positions inside the taglist 
	 
	System.out.println("nbtpos=" + nbtpos.getInt(0) +", "+nbtpos.getInt(1) +", "+nbtpos.getInt(2) );
	//profit 
	}
	return InteractionResultHolder.pass(pe.getItemInHand(hand));
	}
	

 

looks theres is a missing function for store an array in a taglist  nbtpos.setIntArray(apos); nbtpos.putIntArray(apos); nbtpos.addIntArray(apos);

or at least nbtpos.add( int justanIntvalue);

 

#######################

soo how i doo to store int values directly in a listtag wey it end looking like minecraft does ??

    { "pos"  : list<TAG_Int>[3] [
        0,
        0,
        2
      ], 

 

 

thanks for your attention 

Edited by perromercenary00
Link to comment
Share on other sites

It's not clear what you mean by "minecrafts structure_block" but I guess what you are referring to/looking for is?

StructureTemplate.Palette.save(CompoundTag)

That has code to put a ListTag in the compound tag, see newIntegerList()

 

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

	// ########## ########## ########## ##########
	@Override
	public InteractionResultHolder<ItemStack> use(Level warudo, Player pe, InteractionHand hand) {
	if(!warudo.isClientSide)
	{
	ListTag nbtpos = new ListTag();
	BlockPos bpos = new BlockPos( 6,7,8 );
	nbtpos.add(IntTag.valueOf( bpos.getX() ));
	nbtpos.add(IntTag.valueOf( bpos.getY() ));
	nbtpos.add(IntTag.valueOf( bpos.getZ() ));
	System.out.println("nbtpos=" + nbtpos.getInt(0) +", "+nbtpos.getInt(1) +", "+nbtpos.getInt(2) );
	}
	return InteractionResultHolder.pass(pe.getItemInHand(hand));
	}
	

is a weird way to solved it looks more like kinda hacky 

 

google point me to this early this morning but cannat doo anything whit this one 

List<Value> coords = ((ListValue)value).getItems(); ListTag tag = new ListTag(); tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(0), "x").getDouble())); tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(1), "y").getDouble())); tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(2), "z").getDouble())); ltag.add(tag);

 

 

but the result is what iwas needing now my copyed extructures can be picked up by the vainilla structure block 

	{ "blocks" : list<TAG_Compound>[10] [
	{ "pos" : list<TAG_Int>[3] [
	1,
	0,
	1
	],
	"state": 0
	},
	{ "pos" : list<TAG_Int>[3] [
	2,
	0,
	0
	],
	"state": 0
	},
	

 

thanks i gonne write the resto of code later 

Link to comment
Share on other sites

  • perromercenary00 changed the title to [SOLVED][1.19.2] ListTag nbtpos how to store a pos value as int[] array in a nbt listtag

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.