CRT synthetic magic reform: formula function application [CRT] CRAFTTWEAKER MINECRAFT Game

This tutorial is set by the author to use the CC by-NC protocol.

Foreword

The tutorial is suitable for 1.12.2, 1.18.2, and the script has not been tested in other versions.

Due to my limited technology, there must be shortcomings in this tutorial, please forgive me.If you have better suggestions, please point out in the comment area or private message.

The nouns that may involve in the tutorial will not be explained, such as "object".

The role of this script is to use the diamond sword and the last shadow crystal for disorderly synthesis. The synthesized diamond sword maintains the original durability, enchantment and other data, and adds the undead killer 5 enchantment.

For example code

 Import Crafttweaker.enchantments.ienchantment;

import crafttweaker.item.iitemstack;

import crafttweaker.data.idata;

// Import to import related packages, without importing the corresponding package will make the script find the type we created

// Establish two variables to point to synthetic materials, one is a diamond sword, and the other is the last shadow crystal.

// The best declaration of variables to point to the items we want to modify. We must know that the diamond swords pointed to the two are not the same.

// "*" is used to represent all durability.

var snord = ;

var end_crystal = ;

// A disorderly synthetic registry, we need to mark the materials you want to operate (call the "Marked" method), for example, I marked "Mark" to Sword.

// This can be marked at will (such as filling in "END"), and the calling method is "INS.END" to indicate the marked itemstack.

// Recipes.addshapeless (name, output, inputs, function, action)

// If function is used as the third parameter, you can use a function to determine the product.

// If the Action function is the fourth parameter, you can also determine events triggered when the item is synthesized.(Quote from Crafttweaker Simplified Chinese Documents)

recipes.addshapers ("test_sword", sword, [sword.marked ("mark"), end_crystal],

// Add a function as the third parameter.Reference: Formula function

Function (out, ins, cinfo) {

// Create an Enchtag to save read NBT data.Although it is empty now.

Var Enchtag as idata = {};

// Create an ENCHSMITE to preserve the undead killer enchanting

VAR Enchsmite = ; // Isenchantable returns true when there is no enchantment, so an exclamation mark is added before.

If (! Ins.mark.isenchantable) {{

// If this diamond sword itself has enchantment, it traverses all the enchantment

// Here is the input material marked as "MARK" by the "MARKED" method, and obtain the enchantment list through the "Enchantments" method.

For ench in ins.mark.enchantments {

// Determine whether the enchantment traversed by it is the dead killer, if it is not recorded in Enchtag.

If (ench.definition.id! = Enchsmite.id) {

Enchtag+= Ench.maketag ();

}

}

}

// After the cycle is over, add the ENCHTAG to ENCHTAG to add the dead killer 5 enchantment.

// Makeenchantment (5) It means that this enchantment level is 5, and Maketag means returning this enchanting NBT data.

Enchtag+= ENCHSMITE.MAKEENCHANTMENT (5). Maketag (); // Here should be returned to the Itemstack output of the formula, or you can return "NULL" to make the formula invalid.

// Because we want to keep the diamond sword durable and before synthesis, we return to the input diamond sword.

Return ins.mark.withtag (Enchtag);

},

// Can't use the synthetic event here, so it needs to be set as empty

null);

// The following is an example of version 1.18.2

Import Crafttweaker.api.Item.iitemstack;

Import crafttweaker.api.Item.enchantment.enchantment;

// Indicates that the diamond sword supports any durability

var Sword = .anydamage ();

var end_crystal = ;

var enchsmite = ;

Craftingtable.addshapeless ("test_sword", , [Sword, End_crystal], (Output As IitemStack, Inputs As Itemstac k [] => {{

// Delete the dagger of the undead killer, and the method returns other items with the same data after deleting the undead killer. The original input items remain unchanged

Var returnitem = inputs [0] .removeenchantment (Enchsmite);

// Return a item written to the Undead killer 5. As above, the with method calls a item written to the dead killer, and it is not the same as the previous variables.

Return returnitem.withenchantment (Enchsmite, 5);

});

Code result

1.18.2 Example Results:

grateful:

Sinicic CRT's Wiki of CRT

youyihj's gitbook

Official wiki