Skip to content

Commit

Permalink
Random biomes, improved creation gui
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksilassila committed Oct 31, 2020
1 parent 454e495 commit b776f01
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 45 deletions.
7 changes: 4 additions & 3 deletions src/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ generation:
generationDelayInTicks: 0.3 # 2 Will generate 1 row per 2 ticks, 0.5 will generate 2 rows per 1 tick.
maxVariationsPerBiome: 5 # Max locations generated for each biome, lower the value to speed up server startup.
clearSpeedMultiplier: 3 # Removing blocks should be faster than placing them, so you might swant to speed up clearing.
maxBiomeSize: 80 # Minimum width of biome block so that it gets picked up by the generator and added as available variation.
# Should be the same as the biggest island size being generated.
minBiomeSize: 80 # Minimum width of biome block so that it gets picked up by the generator and added as available variation.
# Should be the same as the biggest island size being generated. Read more in Wiki > How does it work

biomeBlacklist: # These biomes do not get picked up by island generator.
- DEEP_OCEAN # Ocean biomes work poorly with islands.
Expand All @@ -53,12 +53,13 @@ tpCooldownTime: 10 # /home and /visit cooldown after damage
illegalIslandNames: # Blocked island names. Useful if you want to reserve name for "official" island
# - spawn
wildernessCoordinateMultiplier: 4 # Player's x and z coordinates gets multiplied by this value when they jump to wilderness.
voidTeleport: true # If enabled, void kills again in islandsWorld
voidTeleport: true # If disabled, void kills again in islandsWorld
islandDamage: false # Enable / disable damage on islands
restrictIslandBlockFlows: true # Let water / lava only flow inside a sphere containing island
disableWilderness: false # Disable wilderness, do not touch unless you know what you are doing
allowHomeOnlyFromOverworld: true # Disable /home in nether and end
disableNeutralTeleports: false # Disable teleporting neutrals to islands with /home command
neutralTeleportRange: 2 # How far neutrals are being teleported around the player
unfinishedIslandTeleports: true # Deny teleports to island that are still being generated.
disableRandomBiome: false # Disable RANDOM biome in island creation
locale: en
34 changes: 24 additions & 10 deletions src/me/aleksilassila/islands/GUIs/CreateGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,36 @@ private List<StaticPane> availableIslandPanes() {

int itemCount = 0;
for (Biome biome : sortedSet) {
if (itemCount == 0 && !plugin.getConfig().getBoolean("disableRandomBiome")) {
pane.addItem(new GuiItem(
createGuiItem(
Material.COMPASS,
Messages.get("gui.create.BIOME_NAME", "RANDOM"),
true,
Messages.get("gui.create.BIOME_LORE", 0)
),
inventoryClickEvent -> {
getSizeGui(null).show(inventoryClickEvent.getWhoClicked());
}), 0, 0);

itemCount++;
}

if (pane.getItems().size() >= (PAGE_HEIGHT - 1) * 9) {
panes.add(pane);
pane = new StaticPane(0, 0, 9, PAGE_HEIGHT - 1);
}

pane.addItem(
new GuiItem(
pane.addItem(new GuiItem(
createGuiItem(
BiomeMaterials.valueOf(biome.name()).getMaterial(),
Messages.get("gui.create.BIOME_NAME", biome.name()),
false,
Messages.get("gui.create.BIOME_LORE", availableLocations.get(biome).size())
BiomeMaterials.valueOf(biome.name()).getMaterial(),
Messages.get("gui.create.BIOME_NAME", biome.name()),
false,
Messages.get("gui.create.BIOME_LORE", availableLocations.get(biome).size())
),
event -> {
getSizeGui(biome).show(event.getWhoClicked());
}), (itemCount % (9 * (PAGE_HEIGHT - 1))) % 9, (itemCount % (9 * (PAGE_HEIGHT - 1))) / 9);
event -> {
getSizeGui(biome).show(event.getWhoClicked());
}), (itemCount % (9 * (PAGE_HEIGHT - 1))) % 9, (itemCount % (9 * (PAGE_HEIGHT - 1))) / 9);
itemCount++;
}

Expand All @@ -90,7 +104,7 @@ private List<StaticPane> availableIslandPanes() {
}

private Gui getSizeGui(Biome biome) {
Gui gui = createPaginatedGUI(2, Messages.get("gui.create.SIZE_TITLE"), availableSizePanes("island " + subcommand + " " + biome.name()));
Gui gui = createPaginatedGUI(2, Messages.get("gui.create.SIZE_TITLE"), availableSizePanes("island " + subcommand + " " + (biome == null ? "RANDOM" : biome.name())));
gui.setOnTopClick(inventoryClickEvent -> inventoryClickEvent.setCancelled(true));

if (plugin.econ != null) {
Expand Down
18 changes: 16 additions & 2 deletions src/me/aleksilassila/islands/Islands.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ public String createNewIsland(Biome biome, int islandSize, Player player) throws
? shape.getHeight() + islandSize / 2
: islandSize;

boolean random = biome == null;

if (biome == null) {
biome = islandGeneration.biomes.getRandomBiome(islandSize);
}

String islandId = layout.createIsland(player.getUniqueId(), islandSize, height, biome);
try {
boolean success = islandGeneration.copyIsland(
Expand All @@ -152,7 +158,8 @@ public String createNewIsland(Biome biome, int islandSize, Player player) throws
),
false,
islandId,
shape
shape,
random
);

if (!success) {
Expand All @@ -177,6 +184,12 @@ public boolean recreateIsland(String islandId, Biome biome, int islandSize, Play
? shape.getHeight() + islandSize / 2
: islandSize;

boolean random = biome == null;

if (biome == null) {
biome = islandGeneration.biomes.getRandomBiome(islandSize);
}

layout.updateIsland(islandId, islandSize, height, biome);

try {
Expand All @@ -191,7 +204,8 @@ public boolean recreateIsland(String islandId, Biome biome, int islandSize, Play
),
true,
islandId,
shape
shape,
random
);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,28 @@ public void onCommand(Player player, String[] args, boolean confirmed) {
return;
}

Biome targetBiome = utils.getTargetBiome(args[0]);

if (targetBiome == null) {
player.sendMessage(Messages.get("error.NO_BIOME_FOUND"));
return;
}

if (plugin.econ != null && !hasFunds(player, plugin.islandPrices.getOrDefault(islandSize, 0.0))) {
player.sendMessage(Messages.get("error.INSUFFICIENT_FUNDS"));
return;
}

if (!availableLocations.containsKey(targetBiome)) {
player.sendMessage(Messages.get("error.NO_LOCATIONS_FOR_BIOME"));
return;
Biome targetBiome;

if (args[0].equalsIgnoreCase("random") && !isRandomBiomeDisabled()) {
targetBiome = null;
} else {
targetBiome = utils.getTargetBiome(args[0]);

if (targetBiome == null) {
player.sendMessage(Messages.get("error.NO_BIOME_FOUND"));
return;
}


if (!availableLocations.containsKey(targetBiome)) {
player.sendMessage(Messages.get("error.NO_LOCATIONS_FOR_BIOME"));
return;
}
}

String islandId = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
public abstract class GenerationSubcommands extends Subcommand {
abstract Islands getPlugin();

boolean isRandomBiomeDisabled() {
return getPlugin().getConfig().getBoolean("disableRandomBiome");
}

boolean validateCommand(Player player, int islandSize) {
if (!player.hasPermission(getPlugin().getCreatePermission(islandSize))) {
player.sendMessage(Messages.get("error.NO_PERMISSION"));
Expand Down Expand Up @@ -51,6 +55,9 @@ public List<String> onTabComplete(Player player, String[] args) {
if (args.length == 1) {
HashMap<Biome, List<Location>> availableLocations = getPlugin().islandGeneration.biomes.availableLocations;

if (!isRandomBiomeDisabled())
availableArgs.add("RANDOM");

for (Biome biome : availableLocations.keySet()) {
availableArgs.add(biome.name());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,23 @@ public void onCommand(Player player, String[] args, boolean confirmed) {
}
}

Biome targetBiome = utils.getTargetBiome(args[0]);
Biome targetBiome;

if (targetBiome == null) {
player.sendMessage(Messages.get("error.NO_BIOME_FOUND"));
return;
}
if (args[0].equalsIgnoreCase("random") && !isRandomBiomeDisabled()) {
targetBiome = null;
} else {
targetBiome = utils.getTargetBiome(args[0]);

if (!plugin.islandGeneration.biomes.availableLocations.containsKey(targetBiome)) {
player.sendMessage(Messages.get("error.NO_LOCATIONS_FOR_BIOME"));
return;
if (targetBiome == null) {
player.sendMessage(Messages.get("error.NO_BIOME_FOUND"));
return;
}


if (!plugin.islandGeneration.biomes.availableLocations.containsKey(targetBiome)) {
player.sendMessage(Messages.get("error.NO_LOCATIONS_FOR_BIOME"));
return;
}
}

if (!confirmed) {
Expand Down
36 changes: 35 additions & 1 deletion src/me/aleksilassila/islands/generation/Biomes.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public class Biomes {
final int maxLocationsPerBiome;
final List<String> biomeBlacklist;

private final Map<Biome, Location> randomLocations;

public Biomes(Islands plugin, World world) {
this.world = world;
this.biggestIslandSize = plugin.getConfig().getInt("generation.maxBiomeSize");
this.biggestIslandSize = plugin.getConfig().getInt("generation.minBiomeSize");
this.plugin = plugin;

this.biomeSearchJumpBlocks = plugin.getConfig().getInt("generation.searchJump");
Expand All @@ -32,6 +34,7 @@ public Biomes(Islands plugin, World world) {
this.biomeBlacklist = plugin.getConfig().getStringList("biomeBlacklist");

this.availableLocations = new HashMap<>();
randomLocations = new HashMap<>();

// Generate biomes and save them to config
if (plugin.getBiomesCache().getString("seed") == null || !plugin.getBiomesCache().getString("seed").equals(String.valueOf(plugin.islandsSourceWorld.getSeed()))) {
Expand Down Expand Up @@ -183,4 +186,35 @@ boolean isSuitableLocation(int xCorner, int zCorner, int rectSize, Biome biome)
}
return true;
}

public Biome getRandomBiome(int islandSize) {
while (true) {
int x = (int) (Math.random() * biomeSearchSize);
int z = (int) (Math.random() * biomeSearchSize);
int y = plugin.islandsWorld.getHighestBlockYAt(x, z);

Biome biome = plugin.islandsSourceWorld.getBiome(x, y, z);

if (isBlacklisted(biome))
continue;

randomLocations.put(biome, new Location(plugin.islandsSourceWorld,
x - islandSize / 2.0,
y,
z - islandSize / 2.0));

return biome;
}
}

public Location getRandomLocation(Biome biome, int islandSize) {
int x = (int) (Math.random() * biomeSearchSize);
int z = (int) (Math.random() * biomeSearchSize);
int y = plugin.islandsWorld.getHighestBlockYAt(x, z);

return randomLocations.getOrDefault(biome, new Location(plugin.islandsSourceWorld,
x - islandSize / 2.0,
y,
z - islandSize / 2.0));
}
}
24 changes: 15 additions & 9 deletions src/me/aleksilassila/islands/generation/IslandGeneration.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,25 @@ public IslandGeneration(Islands plugin) {
}
}

public boolean copyIsland(Player player, Biome biome, int islandSize, Vector target, boolean shouldClearArea, String islandId, Shape shape) throws IllegalArgumentException {
List<Location> locations = biomes.availableLocations.get(biome);
public boolean copyIsland(Player player, Biome biome, int islandSize, Vector target, boolean shouldClearArea, String islandId, Shape shape, boolean random) throws IllegalArgumentException {
Location sourceLocation;

if (locations == null)
throw new IllegalArgumentException();
if (random) {
sourceLocation = plugin.islandGeneration.biomes.getRandomLocation(biome, islandSize);
} else {
List<Location> locations = biomes.availableLocations.get(biome);

if (locations.size() == 0)
throw new IllegalArgumentException();
if (locations == null)
throw new IllegalArgumentException();

if (!canAddQueueItem(player))
throw new IllegalArgumentException();
if (locations.size() == 0)
throw new IllegalArgumentException();

Location sourceLocation = locations.get(new Random().nextInt(locations.size()));
if (!canAddQueueItem(player))
throw new IllegalArgumentException();

sourceLocation = locations.get(new Random().nextInt(locations.size()));
}

int centerY = 100;
while (true) {
Expand Down
2 changes: 1 addition & 1 deletion src/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ gui.visit.SORT=\u00a76\u00a7lSort by {0, choice, 0#date|1#name}

gui.create.TITLE=Create Island
gui.create.BIOME_NAME=\u00a76\u00a7l{0}
gui.create.BIOME_LORE=\u00a77Click for available sizes\n\u00a77{0} variations available
gui.create.BIOME_LORE=\u00a77Click for available sizes{0, choice, 0#|1#\n\u00a77{0} variations available}
gui.create.SIZE_TITLE=Choose island size
gui.create.SIZE_NAME=\u00a76\u00a7l{0}
gui.create.SIZE_LORE=\u00a77Buy price: \u00a7a${1,number,#} \n\u00a77Size: {0}x{0}\n\n\u00a77Click to purchase
Expand Down
2 changes: 1 addition & 1 deletion src/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ gui.visit.SORT=\u00a76\u00a7lSort by {0, choice, 0#date|1#name}

gui.create.TITLE=Create Island
gui.create.BIOME_NAME=\u00a76\u00a7l{0}
gui.create.BIOME_LORE=\u00a77Click for available sizes\n\u00a77{0} variations available
gui.create.BIOME_LORE=\u00a77Click for available sizes{0, choice, 0#|1#\n\u00a77{0} variations available}
gui.create.SIZE_TITLE=Choose island size
gui.create.SIZE_NAME=\u00a76\u00a7l{0}
gui.create.SIZE_LORE=\u00a77Buy price: \u00a7a${1,number,#} \n\u00a77Size: {0}x{0}\n\n\u00a77Click to purchase
Expand Down

0 comments on commit b776f01

Please sign in to comment.