Class StructureBuilder

java.lang.Object
com.ryandw11.structure.structure.StructureBuilder

public class StructureBuilder extends Object
This class is used to make a new Structure. (This class is also used internally to load structures from structure config files).

You can create a structure completely via code or load a structure from a yaml file.

Example using a yaml file:

StructureBuilder builder = new StructureBuilder("MyName", file);
Structure struct = builder.build();

Example using code:

StructureBuilder builder = new StructureBuilder("MyName", file);
builder.setStructureLimitations(new StructureLimitations());
...
Structure struct = builder.build();
  • Field Details

    • name

      protected String name
    • schematic

      protected String schematic
    • probabilityNumerator

      protected int probabilityNumerator
    • probabilityDenominator

      protected int probabilityDenominator
    • priority

      protected int priority
    • compiledSchematic

      protected String compiledSchematic
    • isCompiled

      protected boolean isCompiled
    • structureLocation

      protected StructureLocation structureLocation
    • structureProperties

      protected StructureProperties structureProperties
    • structureLimitations

      protected StructureLimitations structureLimitations
    • sourceMaskProperty

      protected MaskProperty sourceMaskProperty
    • targetMaskProperty

      protected MaskProperty targetMaskProperty
    • subSchematics

      protected SubSchematics subSchematics
    • advancedSubSchematics

      protected AdvancedSubSchematics advancedSubSchematics
    • bottomSpaceFill

      protected BottomSpaceFill bottomSpaceFill
    • lootTables

      protected Map<LootTableType,​RandomCollection<LootTable>> lootTables
    • structureSections

      protected List<StructureSection> structureSections
    • baseRotation

      protected double baseRotation
  • Constructor Details

    • StructureBuilder

      public StructureBuilder(String name, String schematic)
      Build a structure using code.
      Parameters:
      name - The name of the structure.
      schematic - The schematic of the structure.
    • StructureBuilder

      public StructureBuilder(String name, String schematic, List<StructureSection> sections)
      Build a structure.
      Parameters:
      name - The name of the structure.
      schematic - The location of the structure schematic file.
      sections - The list of structure sections.
    • StructureBuilder

      public StructureBuilder(String name, String schematic, StructureSection... sections)
      Build a structure.
      Parameters:
      name - The name of the structure.
      schematic - The location of the structure schematic file.
      sections - The structure sections to add.
    • StructureBuilder

      public StructureBuilder(String name, File file)
      Build a structure using a yaml configuration file.

      No further editing of this class is required if you use this method.

      Errors are outputted to the console. If an error occurs build() will return null.

      Parameters:
      name - The name of the structure.
      file - The file to read from.
  • Method Details

    • setProbability

      public void setProbability(int numerator, int denominator)
      Set the probability of the structure spawning.

      How many times (numerator) a structure should spawn per x (denominator) chunks.

      Parameters:
      numerator - The numerator of the probability fraction.
      denominator - The denominator of the probability fraction.
    • setPriority

      public void setPriority(int priority)
      Set the priority of the structure.

      The lower the number, the greater the priority.

      Parameters:
      priority - The priority of the structure. (Default 100).
    • setCompiledSchematic

      public void setCompiledSchematic(String cschem)
      Set the compiled schematic.

      This will automatically set isCompiled to true if the file is found.

      Parameters:
      cschem - The compiled schematic name. (Include the .cschem)

      This file MUST be in the schematics folder.

      An IllegalArgumentException is thrown when the file is not found.

    • setStructureLimitations

      public void setStructureLimitations(StructureLimitations limitations)
      Set the structure limitations.
      Parameters:
      limitations - The structure limitations.
    • setStructureProperties

      public void setStructureProperties(StructureProperties properties)
      Set the structure properties.
      Parameters:
      properties - The structure properties.
    • setStructureLocation

      public void setStructureLocation(StructureLocation location)
      Set the structure location.
      Parameters:
      location - The structure location.
    • setSourceMaskProperty

      public void setSourceMaskProperty(MaskProperty mask)
      Set the source mask property.
      Parameters:
      mask - The source mask property.
    • setTargetMaskProperty

      public void setTargetMaskProperty(MaskProperty mask)
      Set the target mask property.
      Parameters:
      mask - The target mask property.
    • setBottomSpaceFill

      public void setBottomSpaceFill(BottomSpaceFill bottomSpaceFill)
      Set the bottom space fill property.
      Parameters:
      bottomSpaceFill - The bottom space fill property.
    • setSubSchematics

      public void setSubSchematics(SubSchematics subSchematics)
      Set the (simple) sub-schematic property.
      Parameters:
      subSchematics - The sub-schematic property.
    • setAdvancedSubSchematics

      public void setAdvancedSubSchematics(AdvancedSubSchematics advancedSubSchematics)
      Set the advanced sub-schematic property.
      Parameters:
      advancedSubSchematics - The advanced sub-schematic property.
    • setLootTables

      public void setLootTables(org.bukkit.configuration.ConfigurationSection lootableConfig)
      Set the loot tables from a configuration section.
      Parameters:
      lootableConfig - The loot table configuration section.
    • setLootTables

      public void setLootTables(Map<LootTableType,​RandomCollection<LootTable>> lootTables)
      Set the loot tables using a collection of LootTable.
      Parameters:
      lootTables - The collection of LootTables.
    • addLootTable

      public void addLootTable(LootTable lootTable, double weight)
      Add a loot table to the structure.
      Parameters:
      lootTable - The loot table to add.
      weight - The weight.
    • setBaseRotation

      public void setBaseRotation(double baseRotation)
      Set the base rotation of a structure.

      This is an API only functionality. It sets what the structure should be rotated by, while still allowing for random rotation is desired.

      Parameters:
      baseRotation - The base rotation of a structure. (In Radians.)
    • addStructureSection

      public void addStructureSection(StructureSection structureSection)
      Add a structure section to the structure builder.

      Note: StructureSection.setupSection(ConfigurationSection) is NOT called by this method. You are expected to use a constructor.

      Parameters:
      structureSection - The structure section to add.
    • build

      public Structure build()
      Build the structure.

      Note: This does not check to see if all values are set. If any of the properties are not set than a NullPointerException will occur.

      Returns:
      The structure.
    • save

      public void save(File file) throws IOException
      Save the structure as a structure configuration file.

      This automatically saves the file in the structures folder.

      Parameters:
      file - The file to save.
      Throws:
      IOException - If an IO Exception occurs.