Reformat & add .editorconfig

This commit is contained in:
dfsek
2020-11-06 15:21:42 -07:00
parent bfa55fdb5d
commit 4f40550465
33 changed files with 527 additions and 280 deletions

268
.editorconfig Normal file
View File

@@ -0,0 +1,268 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = false
max_line_length = 120
tab_width = 4
ij_continuation_indent_size = 8
ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = false
ij_smart_tabs = false
ij_wrap_on_typing = false
[*.java]
ij_java_align_consecutive_assignments = false
ij_java_align_consecutive_variable_declarations = false
ij_java_align_group_field_declarations = false
ij_java_align_multiline_annotation_parameters = false
ij_java_align_multiline_array_initializer_expression = false
ij_java_align_multiline_assignment = false
ij_java_align_multiline_binary_operation = false
ij_java_align_multiline_chained_methods = false
ij_java_align_multiline_extends_list = false
ij_java_align_multiline_for = true
ij_java_align_multiline_method_parentheses = false
ij_java_align_multiline_parameters = true
ij_java_align_multiline_parameters_in_calls = false
ij_java_align_multiline_parenthesized_expression = false
ij_java_align_multiline_records = true
ij_java_align_multiline_resources = true
ij_java_align_multiline_ternary_operation = false
ij_java_align_multiline_text_blocks = false
ij_java_align_multiline_throws_list = false
ij_java_align_subsequent_simple_methods = false
ij_java_align_throws_keyword = false
ij_java_annotation_parameter_wrap = off
ij_java_array_initializer_new_line_after_left_brace = false
ij_java_array_initializer_right_brace_on_new_line = false
ij_java_array_initializer_wrap = off
ij_java_assert_statement_colon_on_next_line = false
ij_java_assert_statement_wrap = off
ij_java_assignment_wrap = off
ij_java_binary_operation_sign_on_next_line = false
ij_java_binary_operation_wrap = off
ij_java_blank_lines_after_anonymous_class_header = 0
ij_java_blank_lines_after_class_header = 0
ij_java_blank_lines_after_imports = 1
ij_java_blank_lines_after_package = 1
ij_java_blank_lines_around_class = 1
ij_java_blank_lines_around_field = 0
ij_java_blank_lines_around_field_in_interface = 0
ij_java_blank_lines_around_initializer = 1
ij_java_blank_lines_around_method = 1
ij_java_blank_lines_around_method_in_interface = 1
ij_java_blank_lines_before_class_end = 0
ij_java_blank_lines_before_imports = 1
ij_java_blank_lines_before_method_body = 0
ij_java_blank_lines_before_package = 0
ij_java_block_brace_style = end_of_line
ij_java_block_comment_at_first_column = true
ij_java_call_parameters_new_line_after_left_paren = false
ij_java_call_parameters_right_paren_on_new_line = false
ij_java_call_parameters_wrap = off
ij_java_case_statement_on_separate_line = true
ij_java_catch_on_new_line = false
ij_java_class_annotation_wrap = split_into_lines
ij_java_class_brace_style = end_of_line
ij_java_class_count_to_use_import_on_demand = 30
ij_java_class_names_in_javadoc = 1
ij_java_do_not_indent_top_level_class_members = false
ij_java_do_not_wrap_after_single_annotation = false
ij_java_do_while_brace_force = never
ij_java_doc_add_blank_line_after_description = true
ij_java_doc_add_blank_line_after_param_comments = false
ij_java_doc_add_blank_line_after_return = false
ij_java_doc_add_p_tag_on_empty_lines = true
ij_java_doc_align_exception_comments = true
ij_java_doc_align_param_comments = true
ij_java_doc_do_not_wrap_if_one_line = false
ij_java_doc_enable_formatting = true
ij_java_doc_enable_leading_asterisks = true
ij_java_doc_indent_on_continuation = false
ij_java_doc_keep_empty_lines = true
ij_java_doc_keep_empty_parameter_tag = true
ij_java_doc_keep_empty_return_tag = true
ij_java_doc_keep_empty_throws_tag = true
ij_java_doc_keep_invalid_tags = true
ij_java_doc_param_description_on_new_line = false
ij_java_doc_preserve_line_breaks = false
ij_java_doc_use_throws_not_exception_tag = true
ij_java_else_on_new_line = false
ij_java_enum_constants_wrap = off
ij_java_extends_keyword_wrap = off
ij_java_extends_list_wrap = off
ij_java_field_annotation_wrap = split_into_lines
ij_java_finally_on_new_line = false
ij_java_for_brace_force = never
ij_java_for_statement_new_line_after_left_paren = false
ij_java_for_statement_right_paren_on_new_line = false
ij_java_for_statement_wrap = off
ij_java_generate_final_locals = false
ij_java_generate_final_parameters = false
ij_java_if_brace_force = never
ij_java_imports_layout = *,|,javax.**,java.**,|,$*
ij_java_indent_case_from_switch = true
ij_java_insert_inner_class_imports = false
ij_java_insert_override_annotation = true
ij_java_keep_blank_lines_before_right_brace = 2
ij_java_keep_blank_lines_between_package_declaration_and_header = 2
ij_java_keep_blank_lines_in_code = 2
ij_java_keep_blank_lines_in_declarations = 2
ij_java_keep_control_statement_in_one_line = true
ij_java_keep_first_column_comment = true
ij_java_keep_indents_on_empty_lines = false
ij_java_keep_line_breaks = true
ij_java_keep_multiple_expressions_in_one_line = false
ij_java_keep_simple_blocks_in_one_line = false
ij_java_keep_simple_classes_in_one_line = false
ij_java_keep_simple_lambdas_in_one_line = false
ij_java_keep_simple_methods_in_one_line = false
ij_java_label_indent_absolute = false
ij_java_label_indent_size = 0
ij_java_lambda_brace_style = end_of_line
ij_java_layout_static_imports_separately = true
ij_java_line_comment_add_space = false
ij_java_line_comment_at_first_column = true
ij_java_method_annotation_wrap = split_into_lines
ij_java_method_brace_style = end_of_line
ij_java_method_call_chain_wrap = off
ij_java_method_parameters_new_line_after_left_paren = false
ij_java_method_parameters_right_paren_on_new_line = false
ij_java_method_parameters_wrap = off
ij_java_modifier_list_wrap = false
ij_java_names_count_to_use_import_on_demand = 3
ij_java_new_line_after_lparen_in_record_header = false
ij_java_packages_to_use_import_on_demand = java.awt.*,javax.swing.*
ij_java_parameter_annotation_wrap = off
ij_java_parentheses_expression_new_line_after_left_paren = false
ij_java_parentheses_expression_right_paren_on_new_line = false
ij_java_place_assignment_sign_on_next_line = false
ij_java_prefer_longer_names = true
ij_java_prefer_parameters_wrap = false
ij_java_record_components_wrap = normal
ij_java_repeat_synchronized = true
ij_java_replace_instanceof_and_cast = false
ij_java_replace_null_check = true
ij_java_replace_sum_lambda_with_method_ref = true
ij_java_resource_list_new_line_after_left_paren = false
ij_java_resource_list_right_paren_on_new_line = false
ij_java_resource_list_wrap = off
ij_java_rparen_on_new_line_in_record_header = false
ij_java_space_after_closing_angle_bracket_in_type_argument = false
ij_java_space_after_colon = true
ij_java_space_after_comma = true
ij_java_space_after_comma_in_type_arguments = true
ij_java_space_after_for_semicolon = true
ij_java_space_after_quest = true
ij_java_space_after_type_cast = true
ij_java_space_before_annotation_array_initializer_left_brace = false
ij_java_space_before_annotation_parameter_list = false
ij_java_space_before_array_initializer_left_brace = true
ij_java_space_before_catch_keyword = true
ij_java_space_before_catch_left_brace = true
ij_java_space_before_catch_parentheses = false
ij_java_space_before_class_left_brace = true
ij_java_space_before_colon = true
ij_java_space_before_colon_in_foreach = true
ij_java_space_before_comma = false
ij_java_space_before_do_left_brace = true
ij_java_space_before_else_keyword = true
ij_java_space_before_else_left_brace = true
ij_java_space_before_finally_keyword = true
ij_java_space_before_finally_left_brace = true
ij_java_space_before_for_left_brace = true
ij_java_space_before_for_parentheses = false
ij_java_space_before_for_semicolon = false
ij_java_space_before_if_left_brace = true
ij_java_space_before_if_parentheses = false
ij_java_space_before_method_call_parentheses = false
ij_java_space_before_method_left_brace = true
ij_java_space_before_method_parentheses = false
ij_java_space_before_opening_angle_bracket_in_type_parameter = false
ij_java_space_before_quest = true
ij_java_space_before_switch_left_brace = true
ij_java_space_before_switch_parentheses = false
ij_java_space_before_synchronized_left_brace = true
ij_java_space_before_synchronized_parentheses = false
ij_java_space_before_try_left_brace = true
ij_java_space_before_try_parentheses = false
ij_java_space_before_type_parameter_list = false
ij_java_space_before_while_keyword = true
ij_java_space_before_while_left_brace = true
ij_java_space_before_while_parentheses = false
ij_java_space_inside_one_line_enum_braces = false
ij_java_space_within_empty_array_initializer_braces = false
ij_java_space_within_empty_method_call_parentheses = false
ij_java_space_within_empty_method_parentheses = false
ij_java_spaces_around_additive_operators = true
ij_java_spaces_around_assignment_operators = true
ij_java_spaces_around_bitwise_operators = true
ij_java_spaces_around_equality_operators = true
ij_java_spaces_around_lambda_arrow = true
ij_java_spaces_around_logical_operators = true
ij_java_spaces_around_method_ref_dbl_colon = false
ij_java_spaces_around_multiplicative_operators = true
ij_java_spaces_around_relational_operators = true
ij_java_spaces_around_shift_operators = true
ij_java_spaces_around_type_bounds_in_type_parameters = true
ij_java_spaces_around_unary_operator = true
ij_java_spaces_within_angle_brackets = false
ij_java_spaces_within_annotation_parentheses = false
ij_java_spaces_within_array_initializer_braces = false
ij_java_spaces_within_braces = false
ij_java_spaces_within_brackets = false
ij_java_spaces_within_cast_parentheses = false
ij_java_spaces_within_catch_parentheses = false
ij_java_spaces_within_for_parentheses = false
ij_java_spaces_within_if_parentheses = false
ij_java_spaces_within_method_call_parentheses = false
ij_java_spaces_within_method_parentheses = false
ij_java_spaces_within_parentheses = false
ij_java_spaces_within_switch_parentheses = false
ij_java_spaces_within_synchronized_parentheses = false
ij_java_spaces_within_try_parentheses = false
ij_java_spaces_within_while_parentheses = false
ij_java_special_else_if_treatment = true
ij_java_subclass_name_suffix = Impl
ij_java_ternary_operation_signs_on_next_line = false
ij_java_ternary_operation_wrap = off
ij_java_test_name_suffix = Test
ij_java_throws_keyword_wrap = off
ij_java_throws_list_wrap = off
ij_java_use_external_annotations = false
ij_java_use_fq_class_names = false
ij_java_use_relative_indents = false
ij_java_use_single_class_imports = true
ij_java_variable_annotation_wrap = off
ij_java_visibility = public
ij_java_while_brace_force = never
ij_java_while_on_new_line = false
ij_java_wrap_comments = false
ij_java_wrap_first_method_in_call_chain = false
ij_java_wrap_long_lines = false
[{*.har,*.jsb2,*.jsb3,*.json,.babelrc,.eslintrc,.stylelintrc,bowerrc,jest.config}]
indent_size = 2
ij_json_keep_blank_lines_in_code = 0
ij_json_keep_indents_on_empty_lines = false
ij_json_keep_line_breaks = true
ij_json_space_after_colon = true
ij_json_space_after_comma = true
ij_json_space_before_colon = true
ij_json_space_before_comma = false
ij_json_spaces_within_braces = false
ij_json_spaces_within_brackets = false
ij_json_wrap_long_lines = false
[{*.yaml,*.yml}]
indent_size = 2
ij_yaml_keep_indents_on_empty_lines = false
ij_yaml_keep_line_breaks = true
ij_yaml_space_before_colon = true
ij_yaml_spaces_within_braces = true
ij_yaml_spaces_within_brackets = true

