mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-18 15:18:26 +01:00
Added world generators for overworld, nether and end.
This commit is contained in:
parent
bcb13e2b6d
commit
2a9ddd6579
@ -1,12 +1,8 @@
|
|||||||
package us.tastybento.bskyblock;
|
package us.tastybento.bskyblock;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -18,8 +14,7 @@ import us.tastybento.bskyblock.database.BSBDatabase;
|
|||||||
import us.tastybento.bskyblock.database.managers.IslandsManager;
|
import us.tastybento.bskyblock.database.managers.IslandsManager;
|
||||||
import us.tastybento.bskyblock.database.managers.OfflineHistoryMessages;
|
import us.tastybento.bskyblock.database.managers.OfflineHistoryMessages;
|
||||||
import us.tastybento.bskyblock.database.managers.PlayersManager;
|
import us.tastybento.bskyblock.database.managers.PlayersManager;
|
||||||
import us.tastybento.bskyblock.database.objects.Island;
|
import us.tastybento.bskyblock.generators.IslandWorld;
|
||||||
import us.tastybento.bskyblock.database.objects.Island.SettingsFlag;
|
|
||||||
import us.tastybento.bskyblock.util.VaultHelper;
|
import us.tastybento.bskyblock.util.VaultHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,6 +75,14 @@ public class BSkyBlock extends JavaPlugin{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
// Create the world if it does not exist
|
||||||
|
// TODO: get world name from config.yml
|
||||||
|
Settings.worldName = "BSkyBlock_world";
|
||||||
|
Settings.createNether = true;
|
||||||
|
Settings.createEnd = true;
|
||||||
|
Settings.islandNether = false;
|
||||||
|
Settings.islandEnd = false;
|
||||||
|
new IslandWorld(plugin);
|
||||||
|
|
||||||
// Test: Create a random island and save it
|
// Test: Create a random island and save it
|
||||||
// TODO: ideally this should be in a test class!
|
// TODO: ideally this should be in a test class!
|
||||||
|
@ -18,7 +18,7 @@ import us.tastybento.bskyblock.database.managers.OfflineHistoryMessages.HistoryM
|
|||||||
public class Settings {
|
public class Settings {
|
||||||
/* The settings variables should follow the config order */
|
/* The settings variables should follow the config order */
|
||||||
|
|
||||||
public static final String PERMPREFIX = "askyblock.";
|
public static final String PERMPREFIX = "bskyblock.";
|
||||||
|
|
||||||
/* GENERAL */
|
/* GENERAL */
|
||||||
public static boolean metrics;
|
public static boolean metrics;
|
||||||
@ -163,4 +163,14 @@ public class Settings {
|
|||||||
public static String dbName;
|
public static String dbName;
|
||||||
public static String dbUsername;
|
public static String dbUsername;
|
||||||
public static String dbPassword;
|
public static String dbPassword;
|
||||||
|
|
||||||
|
public static boolean createNether;
|
||||||
|
|
||||||
|
public static boolean useOwnGenerator;
|
||||||
|
|
||||||
|
public static boolean islandNether;
|
||||||
|
|
||||||
|
public static boolean createEnd;
|
||||||
|
|
||||||
|
public static boolean islandEnd;
|
||||||
}
|
}
|
||||||
|
@ -1,80 +0,0 @@
|
|||||||
package us.tastybento.bskyblock.database.managers;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
public class Test {
|
|
||||||
private int id;
|
|
||||||
private String name;
|
|
||||||
private HashMap<Integer, Location> homeLocations;
|
|
||||||
private List<ItemStack> inventory;
|
|
||||||
|
|
||||||
public Test() {}
|
|
||||||
|
|
||||||
public Test(int id, String name) {
|
|
||||||
super();
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the homeLocations
|
|
||||||
*/
|
|
||||||
public HashMap<Integer, Location> getHomeLocations() {
|
|
||||||
return homeLocations;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param homeLocations the homeLocations to set
|
|
||||||
*/
|
|
||||||
public void setHomeLocations(HashMap<Integer, Location> homeLocations) {
|
|
||||||
this.homeLocations = homeLocations;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the inventory
|
|
||||||
*/
|
|
||||||
public List<ItemStack> getInventory() {
|
|
||||||
return inventory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param inventory the inventory to set
|
|
||||||
*/
|
|
||||||
public void setInventory(List<ItemStack> inventory) {
|
|
||||||
this.inventory = inventory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
final String TAB = " \n";
|
|
||||||
|
|
||||||
StringBuilder retValue = new StringBuilder();
|
|
||||||
|
|
||||||
retValue.append("Test (\n ")
|
|
||||||
.append(super.toString()).append(TAB)
|
|
||||||
.append(" id = ").append(this.id).append(TAB)
|
|
||||||
.append(" name = ").append(this.name).append(TAB)
|
|
||||||
.append(" )");
|
|
||||||
|
|
||||||
return retValue.toString();
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,169 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* This file is part of BSkyBlock.
|
||||||
|
*
|
||||||
|
* BSkyBlock is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* BSkyBlock is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with ASkyBlock. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package us.tastybento.bskyblock.generators;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.World.Environment;
|
||||||
|
import org.bukkit.generator.BlockPopulator;
|
||||||
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
import org.bukkit.util.noise.PerlinOctaveGenerator;
|
||||||
|
|
||||||
|
import us.tastybento.bskyblock.config.Settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tastybento
|
||||||
|
* Creates the world
|
||||||
|
*/
|
||||||
|
public class ChunkGeneratorWorld extends ChunkGenerator {
|
||||||
|
Random rand = new Random();
|
||||||
|
PerlinOctaveGenerator gen;
|
||||||
|
//BSkyBlock plugin = BSkyBlock.getPlugin();
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public byte[][] generateBlockSections(World world, Random random, int chunkX, int chunkZ, BiomeGrid biomeGrid) {
|
||||||
|
// Bukkit.getLogger().info("DEBUG: world environment = " + world.getEnvironment().toString());
|
||||||
|
if (world.getEnvironment().equals(World.Environment.NETHER)) {
|
||||||
|
return generateNetherBlockSections(world, random, chunkX, chunkZ, biomeGrid);
|
||||||
|
}
|
||||||
|
byte[][] result = new byte[world.getMaxHeight() / 16][];
|
||||||
|
if (Settings.seaHeight == 0) {
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
for (int x = 0; x < 16; x++) {
|
||||||
|
for (int z = 0; z < 16; z++) {
|
||||||
|
for (int y = 0; y < Settings.seaHeight; y++) {
|
||||||
|
setBlock(result, x, y, z, (byte) Material.STATIONARY_WATER.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBlock(byte[][] result, int x, int y, int z, byte blkid) {
|
||||||
|
// is this chunk part already initialized?
|
||||||
|
if (result[y >> 4] == null) {
|
||||||
|
// Initialize the chunk part
|
||||||
|
result[y >> 4] = new byte[4096];
|
||||||
|
}
|
||||||
|
// set the block (look above, how this is done)
|
||||||
|
result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This needs to be set to return true to override minecraft's default
|
||||||
|
// behavior
|
||||||
|
@Override
|
||||||
|
public boolean canSpawn(World world, int x, int z) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BlockPopulator> getDefaultPopulators(final World world) {
|
||||||
|
return Arrays.asList(new BlockPopulator[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Nether Section
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private byte[][] generateNetherBlockSections(World world, Random random, int chunkX, int chunkZ, BiomeGrid biomeGrid) {
|
||||||
|
// Bukkit.getLogger().info("DEBUG: world environment(nether) = " +
|
||||||
|
// world.getEnvironment().toString());
|
||||||
|
rand.setSeed(world.getSeed());
|
||||||
|
gen = new PerlinOctaveGenerator((long) (random.nextLong() * random.nextGaussian()), 8);
|
||||||
|
byte[][] result = new byte[world.getMaxHeight() / 16][];
|
||||||
|
// This is a nether generator
|
||||||
|
if (!world.getEnvironment().equals(Environment.NETHER)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (Settings.netherRoof) {
|
||||||
|
// Make the roof - common across the world
|
||||||
|
for (int x = 0; x < 16; x++) {
|
||||||
|
for (int z = 0; z < 16; z++) {
|
||||||
|
// Do the ceiling
|
||||||
|
// Bukkit.getLogger().info("debug: " + x + ", " +
|
||||||
|
// (world.getMaxHeight()-1) + ", " + z);
|
||||||
|
int maxHeight = world.getMaxHeight();
|
||||||
|
setBlock(result, x, (maxHeight - 1), z, (byte) Material.BEDROCK.getId());
|
||||||
|
// Next three layers are a mix of bedrock and netherrack
|
||||||
|
for (int y = 2; y < 5; y++) {
|
||||||
|
double r = gen.noise(x, (maxHeight - y), z, 0.5, 0.5);
|
||||||
|
if (r > 0D) {
|
||||||
|
setBlock(result, x, (maxHeight - y), z, (byte) Material.BEDROCK.getId());
|
||||||
|
} else {
|
||||||
|
setBlock(result, x, (maxHeight - y), z, (byte) Material.NETHERRACK.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Next three layers are a mix of netherrack and air
|
||||||
|
for (int y = 5; y < 8; y++) {
|
||||||
|
double r = gen.noise(x, maxHeight - y, z, 0.5, 0.5);
|
||||||
|
if (r > 0D) {
|
||||||
|
setBlock(result, x, (maxHeight - y), z, (byte) Material.NETHERRACK.getId());
|
||||||
|
} else {
|
||||||
|
setBlock(result, x, (maxHeight - y), z, (byte) Material.AIR.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Layer 8 may be glowstone
|
||||||
|
double r = gen.noise(x, maxHeight - 8, z, random.nextFloat(), random.nextFloat());
|
||||||
|
if (r > 0.5D) {
|
||||||
|
// Have blobs of glowstone
|
||||||
|
switch (random.nextInt(4)) {
|
||||||
|
case 1:
|
||||||
|
// Single block
|
||||||
|
setBlock(result, x, (maxHeight - 8), z, (byte) Material.GLOWSTONE.getId());
|
||||||
|
if (x < 14 && z < 14) {
|
||||||
|
setBlock(result, x + 1, (maxHeight - 8), z + 1, (byte) Material.GLOWSTONE.getId());
|
||||||
|
setBlock(result, x + 2, (maxHeight - 8), z + 2, (byte) Material.GLOWSTONE.getId());
|
||||||
|
setBlock(result, x + 1, (maxHeight - 8), z + 2, (byte) Material.GLOWSTONE.getId());
|
||||||
|
setBlock(result, x + 1, (maxHeight - 8), z + 2, (byte) Material.GLOWSTONE.getId());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
// Stalatite
|
||||||
|
for (int i = 0; i < random.nextInt(10); i++) {
|
||||||
|
setBlock(result, x, (maxHeight - 8 - i), z, (byte) Material.GLOWSTONE.getId());
|
||||||
|
}
|
||||||
|
case 3:
|
||||||
|
setBlock(result, x, (maxHeight - 8), z, (byte) Material.GLOWSTONE.getId());
|
||||||
|
if (x > 3 && z > 3) {
|
||||||
|
for (int xx = 0; xx < 3; xx++) {
|
||||||
|
for (int zz = 0; zz < 3; zz++) {
|
||||||
|
setBlock(result, x - xx, (maxHeight - 8 - random.nextInt(2)), z - xx, (byte) Material.GLOWSTONE.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
setBlock(result, x, (maxHeight - 8), z, (byte) Material.GLOWSTONE.getId());
|
||||||
|
}
|
||||||
|
setBlock(result, x, (maxHeight - 8), z, (byte) Material.GLOWSTONE.getId());
|
||||||
|
} else {
|
||||||
|
setBlock(result, x, (maxHeight - 8), z, (byte) Material.AIR.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,126 @@
|
|||||||
|
package us.tastybento.bskyblock.generators;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.WorldCreator;
|
||||||
|
import org.bukkit.WorldType;
|
||||||
|
|
||||||
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
|
import us.tastybento.bskyblock.config.Settings;
|
||||||
|
|
||||||
|
public class IslandWorld {
|
||||||
|
|
||||||
|
//private BSkyBlock plugin;
|
||||||
|
private static World islandWorld;
|
||||||
|
private static World netherWorld;
|
||||||
|
private static World endWorld;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the World object for the island world named in config.yml.
|
||||||
|
* If the world does not exist then it is created.
|
||||||
|
*
|
||||||
|
* @return Bukkit World object for the BSkyBlock overworld
|
||||||
|
*/
|
||||||
|
public IslandWorld(BSkyBlock plugin) {
|
||||||
|
if (Settings.useOwnGenerator) {
|
||||||
|
// Do nothing
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (plugin.getServer().getWorld(Settings.worldName) == null) {
|
||||||
|
Bukkit.getLogger().info("Creating " + plugin.getName() + "'s Island World...");
|
||||||
|
}
|
||||||
|
// Create the world if it does not exist
|
||||||
|
islandWorld = WorldCreator.name(Settings.worldName).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(new ChunkGeneratorWorld())
|
||||||
|
.createWorld();
|
||||||
|
// Make the nether if it does not exist
|
||||||
|
if (Settings.createNether) {
|
||||||
|
if (plugin.getServer().getWorld(Settings.worldName + "_nether") == null) {
|
||||||
|
Bukkit.getLogger().info("Creating " + plugin.getName() + "'s Nether...");
|
||||||
|
}
|
||||||
|
if (!Settings.islandNether) {
|
||||||
|
netherWorld = WorldCreator.name(Settings.worldName + "_nether").type(WorldType.NORMAL).environment(World.Environment.NETHER).createWorld();
|
||||||
|
} else {
|
||||||
|
netherWorld = WorldCreator.name(Settings.worldName + "_nether").type(WorldType.FLAT).generator(new ChunkGeneratorWorld())
|
||||||
|
.environment(World.Environment.NETHER).createWorld();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Make the end if it does not exist
|
||||||
|
if (Settings.createEnd) {
|
||||||
|
if (plugin.getServer().getWorld(Settings.worldName + "_the_end") == null) {
|
||||||
|
Bukkit.getLogger().info("Creating " + plugin.getName() + "'s End World...");
|
||||||
|
}
|
||||||
|
if (!Settings.islandEnd) {
|
||||||
|
endWorld = WorldCreator.name(Settings.worldName + "_the_end").type(WorldType.NORMAL).environment(World.Environment.THE_END).createWorld();
|
||||||
|
} else {
|
||||||
|
endWorld = WorldCreator.name(Settings.worldName + "_the_end").type(WorldType.FLAT).generator(new ChunkGeneratorWorld())
|
||||||
|
.environment(World.Environment.THE_END).createWorld();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fixMultiverse(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fixMultiverse(BSkyBlock plugin) {
|
||||||
|
// Multiverse configuration
|
||||||
|
if (Bukkit.getServer().getPluginManager().isPluginEnabled("Multiverse-Core")) {
|
||||||
|
Bukkit.getLogger().info("Trying to register generator with Multiverse ");
|
||||||
|
try {
|
||||||
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mv import " + Settings.worldName + " normal -g " + plugin.getName());
|
||||||
|
if (!Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mv modify set generator " + plugin.getName() + " " + Settings.worldName)) {
|
||||||
|
Bukkit.getLogger().severe("Multiverse is out of date! - Upgrade to latest version!");
|
||||||
|
}
|
||||||
|
if (netherWorld != null && Settings.createNether && Settings.islandNether) {
|
||||||
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mv import " + Settings.worldName + "_nether nether -g " + plugin.getName());
|
||||||
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mv modify set generator " + plugin.getName() + " " + Settings.worldName + "_nether");
|
||||||
|
}
|
||||||
|
if (endWorld != null && Settings.createEnd && Settings.islandEnd) {
|
||||||
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mv import " + Settings.worldName + "_the_end end -g " + plugin.getName());
|
||||||
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mv modify set generator " + plugin.getName() + " " + Settings.worldName + "_the_end");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Bukkit.getLogger().severe("Not successfull! Disabling " + plugin.getName() + "!");
|
||||||
|
e.printStackTrace();
|
||||||
|
Bukkit.getServer().getPluginManager().disablePlugin(plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the islandWorld
|
||||||
|
*/
|
||||||
|
public static World getIslandWorld() {
|
||||||
|
if (Settings.useOwnGenerator) {
|
||||||
|
return Bukkit.getServer().getWorld(Settings.worldName);
|
||||||
|
}
|
||||||
|
return islandWorld;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the netherWorld
|
||||||
|
*/
|
||||||
|
public static World getNetherWorld() {
|
||||||
|
if (Settings.useOwnGenerator) {
|
||||||
|
return Bukkit.getServer().getWorld(Settings.worldName + "_nether");
|
||||||
|
}
|
||||||
|
return netherWorld;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the endWorld
|
||||||
|
*/
|
||||||
|
public static World getEndWorld() {
|
||||||
|
if (Settings.useOwnGenerator) {
|
||||||
|
return Bukkit.getServer().getWorld(Settings.worldName + "_the_end");
|
||||||
|
}
|
||||||
|
return endWorld;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,154 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* This file is part of BSkyBlock.
|
||||||
|
*
|
||||||
|
* BSkyBlock is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* BSkyBlock is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with BSkyBlock. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package us.tastybento.bskyblock.generators;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.TreeType;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.block.Chest;
|
||||||
|
import org.bukkit.block.CreatureSpawner;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.generator.BlockPopulator;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tastybento
|
||||||
|
* Populates the Nether with appropriate blocks
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class NetherPopulator extends BlockPopulator {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void populate(World world, Random random, Chunk source) {
|
||||||
|
// Rough check - convert spawners to Nether spawners
|
||||||
|
for (int x = 0; x < 16; x++) {
|
||||||
|
for (int y = 0; y < world.getMaxHeight(); y++) {
|
||||||
|
for (int z = 0; z < 16; z++) {
|
||||||
|
Block b = source.getBlock(x, y, z);
|
||||||
|
if (b.getType().equals(Material.MOB_SPAWNER)) {
|
||||||
|
CreatureSpawner cs = (CreatureSpawner) b.getState();
|
||||||
|
switch (random.nextInt(3)) {
|
||||||
|
case 0:
|
||||||
|
cs.setSpawnedType(EntityType.BLAZE);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
cs.setSpawnedType(EntityType.SKELETON);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
cs.setSpawnedType(EntityType.MAGMA_CUBE);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
cs.setSpawnedType(EntityType.BLAZE);
|
||||||
|
}
|
||||||
|
} else if (b.getType().equals(Material.OBSIDIAN)) {
|
||||||
|
b.setType(Material.CHEST);
|
||||||
|
Chest cs = (Chest) b.getState();
|
||||||
|
Inventory chestInv = cs.getInventory();
|
||||||
|
// Fill it with random goodies
|
||||||
|
/*
|
||||||
|
* 2 to 5 stacks of any of the following
|
||||||
|
* Diamonds 1 - 3 6.85% (5/73)
|
||||||
|
* Iron Ingots 1 - 5 6.85% (5/73)
|
||||||
|
* Gold Ingots 1 - 3 20.5% (15/73)
|
||||||
|
* Golden Sword 1 6.85% (5/73)
|
||||||
|
* Golden Chestplate 1 6.85% (5/73)
|
||||||
|
* Flint and Steel 1 6.85% (5/73)
|
||||||
|
* Nether Wart 3 - 7 6.85% (5/73)
|
||||||
|
* Saddle 1 13.7% (10/73)
|
||||||
|
* Golden Horse Armor 1 11.0% (8/73)
|
||||||
|
* Iron Horse Armor 1 6.85% (5/73)
|
||||||
|
* Diamond Horse Armor 1 4.11% (3/73)
|
||||||
|
* Obsidian 2 - 4 2.74% (2/73)
|
||||||
|
*/
|
||||||
|
// Pick how many stacks
|
||||||
|
int numOfStacks = 2 + random.nextInt(3);
|
||||||
|
// Pick the stacks
|
||||||
|
for (int i = 0; i < numOfStacks; i++) {
|
||||||
|
// Pick a random inventory slot
|
||||||
|
int slot = random.nextInt(chestInv.getSize());
|
||||||
|
// Try a few times to find an empty slot (avoids an
|
||||||
|
// infinite loop potential)
|
||||||
|
for (int j = 0; j < chestInv.getSize(); j++) {
|
||||||
|
if (chestInv.getItem(slot) == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
slot = random.nextInt(chestInv.getSize());
|
||||||
|
}
|
||||||
|
int choice = random.nextInt(73);
|
||||||
|
if (choice < 5) {
|
||||||
|
chestInv.setItem(slot, new ItemStack(Material.DIAMOND, random.nextInt(2) + 1));
|
||||||
|
} else if (choice < 10) {
|
||||||
|
chestInv.setItem(slot, new ItemStack(Material.IRON_INGOT, random.nextInt(4) + 1));
|
||||||
|
} else if (choice < 25) {
|
||||||
|
chestInv.setItem(slot, new ItemStack(Material.GOLD_INGOT, random.nextInt(2) + 1));
|
||||||
|
} else if (choice < 30) {
|
||||||
|
chestInv.setItem(slot, new ItemStack(Material.GOLD_SWORD, 1));
|
||||||
|
} else if (choice < 35) {
|
||||||
|
chestInv.setItem(slot, new ItemStack(Material.GOLD_CHESTPLATE, 1));
|
||||||
|
} else if (choice < 40) {
|
||||||
|
chestInv.setItem(slot, new ItemStack(Material.FLINT_AND_STEEL, 1));
|
||||||
|
} else if (choice < 45) {
|
||||||
|
chestInv.setItem(slot, new ItemStack(Material.NETHER_STALK, random.nextInt(4) + 3));
|
||||||
|
} else if (choice < 55) {
|
||||||
|
chestInv.setItem(slot, new ItemStack(Material.SADDLE, 1));
|
||||||
|
} else if (choice < 63) {
|
||||||
|
chestInv.setItem(slot, new ItemStack(Material.GOLD_BARDING, 1));
|
||||||
|
} else if (choice < 68) {
|
||||||
|
chestInv.setItem(slot, new ItemStack(Material.IRON_BARDING, 1));
|
||||||
|
} else if (choice < 71) {
|
||||||
|
chestInv.setItem(slot, new ItemStack(Material.DIAMOND_BARDING, 1));
|
||||||
|
} else {
|
||||||
|
chestInv.setItem(slot, new ItemStack(Material.OBSIDIAN, random.nextInt(3) + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (b.getType().equals(Material.STONE)) {
|
||||||
|
b.setType(Material.QUARTZ_ORE);
|
||||||
|
} else if (b.getType().equals(Material.DIRT)) {
|
||||||
|
world.generateTree(source.getBlock(x, y + 1, z).getLocation(), TreeType.BROWN_MUSHROOM);
|
||||||
|
b.setType(Material.SOUL_SAND);
|
||||||
|
} else if (b.getType().equals(Material.SOUL_SAND) && b.getRelative(BlockFace.UP).getType().equals(Material.AIR)) {
|
||||||
|
//Bukkit.getLogger().info("DEBUG: soul sand found!");
|
||||||
|
if (random.nextInt(9) == 1) {
|
||||||
|
//Bukkit.getLogger().info("DEBUG: Setting to NETHER_WARTS");
|
||||||
|
b.getRelative(BlockFace.UP).setType(Material.NETHER_WARTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Mob spawn
|
||||||
|
/*
|
||||||
|
* if (y == Settings.island_level &&
|
||||||
|
* b.getType().equals(Material.NETHERRACK)) {
|
||||||
|
* Entity e =
|
||||||
|
* world.spawnEntity(b.getRelative(BlockFace.UP,1)
|
||||||
|
* .getLocation(), EntityType.PIG_ZOMBIE);
|
||||||
|
* Bukkit.getLogger().info(e.toString());
|
||||||
|
* //}
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user