Fix formatting issues

Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
solonovamax 2020-11-07 11:14:06 -05:00
parent c0e0dad100
commit 56671ac6a1
No known key found for this signature in database
GPG Key ID: ED0FC2D44CD76482
98 changed files with 1369 additions and 1492 deletions

View File

@ -179,7 +179,7 @@ ij_java_space_before_for_left_brace = true
ij_java_space_before_for_parentheses = false ij_java_space_before_for_parentheses = false
ij_java_space_before_for_semicolon = false ij_java_space_before_for_semicolon = false
ij_java_space_before_if_left_brace = true ij_java_space_before_if_left_brace = true
ij_java_space_before_if_parentheses = true ij_java_space_before_if_parentheses = false
ij_java_space_before_method_call_parentheses = false ij_java_space_before_method_call_parentheses = false
ij_java_space_before_method_left_brace = true ij_java_space_before_method_left_brace = true
ij_java_space_before_method_parentheses = false ij_java_space_before_method_parentheses = false
@ -340,7 +340,7 @@ ij_json_wrap_long_lines = false
[{*.yaml,*.yml}] [{*.yaml,*.yml}]
indent_size = 2 indent_size = 2
ij_yaml_keep_indents_on_empty_lines = false ij_yaml_keep_indents_on_empty_lines = true
ij_yaml_keep_line_breaks = true ij_yaml_keep_line_breaks = true
ij_yaml_space_before_colon = true ij_yaml_space_before_colon = true
ij_yaml_spaces_within_braces = true ij_yaml_spaces_within_braces = true

3
.idea/misc.xml generated
View File

@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="EntryPointsManager"> <component name="EntryPointsManager">
<entry_points version="2.0">
<entry_point TYPE="field" FQNAME="com.dfsek.terra.util.StructureTypeEnum NETHER_FORTRESS" />
</entry_points>
<list size="1"> <list size="1">
<item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" /> <item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" />
</list> </list>

17
Terra.iml Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="CheckStyle-IDEA-Module">
<option name="configuration">
<map />
</option>
</component>
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>SPIGOT</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
</module>

View File

