!World gen refactor

This commit is contained in:
Indyuce 2020-04-10 17:11:31 +02:00
parent b7faab2a49
commit 4e1e03a145
9 changed files with 185 additions and 95 deletions

View File

@ -17,23 +17,22 @@ import org.bukkit.inventory.meta.ItemMeta;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.util.MushroomState;
import net.Indyuce.mmoitems.api.worldgen.WorldGenTemplate;
import net.Indyuce.mmoitems.manager.BlockManager;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.ItemTag;
public class CustomBlock {
private final int id;
private final MushroomState state;
private final int id;
private final String blockName;
private final String templateName;
private final List<String> lore = new ArrayList<String>();
private final int minExp;
private final int maxExp;
private final int requiredPower;
private final WorldGenTemplate template;
private final List<String> lore = new ArrayList<>();
private final int minExp, maxExp, requiredPower;
public CustomBlock(int id, MushroomState state, ConfigurationSection config) {
this.id = id;
public CustomBlock(MushroomState state, ConfigurationSection config) {
this.id = Integer.valueOf(config.getName());
this.state = state;
Validate.notNull(config, "Could not read custom block config");
@ -45,9 +44,7 @@ public class CustomBlock {
minExp = config.getInt("min-xp", 0);
maxExp = config.getInt("max-xp", 0);
requiredPower = config.getInt("required-power", 0);
templateName = config.getString("gen-template", "");
MMOItems.plugin.getWorldGen().register(this);
template = config.contains("gen-template") ? MMOItems.plugin.getWorldGen().getOrThrow(config.get("gen-template").toString()) : null;
}
public int getId() {
@ -58,19 +55,27 @@ public class CustomBlock {
return blockName;
}
public String getTemplateName() {
return templateName;
public MushroomState getState() {
return state;
}
public boolean hasGenTemplate() {
return template != null;
}
public WorldGenTemplate getGenTemplate() {
return template;
}
public List<String> getLore() {
return lore;
}
public int getMinXPDrop() {
public int getMinExpDrop() {
return minExp;
}
public int getMaxXPDrop() {
public int getMaxExpDrop() {
return maxExp;
}
@ -78,27 +83,6 @@ public class CustomBlock {
return requiredPower;
}
// Depending on the id, return the mushroom type this block
// is supposed to feature.
public Material getType() {
return MMOItems.plugin.getCustomBlocks().getType(id);
}
// From the Id, check which sides to apply data to.
// This will return the blockstate of the blocks id.
public BlockData getBlockData() {
MultipleFacing mfData = (MultipleFacing) getType().createBlockData();
mfData.setFace(BlockFace.UP, state.up);
mfData.setFace(BlockFace.DOWN, state.down);
mfData.setFace(BlockFace.NORTH, state.north);
mfData.setFace(BlockFace.SOUTH, state.south);
mfData.setFace(BlockFace.EAST, state.east);
mfData.setFace(BlockFace.WEST, state.west);
return mfData;
}
// Convert block data into Item
public ItemStack getItem() {
ItemStack item = new ItemStack(Material.CLAY_BALL);
@ -113,7 +97,11 @@ public class CustomBlock {
item.setItemMeta(meta);
return MMOLib.plugin.getNMS().getNBTItem(item).addTag(new ItemTag("MMOITEMS_DISABLE_CRAFTING", true), new ItemTag("MMOITEMS_DISABLE_SMITHING", true), new ItemTag("MMOITEMS_DISABLE_ENCHANTING", true), new ItemTag("MMOITEMS_DISABLE_REPAIRING", true), new ItemTag("MMOITEMS_BLOCK_ID", id), new ItemTag("CustomModelData", id + 1000)).toItem();
return MMOLib.plugin.getNMS().getNBTItem(item)
.addTag(new ItemTag("MMOITEMS_DISABLE_CRAFTING", true), new ItemTag("MMOITEMS_DISABLE_SMITHING", true),
new ItemTag("MMOITEMS_DISABLE_ENCHANTING", true), new ItemTag("MMOITEMS_DISABLE_REPAIRING", true),
new ItemTag("MMOITEMS_BLOCK_ID", id), new ItemTag("CustomModelData", id + 1000))
.toItem();
}
// Gets a new CustomBlock instance from a mushroom blockstate.
@ -123,7 +111,8 @@ public class CustomBlock {
if (!(data instanceof MultipleFacing))
return null;
MultipleFacing mfData = (MultipleFacing) data;
MushroomState state = new MushroomState(data.getMaterial(), mfData.hasFace(BlockFace.UP), mfData.hasFace(BlockFace.DOWN), mfData.hasFace(BlockFace.WEST), mfData.hasFace(BlockFace.EAST), mfData.hasFace(BlockFace.SOUTH), mfData.hasFace(BlockFace.NORTH));
MushroomState state = new MushroomState(data.getMaterial(), mfData.hasFace(BlockFace.UP), mfData.hasFace(BlockFace.DOWN),
mfData.hasFace(BlockFace.WEST), mfData.hasFace(BlockFace.EAST), mfData.hasFace(BlockFace.SOUTH), mfData.hasFace(BlockFace.NORTH));
BlockManager manager = MMOItems.plugin.getCustomBlocks();
return manager.isVanilla(state) ? null : manager.getBlock(state);

View File

@ -1,18 +1,21 @@
package net.Indyuce.mmoitems.api.util;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.MultipleFacing;
public class MushroomState {
public final Material id;
public final boolean up, down, west, east, south, north;
private final Material material;
private final boolean up, down, west, east, south, north;
/*
* help generate an unique identifier that only depends on the parameters of
* a mushroom block. ids are unique because they correspond to one specific
* mushroom state
*/
public MushroomState(Material id, boolean up, boolean down, boolean west, boolean east, boolean south, boolean north) {
this.id = id;
public MushroomState(Material material, boolean up, boolean down, boolean west, boolean east, boolean south, boolean north) {
this.material = material;
this.up = up;
this.down = down;
this.west = west;
@ -22,11 +25,31 @@ public class MushroomState {
}
public int getUniqueId() {
String first = id == Material.BROWN_MUSHROOM_BLOCK ? "0" : id == Material.RED_MUSHROOM_BLOCK ? "1" : "2";
return Integer.parseInt(first + (up ? "1" : "0") + (down ? "1" : "0") + (west ? "1" : "0") + (east ? "1" : "0") + (south ? "1" : "0") + (north ? "1" : "0"));
String first = material == Material.BROWN_MUSHROOM_BLOCK ? "0" : material == Material.RED_MUSHROOM_BLOCK ? "1" : "2";
return Integer.parseInt(
first + (up ? "1" : "0") + (down ? "1" : "0") + (west ? "1" : "0") + (east ? "1" : "0") + (south ? "1" : "0") + (north ? "1" : "0"));
}
public boolean equals(MushroomState state) {
public boolean matches(MushroomState state) {
return up == state.up && down == state.down && west == state.west && east == state.east && south == state.south && north == state.north;
}
public Material getType() {
return material;
}
// From the Id, check which sides to apply data to.
// This will return the blockstate of the blocks id.
public BlockData getBlockData() {
MultipleFacing blockData = (MultipleFacing) material.createBlockData();
blockData.setFace(BlockFace.UP, up);
blockData.setFace(BlockFace.DOWN, down);
blockData.setFace(BlockFace.NORTH, north);
blockData.setFace(BlockFace.SOUTH, south);
blockData.setFace(BlockFace.EAST, east);
blockData.setFace(BlockFace.WEST, west);
return blockData;
}
}

View File

@ -10,8 +10,8 @@ import org.bukkit.block.Biome;
import org.bukkit.configuration.ConfigurationSection;
public class WorldGenTemplate {
public final double chunkChance;
public final int minDepth, maxDepth, veinSize, veinCount;
private final double chunkChance;
private final int minDepth, maxDepth, veinSize, veinCount;
private final List<Material> replaceable = new ArrayList<>();
private final List<String> worldWhitelist = new ArrayList<>(), worldBlacklist = new ArrayList<>();
@ -24,16 +24,10 @@ public class WorldGenTemplate {
config.getStringList("replace").forEach(str -> replaceable.add(Material.valueOf(str.toUpperCase().replace("-", "_").replace(" ", "_"))));
for (String world : config.getStringList("worlds"))
if (world.contains("!"))
worldBlacklist.add(world.toUpperCase());
else
worldWhitelist.add(world.toUpperCase());
(world.contains("!") ? worldBlacklist : worldWhitelist).add(world.toLowerCase());
for (String biome : config.getStringList("biomes"))
if (biome.contains("!"))
biomeBlacklist.add(biome.toUpperCase());
else
biomeWhitelist.add(biome.toUpperCase());
(biome.contains("!") ? biomeBlacklist : biomeWhitelist).add(biome.toUpperCase().replace("-", "_").replace(" ", "_"));
chunkChance = config.getDouble("chunk-chance");
slimeChunk = config.getBoolean("slime-chunk", false);
@ -49,6 +43,26 @@ public class WorldGenTemplate {
veinCount = config.getInt("vein-count");
}
public double getChunkChance() {
return chunkChance;
}
public int getVeinSize() {
return veinSize;
}
public int getVeinCount() {
return veinCount;
}
public int getMinDepth() {
return minDepth;
}
public int getMaxDepth() {
return maxDepth;
}
public boolean canGenerate(Location pos) {
// check world list

View File

@ -30,9 +30,9 @@ public class MMOItemsBlockType implements BlockType {
@Override
public void place(Location loc, RegeneratingBlock regenerating) {
CustomBlock block = MMOItems.plugin.getCustomBlocks().getBlock(id);
loc.getBlock().setType(block.getType());
loc.getBlock().setType(block.getState().getType());
if (MMOLib.plugin.getVersion().isStrictlyHigher(1, 12))
loc.getBlock().setBlockData(block.getBlockData());
loc.getBlock().setBlockData(block.getState().getBlockData());
}
public static boolean matches(Block block) {

View File

@ -56,7 +56,7 @@ public class CustomBlockListener implements Listener {
CustomBlock block = CustomBlock.getFromData(event.getBlock().getBlockData());
if (block != null) {
event.setDropItems(false);
event.setExpToDrop(event.getPlayer().getGameMode() == GameMode.CREATIVE ? 0 : CustomBlockListener.getPickaxePower(event.getPlayer()) >= block.getRequiredPower() ? block.getMaxXPDrop() == 0 && block.getMinXPDrop() == 0 ? 0 : random.nextInt((block.getMaxXPDrop() - block.getMinXPDrop()) + 1) + block.getMinXPDrop() : 0);
event.setExpToDrop(event.getPlayer().getGameMode() == GameMode.CREATIVE ? 0 : CustomBlockListener.getPickaxePower(event.getPlayer()) >= block.getRequiredPower() ? block.getMaxExpDrop() == 0 && block.getMinExpDrop() == 0 ? 0 : random.nextInt((block.getMaxExpDrop() - block.getMinExpDrop()) + 1) + block.getMinExpDrop() : 0);
}
}
}
@ -90,8 +90,8 @@ public class CustomBlockListener implements Listener {
Block oldState = modify;
Material cachedType = modify.getType();
BlockData cachedData = modify.getBlockData();
modify.setType(block.getType(), false);
modify.setBlockData(block.getBlockData(), false);
modify.setType(block.getState().getType(), false);
modify.setBlockData(block.getState().getBlockData(), false);
MMOLib.plugin.getNMS().playArmAnimation(event.getPlayer());
modify.getWorld().playSound(event.getPlayer().getLocation(), MMOLib.plugin.getNMS().getBlockPlaceSound(modify), 0.8f, 1.0f);

View File

@ -17,26 +17,58 @@ import net.Indyuce.mmoitems.api.CustomBlock;
import net.Indyuce.mmoitems.api.util.MushroomState;
public class BlockManager {
private final static List<Integer> downIds = Arrays.asList(new Integer[] { 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160 });
private final static List<Integer> eastIds = Arrays.asList(new Integer[] { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160 });
private final static List<Integer> northIds = Arrays.asList(new Integer[] { 4, 5, 6, 7, 8, 9, 16, 17, 18, 19, 20, 21, 22, 31, 32, 33, 34, 35, 36, 37, 38, 47, 48, 49, 50, 51, 52, 53, 55, 56, 57, 58, 63, 64, 65, 66, 67, 68, 77, 78, 79, 80, 81, 82, 83, 84, 93, 94, 95, 96, 97, 98, 99, 107, 108, 109, 110, 111, 112, 113, 114, 123, 124, 125, 126, 127, 128, 129, 138, 139, 140, 141, 142, 143, 144, 145, 154, 155, 156, 157, 158, 159, 160 });
private final static List<Integer> southIds = Arrays.asList(new Integer[] { 2, 3, 6, 7, 8, 9, 13, 14, 15, 19, 20, 21, 22, 27, 28, 29, 30, 35, 36, 37, 38, 43, 44, 45, 46, 51, 52, 53, 55, 56, 57, 58, 61, 62, 65, 66, 67, 68, 73, 74, 75, 76, 81, 82, 83, 84, 89, 90, 91, 92, 97, 98, 99, 103, 104, 105, 106, 111, 112, 113, 114, 119, 120, 121, 122, 127, 128, 129, 134, 135, 136, 137, 142, 143, 144, 145, 150, 151, 152, 153, 158, 159, 160 });
private final static List<Integer> upIds = Arrays.asList(new Integer[] { 8, 9, 12, 15, 18, 21, 22, 25, 26, 29, 30, 33, 34, 37, 38, 41, 42, 45, 46, 49, 50, 53, 57, 58, 60, 62, 64, 67, 68, 71, 72, 75, 76, 79, 80, 83, 84, 87, 88, 91, 92, 95, 96, 99, 101, 102, 105, 106, 109, 110, 113, 114, 117, 118, 121, 122, 125, 126, 128, 129, 132, 133, 136, 137, 140, 141, 144, 145, 148, 149, 152, 153, 156, 157, 160 });
private final static List<Integer> westIds = Arrays.asList(new Integer[] { 1, 3, 5, 7, 9, 11, 12, 14, 15, 17, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 56, 58, 59, 60, 61, 62, 63, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159 });
private final static List<Integer> downIds = Arrays.asList(new Integer[] { 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
91, 92, 93, 94, 95, 96, 97, 98, 99, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160 });
private final static List<Integer> eastIds = Arrays
.asList(new Integer[] { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 115, 116, 117, 118, 119, 120,
121, 122, 123, 124, 125, 126, 127, 128, 129, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160 });
private final static List<Integer> northIds = Arrays
.asList(new Integer[] { 4, 5, 6, 7, 8, 9, 16, 17, 18, 19, 20, 21, 22, 31, 32, 33, 34, 35, 36, 37, 38, 47, 48, 49, 50, 51, 52, 53, 55, 56,
57, 58, 63, 64, 65, 66, 67, 68, 77, 78, 79, 80, 81, 82, 83, 84, 93, 94, 95, 96, 97, 98, 99, 107, 108, 109, 110, 111, 112, 113,
114, 123, 124, 125, 126, 127, 128, 129, 138, 139, 140, 141, 142, 143, 144, 145, 154, 155, 156, 157, 158, 159, 160 });
private final static List<Integer> southIds = Arrays
.asList(new Integer[] { 2, 3, 6, 7, 8, 9, 13, 14, 15, 19, 20, 21, 22, 27, 28, 29, 30, 35, 36, 37, 38, 43, 44, 45, 46, 51, 52, 53, 55, 56,
57, 58, 61, 62, 65, 66, 67, 68, 73, 74, 75, 76, 81, 82, 83, 84, 89, 90, 91, 92, 97, 98, 99, 103, 104, 105, 106, 111, 112, 113,
114, 119, 120, 121, 122, 127, 128, 129, 134, 135, 136, 137, 142, 143, 144, 145, 150, 151, 152, 153, 158, 159, 160 });
private final static List<Integer> upIds = Arrays.asList(new Integer[] { 8, 9, 12, 15, 18, 21, 22, 25, 26, 29, 30, 33, 34, 37, 38, 41, 42, 45, 46,
49, 50, 53, 57, 58, 60, 62, 64, 67, 68, 71, 72, 75, 76, 79, 80, 83, 84, 87, 88, 91, 92, 95, 96, 99, 101, 102, 105, 106, 109, 110, 113,
114, 117, 118, 121, 122, 125, 126, 128, 129, 132, 133, 136, 137, 140, 141, 144, 145, 148, 149, 152, 153, 156, 157, 160 });
private final static List<Integer> westIds = Arrays
.asList(new Integer[] { 1, 3, 5, 7, 9, 11, 12, 14, 15, 17, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 56, 58,
59, 60, 61, 62, 63, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112,
114, 116, 118, 120, 122, 124, 126, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159 });
/*
* maps the custom block id to the custom block instance
*/
private final Map<Integer, CustomBlock> customBlocks = new HashMap<>();
private final Map<Integer, Integer> mushroomStateValue = new HashMap<>();
/*
* maps the mushroomState unique ID to the MMOItems custom block. can also
* be used to check if a mushroom state is being used by MMOItems or not.
*/
private final Map<Integer, CustomBlock> mushroomStateValue = new HashMap<>();
public BlockManager() {
reload();
}
public void register(CustomBlock block) {
customBlocks.put(block.getId(), block);
mushroomStateValue.put(block.getState().getUniqueId(), block);
if (block.hasGenTemplate())
MMOItems.plugin.getWorldGen().assign(block, block.getGenTemplate());
}
public CustomBlock getBlock(int id) {
return id > 0 && id < 161 && id != 54 ? customBlocks.get(id) : null;
}
public CustomBlock getBlock(MushroomState state) {
return customBlocks.get(mushroomStateValue.get(state.getUniqueId()));
return customBlocks.get(state.getUniqueId());
}
public Collection<CustomBlock> getAll() {
@ -55,10 +87,6 @@ public class BlockManager {
return type == Material.BROWN_MUSHROOM_BLOCK || type == Material.MUSHROOM_STEM || type == Material.RED_MUSHROOM_BLOCK;
}
public Material getType(int id) {
return id < 54 ? Material.BROWN_MUSHROOM_BLOCK : id > 99 ? Material.MUSHROOM_STEM : Material.RED_MUSHROOM_BLOCK;
}
public void reload() {
customBlocks.clear();
FileConfiguration config = new ConfigFile("custom-blocks").getConfig();
@ -68,11 +96,14 @@ public class BlockManager {
try {
MushroomState state = new MushroomState(getType(id), upIds.contains(id), downIds.contains(id), westIds.contains(id),
eastIds.contains(id), southIds.contains(id), northIds.contains(id));
customBlocks.put(id, new CustomBlock(id, state, config.getConfigurationSection("" + id)));
mushroomStateValue.put(state.getUniqueId(), id);
register(new CustomBlock(state, config.getConfigurationSection("" + id)));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load custom block " + id + ": " + exception.getMessage());
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load custom block '" + id + "': " + exception.getMessage());
}
}
private Material getType(int id) {
return id < 54 ? Material.BROWN_MUSHROOM_BLOCK : id > 99 ? Material.MUSHROOM_STEM : Material.RED_MUSHROOM_BLOCK;
}
}

View File

@ -3,7 +3,9 @@ package net.Indyuce.mmoitems.manager;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
@ -20,7 +22,13 @@ import net.Indyuce.mmoitems.api.worldgen.WorldGenTemplate;
public class WorldGenManager implements Listener {
private final Map<String, WorldGenTemplate> templates = new HashMap<>();
private final Map<Integer, String> assigned = new HashMap<>();
/*
* maps a custom block to the world generator template so that it is later
* easier to access all the blocks which must be placed when generating a
* world.
*/
private final Map<CustomBlock, WorldGenTemplate> assigned = new HashMap<>();
private static final BlockFace[] faces = { BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST, BlockFace.EAST, BlockFace.DOWN, BlockFace.UP };
private static final Random random = new Random();
@ -29,13 +37,22 @@ public class WorldGenManager implements Listener {
if (!MMOItems.plugin.getLanguage().worldGenEnabled)
return;
FileConfiguration config = new ConfigFile("gen-templates").getConfig();
config.getKeys(false).forEach(e -> templates.put(e, new WorldGenTemplate(config.getConfigurationSection(e))));
reload();
Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin);
}
public void register(CustomBlock block) {
assigned.put(block.getId(), block.getTemplateName());
public WorldGenTemplate getOrThrow(String id) {
Validate.isTrue(templates.containsKey(id), "Could not find gen template with ID '" + id + "'");
return templates.get(id);
}
/*
* it is mandatory to call this function after registering the custom block
* if you want the custom block to be
*/
public void assign(CustomBlock block, WorldGenTemplate template) {
Validate.notNull(template, "Cannot assign a null template to a custom block");
assigned.put(block, template);
}
@EventHandler
@ -43,21 +60,19 @@ public class WorldGenManager implements Listener {
if (!event.isNewChunk())
return;
for (int blocks : assigned.keySet()) {
WorldGenTemplate wgt = templates.get(assigned.get(blocks));
if (random.nextDouble() < wgt.chunkChance)
for (int i = 0; i < wgt.veinCount; i++) {
int y = random.nextInt((wgt.maxDepth - wgt.minDepth) + 1) + wgt.minDepth;
assigned.forEach((block, template) -> {
if (random.nextDouble() < template.getChunkChance())
for (int i = 0; i < template.getVeinCount(); i++) {
int y = random.nextInt(template.getMaxDepth() - template.getMinDepth() + 1) + template.getMinDepth();
Location generatePoint = event.getChunk().getBlock(random.nextInt(16), y, random.nextInt(16)).getLocation();
if (wgt.canGenerate(generatePoint)) {
CustomBlock block = MMOItems.plugin.getCustomBlocks().getBlock(blocks);
if (template.canGenerate(generatePoint)) {
Block modify = event.getWorld().getBlockAt(generatePoint);
for (int j = 0; j < wgt.veinSize; j++) {
if (wgt.canReplace(modify.getType())) {
modify.setType(block.getType(), false);
modify.setBlockData(block.getBlockData(), false);
for (int j = 0; j < template.getVeinSize(); j++) {
if (template.canReplace(modify.getType())) {
modify.setType(block.getState().getType(), false);
modify.setBlockData(block.getState().getBlockData(), false);
}
BlockFace nextFace = faces[random.nextInt(faces.length)];
@ -65,6 +80,19 @@ public class WorldGenManager implements Listener {
}
}
}
}
});
}
public void reload() {
templates.clear();
FileConfiguration config = new ConfigFile("gen-templates").getConfig();
for (String key : config.getKeys(false))
try {
templates.put(key, new WorldGenTemplate(config.getConfigurationSection(key)));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "An error occured when loading gen template '" + key + "': " + exception.getMessage());
}
}
}

View File

@ -42,8 +42,10 @@ default:
item-glow: true
item-upgrading:
# Display name suffix for upgraded items.
name-suffix: '&f &a+#lvl#'
# Whether to display in Item Name or Lore
# Disable if item renaming is available to players.
# If set to 'false', remember to include
@ -85,16 +87,19 @@ item-ability:
cooldown: 4
gem-sockets:
# Define the text you need to enter in the
# item gem sockets if you want to create an
# uncolored gem socket i.e a socket for any type of gem.
uncolored: 'Uncolored'
custom-blocks:
# Whether or not custom blocks should
# generate in the world according to
# their generation template.
enable-world-gen: false
# Whether or not to remove mushroom block drops
# from the droplist when mining a mushroom block
# with silk-touch.

View File

@ -22,9 +22,9 @@ slime-chunks-only:
replace: [STONE]
# Use this option to only enable this template in slime chunks
chunk-chance: 0.6
slime-chunk: true
chunk-chance: 0.6
depth: 0=100
vein-size: 1
vein-count: 4