CraftTweaker

CraftTweaker

151M Downloads

[Question] How to allow item with certain NBT tags that have any valid value

brisingraerowing opened this issue ยท 5 comments

commented

Issue Description:

I would like to create a script to convert player heads that are named into an actual head for that player.
E.g. A player head named Iskall85 would convert into Iskall's head. I want this to work for any CustomName value (doesn't have to be a valid player name, as I don't think I can validate that easily).

The main issue here is how to allow only heads that have a Display NBT tag with the CustomName tag set to any value. I also would like to know how to copy the value of the CustomName tag to the output's SkullOwner tag (I'm guessing I would have to build that manually using the IData interface).

What happens:

N/A

What you expected to happen:

N/A

Script used (Please Pastebin or gist your script, posting an unpasted or ungist'd script will automatically close this issue):

No script yet.

Minetweaker.log file (Please Pastebin or gist your file, posting an unpasted or ungist'd file will automatically close this issue):

No log.


Affected Versions (Do not use "latest"):

  • Minecraft: 1.12.2
  • Forge: 2542
  • Crafttweaker: 4.0.10

Your most recent log file where the issue was present:

N/A
[pastebin/gist/etc link here]

commented

discord.blamejared.com is a better to ask questions like this, so if you don't mind, can you move the question there? also what have you tried?

commented

Here's what I have:

recipes.addShapeless("HeadConversion", <minecraft:skull:3>.mark("output_head"), [<minecraft:skull:3>.mark("input_head")],
function(output, input, crafting) {
    val input_tag = input.input_head.tag;
    if (input_tag.contains("display")) {
      val display_tag = input_tag.display;
      if (display_tag.contains("Name")) {
        val head = output.output_head.withEmptyTag();
        head.tag.SkullOwner = display_tag.Name;
        return head;
      }
    }
    return null;
  });

It fails on the first line with the message "no method with that name available" when entering a world.

I previously had

recipes.addShapeless("HeadConversion", <minecraft:skull:3>.mark("output_head"), [<minecraft:skull:3>.mark("input_head")],
function(output, input, crafting) {
    val input_tag = input.input_head.tag;
    if (input_tag.contains("display")) {
      val display_tag = input_tag.display;
      if (display_tag.contains("Name")) {
        val data = {} as IData;
        data.SkullOwner = display_tag.Name.asString();
        return output.output_head.withTag(data);
      }
    }
    return null;
  });

And that failed with the message "';' expected" on the line 'val data = {} as IData;' If I wrapped the '{} as IData' in parenthesis, the error would change to "')' expected".

commented

once again, discord is the place for this (since other people may have ideas as well)

you don't need to mark the output, that actually just doesn't work, the output is already given in the function

commented

I've never been able to get Discord to work on my computer. Not even in the browser. Never could figure out why. I can see things, but even if I have an account set up and am allowed to post, posting fails with an unknown error from Windows.

commented

I just figured out what causes the discord issue thanks to a minidump I loaded into WinDbg. I'll continue this on Discord since I should be able to post now.