Part.3.1 Advanced formula -modular machine

This tutorial is set by the author's setting without permission.

Modular machine: community version from entry to the soil -part.3.1 Advanced formula application

This tutorial is displaying modular machinery: the community version of CRT's advanced available API.

The main modules used in this tutorial are modular machinery: community version -1.11.1 -R33, Crafttweaker.

Note: The content of this tutorial may change at any time. Please carefully compare the module version used in this tutorial, so as not to cause module updates to cause inexplicable error problems.

Tutorial directory:

Part.1 Basic Machinery Creation

Part.2 Basic Formula Create

PART.3.1 Advanced Formula (Current)

Part 3.2 Formula adapter recipeadapter (unfinished)

Part.3.3 Mechanical event system (unfinished)

Part.4.1 parallel formula processing (unfinished)

Part.4.2 Factory system (unfinished)

Part.4.3 Factory event system (unfinished)

Part.4.4 Smart Data Interface (unfinished)

Part.4.5 Unilateral / multi -square mechanical upgrade (unfinished)

Part.4.6 Custom GUI information (unfinished)

Part.5 configuration file analysis (unfinished)

Environmental preparation

This tutorial is highly recommended to use Visual Studio Code (hereinafter referred to as vScode), which can greatly reduce your magic workload.

Using VSCODE, you can use its powerful functions to complete complex operations faster. At the same time, it has code prompts to greatly reduce the difficulty and error rate of code reading. At the same time, you can install plug -in to expand the function to make it stronger.

Reading this tutorial means that you are familiar with most of the advanced use of Zenscript, and you have learned about basic mechanical creation and formula creation.

Module

If you have installed Crafttweaker and modular mechanical body and the game has been started, you can skip this description.

To create a formula, you need to use Crafttweaker (any version).

To view the created formula, you need to use Jei (any version).

Advanced API

Advanced API allows you to use Cracttweaker to create richer mechanisms and functions.

Recipemodifierbuilder

RecipemodifierBuilder can be used to build a recipemodifier, and the recipemodifier is the key to dynamically modify the formula input and output.

Guide package:

 Import Mods.modularMachinery.RcipeModifierbuilder; 

RECIPEMODIFIERBUILDER provides two uses:

 recipemodifierbuilder.newbuilder ()

// Type = Type of using recipemodifier

// iOTypestr = Recipemodifier is applied to input or output?("Input" is input, "utput" is output)

// value = recipemodifier value (type Float)

// Operation = recipemodifier value will be calculated?(0 is plus, 1 is multiplication, default 0)

// AFFECTCHANCE = RECIPEMODIFIER is applied to probability?(True is app, FALSE is not applied, default FALSE)

Recipemodifierbuilder.create (String Type, String IOTYPESTR, Float Value, Int Operation, Boolean Affectchance)

Both methods are the same.

ReCiPemodifierBuilder usage case:

 // builder mode

Recipemodifierbuilder.newbuilder ()

#Definition to apply the type of recipemodifier

.SetRequirementType ("ModularMachinery: Energy")

#The recipermodifier will be applied to input or output?("Input" is input, "utput" is output)

.Setiotype ("Input")

#Which method will be calculated by#recipemodifier value?(0 is plus, 1 is multiplication, default 0)

.Setoperation (1)

#Define the value of recipemodifier (type Float)

.SetValue (0.1)

#RECIPEMODIFIER is applied to probability?(True is app, FALSE is not applied, default FALSE)

.SaafectChance (false)

#RECIPEMODIFIER, and check the legitimacy of the parameters above

.Build ();

// Quick Construction Mode

RecipeModifierBuilder.create("modularmachinery:energy", "input", 0.1, 1, false).setValue(0).build();

^

// Create () You can also call the above method content

ImachineController

ImachineController is an interface provided by MMCE for Crafttweaker, which provides a lot of functions that directly operate the controller.

ImachineController can be obtained through most mechanical events.

List of interface methods:

Zengetter:

 // Get the world where the controller is located.

IWorld World

// Get the controller block state.

IBlockState Blockstate

// Get the position of the controller square.

IBLOCKPOS POS

// Get machinery at the time of the current world (non -world time, enter the exit world will be reset)

int TickSexisted

// Get the formula where the controller is running is always returning an array (will not return NULL).

