Package net.mcreator.blockly
Class BlocklyToCode
java.lang.Object
net.mcreator.blockly.BlocklyToCode
- All Implemented Interfaces:
IGeneratorProvider,IWorkspaceProvider
- Direct Known Subclasses:
BlocklyToFeature,BlocklyToJava,BlocklyToJSONTrigger
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<IBlockGenerator> protected final BlocklyEditorTypeprotected String -
Constructor Summary
ConstructorsConstructorDescriptionBlocklyToCode(Workspace workspace, ModElement parent, BlocklyEditorType blocklyEditorType, String sourceXML, TemplateGenerator templateGenerator, IBlockGenerator... externalGenerators) BlocklyToCode(Workspace workspace, ModElement parent, BlocklyEditorType editorType, TemplateGenerator templateGenerator, IBlockGenerator... externalGenerators) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddCompileNote(BlocklyCompileNote compileNote) final voidaddDependency(Dependency dependency) final voidaddTemplate(String template) final BlocklyToCodeprotected voidThis method is executed after the constructor is called, before the code is generatedbooleancheckIfDepProviderInputsProvide(Dependency dependency) final voidvoidstatic StringdirectProcessOutputBlock(BlocklyToCode master, Element element) Helper method to get the code of an output block and remove surrounding parentheses if possiblestatic StringdirectProcessStatementBlock(BlocklyToCode master, Element element) intReturns the count of blocks currently processed from the block arrangement.final List<BlocklyCompileNote> final List<Dependency> final Stringfinal StringgetStatementInputsMatching(Predicate<StatementInput> predicate) final TemplateGeneratorThis method returns collection of machine names of all blocks that are present in the provided Blockly arrangementfinal Workspacefinal voidprotected voidpostBlocksPlacement(Document doc, Element startBlock, List<Element> baseBlocks) This method contains the code needing to be executed after blocks are placed.protected voidpreBlocksPlacement(Document doc, Element startBlock) This method contains the code needing to be executed before blocks are placed.final voidprocessBlockProcedure(List<Element> blocks) final voidprocessOutputBlock(Element condition) final voidprocessOutputBlockToInt(Element element) Helper method to process an output block and cast to int when neededfinal voidHelper method to process an output block and remove surrounding parentheses if possiblefinal voidprocessOutputBlockWithoutParentheses(Element element, String blacklist) Helper method to process an output block and remove surrounding parentheses if possiblefinal voidpushDepProviderInputStack(DependencyProviderInput statementInput) voidsetHeadSection(String headSection) voidsetTailSection(String tailSection) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.mcreator.generator.IGeneratorProvider
getGenerator, getGeneratorConfiguration, getGeneratorStatsMethods inherited from interface net.mcreator.workspace.IWorkspaceProvider
getFileManager, getFolderManager, getModElementManager, getWorkspaceFolder, getWorkspaceInfo, getWorkspaceSettings, getWorkspaceUserSettings
-
Field Details
-
blockGenerators
-
editorType
-
lastProceduralBlockType
-
-
Constructor Details
-
BlocklyToCode
public BlocklyToCode(Workspace workspace, ModElement parent, BlocklyEditorType editorType, @Nullable TemplateGenerator templateGenerator, IBlockGenerator... externalGenerators) -
BlocklyToCode
public BlocklyToCode(Workspace workspace, ModElement parent, BlocklyEditorType blocklyEditorType, String sourceXML, TemplateGenerator templateGenerator, IBlockGenerator... externalGenerators) throws TemplateGeneratorException - Parameters:
workspace-The
Workspaceexecuting the codeblocklyEditorType-Blockly editor type
sourceXML-The XML code used by Blockly
templateGenerator-The folder location in each
Generatorcontaining the code template files- Throws:
TemplateGeneratorException
-
-
Method Details
-
preBlocksPlacement
protected void preBlocksPlacement(Document doc, Element startBlock) throws TemplateGeneratorException This method contains the code needing to be executed before blocks are placed.
- Parameters:
doc- Blockly XML documentstartBlock- The basic block of the editor used to get other blocks.- Throws:
TemplateGeneratorException
-
postBlocksPlacement
This method contains the code needing to be executed after blocks are placed.
- Parameters:
doc- Blockly XML documentstartBlock- The basic block of the editor used to get other blocks.baseBlocks- A list of all blocks placed under start block.
-
beforeGenerate
protected void beforeGenerate()This method is executed after the constructor is called, before the code is generated
-
getGeneratedCode
-
getExtraTemplatesCode
- Throws:
TemplateGeneratorException
-
getCompileNotes
-
getParent
-
getEditorType
-
getDependencies
-
append
-
clearCodeGeneratorBuffer
public final void clearCodeGeneratorBuffer() -
addCompileNote
-
addDependency
-
getTemplateGenerator
-
getWorkspace
- Specified by:
getWorkspacein interfaceIWorkspaceProvider
-
pushDepProviderInputStack
-
popDepProviderInputStack
public final void popDepProviderInputStack() -
checkIfDepProviderInputsProvide
-
getStatementInputsMatching
-
addTemplate
-
processBlockProcedure
- Throws:
TemplateGeneratorException
-
processOutputBlock
- Throws:
TemplateGeneratorException
-
directProcessOutputBlock
public static String directProcessOutputBlock(BlocklyToCode master, Element element) throws TemplateGeneratorException - Throws:
TemplateGeneratorException
-
directProcessStatementBlock
public static String directProcessStatementBlock(BlocklyToCode master, Element element) throws TemplateGeneratorException - Throws:
TemplateGeneratorException
-
processOutputBlockWithoutParentheses
public final void processOutputBlockWithoutParentheses(Element element) throws TemplateGeneratorException Helper method to process an output block and remove surrounding parentheses if possible- Parameters:
element- The element to process- Throws:
TemplateGeneratorException- If the template can't be generated
-
processOutputBlockWithoutParentheses
public final void processOutputBlockWithoutParentheses(Element element, String blacklist) throws TemplateGeneratorException Helper method to process an output block and remove surrounding parentheses if possible- Parameters:
element- The element to processblacklist- The characters that can't be contained at the top nesting level when optimizing the element- Throws:
TemplateGeneratorException- If the template can't be generated
-
directProcessOutputBlockWithoutParentheses
public String directProcessOutputBlockWithoutParentheses(Element element) throws TemplateGeneratorException Helper method to get the code of an output block and remove surrounding parentheses if possible- Parameters:
element- The element to process- Returns:
- The generated code of the element with parentheses optimization
- Throws:
TemplateGeneratorException- If the template can't be generated
-
processOutputBlockToInt
Helper method to process an output block and cast to int when needed- Parameters:
element- The element to process- Throws:
TemplateGeneratorException- If the template can't be generated
-
getUsedBlocks
This method returns collection of machine names of all blocks that are present in the provided Blockly arrangement- Returns:
- Unmodifiable collection of machine names of all blocks that are present in the provided Blockly arrangement
-
setHeadSection
-
setTailSection
-
clearSections
public void clearSections() -
getHeadSection
-
getTailSection
-
getBlockCount
public int getBlockCount()Returns the count of blocks currently processed from the block arrangement.- Returns:
- The total number of blocks.
-