Scavenge

Scavenge

2M Downloads

The property "scavenge_player:has_item_tag" didn't work.

854342681 opened this issue ยท 7 comments

commented

I want to right click gold block with a item, which have nbt tag.and give me something. But it still can use same item which no nbt tag to fire it.
Following the code.

{
	"scripts": {
		"id": "lightning",
		"swing": true,
		"drop_rule": "player_inv",
		"loot_seed": 0,
		"properties": [
        {
            "property": "scavenge_player:is_hand",
            "main_hand": true
        },
        {
            "property": "scavenge_player:has_item_nbt",
            "nbt":"'tag':'{mekData: {EnergyContainers: [{Container: 0b, stored: \"1000000\"}]}}'"        
        },
        {
            "property": "scavenge_player:has_item",
            "item": "mekanism:energy_tablet"
        },
        {
            "property": "scavenge_player:consume_item",
            "amount": 1,
            "chance": 100.0
        }],
		"loot": [ 
            {
            "lootPool": "23"
        }],
		"type": {            
            "type": "right_click",
            "consume": true,
            "show": true
        },
		"targets": [
            {
            "type": "blocks",
            "id": [
                "minecraft:gold_block"
            ]
        }]
	}
}
commented

The command/give @s mekanism:energy_tablet{mekData:{EnergyContainers:[{Container:0b,stored:"1000000"}]}}can run in game.
And I try some

"nbt":'"tag":"{mekData: {EnergyContainers: [{Container: 0b, stored: \"1000000\"}]}}"'
"nbt":"\"tag\":{mekData: {EnergyContainers: [{Container: 0b, stored: \"1000000\"}]}}"
"nbt":"{mekData: {EnergyContainers: [{Container: 0b, stored: \"1000000\"}]}}"

All of them not correct syntax, help me please!

commented

Please enable script dumping and look what that outputs. (if that crashes: then provide your crashlog)

My guess is:

'tag'

is not NBT conform. You need to exchange ' with " because otherwise minecrafts NBT Parser will just say: "not valid NBT"
If you want to test which NBTCode is valid. use minecrafts command line and use a Command that allows NBT to be written.

Small side note: Since i am using Gson: if you use ' instead of a " for a string it will practically wait to find the next ' instead of ".

So this should fix it.

"nbt":'"tag":"{mekData: {EnergyContainers: [{Container: 0b, stored: \"1000000\"}]}}"'

But please validate your NBT code with minecrafts Life Code Validator the command line

commented

"nbt":'"tag":"{"mekData": {"EnergyContainers": [{"Container": 0b, "stored": "1000000"}]}}"'
This should work.

commented

I tried it, also not a correct syntax.And I try some another syntax, It's work, can be seen in JEI, also have script output, but no effect when I use item which same NBT. Interest thing is that, when I use same format code test on a diamond sword with NBT{"Enchantments":[{"id":"minecraft:sharpness","lvl":10}]} , the code work perfectly.
mekanism:energy_tablet script output code:

{
	"scripts": [
		{
			"id": "minecraft:lightning",
			"swing": true,
			"drop_rule": "player_inv",
			"loot_seed": 0,
			"targets": {
				"type": "blocks",
				"id": [
					"minecraft:gold_block"
				]
			},
			"properties": [
				{
					"main_hand": true,
					"jei_visible": true,
					"property": "scavenge_player:is_hand"
				},
				{
					"item": "mekanism:energy_tablet",
					"jei_visible": true,
					"property": "scavenge_player:has_item"
				},
				{
					"nbt": {
						"mekData": {
							"EnergyContainers": [
								{
									"Container": 0,
									"stored": "1000000"
								}
							]
						}
					},
					"jei_visible": true,
					"property": "scavenge_player:has_item_nbt"
				}
			],
			"loot": [
				{
					"lootPool": "minecraft:lightning"
				}
			],
			"type": {
				"type": "right_click",
				"consume": true,
				"show": true
			}
		}
	]
}

mekanism:energy_tablet code:

{
	"scripts": {
		"id": "lightning",
		"swing": true,
		"drop_rule": "player_inv",
		"loot_seed": 0,
		"properties": [
        {
            "property": "scavenge_player:is_hand",
            "main_hand": true
        },
        {
            "property": "scavenge_player:has_item",
            "item": "mekanism:energy_tablet"
        },
        {
            "property": "scavenge_player:has_item_nbt",
            "nbt":{
                "mekData":{
                    "EnergyContainers":[{
                        "Container":0,
                        "stored":"1000000"
                    }]
                }
            }
        }
        ],
		"loot": [ 
            {
            "lootPool": "lightning"
        }],
		"type": {            
            "type": "right_click",
            "consume": true,
            "show": true
        },
		"targets": [
            {
            "type": "blocks",
            "id": [
                "minecraft:gold_block"
            ]
        }]
	}
}

This is a test code on diamond sword:

{
	"scripts": {
		"id": "lightning",
		"swing": true,
		"drop_rule": "player_inv",
		"loot_seed": 0,
		"properties": [
        {
            "property": "scavenge_player:is_hand",
            "main_hand": true
        },
        {
            "property": "scavenge_player:has_item",
            "item": "minecraft:diamond_sword"
        },
        {
            "property": "scavenge_player:has_item_nbt",
            "nbt":{
                "Enchantments":[{
                    "id":"minecraft:sharpness",
                    "lvl":10
                }]
            }
        }
        ],
		"loot": [ 
            {
            "lootPool": "lightning"
        }],
		"type": {            
            "type": "right_click",
            "consume": true,
            "show": true
        },
		"targets": [
            {
            "type": "blocks",
            "id": [
                "minecraft:gold_block"
            ]
        }]
	}
}
commented

ok i look into it. Will take a couple days since i am in the middle of a port project...

commented

Thanks for your help, have a nice day.

commented

@854342681 ok i looked into it...
The NBT you written is correct. But in this case this looks more like that mekanisms custom number format isn't really "nice" with NBT compare since it is a Long+Short that is supposed to make a "double" more efficient... (As if Scientific Notation isn't already insanely optimized on CPUs but I digress)

Floating point numbers are lets say hard to compare... Because they are not always exactly the same...
If you want to know the issues with it look up "Floating Point Numbers - Computerphile" and see what HairPulling problem it is...

And converting it into a string makes it actually worse because the strings get the "output" of the supposed floating point number which can differ based on how the PC decides to round the number...
1+2 => 3.0000000001 or 2.99999999999 (As I said Hairpulling)

So because of this I don't think this is exactly a scavenge but a mekanism problem... Well mekanism tries to be special problem and you having to deal with floating point numbers instead of integers...