@ -39,7 +39,7 @@ public class TerraWorld {
for(int i = 0; i < config.biomeList.size(); i++) { for(int i = 0; i < config.biomeList.size(); i++) {
String partName = config.biomeList.get(i); String partName = config.biomeList.get(i);
try { try {
if (partName.startsWith("BIOME:")) { if(partName.startsWith("BIOME:")) {
UserDefinedBiome[][] temp = new UserDefinedBiome[1][1]; UserDefinedBiome[][] temp = new UserDefinedBiome[1][1];
UserDefinedBiome b = config.getBiomes().get(partName.substring(6)).getBiome(); UserDefinedBiome b = config.getBiomes().get(partName.substring(6)).getBiome();
temp[0][0] = b; temp[0][0] = b;

View File

@ -21,11 +21,11 @@ public class TerraBiomeGrid extends BiomeGrid {
public TerraBiomeGrid(World w, double freq1, double freq2, BiomeZone zone, ConfigPack c, UserDefinedGrid erosion) { public TerraBiomeGrid(World w, double freq1, double freq2, BiomeZone zone, ConfigPack c, UserDefinedGrid erosion) {
super(w, freq1, freq2, 0, 0); super(w, freq1, freq2, 0, 0);
if (c.biomeBlend) { if(c.biomeBlend) {
perturb = new CoordinatePerturb(c.blendFreq, c.blendAmp, w.getSeed()); perturb = new CoordinatePerturb(c.blendFreq, c.blendAmp, w.getSeed());
} }
this.zone = zone; this.zone = zone;
if (c.erosionEnable) { if(c.erosionEnable) {
erode = new ErosionNoise(c.erosionFreq, c.erosionThresh, c.erosionOctaves, w.getSeed()); erode = new ErosionNoise(c.erosionFreq, c.erosionThresh, c.erosionOctaves, w.getSeed());
this.erosionGrid = erosion; this.erosionGrid = erosion;
} }
@ -39,7 +39,7 @@ public class TerraBiomeGrid extends BiomeGrid {
public Biome getBiome(int x, int z, GenerationPhase phase) { public Biome getBiome(int x, int z, GenerationPhase phase) {
int xp = x; int xp = x;
int zp = z; int zp = z;
if (perturb != null && phase.equals(GenerationPhase.PALETTE_APPLY)) { if(perturb != null && phase.equals(GenerationPhase.PALETTE_APPLY)) {
Vector2 perturbCoords = perturb.getShiftedCoords(x, z); Vector2 perturbCoords = perturb.getShiftedCoords(x, z);
xp = (int) perturbCoords.getX(); xp = (int) perturbCoords.getX();
zp = (int) perturbCoords.getZ(); zp = (int) perturbCoords.getZ();

View File

@ -58,7 +58,7 @@ public class SimplexCarver extends Carver {
if(finalNoise > 0.5) { if(finalNoise > 0.5) {
c.carve(x - ox, y, z - oz, type); c.carve(x - ox, y, z - oz, type);
double finalNoiseUp = (-0.05 * Math.abs((y + 1) - (heightNoise * 16 + 24)) + 1 - simplex) * hc; double finalNoiseUp = (-0.05 * Math.abs((y + 1) - (heightNoise * 16 + 24)) + 1 - simplex) * hc;
if (finalNoiseUp > 0.5) { if(finalNoiseUp > 0.5) {
type = CarvingData.CarvingType.CENTER; type = CarvingData.CarvingType.CENTER;
} else type = CarvingData.CarvingType.TOP; } else type = CarvingData.CarvingType.TOP;
} }

View File

@ -158,6 +158,22 @@ public class ConfigPack extends YamlConfiguration {
LangUtil.log("config-pack.loaded", Level.INFO, getID(), String.valueOf((System.nanoTime() - l) / 1000000D)); LangUtil.log("config-pack.loaded", Level.INFO, getID(), String.valueOf((System.nanoTime() - l) / 1000000D));
} }
public String getID() {
return id;
}
public Map<String, BiomeConfig> getBiomes() {
return biomes;
}
public StructureConfig getStructure(String id) {
return structures.get(id);
}
public BiomeGridConfig getBiomeGrid(String id) {
return grids.get(id);
}
public static synchronized void loadAll(JavaPlugin main) { public static synchronized void loadAll(JavaPlugin main) {
configs.clear(); configs.clear();
File file = new File(main.getDataFolder(), "packs"); File file = new File(main.getDataFolder(), "packs");
@ -188,22 +204,6 @@ public class ConfigPack extends YamlConfiguration {
} }
} }
public String getID() {
return id;
}
public Map<String, BiomeConfig> getBiomes() {
return biomes;
}
public StructureConfig getStructure(String id) {
return structures.get(id);
}
public BiomeGridConfig getBiomeGrid(String id) {
return grids.get(id);
}
public static synchronized ConfigPack fromID(String id) { public static synchronized ConfigPack fromID(String id) {
return configs.get(id); return configs.get(id);
} }

View File

@ -42,7 +42,7 @@ public class WorldConfig {
FileConfiguration config = new YamlConfiguration(); FileConfiguration config = new YamlConfiguration();
Debug.info("Loading config " + configID + " for world " + worldID); Debug.info("Loading config " + configID + " for world " + worldID);
try { // Load/create world config file try { // Load/create world config file
if (configID == null || configID.equals("")) if(configID == null || configID.equals(""))
throw new ConfigException("Config pack unspecified in bukkit.yml!", worldID); throw new ConfigException("Config pack unspecified in bukkit.yml!", worldID);
File configFile = new File(main.getDataFolder() + File.separator + "worlds", worldID + ".yml"); File configFile = new File(main.getDataFolder() + File.separator + "worlds", worldID + ".yml");
if(!configFile.exists()) { if(!configFile.exists()) {
@ -58,19 +58,19 @@ public class WorldConfig {
tConfig = ConfigPack.fromID(configID); tConfig = ConfigPack.fromID(configID);
if (tConfig == null) if(tConfig == null)
throw new ConfigException("No such config pack: \"" + configID + "\". This pack either does not exist, or failed to load due to configuration errors.", worldID); throw new ConfigException("No such config pack: \"" + configID + "\". This pack either does not exist, or failed to load due to configuration errors.", worldID);
// Load image stuff // Load image stuff
try { try {
biomeXChannel = ImageLoader.Channel.valueOf(Objects.requireNonNull(config.getString("image.channels.biome-x", "red")).toUpperCase()); biomeXChannel = ImageLoader.Channel.valueOf(Objects.requireNonNull(config.getString("image.channels.biome-x", "red")).toUpperCase());
biomeZChannel = ImageLoader.Channel.valueOf(Objects.requireNonNull(config.getString("image.channels.biome-z", "green")).toUpperCase()); biomeZChannel = ImageLoader.Channel.valueOf(Objects.requireNonNull(config.getString("image.channels.biome-z", "green")).toUpperCase());
if (biomeZChannel.equals(biomeXChannel)) if(biomeZChannel.equals(biomeXChannel))
throw new InvalidConfigurationException("2 objects share the same image channels: biome-x and biome-z"); throw new InvalidConfigurationException("2 objects share the same image channels: biome-x and biome-z");
zoneChannel = ImageLoader.Channel.valueOf(Objects.requireNonNull(config.getString("image.channels.zone", "blue")).toUpperCase()); zoneChannel = ImageLoader.Channel.valueOf(Objects.requireNonNull(config.getString("image.channels.zone", "blue")).toUpperCase());
if (zoneChannel.equals(biomeXChannel) || zoneChannel.equals(biomeZChannel)) if(zoneChannel.equals(biomeXChannel) || zoneChannel.equals(biomeZChannel))
throw new InvalidConfigurationException("2 objects share the same image channels: zone and biome-x/z"); throw new InvalidConfigurationException("2 objects share the same image channels: zone and biome-x/z");
if (fromImage) { if(fromImage) {
try { try {
//noinspection ConstantConditions //noinspection ConstantConditions
imageLoader = new ImageLoader(new File(config.getString("image.file")), imageLoader = new ImageLoader(new File(config.getString("image.file")),

View File

@ -70,7 +70,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
} }
public static synchronized void fixChunk(Chunk c) { public static synchronized void fixChunk(Chunk c) {
if (!(c.getWorld().getGenerator() instanceof TerraChunkGenerator)) throw new IllegalArgumentException(); if(!(c.getWorld().getGenerator() instanceof TerraChunkGenerator)) throw new IllegalArgumentException();
popMap.get(c.getWorld()).checkNeighbors(c.getX(), c.getZ(), c.getWorld()); popMap.get(c.getWorld()).checkNeighbors(c.getX(), c.getZ(), c.getWorld());
} }
@ -82,10 +82,10 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
@Override @Override
public ChunkData generateBase(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, ChunkInterpolator interpolator) { public ChunkData generateBase(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, ChunkInterpolator interpolator) {
if (needsLoad) load(world); // Load population data for world. if(needsLoad) load(world); // Load population data for world.
ChunkData chunk = createChunkData(world); ChunkData chunk = createChunkData(world);
TerraWorld tw = TerraWorld.getWorld(world); TerraWorld tw = TerraWorld.getWorld(world);
if (!tw.isSafe()) return chunk; if(!tw.isSafe()) return chunk;
ConfigPack config = tw.getConfig(); ConfigPack config = tw.getConfig();
int xOrig = (chunkX << 4); int xOrig = (chunkX << 4);
int zOrig = (chunkZ << 4); int zOrig = (chunkZ << 4);
@ -109,7 +109,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
slab.getStairs(), slab.getSlabThreshold(), interpolator); slab.getStairs(), slab.getSlabThreshold(), interpolator);
} }
paletteLevel++; paletteLevel++;
} else if (y <= sea) { } else if(y <= sea) {
chunk.setBlock(x, y, z, seaPalette.get(sea - y, x + xOrig, z + zOrig)); chunk.setBlock(x, y, z, seaPalette.get(sea - y, x + xOrig, z + zOrig));
paletteLevel = 0; paletteLevel = 0;
} else paletteLevel = 0; } else paletteLevel = 0;
@ -121,15 +121,15 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
private void prepareBlockPart(BlockData down, BlockData orig, ChunkData chunk, Vector block, Map<Material, Palette<BlockData>> slabs, private void prepareBlockPart(BlockData down, BlockData orig, ChunkData chunk, Vector block, Map<Material, Palette<BlockData>> slabs,
Map<Material, Palette<BlockData>> stairs, double thresh, ChunkInterpolator interpolator) { Map<Material, Palette<BlockData>> stairs, double thresh, ChunkInterpolator interpolator) {
if (interpolator.getNoise(block.getBlockX(), block.getBlockY() - 0.4, block.getBlockZ()) > thresh) { if(interpolator.getNoise(block.getBlockX(), block.getBlockY() - 0.4, block.getBlockZ()) > thresh) {
if (stairs != null) { if(stairs != null) {
Palette<BlockData> stairPalette = stairs.get(down.getMaterial()); Palette<BlockData> stairPalette = stairs.get(down.getMaterial());
if (stairPalette != null) { if(stairPalette != null) {
BlockData stair = stairPalette.get(0, block.getBlockX(), block.getBlockZ()); BlockData stair = stairPalette.get(0, block.getBlockX(), block.getBlockZ());
Stairs stairNew = (Stairs) stair.clone(); Stairs stairNew = (Stairs) stair.clone();
if (interpolator.getNoise(block.getBlockX() - 0.5, block.getBlockY(), block.getBlockZ()) > thresh) { if(interpolator.getNoise(block.getBlockX() - 0.5, block.getBlockY(), block.getBlockZ()) > thresh) {
stairNew.setFacing(BlockFace.WEST); stairNew.setFacing(BlockFace.WEST);
} else if (interpolator.getNoise(block.getBlockX(), block.getBlockY(), block.getBlockZ() - 0.5) > thresh) { } else if(interpolator.getNoise(block.getBlockX(), block.getBlockY(), block.getBlockZ() - 0.5) > thresh) {
stairNew.setFacing(BlockFace.NORTH); stairNew.setFacing(BlockFace.NORTH);
} else if(interpolator.getNoise(block.getBlockX(), block.getBlockY(), block.getBlockZ() + 0.5) > thresh) { } else if(interpolator.getNoise(block.getBlockX(), block.getBlockY(), block.getBlockZ() + 0.5) > thresh) {
stairNew.setFacing(BlockFace.SOUTH); stairNew.setFacing(BlockFace.SOUTH);

View File

@ -40,7 +40,7 @@ public class UserDefinedGenerator extends Generator {
for(int y = 0; y < 256; y++) { for(int y = 0; y < 256; y++) {
Palette<BlockData> d = DataUtil.BLANK_PALETTE; Palette<BlockData> d = DataUtil.BLANK_PALETTE;
for(Map.Entry<Integer, Palette<BlockData>> e : paletteMap.entrySet()) { for(Map.Entry<Integer, Palette<BlockData>> e : paletteMap.entrySet()) {
if (e.getKey() >= y) { if(e.getKey() >= y) {
d = e.getValue(); d = e.getValue();
break; break;
} }

View File

@ -15,9 +15,9 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
public class ImageLoader { public class ImageLoader {
private static final double INVERSE_ROOT_2 = 0.7071067811865475;
private final BufferedImage image; private final BufferedImage image;
private final Align align; private final Align align;
private static final double INVERSE_ROOT_2 = 0.7071067811865475;
public ImageLoader(File file, Align align) throws IOException { public ImageLoader(File file, Align align) throws IOException {
image = ImageIO.read(file); image = ImageIO.read(file);
@ -60,9 +60,9 @@ public class ImageLoader {
} }
public void debug(boolean genStep, World w) { public void debug(boolean genStep, World w) {
if (!ConfigUtil.debug) return; if(!ConfigUtil.debug) return;
BufferedImage newImg = copyImage(image); BufferedImage newImg = copyImage(image);
if (genStep) { if(genStep) {
newImg = redrawStepped(image, w, align); newImg = redrawStepped(image, w, align);
} }
DebugGUI debugGUI = new DebugGUI(newImg); DebugGUI debugGUI = new DebugGUI(newImg);
@ -90,20 +90,6 @@ public class ImageLoader {
} }
} }
public void debug(boolean genStep, World w) {
if(!ConfigUtil.debug) return;
BufferedImage newImg = copyImage(image);
if(genStep) {
newImg = redrawStepped(image, w, align);
}
DebugGUI debugGUI = new DebugGUI(newImg);
debugGUI.start();
}
public double getNoiseVal(int x, int y, Channel channel) {
return ((double) (getChannel(x, y, channel) - 128) / 128) * inverseRoot2;
}
public Align getAlign() { public Align getAlign() {
return align; return align;
} }

View File

@ -37,7 +37,7 @@ public class NoiseFunction2 implements Function {
public double get(double x, double z) { public double get(double x, double z) {
for(int i = 0; i < cacheX.length; i++) { for(int i = 0; i < cacheX.length; i++) {
if (cacheX[i] == x && cacheZ[i] == z) return cacheValues[i]; if(cacheX[i] == x && cacheZ[i] == z) return cacheValues[i];
} }
cacheX[0] = x; cacheX[0] = x;
cacheZ[0] = z; cacheZ[0] = z;

View File

@ -60,7 +60,7 @@ public class FloraPopulator extends GaeaBlockPopulator {
item = biome.getDecorator().getFlora().get(f.getFloraNoise(), originX + x, originZ + z); item = biome.getDecorator().getFlora().get(f.getFloraNoise(), originX + x, originZ + z);
else item = biome.getDecorator().getFlora().get(random); else item = biome.getDecorator().getFlora().get(random);
for(Block highest : item.getValidSpawnsAt(chunk, x, z, c.getFloraHeights(item))) { for(Block highest : item.getValidSpawnsAt(chunk, x, z, c.getFloraHeights(item))) {
if (random.nextInt(100) < biome.getDecorator().getFloraChance()) if(random.nextInt(100) < biome.getDecorator().getFloraChance())
item.plant(highest.getLocation()); item.plant(highest.getLocation());
} }
} }
@ -75,12 +75,12 @@ public class FloraPopulator extends GaeaBlockPopulator {
for(Block block : getValidTreeSpawnsAt(chunk, x, z, new Range(0, 254))) { for(Block block : getValidTreeSpawnsAt(chunk, x, z, new Range(0, 254))) {
Tree tree = biome.getDecorator().getTrees().get(random); Tree tree = biome.getDecorator().getTrees().get(random);
Range range = world.getConfig().getBiome(biome).getTreeRange(tree); Range range = world.getConfig().getBiome(biome).getTreeRange(tree);
if (!range.isInRange(block.getY())) continue; if(!range.isInRange(block.getY())) continue;
try { try {
Location l = block.getLocation(); Location l = block.getLocation();
TreeGenerateEvent event = new TreeGenerateEvent(world, l, tree); TreeGenerateEvent event = new TreeGenerateEvent(world, l, tree);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) tree.plant(l, random, Terra.getInstance()); if(!event.isCancelled()) tree.plant(l, random, Terra.getInstance());
} catch(NullPointerException ignore) { } catch(NullPointerException ignore) {
} }
} }
@ -90,7 +90,7 @@ public class FloraPopulator extends GaeaBlockPopulator {
public static List<Block> getValidTreeSpawnsAt(Chunk chunk, int x, int z, Range check) { public static List<Block> getValidTreeSpawnsAt(Chunk chunk, int x, int z, Range check) {
List<Block> blocks = new ArrayList<>(); List<Block> blocks = new ArrayList<>();
for(int y : check) { for(int y : check) {
if (chunk.getBlock(x, y, z).getType().isSolid() && chunk.getBlock(x, y + 1, z).getType().isAir()) { if(chunk.getBlock(x, y, z).getType().isSolid() && chunk.getBlock(x, y + 1, z).getType().isAir()) {
blocks.add(chunk.getBlock(x, y + 1, z)); blocks.add(chunk.getBlock(x, y + 1, z));
} }
} }

View File

@ -44,7 +44,7 @@ public class OrePopulator extends GaeaBlockPopulator {
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if(!event.isCancelled()) { if(!event.isCancelled()) {
if(ore.crossChunks()) ore.doVein(v, chunk, random); if(ore.crossChunks()) ore.doVein(v, chunk, random);
else ore.doVeinSingle(new Vector(x, y, z), chunk, random); else ore.doVeinSingleChunk(new Vector(x, y, z), chunk, random);
} }
} }
} }

View File

@ -145,15 +145,6 @@ public class Vector2 implements Cloneable {
return dx * dx + dz * dz; return dx * dx + dz * dz;
} }
@Override
public boolean equals(Object obj) {
if(!(obj instanceof Vector2)) {
return false;
}
Vector2 other = (Vector2) obj;
return other.x == this.x && other.z == this.z;
}
@Override @Override
public int hashCode() { public int hashCode() {
int hash = 17; int hash = 17;
@ -164,7 +155,7 @@ public class Vector2 implements Cloneable {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof Vector2)) { if(!(obj instanceof Vector2)) {
return false; return false;
} }
Vector2 other = (Vector2) obj; Vector2 other = (Vector2) obj;

View File

@ -54,7 +54,7 @@ public class Structure implements Serializable {
this.uuid = UUID.randomUUID(); this.uuid = UUID.randomUUID();
this.spawns = new HashSet<>(); this.spawns = new HashSet<>();
this.inventories = new HashSet<>(); this.inventories = new HashSet<>();
if (l1.getX() > l2.getX() || l1.getY() > l2.getY() || l1.getZ() > l2.getZ()) if(l1.getX() > l2.getX() || l1.getY() > l2.getY() || l1.getZ() > l2.getZ())
throw new IllegalArgumentException("Invalid locations provided!"); throw new IllegalArgumentException("Invalid locations provided!");
structure = new StructureContainedBlock[l2.getBlockX() - l1.getBlockX() + 1][l2.getBlockZ() - l1.getBlockZ() + 1][l2.getBlockY() - l1.getBlockY() + 1]; structure = new StructureContainedBlock[l2.getBlockX() - l1.getBlockX() + 1][l2.getBlockZ() - l1.getBlockZ() + 1][l2.getBlockY() - l1.getBlockY() + 1];
for(int x = 0; x <= l2.getBlockX() - l1.getBlockX(); x++) { for(int x = 0; x <= l2.getBlockX() - l1.getBlockX(); x++) {
@ -68,16 +68,16 @@ public class Structure implements Serializable {
int pullOffset = 0; int pullOffset = 0;
StructureSpawnRequirement requirement = StructureSpawnRequirement.BLANK; StructureSpawnRequirement requirement = StructureSpawnRequirement.BLANK;
try { try {
if (state instanceof Sign) { // Magic sign stuff if(state instanceof Sign) { // Magic sign stuff
Sign s = (Sign) b.getState(); Sign s = (Sign) b.getState();
if (s.getLine(0).equals("[TERRA]")) { if(s.getLine(0).equals("[TERRA]")) {
try { try {
d = Bukkit.createBlockData(s.getLine(2) + s.getLine(3)); d = Bukkit.createBlockData(s.getLine(2) + s.getLine(3));
useState = false; useState = false;
if (s.getLine(1).equals("[CENTER]")) { if(s.getLine(1).equals("[CENTER]")) {
centerX = x; centerX = x;
centerZ = z; centerZ = z;
} else if (s.getLine(1).startsWith("[SPAWN=") && s.getLine(1).endsWith("]")) { } else if(s.getLine(1).startsWith("[SPAWN=") && s.getLine(1).endsWith("]")) {
String og = s.getLine(1); String og = s.getLine(1);
String spawn = og.substring(og.indexOf("=") + 1, og.length() - 1); String spawn = og.substring(og.indexOf("=") + 1, og.length() - 1);
try { try {
@ -85,7 +85,7 @@ public class Structure implements Serializable {
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
throw new InitializationException("Invalid spawn type: " + spawn, b.getLocation()); throw new InitializationException("Invalid spawn type: " + spawn, b.getLocation());
} }
} else if (s.getLine(1).startsWith("[PULL=") && s.getLine(1).endsWith("]")) { } else if(s.getLine(1).startsWith("[PULL=") && s.getLine(1).endsWith("]")) {
String og = s.getLine(1); String og = s.getLine(1);
String spawn = og.substring(og.indexOf("=") + 1, og.indexOf("_")); String spawn = og.substring(og.indexOf("=") + 1, og.indexOf("_"));
pullOffset = Integer.parseInt(og.substring(og.indexOf("_") + 1, og.length() - 1)); pullOffset = Integer.parseInt(og.substring(og.indexOf("_") + 1, og.length() - 1));
@ -106,15 +106,15 @@ public class Structure implements Serializable {
throw new InitializationException("Invalid sign.", b.getLocation()); throw new InitializationException("Invalid sign.", b.getLocation());
} }
StructureContainedBlock block = new StructureContainedBlock(x, y, z, useState ? state : null, d, requirement, pull, pullOffset); StructureContainedBlock block = new StructureContainedBlock(x, y, z, useState ? state : null, d, requirement, pull, pullOffset);
if (state instanceof BlockInventoryHolder) { if(state instanceof BlockInventoryHolder) {
inventories.add(new StructureContainedInventory(((BlockInventoryHolder) state).getInventory(), block)); inventories.add(new StructureContainedInventory(((BlockInventoryHolder) state).getInventory(), block));
} }
if (!requirement.equals(StructureSpawnRequirement.BLANK)) spawns.add(block); if(!requirement.equals(StructureSpawnRequirement.BLANK)) spawns.add(block);
structure[x][z][y] = block; structure[x][z][y] = block;
} }
} }
} }
if (centerX < 0 || centerZ < 0) throw new InitializationException("No structure center specified.", null); if(centerX < 0 || centerZ < 0) throw new InitializationException("No structure center specified.", null);
structureInfo = new StructureInfo(l2.getBlockX() - l1.getBlockX() + 1, l2.getBlockY() - l1.getBlockY() + 1, l2.getBlockZ() - l1.getBlockZ() + 1, new Vector2(centerX, centerZ)); structureInfo = new StructureInfo(l2.getBlockX() - l1.getBlockX() + 1, l2.getBlockY() - l1.getBlockY() + 1, l2.getBlockZ() - l1.getBlockZ() + 1, new Vector2(centerX, centerZ));
} }
@ -177,33 +177,13 @@ public class Structure implements Serializable {
} }
/** /**
* Paste structure at an origin location, confined to a single chunk. * Get GaeaStructureInfo object
* *
* @param origin Origin location * @return Structure Info
* @param chunk Chunk to confine pasting to
* @param r Rotation
*/ */
public void paste(Location origin, Chunk chunk, Rotation r) { @NotNull
int xOr = (chunk.getX() << 4); public StructureInfo getStructureInfo() {
int zOr = (chunk.getZ() << 4); return structureInfo;
Range intersectX = new Range(xOr, xOr + 16).sub(origin.getBlockX() - structureInfo.getCenterX());
Range intersectZ = new Range(zOr, zOr + 16).sub(origin.getBlockZ() - structureInfo.getCenterZ());
if (intersectX == null || intersectZ == null) return;
executeForBlocksInRange(intersectX, getRange(Axis.Y, r), intersectZ, block -> pasteBlock(block, origin, r), r);
Debug.info(intersectX.toString() + " : " + intersectZ.toString());
}
public boolean checkSpawns(Location origin, Rotation r) {
for(StructureContainedBlock b : spawns) {
Vector2 rot = getRotatedCoords(new Vector2(b.getX() - structureInfo.getCenterX(), b.getZ() - structureInfo.getCenterZ()), r);
if (!b.getRequirement().matches(origin.getWorld(), (int) rot.getX() + origin.getBlockX(), origin.getBlockY() + b.getY(), (int) rot.getZ() + origin.getBlockZ()))
return false;
}
return true;
}
public HashSet<StructureContainedInventory> getInventories() {
return inventories;
} }
/** /**
@ -218,23 +198,11 @@ public class Structure implements Serializable {
int zOr = (chunk.getZ() << 4); int zOr = (chunk.getZ() << 4);
Range intersectX = new Range(xOr, xOr + 16).sub(origin.getBlockX() - structureInfo.getCenterX()); Range intersectX = new Range(xOr, xOr + 16).sub(origin.getBlockX() - structureInfo.getCenterX());
Range intersectZ = new Range(zOr, zOr + 16).sub(origin.getBlockZ() - structureInfo.getCenterZ()); Range intersectZ = new Range(zOr, zOr + 16).sub(origin.getBlockZ() - structureInfo.getCenterZ());
if (intersectX == null || intersectZ == null) return; if(intersectX == null || intersectZ == null) return;
executeForBlocksInRange(intersectX, getRange(Axis.Y, r), intersectZ, block -> pasteBlock(block, origin, r), r); executeForBlocksInRange(intersectX, getRange(Axis.Y, r), intersectZ, block -> pasteBlock(block, origin, r), r);
Debug.info(intersectX.toString() + " : " + intersectZ.toString()); Debug.info(intersectX.toString() + " : " + intersectZ.toString());
} }
/**
* Test whether a set of coordinates is within the current structure
*
* @param x X coordinate
* @param y Y coordinate
* @param z Z coordinate
* @return True if coordinate set is in structure, false if it is not.
*/
private boolean isInStructure(int x, int y, int z) {
return x < structureInfo.getSizeX() && y < structureInfo.getSizeY() && z < structureInfo.getSizeZ() && x >= 0 && y >= 0 && z >= 0;
}
/** /**
* Paste a single StructureDefinedBlock at an origin location, offset by its coordinates. * Paste a single StructureDefinedBlock at an origin location, offset by its coordinates.
* *
@ -250,8 +218,8 @@ public class Structure implements Serializable {
Block worldBlock = loc.getBlock(); Block worldBlock = loc.getBlock();
main: main:
while(worldBlock.isEmpty()) { while(worldBlock.isEmpty()) {
if (loc.getBlockY() > 255 || loc.getBlockY() < 0) return; if(loc.getBlockY() > 255 || loc.getBlockY() < 0) return;
if (block.getPull() == null) break; if(block.getPull() == null) break;
switch(block.getPull()) { switch(block.getPull()) {
case UP: case UP:
worldBlock = worldBlock.getRelative(BlockFace.UP); worldBlock = worldBlock.getRelative(BlockFace.UP);
@ -265,16 +233,16 @@ public class Structure implements Serializable {
} }
int offset = block.getPullOffset(); int offset = block.getPullOffset();
if (offset != 0) if(offset != 0)
worldBlock = worldBlock.getRelative((offset > 0) ? BlockFace.UP : BlockFace.DOWN, Math.abs(offset)); worldBlock = worldBlock.getRelative((offset > 0) ? BlockFace.UP : BlockFace.DOWN, Math.abs(offset));
if (data instanceof Rotatable) { if(data instanceof Rotatable) {
BlockFace rt = getRotatedFace(((Rotatable) data).getRotation(), r); BlockFace rt = getRotatedFace(((Rotatable) data).getRotation(), r);
((Rotatable) data).setRotation(rt); ((Rotatable) data).setRotation(rt);
} else if (data instanceof Directional) { } else if(data instanceof Directional) {
BlockFace rt = getRotatedFace(((Directional) data).getFacing(), r); BlockFace rt = getRotatedFace(((Directional) data).getFacing(), r);
((Directional) data).setFacing(rt); ((Directional) data).setFacing(rt);
} else if (data instanceof MultipleFacing) { } else if(data instanceof MultipleFacing) {
MultipleFacing mfData = (MultipleFacing) data; MultipleFacing mfData = (MultipleFacing) data;
Map<BlockFace, Boolean> faces = new HashMap<>(); Map<BlockFace, Boolean> faces = new HashMap<>();
for(BlockFace f : mfData.getAllowedFaces()) { for(BlockFace f : mfData.getAllowedFaces()) {
@ -283,13 +251,13 @@ public class Structure implements Serializable {
for(Map.Entry<BlockFace, Boolean> face : faces.entrySet()) { for(Map.Entry<BlockFace, Boolean> face : faces.entrySet()) {
mfData.setFace(getRotatedFace(face.getKey(), r), face.getValue()); mfData.setFace(getRotatedFace(face.getKey(), r), face.getValue());
} }
} else if (data instanceof Rail) { } else if(data instanceof Rail) {
Rail.Shape newShape = getRotatedRail(((Rail) data).getShape(), r); Rail.Shape newShape = getRotatedRail(((Rail) data).getShape(), r);
((Rail) data).setShape(newShape); ((Rail) data).setShape(newShape);
} else if (data instanceof Orientable) { } else if(data instanceof Orientable) {
org.bukkit.Axis newAxis = getRotatedAxis(((Orientable) data).getAxis(), r); org.bukkit.Axis newAxis = getRotatedAxis(((Orientable) data).getAxis(), r);
((Orientable) data).setAxis(newAxis); ((Orientable) data).setAxis(newAxis);
} else if (data instanceof RedstoneWire) { } else if(data instanceof RedstoneWire) {
Map<BlockFace, RedstoneWire.Connection> connections = new HashMap<>(); Map<BlockFace, RedstoneWire.Connection> connections = new HashMap<>();
RedstoneWire rData = (RedstoneWire) data; RedstoneWire rData = (RedstoneWire) data;
for(BlockFace f : rData.getAllowedFaces()) { for(BlockFace f : rData.getAllowedFaces()) {
@ -300,26 +268,12 @@ public class Structure implements Serializable {
} }
} }
worldBlock.setBlockData(data, false); worldBlock.setBlockData(data, false);
if (block.getState() != null) { if(block.getState() != null) {
block.getState().getState(worldBlock.getState()).update(true, false); block.getState().getState(worldBlock.getState()).update(true, false);
} }
} }
} }
@NotNull
private Range getRawRange(@NotNull Axis a) {
switch(a) {
case X:
return new Range(0, structureInfo.getSizeX());
case Y:
return new Range(0, structureInfo.getSizeY());
case Z:
return new Range(0, structureInfo.getSizeZ());
default:
throw new IllegalArgumentException();
}
}
/** /**
* Execute a Consumer for all blocks in a cuboid region defined by 3 Ranges, accounting for rotation. * Execute a Consumer for all blocks in a cuboid region defined by 3 Ranges, accounting for rotation.
* *
@ -335,7 +289,7 @@ public class Structure implements Serializable {
for(int z : zM) { for(int z : zM) {
Vector2 c = getRotatedCoords(new Vector2(x - structureInfo.getCenterX(), z - structureInfo.getCenterZ()), r); Vector2 c = getRotatedCoords(new Vector2(x - structureInfo.getCenterX(), z - structureInfo.getCenterZ()), r);
c.add(new Vector2(structureInfo.getCenterX(), structureInfo.getCenterZ())); c.add(new Vector2(structureInfo.getCenterX(), structureInfo.getCenterZ()));
if (isInStructure((int) c.getX(), y, (int) c.getZ())) { if(isInStructure((int) c.getX(), y, (int) c.getZ())) {
StructureContainedBlock b = structure[(int) c.getX()][(int) c.getZ()][y]; StructureContainedBlock b = structure[(int) c.getX()][(int) c.getZ()][y];
exec.accept(new StructureContainedBlock(x - getStructureInfo().getCenterX(), y, z - getStructureInfo().getCenterZ(), b.getState(), b.getBlockData(), b.getRequirement(), b.getPull(), b.getPullOffset())); exec.accept(new StructureContainedBlock(x - getStructureInfo().getCenterX(), y, z - getStructureInfo().getCenterZ(), b.getState(), b.getBlockData(), b.getRequirement(), b.getPull(), b.getPullOffset()));
} }
@ -345,30 +299,46 @@ public class Structure implements Serializable {
} }
/** /**
* Get GaeaStructureInfo object * Test whether a set of coordinates is within the current structure
* *
* @return Structure Info * @param x X coordinate
* @param y Y coordinate
* @param z Z coordinate
* @return True if coordinate set is in structure, false if it is not.
*/ */
@NotNull private boolean isInStructure(int x, int y, int z) {
public StructureInfo getStructureInfo() { return x < structureInfo.getSizeX() && y < structureInfo.getSizeY() && z < structureInfo.getSizeZ() && x >= 0 && y >= 0 && z >= 0;
return structureInfo;
} }
@NotNull @NotNull
public Range getRange(@NotNull Axis a, @NotNull Rotation r) { public Range getRange(@NotNull Axis a, @NotNull Rotation r) {
if (a.equals(Axis.Y)) return getRawRange(a); if(a.equals(Axis.Y)) return getRawRange(a);
Vector2 center = new Vector2(structureInfo.getCenterX(), structureInfo.getCenterZ()); Vector2 center = new Vector2(structureInfo.getCenterX(), structureInfo.getCenterZ());
Range x = getRawRange(Axis.X); Range x = getRawRange(Axis.X);
Range z = getRawRange(Axis.Z); Range z = getRawRange(Axis.Z);
Vector2 min = getRotatedCoords(new Vector2(x.getMin(), z.getMin()).subtract(center), r.inverse()).add(center); Vector2 min = getRotatedCoords(new Vector2(x.getMin(), z.getMin()).subtract(center), r.inverse()).add(center);
Vector2 max = getRotatedCoords(new Vector2(x.getMax(), z.getMax()).subtract(center), r.inverse()).add(center); Vector2 max = getRotatedCoords(new Vector2(x.getMax(), z.getMax()).subtract(center), r.inverse()).add(center);
if (a.equals(Axis.X)) if(a.equals(Axis.X))
return new Range((int) Math.floor(Math.min(min.getX(), max.getX())), (int) Math.ceil(Math.max(min.getX(), max.getX())) + 1); return new Range((int) Math.floor(Math.min(min.getX(), max.getX())), (int) Math.ceil(Math.max(min.getX(), max.getX())) + 1);
else else
return new Range((int) Math.floor(Math.min(min.getZ(), max.getZ())), (int) Math.ceil(Math.max(min.getZ(), max.getZ())) + 1); return new Range((int) Math.floor(Math.min(min.getZ(), max.getZ())), (int) Math.ceil(Math.max(min.getZ(), max.getZ())) + 1);
} }
@NotNull
private Range getRawRange(@NotNull Axis a) {
switch(a) {
case X:
return new Range(0, structureInfo.getSizeX());
case Y:
return new Range(0, structureInfo.getSizeY());
case Z:
return new Range(0, structureInfo.getSizeZ());
default:
throw new IllegalArgumentException();
}
}
/** /**
* From an origin location (First bound) fetch the second bound. * From an origin location (First bound) fetch the second bound.
* *

View File

@ -21,7 +21,7 @@ public enum StructureSpawnRequirement implements Serializable {
ConfigPack wc = tw.getConfig(); ConfigPack wc = tw.getConfig();
UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE); UserDefinedBiome b = (UserDefinedBiome) tw.getGrid().getBiome(x, z, GenerationPhase.POPULATE);
BiomeConfig c = wc.getBiome(b); BiomeConfig c = wc.getBiome(b);
if (y <= c.getOcean().getSeaLevel()) return false; if(y <= c.getOcean().getSeaLevel()) return false;
return b.getGenerator().getNoise(getNoise(w), w, x, y, z) <= 0; return b.getGenerator().getNoise(getNoise(w), w, x, y, z) <= 0;
} }
}, OCEAN { }, OCEAN {
@ -30,7 +30,7 @@ public enum StructureSpawnRequirement implements Serializable {
setNoise(w, x, y, z); setNoise(w, x, y, z);
UserDefinedBiome b = (UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome(x, z, GenerationPhase.POPULATE); UserDefinedBiome b = (UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome(x, z, GenerationPhase.POPULATE);
BiomeConfig c = TerraWorld.getWorld(w).getConfig().getBiome(b); BiomeConfig c = TerraWorld.getWorld(w).getConfig().getBiome(b);
if (y > c.getOcean().getSeaLevel()) return false; if(y > c.getOcean().getSeaLevel()) return false;
return b.getGenerator().getNoise(getNoise(w), w, x, y, z) <= 0; return b.getGenerator().getNoise(getNoise(w), w, x, y, z) <= 0;
} }
}, LAND { }, LAND {
@ -52,7 +52,7 @@ public enum StructureSpawnRequirement implements Serializable {
private static void setNoise(World w, int x, int y, int z) { private static void setNoise(World w, int x, int y, int z) {
TerraWorld tw = TerraWorld.getWorld(w); TerraWorld tw = TerraWorld.getWorld(w);
ConfigPack wc = tw.getConfig(); ConfigPack wc = tw.getConfig();
if (getNoise(w) == null) { if(getNoise(w) == null) {
FastNoiseLite gen = new FastNoiseLite((int) w.getSeed()); FastNoiseLite gen = new FastNoiseLite((int) w.getSeed());
gen.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2); gen.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
gen.setFractalType(FastNoiseLite.FractalType.FBm); gen.setFractalType(FastNoiseLite.FractalType.FBm);

View File

@ -63,9 +63,9 @@ public class EntityFeature implements Feature {
for(int j = 1; j < inSize + 1; j++) for(int j = 1; j < inSize + 1; j++)
if(!in.contains(on.getRelative(BlockFace.UP, j).getType())) canSpawn = false; if(!in.contains(on.getRelative(BlockFace.UP, j).getType())) canSpawn = false;
if (canSpawn) break; if(canSpawn) break;
} }
if (canSpawn) { if(canSpawn) {
Debug.info("Spawning entity at " + attempt); Debug.info("Spawning entity at " + attempt);
chunk.getWorld().spawnEntity(attempt.add(0.5, 2, 0.5), type); // Add 0.5 to X & Z so entity spawns in center of block. chunk.getWorld().spawnEntity(attempt.add(0.5, 2, 0.5), type); // Add 0.5 to X & Z so entity spawns in center of block.
} }

View File

@ -40,7 +40,7 @@ public final class RotationUtil {
BlockFace n = f; BlockFace n = f;
int rotateNum = r.getDegrees() / 90; int rotateNum = r.getDegrees() / 90;
int rn = faceRotation(f); int rn = faceRotation(f);
if (rn >= 0) { if(rn >= 0) {
n = fromRotation(faceRotation(n) + 4 * rotateNum); n = fromRotation(faceRotation(n) + 4 * rotateNum);
} }
return n; return n;
@ -141,10 +141,10 @@ public final class RotationUtil {
final boolean shouldSwitch = r.equals(Structure.Rotation.CW_90) || r.equals(Structure.Rotation.CCW_90); final boolean shouldSwitch = r.equals(Structure.Rotation.CW_90) || r.equals(Structure.Rotation.CCW_90);
switch(orig) { switch(orig) {
case X: case X:
if (shouldSwitch) other = org.bukkit.Axis.Z; if(shouldSwitch) other = org.bukkit.Axis.Z;
break; break;
case Z: case Z:
if (shouldSwitch) other = org.bukkit.Axis.X; if(shouldSwitch) other = org.bukkit.Axis.X;
break; break;
} }
return other; return other;
@ -231,94 +231,4 @@ public final class RotationUtil {
} }
return orig; return orig;
} }
/**
* Get an integer representation of a BlockFace, to perform math on.
*
* @param f BlockFace to get integer for
* @return integer representation of BlockFace
*/
public static int faceRotation(BlockFace f) {
switch(f) {
case NORTH:
return 0;
case NORTH_NORTH_EAST:
return 1;
case NORTH_EAST:
return 2;
case EAST_NORTH_EAST:
return 3;
case EAST:
return 4;
case EAST_SOUTH_EAST:
return 5;
case SOUTH_EAST:
return 6;
case SOUTH_SOUTH_EAST:
return 7;
case SOUTH:
return 8;
case SOUTH_SOUTH_WEST:
return 9;
case SOUTH_WEST:
return 10;
case WEST_SOUTH_WEST:
return 11;
case WEST:
return 12;
case WEST_NORTH_WEST:
return 13;
case NORTH_WEST:
return 14;
case NORTH_NORTH_WEST:
return 15;
default:
return -1;
}
}
/**
* Convert integer to BlockFace representation
*
* @param r integer to get BlockFace for
* @return BlockFace represented by integer.
*/
public static BlockFace fromRotation(int r) {
switch(Math.floorMod(r, 16)) {
case 0:
return BlockFace.NORTH;
case 1:
return BlockFace.NORTH_NORTH_EAST;
case 2:
return BlockFace.NORTH_EAST;
case 3:
return BlockFace.EAST_NORTH_EAST;
case 4:
return BlockFace.EAST;
case 5:
return BlockFace.EAST_SOUTH_EAST;
case 6:
return BlockFace.SOUTH_EAST;
case 7:
return BlockFace.SOUTH_SOUTH_EAST;
case 8:
return BlockFace.SOUTH;
case 9:
return BlockFace.SOUTH_SOUTH_WEST;
case 10:
return BlockFace.SOUTH_WEST;
case 11:
return BlockFace.WEST_SOUTH_WEST;
case 12:
return BlockFace.WEST;
case 13:
return BlockFace.WEST_NORTH_WEST;
case 14:
return BlockFace.NORTH_WEST;
case 15:
return BlockFace.NORTH_NORTH_WEST;
default:
throw new IllegalArgumentException();
}
}
} }

View File

@ -36,16 +36,9 @@ public final class WorldEditUtil {
return new Location[] {l1, l2}; return new Location[] {l1, l2};
} }
public static WorldEditPlugin getWorldEdit() {
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
if (p instanceof WorldEditPlugin) return (WorldEditPlugin) p;
Bukkit.getLogger().severe("[Terra] a command requiring WorldEdit was executed, but WorldEdit was not detected!");
return null;
}
public static Location[] getSelectionPositions(Player sender) { public static Location[] getSelectionPositions(Player sender) {
WorldEditPlugin we = WorldEditUtil.getWorldEdit(); WorldEditPlugin we = WorldEditUtil.getWorldEdit();
if (we == null) { if(we == null) {
sender.sendMessage("WorldEdit is not installed! Please install WorldEdit before attempting to export structures."); sender.sendMessage("WorldEdit is not installed! Please install WorldEdit before attempting to export structures.");
return null; return null;
} }
@ -66,4 +59,11 @@ public final class WorldEditUtil {
Location l2 = new Location(sender.getWorld(), max.getBlockX(), max.getBlockY(), max.getBlockZ()); Location l2 = new Location(sender.getWorld(), max.getBlockX(), max.getBlockY(), max.getBlockZ());
return new Location[] {l1, l2}; return new Location[] {l1, l2};
} }
public static WorldEditPlugin getWorldEdit() {
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
if(p instanceof WorldEditPlugin) return (WorldEditPlugin) p;
Bukkit.getLogger().severe("[Terra] a command requiring WorldEdit was executed, but WorldEdit was not detected!");
return null;
}
} }