// Ordinary machinery will always return an array of 1 (but the content may be NULL), and the factory will return any array of any size and everything is non -NULL (may be returned to the empty array).

Activemachinerecipe [] ActiveRecipelist

// Whether the machine is running, if it runs back to True, opposite False.

boolean isworking

// The mechanical structure registration name formed by the controller (such as: "ModularMachinery: Machine_1"), if it is formed, returns NULL.

// Note: It's "ModularMachinery: Machine_1" instead of "Machine_1"!

String Formedmachinename

// Get customized data, Zenscript can be used to store data, and the data will be stored in NBT when the game is closed.

IDATA CUSTMATA

// Get all the intelligent data interface data bound to the controller

// This method will return an internal data of a set of intelligent data interfaces. If not, it is an empty array, but it will never be NULL

SMARTINTERFACEDATA [] SMARTINTERFACEDALIST

// Get the mechanical upgrade of the controller found

// Note: Returned a set of string arrays, which are registered names for mechanical upgrades.

String [] Foundmodifiers

Zensetter:

 // Save the custom data. This method needs to be called when the customized data obtained is changed.

IDATA CUSTMATA

// Cover the current state message of the controller

String StatusMessage

ZenMethod:

 // Add a customized name recipemodifier to the controller and will be synchronized to the running formula.void addmodifier (String Key, Recipemodifier Modifier);

// Delete RECIPEMODIFIER with the corresponding name to the controller.

void remainmodifier (String Key);

// Check whether the controller already has the corresponding name recipemodifier. True exists, vice versa.

Boolean Hasmodifier (String Key);

// Get the specified smart data interface data bound to the controller.

// The return value may be null.

SMARTINTERFACEDATA GETSMARTINTERFACEDATA (String Type);

// Whether the specified registered registered mechanical upgrade has been found in the mechanical.

Boolean Hasmodifierreplacement (String ModifierName);

Advanced CRT formula

Miscellaneous items:

 // Set the NBT displayed during the formula preview, which does not affect the formula NBT matching

setpreViewNbt (IDATA NBT)

#Example

addIteminput (). Setpreviewnbt ({mana: 100000})

// Add jei prompts to the formula

adDRecipeTooltip (String ... Tooltips)

#Example (Support multiple prompts at one time) (Note: If you do not support the native name, if you need localization, please handle your uninvited name) by yourself)

adDRecipeTooltip

catalyst:

Catalyst is a special item input that can add a set of semi -permanent recipemodifier to the target formula when checking the formula and meeting the requirements, and it is an optional input.

 // Add catalyst input

// Tooltips = Jei mouse prompt, as an array, can be passed into multiple

// modifiers = formula modifier, as an array, can be passed into multiple cases

addcatalystinput (IINGREDIENT Input, String [] Tooltips, RecipemodifierBuilder [] Modifiers)

#Example

Addcatalystinput (, ["Endless catalyst as a catalyst input, reduce the energy consumption by 90%"], [recipemodifierbuilder.create ("ModularMachry: Energy", "Input", 0. 1, 1, false)])))

Custom NBT checker:

Custom NBT checker allows you to check whether the item matches the corresponding NBT through Zenscript.

usage:

 // Set customized NBT checkup (only input of items type)

Setnbtchecker (ImachineController Controller, AdvancediteMnbtchecker Checker)

#Example

Import Crafttweaker.item.iitemstack; Import Mods.modularMachinery.imachineController;

addIteminput (<). Setnbtchecker (FUNCTION (CTRL As ImachineController, ITEM As Iitemstack) {{{{{{{{{{{{{{

Val nbt = item.tag.asmap ();

If (nbt ["mana"]. Asint ()> 1919810) {{

#Return TRUE is matching

Return true;

} Else {

#Returning to false is not matching

Return false;

}

})

Customized item modifier:

The customized item modifier allows you to modify the input and output content of the item through Zenscript.

 // Set customized items modifier (only input and output of items type)

additemmodifier (ImachineController Controller, AdvancediteMMOFier Modifier)

#Example

import crafttweaker.item.iitemstack;

Import Mods.modularMachinery.imachineController;

addIteminput (). Additemmodifier (Function (Ctrl As ImachineController, OldItem AS IITEMSTACK) as iItemstack {

If (OldITEM.AMOUNT> = 2) {{

#Return to new items

Return *4;

} Else {

#Return to new items

Return *2;

}