Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixtrin committed Mar 16, 2022
2 parents c21053e + 424f569 commit e628ce5
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ch.mixin</groupId>
<artifactId>IslandGenerator</artifactId>
<version>1.2.2</version>
<version>1.2.3</version>
<packaging>jar</packaging>

<name>IslandGenerator</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class ConfigCommand extends SubCommand {
private final HashMap<String, SubCommand> subCommandMap;
private final HashMap<String, Integer> numberMinList;
private final List<String> integerList;

public ConfigCommand(IslandGeneratorPlugin plugin) {
super(plugin);
Expand All @@ -25,6 +26,10 @@ public ConfigCommand(IslandGeneratorPlugin plugin) {
numberMinList.put("spawnRadius", 1);
numberMinList.put("islandDistance", 1);
numberMinList.put("islandRadius", 1);

integerList = new ArrayList<>();
integerList.add("maximumHeight");
integerList.add("minimumHeight");
}

@Override
Expand Down Expand Up @@ -54,8 +59,15 @@ public void execute(CommandSender sender, List<String> arguments) {
}

String key = arguments.get(0);
if (numberMinList.containsKey(key)) {
int min = numberMinList.get(key);
if (numberMinList.containsKey(key) || integerList.contains(key)) {
boolean checkMinimum = false;
int min = 0;

if (numberMinList.containsKey(key)) {
checkMinimum = true;
min = numberMinList.get(key);
}

int value;

try {
Expand All @@ -65,7 +77,7 @@ public void execute(CommandSender sender, List<String> arguments) {
return;
}

if (value < min) {
if (checkMinimum && value < min) {
sender.sendMessage(ChatColor.RED + "Value must be at least " + min + ".");
return;
}
Expand All @@ -86,6 +98,7 @@ public List<String> getOptions(List<String> arguments) {
if (arguments.size() == 1) {
options.addAll(subCommandMap.keySet());
options.addAll(numberMinList.keySet());
options.addAll(integerList);
} else if (arguments.size() == 2) {
options.add("<value>");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@ public void startIslandGeneration() {
HashMap<String, WorldData> worldDataMap = plugin.getMetaData().getWorldDataMap();
Random random = plugin.getRandom();
HashMap<World, ArrayList<IslandData>> islandDataMap = new HashMap<>();
List<String> worldNames = IslandGeneratorPlugin.PLUGIN.getConfig().getStringList("worlds");
List<String> worldNames = plugin.getConfig().getStringList("worlds");

int maximumHeight = plugin.getConfig().getInt("maximumHeight");
int minimumHeight = plugin.getConfig().getInt("minimumHeight");
int centerHeight = (maximumHeight - minimumHeight) / 2;

int spawnRadius = plugin.getConfig().getInt("spawnRadius");
int islandDistance = plugin.getConfig().getInt("islandDistance");

for (String worldName : worldNames) {
World world = plugin.getServer().getWorld(worldName);
Expand All @@ -99,15 +106,14 @@ public void startIslandGeneration() {
islandDataMap.put(world, newIslandDataList);
int limit = worldData.getSpawnRadius();

if (limit >= plugin.getConfig().getInt("spawnRadius"))
if (limit >= spawnRadius)
continue;

ArrayList<IslandData> islandDatas = worldData.getIslandDatas();
int yCenter = world.getMaxHeight() / 2;
int yMin = Math.max(0, yCenter - plugin.getConfig().getInt("spawnRadius"));
int yMax = Math.min(world.getMaxHeight(), yCenter + plugin.getConfig().getInt("spawnRadius"));
int yMin = Math.max(minimumHeight, centerHeight - spawnRadius);
int yMax = Math.min(maximumHeight, centerHeight + spawnRadius);

int iterations = (int) (Math.pow(2 * plugin.getConfig().getInt("spawnRadius") + 1, 2) * (yMax - yMin + 1) / Math.pow(plugin.getConfig().getInt("islandDistance"), 3));
int iterations = (int) (Math.pow(2 * spawnRadius + 1, 2) * (yMax - yMin + 1) / Math.pow(islandDistance, 3));
consolePrint("Island Pointing: " + worldName + " x" + iterations);
int percentile = 0;

Expand All @@ -118,9 +124,9 @@ public void startIslandGeneration() {
consolePrint("Island Pointing: " + worldName + " " + percentile + "%");
}

int x = random.nextInt(plugin.getConfig().getInt("spawnRadius") + 1) * (random.nextBoolean() ? 1 : -1);
int x = random.nextInt(spawnRadius + 1) * (random.nextBoolean() ? 1 : -1);
int y = random.nextInt(yMax + 1 - yMin) + yMin;
int z = random.nextInt(plugin.getConfig().getInt("spawnRadius") + 1) * (random.nextBoolean() ? 1 : -1);
int z = random.nextInt(spawnRadius + 1) * (random.nextBoolean() ? 1 : -1);

if (x < limit && x > -limit
&& y < limit && y > -limit
Expand All @@ -130,7 +136,7 @@ public void startIslandGeneration() {

Coordinate3D newIslandCenter = new Coordinate3D(x, y, z);
for (IslandData islandData : islandDatas) {
if (newIslandCenter.distance(islandData.getIslandCenter()) < plugin.getConfig().getInt("islandDistance"))
if (newIslandCenter.distance(islandData.getIslandCenter()) < islandDistance)
continue islandLoop;
}

Expand All @@ -139,7 +145,7 @@ public void startIslandGeneration() {
newIslandDataList.add(newIslandData);
}

worldData.setSpawnRadius(plugin.getConfig().getInt("spawnRadius"));
worldData.setSpawnRadius(spawnRadius);
consolePrint("Finish Island Pointing: " + worldName);
consolePrint("+" + newIslandDataList.size() + " new Islands");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,33 @@
import java.util.Random;

public class IslandConstructor {
private final IslandGeneratorPlugin plugin;
private final IslandShapeGenerator islandShapeGenerator;
private final NameGenerator nameGenerator = new NameGenerator(new Random());
private final TitleGenerator titleGenerator = new TitleGenerator(new Random());

public IslandConstructor(IslandGeneratorPlugin plugin) {
this.plugin = plugin;
islandShapeGenerator = new IslandShapeGenerator(plugin);
}

public IslandBlueprint constructIsland(World world, IslandData islandData) {
Coordinate3D center = islandData.getIslandCenter();
IslandConstructorPremise islandConstructorPremise = new IslandConstructorPremise();
IslandShape islandShape = islandShapeGenerator.generateIslandShape(world.getMaxHeight());
IslandShape islandShape = islandShapeGenerator.generateIslandShape(
plugin.getConfig().getInt("maximumHeight")
- plugin.getConfig().getInt("minimumHeight")
);

int maximumHeight = plugin.getConfig().getInt("maximumHeight");
int minimumHeight = plugin.getConfig().getInt("minimumHeight");

ArrayList<Coordinate3D> emptyRoofSpaces = new ArrayList<>(islandShape.getLayerTop());

Coordinate3D lootPosition = constructLootPosition(center, emptyRoofSpaces);
HashMap<Coordinate3D, Material> blockMap = constructBlocks(islandConstructorPremise, center, islandShape);
HashMap<Coordinate3D, Material> blockMap = constructBlocks(islandConstructorPremise, center, maximumHeight, minimumHeight, islandShape);
HashMap<Coordinate3D, TreeType> treeMap = constructTrees(islandConstructorPremise, center, emptyRoofSpaces);
ArrayList<Coordinate3D> cactusList = constructCacti(islandConstructorPremise, center, emptyRoofSpaces, blockMap);
ArrayList<Coordinate3D> cactusList = constructCacti(islandConstructorPremise, center, maximumHeight, minimumHeight, emptyRoofSpaces, blockMap);

ArrayList<String> names = constructNames();
Coordinate3D nameLocation = lootPosition.sum(0, 3, 0);
Expand All @@ -51,22 +59,31 @@ private Coordinate3D constructLootPosition(Coordinate3D center, ArrayList<Coordi
return lootPosition;
}

private HashMap<Coordinate3D, Material> constructBlocks(IslandConstructorPremise islandConstructorPremise, Coordinate3D center, IslandShape islandShape) {
private HashMap<Coordinate3D, Material> constructBlocks(IslandConstructorPremise islandConstructorPremise, Coordinate3D center, int maximumHeight, int minimumHeight, IslandShape islandShape) {
HashMap<Coordinate3D, Material> blockMap = new HashMap<>();

if (islandConstructorPremise.getBlockTypesBot().size() > 0) {
for (Coordinate3D c3d : islandShape.getLayerBot()) {
blockMap.put(c3d.sum(center), Functions.getRandomWithWeights(islandConstructorPremise.getBlockTypesBot()));
Coordinate3D point = c3d.sum(center);

if (point.getY() >= minimumHeight && point.getY() <= maximumHeight)
blockMap.put(point, Functions.getRandomWithWeights(islandConstructorPremise.getBlockTypesBot()));
}
}

for (Coordinate3D c3d : islandShape.getLayerMid()) {
blockMap.put(c3d.sum(center), Functions.getRandomWithWeights(islandConstructorPremise.getBlockTypesMid()));
Coordinate3D point = c3d.sum(center);

if (point.getY() >= minimumHeight && point.getY() <= maximumHeight)
blockMap.put(point, Functions.getRandomWithWeights(islandConstructorPremise.getBlockTypesMid()));
}

if (islandConstructorPremise.getBlockTypesTop().size() > 0) {
for (Coordinate3D c3d : islandShape.getLayerTop()) {
blockMap.put(c3d.sum(center), Functions.getRandomWithWeights(islandConstructorPremise.getBlockTypesTop()));
Coordinate3D point = c3d.sum(center);

if (point.getY() >= minimumHeight && point.getY() <= maximumHeight)
blockMap.put(point, Functions.getRandomWithWeights(islandConstructorPremise.getBlockTypesTop()));
}
}

Expand All @@ -89,7 +106,7 @@ private HashMap<Coordinate3D, TreeType> constructTrees(IslandConstructorPremise
return treeMap;
}

private ArrayList<Coordinate3D> constructCacti(IslandConstructorPremise islandConstructorPremise, Coordinate3D center, ArrayList<Coordinate3D> emptyRoofSpaces, HashMap<Coordinate3D, Material> blockMap) {
private ArrayList<Coordinate3D> constructCacti(IslandConstructorPremise islandConstructorPremise, Coordinate3D center, int maximumHeight, int minimumHeight, ArrayList<Coordinate3D> emptyRoofSpaces, HashMap<Coordinate3D, Material> blockMap) {
ArrayList<Coordinate3D> cactusList = new ArrayList<>();

for (int i = 0; i < emptyRoofSpaces.size(); i++) {
Expand All @@ -104,7 +121,12 @@ private ArrayList<Coordinate3D> constructCacti(IslandConstructorPremise islandCo
i--;

for (int height = 0; height < 3; height++) {
cactusList.add(c3d.sum(center).sum(0, height + 1, 0));
Coordinate3D point = c3d.sum(center).sum(0, height + 1, 0);

if (point.getY() < minimumHeight || point.getY() > maximumHeight)
break;

cactusList.add(point);
height++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import java.util.stream.Collectors;

public class IslandShapeGenerator {
private IslandGeneratorPlugin plugin;
private final IslandGeneratorPlugin plugin;
private IslandShapePremise islandShapePremise;

public IslandShapeGenerator(IslandGeneratorPlugin plugin) {
this.plugin = plugin;
}

public IslandShape generateIslandShape(int worldMaxHeight) {
public IslandShape generateIslandShape(int spawnRegionHeight) {
islandShapePremise = new IslandShapePremise(plugin.getConfig().getInt("islandDistance"), plugin.getConfig().getInt("islandRadius"));

ArrayList<Coordinate2D> basePlane = generateBasePlane();
Expand All @@ -28,7 +28,7 @@ public IslandShape generateIslandShape(int worldMaxHeight) {

subPlane = new ArrayList<>(basePlane);

for (int i = 1; i <= worldMaxHeight && i <= plugin.getConfig().getInt("islandDistance") * 0.5; i++) {
for (int i = 1; i <= spawnRegionHeight && i <= plugin.getConfig().getInt("islandDistance") * 0.5; i++) {
subPlane = generateSubPlane(subPlane, islandShapePremise.getPlaneTopReducers(), islandShapePremise.getTopFlatness());
if (subPlane.size() == 0)
break;
Expand All @@ -37,7 +37,7 @@ public IslandShape generateIslandShape(int worldMaxHeight) {

subPlane = new ArrayList<>(basePlane);

for (int i = 1; i <= worldMaxHeight && i <= plugin.getConfig().getInt("islandDistance") * 0.5; i++) {
for (int i = 1; i <= spawnRegionHeight && i <= plugin.getConfig().getInt("islandDistance") * 0.5; i++) {
subPlane = generateSubPlane(subPlane, islandShapePremise.getPlaneBotReducers(), islandShapePremise.getBotFlatness());
if (subPlane.size() == 0)
break;
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ islandRadius: 20
tickBuffer: 1
worlds:
- world
maximumHeight: 255
minimumHeight: 0
lootMultiplier: 20

0 comments on commit e628ce5

Please sign in to comment.