Class BlocklyToCode

java.lang.Object
net.mcreator.blockly.BlocklyToCode
All Implemented Interfaces:
IGeneratorProvider, IWorkspaceProvider
Direct Known Subclasses:
BlocklyToFeature, BlocklyToJava, BlocklyToJavaScript, BlocklyToJSONTrigger

public abstract class BlocklyToCode extends Object implements IGeneratorProvider
  • Field Details

  • Constructor Details

  • 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 document
      startBlock - The basic block of the editor used to get other blocks.
      Throws:
      TemplateGeneratorException
    • postBlocksPlacement

      protected void postBlocksPlacement(Document doc, Element startBlock, List<Element> baseBlocks)

      This method contains the code needing to be executed after blocks are placed.

      Parameters:
      doc - Blockly XML document
      startBlock - 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

      public final String getGeneratedCode()
    • getExtraTemplatesCode

      public final String getExtraTemplatesCode() throws TemplateGeneratorException
      Throws:
      TemplateGeneratorException
    • getCompileNotes

      public final List<BlocklyCompileNote> getCompileNotes()
    • getParent

      public ModElement getParent()
    • getEditorType

      public BlocklyEditorType getEditorType()
    • getDependencies

      public final List<Dependency> getDependencies()
    • append

      public final BlocklyToCode append(Object data)
    • clearCodeGeneratorBuffer

      public final void clearCodeGeneratorBuffer()
    • addCompileNote

      public final void addCompileNote(BlocklyCompileNote compileNote)
    • addDependency

      public final void addDependency(Dependency dependency)
    • getTemplateGenerator

      @Nullable public final TemplateGenerator getTemplateGenerator()
    • getWorkspace

      @Nonnull public final Workspace getWorkspace()
      Specified by:
      getWorkspace in interface IWorkspaceProvider
    • pushDepProviderInputStack

      public final void pushDepProviderInputStack(DependencyProviderInput statementInput)
    • popDepProviderInputStack

      public final void popDepProviderInputStack()
    • checkIfDepProviderInputsProvide

      public boolean checkIfDepProviderInputsProvide(Dependency dependency)
    • getStatementInputsMatching

      public List<StatementInput> getStatementInputsMatching(Predicate<StatementInput> predicate)
    • addTemplate

      public final void addTemplate(String template)
    • processBlockProcedure

      public final void processBlockProcedure(List<Element> blocks) throws TemplateGeneratorException
      Throws:
      TemplateGeneratorException
    • processOutputBlock

      public final void processOutputBlock(Element condition) throws TemplateGeneratorException
      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 proces
      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 proces
      blacklist - 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 proces
      Returns:
      The generated code of the element with parentheses optimization
      Throws:
      TemplateGeneratorException - If the template can't be generated
    • processOutputBlockToInt

      public final void processOutputBlockToInt(Element element) throws TemplateGeneratorException
      Helper method to process an output block and cast to int when needed
      Parameters:
      element - The element to proces
      Throws:
      TemplateGeneratorException - If the template can't be generated
    • processOutputBlockToStringCompatible

      public final String processOutputBlockToStringCompatible(Element element) throws TemplateGeneratorException
      Helper method to process an output block to an object that can be converted to string and handles an edge case of custom MCItem objects that are not mapped correctly
      Parameters:
      element - The element to proces
      Throws:
      TemplateGeneratorException - If the template can't be generated
    • getUsedBlocks

      public Collection<String> 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

      public void setHeadSection(String headSection)
    • setTailSection

      public void setTailSection(String tailSection)
    • clearSections

      public void clearSections()
    • getHeadSection

      public String getHeadSection()
    • getTailSection

      public String getTailSection()
    • getBlockCount

      public int getBlockCount()
      Returns the count of blocks currently processed from the block arrangement.
      Returns:
      The total number of blocks.