View File

@@ -86,6 +86,17 @@ public class TerraWorld {
return map.computeIfAbsent(w, TerraWorld::new);
}
public static synchronized void invalidate() {
map.clear();
for(WorldConfig config : loaded.values()) {
config.load(); // Reload all stored WorldConfigs
}
}
public static int numWorlds() {
return map.size();
}
public TerraBiomeGrid getGrid() {
return grid;
}
@@ -102,17 +113,6 @@ public class TerraWorld {
return zone;
}
public static synchronized void invalidate() {
map.clear();
for(WorldConfig config : loaded.values()) {
config.load(); // Reload all stored WorldConfigs
}
}
public static int numWorlds() {
return map.size();
}
public boolean isSafe() {
return safe;
}

View File

@@ -14,12 +14,11 @@ import java.util.logging.Level;
public class TerraBiomeGrid extends BiomeGrid {
private static int failNum = 0;
private final BiomeZone zone;
private CoordinatePerturb perturb;
private ErosionNoise erode;
private UserDefinedGrid erosionGrid;
private final BiomeZone zone;
public TerraBiomeGrid(World w, double freq1, double freq2, BiomeZone zone, ConfigPack c, UserDefinedGrid erosion) {
super(w, freq1, freq2, 0, 0);
if(c.biomeBlend) {

View File

@@ -39,6 +39,10 @@ public class SimplexCarver extends Carver {
hasCaves.setFrequency(0.005f);
}
private static double acot(double x) {
return Math.PI / 2 - Math.atan(x);
}
@Override
public Worm getWorm(long l, Vector vector) {
return null;
@@ -76,8 +80,4 @@ public class SimplexCarver extends Carver {
}
return c;
}
private static double acot(double x) {
return Math.PI / 2 - Math.atan(x);
}
}

View File

@@ -37,7 +37,7 @@ public class UserDefinedCarver extends Carver {
@Override
public Worm getWorm(long l, Vector vector) {
Random r = new Random(l + hash);
return new UserDefinedWorm((int) (length.get(r) / 2), r, vector, radius.getMax(), topCut, bottomCut);
return new UserDefinedWorm(length.get(r) / 2, r, vector, radius.getMax(), topCut, bottomCut);
}
@Override

View File

@@ -3,9 +3,9 @@ package com.dfsek.terra.command.biome;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
import com.dfsek.terra.config.genconfig.biome.BiomeSnowConfig;
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.generation.TerraChunkGenerator;
import org.bukkit.World;

View File

@@ -1,7 +1,6 @@
package com.dfsek.terra.config;
import com.dfsek.terra.config.base.ConfigPack;
import org.apache.commons.io.FileUtils;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;

View File

@@ -11,10 +11,10 @@ import com.dfsek.terra.config.genconfig.CarverConfig;
import com.dfsek.terra.config.genconfig.FloraConfig;
import com.dfsek.terra.config.genconfig.OreConfig;
import com.dfsek.terra.config.genconfig.PaletteConfig;
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
import com.dfsek.terra.config.genconfig.TreeConfig;
import com.dfsek.terra.config.genconfig.biome.AbstractBiomeConfig;
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.util.StructureTypeEnum;
import org.bukkit.configuration.ConfigurationSection;
@@ -40,6 +40,25 @@ import java.util.stream.Collectors;
*/
public class ConfigPack extends YamlConfiguration {
private static final Map<String, ConfigPack> configs = new HashMap<>();
public final List<String> biomeList;
public final double zoneFreq;
public final double freq1;
public final double freq2;
public final double erosionFreq;
public final double erosionThresh;
public final boolean erosionEnable;
public final int erosionOctaves;
public final String erosionName;
public final int blendAmp;
public final boolean biomeBlend;
public final double blendFreq;
public final int octaves;
public final double frequency;
public final boolean vanillaCaves;
public final boolean vanillaStructures;
public final boolean vanillaDecoration;
public final boolean vanillaMobs;
public final Map<StructureTypeEnum, StructureConfig> locatable = new HashMap<>();
private final Map<String, OreConfig> ores;
private final Map<String, PaletteConfig> palettes;
private final Map<String, CarverConfig> carvers;
@@ -50,38 +69,9 @@ public class ConfigPack extends YamlConfiguration {
private final Map<String, BiomeGridConfig> grids;
private final Map<String, TreeConfig> trees;
private final Set<StructureConfig> allStructures = new HashSet<>();
private final File dataFolder;
private final String id;
public final List<String> biomeList;
public final double zoneFreq;
public final double freq1;
public final double freq2;
public final double erosionFreq;
public final double erosionThresh;
public final boolean erosionEnable;
public final int erosionOctaves;
public final String erosionName;
public final int blendAmp;
public final boolean biomeBlend;
public final double blendFreq;
public final int octaves;
public final double frequency;
public final boolean vanillaCaves;
public final boolean vanillaStructures;
public final boolean vanillaDecoration;
public final boolean vanillaMobs;
public final Map<StructureTypeEnum, StructureConfig> locatable = new HashMap<>();
public ConfigPack(File file) throws IOException, InvalidConfigurationException {
long l = System.nanoTime();
load(new File(file, "pack.yml"));
@@ -168,26 +158,6 @@ public class ConfigPack extends YamlConfiguration {
LangUtil.log("config-pack.loaded", Level.INFO, getID(), String.valueOf((System.nanoTime() - l) / 1000000D));
}
public Map<StructureTypeEnum, StructureConfig> getLocatable() {
return locatable;
}
public Map<String, AbstractBiomeConfig> getAbstractBiomes() {
return abstractBiomes;
}
public Map<String, BiomeConfig> getBiomes() {
return biomes;
}
public Map<String, CarverConfig> getCarvers() {
return carvers;
}
public Set<StructureConfig> getAllStructures() {
return allStructures;
}
public static synchronized void loadAll(JavaPlugin main) {
configs.clear();
File file = new File(main.getDataFolder(), "packs");
@@ -217,6 +187,30 @@ public class ConfigPack extends YamlConfiguration {
}
}
public static synchronized ConfigPack fromID(String id) {
return configs.get(id);
}
public Map<StructureTypeEnum, StructureConfig> getLocatable() {
return locatable;
}
public Map<String, AbstractBiomeConfig> getAbstractBiomes() {
return abstractBiomes;
}
public Map<String, BiomeConfig> getBiomes() {
return biomes;
}
public Map<String, CarverConfig> getCarvers() {
return carvers;
}
public Set<StructureConfig> getAllStructures() {
return allStructures;
}
public File getDataFolder() {
return dataFolder;
}
@@ -225,10 +219,6 @@ public class ConfigPack extends YamlConfiguration {
return id;
}
public static synchronized ConfigPack fromID(String id) {
return configs.get(id);
}
public BiomeConfig getBiome(UserDefinedBiome b) {
for(BiomeConfig biome : biomes.values()) {
if(biome.getBiome().equals(b)) return biome;

View File

@@ -19,21 +19,17 @@ import java.util.logging.Level;
public class WorldConfig {
private final String worldID;
private final String configID;
private final GaeaPlugin main;
public boolean fromImage;
public ConfigPack config;
public ImageLoader.Channel biomeXChannel;
public ImageLoader.Channel biomeZChannel;
public ImageLoader.Channel zoneChannel;
public ImageLoader imageLoader;
private ConfigPack tConfig;
private final String worldID;
private final String configID;
private final GaeaPlugin main;
public WorldConfig(String w, String configID, GaeaPlugin main) {
this.worldID = w;

View File

@@ -40,14 +40,6 @@ public class PaletteConfig extends TerraConfig {
palette = getPalette(getMapList("layers"), pal);
}
public Palette<BlockData> getPalette() {
return palette;
}
public String getID() {
return paletteID;
}
@SuppressWarnings("unchecked")
protected static Palette<BlockData> getPalette(List<Map<?, ?>> maps, Palette<BlockData> p) throws InvalidConfigurationException {
for(Map<?, ?> m : maps) {
@@ -76,6 +68,14 @@ public class PaletteConfig extends TerraConfig {
return p;
}
public Palette<BlockData> getPalette() {
return palette;
}
public String getID() {
return paletteID;
}
@Override
public String toString() {
return "Palette with ID " + getID() + " with " + getPalette().getSize() + " layers, using Simplex: " + useNoise;

View File

@@ -12,8 +12,8 @@ import java.util.List;
public class AbstractBiomeConfig extends TerraConfig {
private final String biomeID;
private final String equation;
private BiomeSlabConfig slabs;
private final int seaLevel;
private BiomeSlabConfig slabs;
private List<String> structureConfigs;
private BiomePaletteConfig palette;
private BiomeFloraConfig flora;

View File

@@ -34,10 +34,9 @@ public class BiomeConfig extends TerraConfig {
private final BiomeOceanConfig ocean;
private final BiomeSlabConfig slab;
private final BiomeSnowConfig snow;
private String eq;
private final List<StructureConfig> structures;
private final ConfigPack config;
private String eq;
public BiomeConfig(File file, ConfigPack config) throws InvalidConfigurationException, IOException {
super(file, config);

View File

@@ -16,9 +16,9 @@ import org.polydev.gaea.world.palette.RandomPalette;
import java.util.Random;
public class BiomeOceanConfig extends TerraConfigSection {
private static final Palette<BlockData> oceanDefault = new RandomPalette<BlockData>(new Random(0)).add(Material.WATER.createBlockData(), 1);
private final Palette<BlockData> ocean;
private final int seaLevel;
private static final Palette<BlockData> oceanDefault = new RandomPalette<BlockData>(new Random(0)).add(Material.WATER.createBlockData(), 1);
public BiomeOceanConfig(@NotNull TerraConfig parent) throws InvalidConfigurationException {
super(parent);

View File

@@ -22,7 +22,7 @@ import java.util.Random;
public class BiomeSlabConfig extends TerraConfigSection {
private final Map<Material, Palette<BlockData>> slabs;
private final Map<Material, Palette<BlockData>> stairs;
private double slabThreshold;
private final double slabThreshold;
public BiomeSlabConfig(@NotNull TerraConfig parent) throws InvalidConfigurationException {
super(parent);

View File

@@ -22,9 +22,12 @@ public class EntityFeatureConfig implements FeatureConfig {
if(! items.containsKey("entity")) throw new ConfigException("No EntityType specified!", "EntityFeature");
if(! items.containsKey("amount")) throw new ConfigException("No amount specified!", "EntityFeature");
if(! items.containsKey("attempts")) throw new ConfigException("Attempts not specified!", "EntityFeature");
if(! items.containsKey("in-height")) throw new ConfigException("Spawn Checking Height not specified!", "EntityFeature");
if(! items.containsKey("spawnable-on")) throw new ConfigException("No Spawnable-on materials specified!", "EntityFeature");
if(! items.containsKey("spawnable-in")) throw new ConfigException("No Spawnable-in materials specified!", "EntityFeature");
if(! items.containsKey("in-height"))
throw new ConfigException("Spawn Checking Height not specified!", "EntityFeature");
if(! items.containsKey("spawnable-on"))
throw new ConfigException("No Spawnable-on materials specified!", "EntityFeature");
if(! items.containsKey("spawnable-in"))
throw new ConfigException("No Spawnable-in materials specified!", "EntityFeature");
EntityType type;
try {
@@ -52,6 +55,7 @@ public class EntityFeatureConfig implements FeatureConfig {
this.feature = new EntityFeature(type, amount, attempts, on, in, height);
Debug.info("Loaded EntityFeature with type: " + type);
}
@Override
public Feature getFeature() {
return feature;

View File

@@ -1,6 +1,5 @@
package com.dfsek.terra.config.genconfig.structure;
import com.dfsek.terra.config.TerraConfigSection;
import com.dfsek.terra.structure.features.Feature;
public interface FeatureConfig {

View File

@@ -14,14 +14,14 @@ public class OreVeinGenerateEvent extends TerraWorldEvent implements Cancellable
this.config = config;
}
public void setConfig(OreConfig config) {
this.config = config;
}
public OreConfig getConfig() {
return config;
}
public void setConfig(OreConfig config) {
this.config = config;
}
@Override
public boolean isCancelled() {
return cancelled;

View File

@@ -16,14 +16,14 @@ public abstract class TerraWorldEvent extends Event {
this.location = l.clone();
}
@Override
@NotNull
public HandlerList getHandlers() {
public static HandlerList getHandlerList() {
return HANDLERS;
}
@Override
@NotNull
public static HandlerList getHandlerList() {
public HandlerList getHandlers() {
return HANDLERS;
}

View File

@@ -14,14 +14,14 @@ public class TreeGenerateEvent extends TerraWorldEvent implements Cancellable {
this.tree = tree;
}
public void setTree(Tree tree) {
this.tree = tree;
}
public Tree getTree() {
return tree;
}
public void setTree(Tree tree) {
this.tree = tree;
}
@Override
public boolean isCancelled() {
return cancelled;

View File

@@ -13,7 +13,6 @@ import com.dfsek.terra.population.FloraPopulator;
import com.dfsek.terra.population.OrePopulator;
import com.dfsek.terra.population.SnowPopulator;
import com.dfsek.terra.population.StructurePopulator;
import com.dfsek.terra.structure.StructureSpawnRequirement;
import com.dfsek.terra.util.DataUtil;
import org.bukkit.Chunk;
import org.bukkit.Material;
@@ -26,12 +25,10 @@ import org.bukkit.generator.BlockPopulator;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.biome.Biome;
import org.polydev.gaea.biome.BiomeGrid;
import org.polydev.gaea.generation.GaeaChunkGenerator;
import org.polydev.gaea.generation.GenerationPhase;
import org.polydev.gaea.generation.GenerationPopulator;
import org.polydev.gaea.math.ChunkInterpolator;
import org.polydev.gaea.math.FastNoiseLite;
import org.polydev.gaea.population.PopulationManager;
import org.polydev.gaea.profiler.WorldProfiler;
import org.polydev.gaea.world.palette.Palette;
@@ -47,12 +44,10 @@ import java.util.Random;
import java.util.logging.Level;
public class TerraChunkGenerator extends GaeaChunkGenerator {
private final PopulationManager popMan = new PopulationManager(Terra.getInstance());
private boolean needsLoad = true;
private final ConfigPack configPack;
private static final Map<World, PopulationManager> popMap = new HashMap<>();
private final PopulationManager popMan = new PopulationManager(Terra.getInstance());
private final ConfigPack configPack;
private boolean needsLoad = true;
public TerraChunkGenerator(ConfigPack c) {
super(ChunkInterpolator.InterpolationType.TRILINEAR);
@@ -62,6 +57,22 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
popMan.attach(new SnowPopulator());
}
public static synchronized void saveAll() {
for(Map.Entry<World, PopulationManager> e : popMap.entrySet()) {
try {
e.getValue().saveBlocks(e.getKey());
Debug.info("Saved data for world " + e.getKey().getName());
} catch(IOException ioException) {
ioException.printStackTrace();
}
}
}
public static synchronized void fixChunk(Chunk c) {
if(! (c.getWorld().getGenerator() instanceof TerraChunkGenerator)) throw new IllegalArgumentException();
popMap.get(c.getWorld()).checkNeighbors(c.getX(), c.getZ(), c.getWorld());
}
@Override
public ChunkData generateBase(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, ChunkInterpolator interpolator) {
if(needsLoad) load(world); // Load population data for world.
@@ -143,28 +154,12 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
needsLoad = false;
}
public static synchronized void saveAll() {
for(Map.Entry<World, PopulationManager> e : popMap.entrySet()) {
try {
e.getValue().saveBlocks(e.getKey());
Debug.info("Saved data for world " + e.getKey().getName());
} catch(IOException ioException) {
ioException.printStackTrace();
}
}
}
@Override
public void attachProfiler(WorldProfiler p) {
super.attachProfiler(p);
popMan.attachProfiler(p);
}
public static synchronized void fixChunk(Chunk c) {
if(! (c.getWorld().getGenerator() instanceof TerraChunkGenerator)) throw new IllegalArgumentException();
popMap.get(c.getWorld()).checkNeighbors(c.getX(), c.getZ(), c.getWorld());
}
@Override
public int getNoiseOctaves(World world) {
return configPack.octaves;

View File

@@ -19,6 +19,7 @@ import java.util.Map;
import java.util.TreeMap;
public class UserDefinedGenerator extends Generator {
private static final Object noiseLock = new Object();
private final Expression noiseExp;
private final Scope s = new Scope();
private final Variable xVar = s.getVariable("x");
@@ -28,11 +29,8 @@ public class UserDefinedGenerator extends Generator {
private final Palette<BlockData>[] palettes = new Palette[256];
private final NoiseFunction2 n2 = new NoiseFunction2();
private final NoiseFunction3 n3 = new NoiseFunction3();
private final boolean preventSmooth;
private static final Object noiseLock = new Object();
public UserDefinedGenerator(String equation, List<Variable> v, TreeMap<Integer, Palette<BlockData>> pa, boolean preventSmooth) throws ParseException {
Parser p = new Parser();

View File

@@ -24,24 +24,6 @@ public class ImageLoader {
this.align = align;
}
public int getChannel(int x, int y, Channel channel) {
int rgb;
rgb = align.getRGB(image, x, y);
switch(channel) {
case RED:
return rgb >> 16 & 0xff;
case GREEN:
return rgb >> 8 & 0xff;
case BLUE:
return rgb & 0xff;
case ALPHA:
return rgb >> 32 & 0xff;
default:
throw new IllegalArgumentException();
}
}
public static void debugWorld(boolean genStep, World w) {
if(! ConfigUtil.debug) return;
BufferedImage newImg = new WorldImageGenerator(w, 1024, 1024).drawWorld(0, 0).getDraw();
@@ -69,6 +51,31 @@ public class ImageLoader {
return newImg;
}
private static BufferedImage copyImage(BufferedImage source) {
BufferedImage b = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
Graphics g = b.getGraphics();
g.drawImage(source, 0, 0, null);
g.dispose();
return b;
}
public int getChannel(int x, int y, Channel channel) {
int rgb;
rgb = align.getRGB(image, x, y);
switch(channel) {
case RED:
return rgb >> 16 & 0xff;
case GREEN:
return rgb >> 8 & 0xff;
case BLUE:
return rgb & 0xff;
case ALPHA:
return rgb >> 32 & 0xff;
default:
throw new IllegalArgumentException();
}
}
public void debug(boolean genStep, World w) {
if(! ConfigUtil.debug) return;
BufferedImage newImg = copyImage(image);
@@ -83,14 +90,6 @@ public class ImageLoader {
return ((double) (getChannel(x, y, channel) - 128) / 128) * inverseRoot2;
}
private static BufferedImage copyImage(BufferedImage source) {
BufferedImage b = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
Graphics g = b.getGraphics();
g.drawImage(source, 0, 0, null);
g.dispose();
return b;
}
public Align getAlign() {
return align;
}
@@ -113,10 +112,10 @@ public class ImageLoader {
}
};
public abstract int getRGB(BufferedImage image, int x, int y);
private static int getRGBNoAlign(BufferedImage image, int x, int y) {
return image.getRGB(Math.floorMod(x, image.getWidth()), Math.floorMod(y, image.getHeight()));
}
public abstract int getRGB(BufferedImage image, int x, int y);
}
}

View File

@@ -8,8 +8,8 @@ import parsii.eval.Function;
import java.util.List;
public class NoiseFunction2 implements Function {
private FastNoiseLite gen;
private final Cache cache = new Cache();
private FastNoiseLite gen;
@Override
public int getNumberOfArguments() {
@@ -34,6 +34,7 @@ public class NoiseFunction2 implements Function {
private final double[] cacheX = new double[ConfigUtil.cacheSize];
private final double[] cacheZ = new double[ConfigUtil.cacheSize];
private final double[] cacheValues = new double[ConfigUtil.cacheSize];
public double get(double x, double z) {
for(int i = 0; i < cacheX.length; i++) {
if(cacheX[i] == x && cacheZ[i] == z) return cacheValues[i];
@@ -41,10 +42,10 @@ public class NoiseFunction2 implements Function {
cacheX[0] = x;
cacheZ[0] = z;
cacheValues[0] = gen.getNoise(x, z);
for(int i = 0; i < cacheX.length-1; i++) {
cacheX[i+1] = cacheX[i];
cacheZ[i+1] = cacheZ[i];
cacheValues[i+1] = cacheValues[i];
for(int i = 0; i < cacheX.length - 1; i++) {
cacheX[i + 1] = cacheX[i];
cacheZ[i + 1] = cacheZ[i];
cacheValues[i + 1] = cacheValues[i];
}
return cacheValues[0];
}

View File

@@ -30,6 +30,36 @@ import java.util.Random;
* Populates Flora and Trees
*/
public class FloraPopulator extends GaeaBlockPopulator {
private static boolean doTrees(@NotNull UserDefinedBiome biome, TerraWorld world, @NotNull Random random, @NotNull Chunk chunk, int x, int z) {
for(Block block : getValidTreeSpawnsAt(chunk, x, z, new Range(0, 254))) {
Tree tree = biome.getDecorator().getTrees().get(random);
Range range = world.getConfig().getBiome(biome).getTreeRange(tree);
if(! range.isInRange(block.getY())) continue;
try {
Location l = block.getLocation();
TreeGenerateEvent event = new TreeGenerateEvent(world, l, tree);
Bukkit.getPluginManager().callEvent(event);
if(! event.isCancelled()) tree.plant(l, random, Terra.getInstance());
} catch(NullPointerException ignore) {
}
}
return false;
}
private static int offset(Random r, int i) {
return Math.min(Math.max(i + r.nextInt(3) - 1, 0), 15);
}
public static List<Block> getValidTreeSpawnsAt(Chunk chunk, int x, int z, Range check) {
List<Block> blocks = new ArrayList<>();
for(int y : check) {
if(chunk.getBlock(x, y, z).getType().isSolid() && chunk.getBlock(x, y + 1, z).getType().isAir()) {
blocks.add(chunk.getBlock(x, y + 1, z));
}
}
return blocks;
}
@Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("FloraTime")) {
@@ -70,34 +100,4 @@ public class FloraPopulator extends GaeaBlockPopulator {
}
}
}
private static boolean doTrees(@NotNull UserDefinedBiome biome, TerraWorld world, @NotNull Random random, @NotNull Chunk chunk, int x, int z) {
for(Block block : getValidTreeSpawnsAt(chunk, x, z, new Range(0, 254))) {
Tree tree = biome.getDecorator().getTrees().get(random);
Range range = world.getConfig().getBiome(biome).getTreeRange(tree);
if(! range.isInRange(block.getY())) continue;
try {
Location l = block.getLocation();
TreeGenerateEvent event = new TreeGenerateEvent(world, l, tree);
Bukkit.getPluginManager().callEvent(event);
if(! event.isCancelled()) tree.plant(l, random, Terra.getInstance());
} catch(NullPointerException ignore) {
}
}
return false;
}
private static int offset(Random r, int i) {
return Math.min(Math.max(i + r.nextInt(3) - 1, 0), 15);
}
public static List<Block> getValidTreeSpawnsAt(Chunk chunk, int x, int z, Range check) {
List<Block> blocks = new ArrayList<>();
for(int y : check) {
if(chunk.getBlock(x, y, z).getType().isSolid() && chunk.getBlock(x, y + 1, z).getType().isAir()) {
blocks.add(chunk.getBlock(x, y + 1, z));
}
}
return blocks;
}
}

View File

@@ -27,6 +27,11 @@ public class Vector2 implements Cloneable {
return x;
}
public Vector2 setX(double x) {
this.x = x;
return this;
}
/**
* Get Z component
*
@@ -36,6 +41,11 @@ public class Vector2 implements Cloneable {
return z;
}
public Vector2 setZ(double z) {
this.z = z;
return this;
}
/**
* Multiply X and Z components by a value.
*
@@ -164,14 +174,4 @@ public class Vector2 implements Cloneable {
throw new Error(e);
}
}
public Vector2 setX(double x) {
this.x = x;
return this;
}
public Vector2 setZ(double z) {
this.z = z;
return this;
}
}

View File

@@ -6,13 +6,12 @@ import java.util.HashSet;
import java.util.Set;
public class Rectangle extends Polygon {
private Vector2 min;
private Vector2 max;
private final Vector2 min;
private final Vector2 max;
public Rectangle(Vector2 min, Vector2 max) {
this.max = new Vector2(Math.min(min.getX(), max.getX()), Math.min(min.getZ(), max.getZ()));
this.min = new Vector2(Math.max(min.getX(), max.getX()), Math.max(min.getZ(), max.getZ()));
;
}
public Rectangle(Vector2 center, double xRadius, double zRadius) {

View File

@@ -8,6 +8,11 @@ import java.util.List;
public abstract class VoxelGeometry {
public List<Vector> geometry = new ArrayList<>();
public static VoxelGeometry getBlank() {
return new VoxelGeometry() {
};
}
public List<Vector> getGeometry() {
return geometry;
}
@@ -19,9 +24,4 @@ public abstract class VoxelGeometry {
public void merge(VoxelGeometry other) {
geometry.addAll(other.geometry);
}
public static VoxelGeometry getBlank() {
return new VoxelGeometry() {
};
}
}

View File

@@ -47,15 +47,6 @@ public class Structure implements Serializable {
private final HashSet<StructureContainedBlock> spawns;
private final HashSet<StructureContainedInventory> inventories;
@NotNull
public static Structure load(@NotNull File f) throws IOException {
try {
return fromFile(f);
} catch(ClassNotFoundException e) {
throw new IllegalArgumentException("Provided file does not contain a GaeaStructure.");
}
}
public Structure(@NotNull Location l1, @NotNull Location l2, @NotNull String id) throws InitializationException {
int centerX = - 1, centerZ = - 1;
this.id = id;
@@ -126,6 +117,45 @@ public class Structure implements Serializable {
structureInfo = new StructureInfo(l2.getBlockX() - l1.getBlockX() + 1, l2.getBlockY() - l1.getBlockY() + 1, l2.getBlockZ() - l1.getBlockZ() + 1, new Vector2(centerX, centerZ));
}
@NotNull
public static Structure load(@NotNull File f) throws IOException {
try {
return fromFile(f);
} catch(ClassNotFoundException e) {
throw new IllegalArgumentException("Provided file does not contain a GaeaStructure.");
}
}
/**
* Load a structure from a file.
*
* @param f File to load from
* @return The structure loaded
* @throws IOException If file access error occurs
* @throws ClassNotFoundException If structure data is invalid.
*/
@NotNull
private static Structure fromFile(@NotNull File f) throws IOException, ClassNotFoundException {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
Object o = ois.readObject();
ois.close();
return (Structure) o;
}
@NotNull
public static Structure fromStream(@NotNull InputStream f) throws IOException, ClassNotFoundException {
ObjectInputStream ois = new ObjectInputStream(f);
Object o = ois.readObject();
ois.close();
return (Structure) o;
}
private static void toFile(@NotNull Serializable o, @NotNull File f) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
oos.writeObject(o);
oos.close();
}
/**
* Get GaeaStructureInfo object
*
@@ -305,36 +335,6 @@ public class Structure implements Serializable {
toFile(this, f);
}
/**
* Load a structure from a file.
*
* @param f File to load from
* @return The structure loaded
* @throws IOException If file access error occurs
* @throws ClassNotFoundException If structure data is invalid.
*/
@NotNull
private static Structure fromFile(@NotNull File f) throws IOException, ClassNotFoundException {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
Object o = ois.readObject();
ois.close();
return (Structure) o;
}
@NotNull
public static Structure fromStream(@NotNull InputStream f) throws IOException, ClassNotFoundException {
ObjectInputStream ois = new ObjectInputStream(f);
Object o = ois.readObject();
ois.close();
return (Structure) o;
}
private static void toFile(@NotNull Serializable o, @NotNull File f) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
oos.writeObject(o);
oos.close();
}
@NotNull
public String getId() {
return id;
@@ -386,10 +386,6 @@ public class Structure implements Serializable {
this.degrees = degrees;
}
public int getDegrees() {
return degrees;
}
public static Rotation fromDegrees(int deg) {
switch(Math.floorMod(deg, 360)) {
case 0:
@@ -405,6 +401,10 @@ public class Structure implements Serializable {
}
}
public int getDegrees() {
return degrees;
}
public Rotation inverse() {
switch(this) {
case NONE:

View File

@@ -17,7 +17,6 @@ import java.io.Serializable;
public class StructureContainedBlock implements Serializable {
public static final long serialVersionUID = 6143969483382710947L;
private final SerializableBlockData bl;
private transient BlockData data;
private final Pull pull;
private final int pullOffset;
private final int x;
@@ -25,6 +24,7 @@ public class StructureContainedBlock implements Serializable {
private final int z;
private final SerializableBlockState state;
private final StructureSpawnRequirement requirement;
private transient BlockData data;
public StructureContainedBlock(int x, int y, int z, BlockState state, BlockData d, StructureSpawnRequirement spawn, Pull pull, int pullOffset) {
if(state instanceof Sign) {
@@ -93,6 +93,6 @@ public class StructureContainedBlock implements Serializable {
}
public enum Pull {
UP, NONE, DOWN;
UP, NONE, DOWN
}
}

View File

@@ -3,7 +3,6 @@ package com.dfsek.terra.structure;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
import org.bukkit.World;
import org.polydev.gaea.generation.GenerationPhase;
@@ -50,8 +49,6 @@ public enum StructureSpawnRequirement implements Serializable {
private static final long serialVersionUID = - 175639605885943679L;
private static final transient Map<World, FastNoiseLite> noiseMap = new HashMap<>();
public abstract boolean matches(World w, int x, int y, int z);
public static void putNoise(World w, FastNoiseLite noise) {
noiseMap.putIfAbsent(w, noise);
}
@@ -72,4 +69,6 @@ public enum StructureSpawnRequirement implements Serializable {
putNoise(w, gen);
}
}
public abstract boolean matches(World w, int x, int y, int z);
}

View File

@@ -12,8 +12,6 @@ import org.bukkit.entity.EntityType;
import org.polydev.gaea.math.MathUtil;
import org.polydev.gaea.math.Range;
import java.util.List;
import java.util.Random;
import java.util.Set;
@@ -24,6 +22,7 @@ public class EntityFeature implements Feature {
private final Set<Material> in;
private final Set<Material> stand;
private final int inSize;
public EntityFeature(EntityType type, Range amount, int attempts, Set<Material> stand, Set<Material> in, int inSize) {
this.type = type;
this.amount = amount;
@@ -33,6 +32,10 @@ public class EntityFeature implements Feature {
this.inSize = inSize;
}
private static boolean isInChunk(Chunk c, Location l) {
return Math.floorDiv(l.getBlockX(), 16) == c.getX() && Math.floorDiv(l.getBlockZ(), 16) == c.getZ();
}
@Override
public void apply(Structure structure, Location l, Chunk chunk) {
Random random = new Random(MathUtil.getCarverChunkSeed(chunk.getX(), chunk.getZ(), chunk.getWorld().getSeed()));
@@ -49,8 +52,8 @@ public class EntityFeature implements Feature {
for(int i = 0; i < amountSpawn && i < attempts; i++) {
int yv = y.get(random);
Location attempt = l.clone().add(x.get(random)-cx, yv, z.get(random)-cz);
if(!isInChunk(chunk, attempt)) continue; // Don't attempt spawn if not in current chunk.
Location attempt = l.clone().add(x.get(random) - cx, yv, z.get(random) - cz);
if(! isInChunk(chunk, attempt)) continue; // Don't attempt spawn if not in current chunk.
boolean canSpawn = false;
while(yv >= 0 && attempt.getBlockY() >= l.getBlockY()) { // Go down, see if valid spawns exist.
@@ -59,9 +62,10 @@ public class EntityFeature implements Feature {
attempt.subtract(0, 1, 0);
yv--;
if(!stand.contains(on.getType())) continue;
if(! stand.contains(on.getType())) continue;
for(int j = 1; j < inSize + 1; j++) if(! in.contains(on.getRelative(BlockFace.UP, j).getType())) canSpawn = false;
for(int j = 1; j < inSize + 1; j++)
if(! in.contains(on.getRelative(BlockFace.UP, j).getType())) canSpawn = false;
if(canSpawn) break;
}
@@ -72,10 +76,6 @@ public class EntityFeature implements Feature {
}
}
private static boolean isInChunk(Chunk c, Location l) {
return Math.floorDiv(l.getBlockX(), 16) == c.getX() && Math.floorDiv(l.getBlockZ(), 16) == c.getZ();
}
@Override
public void apply(Structure structure, Location l, Random random) {
int amountSpawn = amount.get(random);
@@ -90,7 +90,7 @@ public class EntityFeature implements Feature {
for(int i = 0; i < amountSpawn && i < attempts; i++) {
int yv = y.get(random);
Location attempt = l.clone().add(x.get(random)-cx, yv, z.get(random)-cz);
Location attempt = l.clone().add(x.get(random) - cx, yv, z.get(random) - cz);
boolean canSpawn = false;
while(yv >= 0 && attempt.getBlockY() >= l.getBlockY()) { // Go down, see if valid spawns exist.
@@ -99,9 +99,10 @@ public class EntityFeature implements Feature {
attempt.subtract(0, 1, 0);
yv--;
if(!stand.contains(on.getType())) continue;
if(! stand.contains(on.getType())) continue;
for(int j = 1; j < inSize + 1; j++) if(! in.contains(on.getRelative(BlockFace.UP, j).getType())) canSpawn = false;
for(int j = 1; j < inSize + 1; j++)
if(! in.contains(on.getRelative(BlockFace.UP, j).getType())) canSpawn = false;
if(canSpawn) break;
}

View File

@@ -8,5 +8,6 @@ import java.util.Random;
public interface Feature {
void apply(Structure structure, Location l, Chunk chunk);
void apply(Structure structure, Location l, Random random);
}

View File

@@ -25,12 +25,12 @@ public enum StructureTypeEnum {
RUINED_PORTAL(StructureType.RUINED_PORTAL),
BASTION_REMNANT(StructureType.BASTION_REMNANT);
private final StructureType type;
StructureTypeEnum(StructureType type) {
this.type = type;
}
private final StructureType type;
public StructureType getType() {
return type;
}