Skip to content

Commit

Permalink
Merge branch 'release/v1.0.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
hoqhuuep committed Jun 12, 2017
2 parents e19b4d4 + d9cdfcf commit 775fb35
Show file tree
Hide file tree
Showing 10 changed files with 311 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.github.hoqhuuep.islandcraft.core.ICLogger;

public class EbeanServerUtil {
public static EbeanServer build(final JavaPlugin javaPlugin) {
public static EbeanServer build(final IslandCraftPlugin javaPlugin) {
ICLogger.logger.info("Creating EbeanServer for plugin with name: " + javaPlugin.getDescription().getName());
final String name = javaPlugin.getDescription().getName();
final ConfigurationSection configurationSection = javaPlugin.getConfig().getConfigurationSection("database");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.mcstats.Metrics;
// import org.mcstats.Metrics;

import com.avaje.ebean.EbeanServer;
import com.github.hoqhuuep.islandcraft.api.ICLocation;
Expand Down Expand Up @@ -206,7 +206,6 @@ public void onDisable() {
ICLogger.logger = null;
}

@Override
public List<Class<?>> getDatabaseClasses() {
final Class<?>[] classes = { EbeanServerIslandDatabase.IslandBean.class,
EbeanServerIslandDatabase.IslandPK.class };
Expand Down
2 changes: 1 addition & 1 deletion IslandCraft-Bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: IslandCraft
version: 1.0.7
version: 1.0.8
description: Changes the biome distribution of the world to create an ocean with islands
author: hoqhuuep
website: http://dev.bukkit.org/bukkit-plugins/islandcraft/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
package com.github.hoqhuuep.islandcraft.nms.v1_12_R1;

import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.bukkit.block.Biome;
import org.bukkit.craftbukkit.v1_12_R1.block.CraftBlock;

import net.minecraft.server.v1_12_R1.BiomeBase;
import net.minecraft.server.v1_12_R1.BiomeCache;
import net.minecraft.server.v1_12_R1.BlockPosition;
import net.minecraft.server.v1_12_R1.WorldChunkManager;

import com.github.hoqhuuep.islandcraft.api.ICBiome;
import com.github.hoqhuuep.islandcraft.nms.BiomeGenerator;

public class CustomWorldChunkManager extends WorldChunkManager {
private static final Map<ICBiome, BiomeBase> biomeMap = new EnumMap<ICBiome, BiomeBase>(ICBiome.class);

static {
biomeMap.put(ICBiome.BEACH, CraftBlock.biomeToBiomeBase(Biome.BEACHES));
biomeMap.put(ICBiome.BIRCH_FOREST, CraftBlock.biomeToBiomeBase(Biome.BIRCH_FOREST));
biomeMap.put(ICBiome.BIRCH_FOREST_HILLS, CraftBlock.biomeToBiomeBase(Biome.BIRCH_FOREST_HILLS));
biomeMap.put(ICBiome.BIRCH_FOREST_HILLS_M, CraftBlock.biomeToBiomeBase(Biome.MUTATED_BIRCH_FOREST_HILLS));
biomeMap.put(ICBiome.BIRCH_FOREST_M, CraftBlock.biomeToBiomeBase(Biome.MUTATED_BIRCH_FOREST));
biomeMap.put(ICBiome.COLD_BEACH, CraftBlock.biomeToBiomeBase(Biome.COLD_BEACH));
biomeMap.put(ICBiome.COLD_TAIGA, CraftBlock.biomeToBiomeBase(Biome.TAIGA_COLD));
biomeMap.put(ICBiome.COLD_TAIGA_HILLS, CraftBlock.biomeToBiomeBase(Biome.TAIGA_COLD_HILLS));
biomeMap.put(ICBiome.COLD_TAIGA_M, CraftBlock.biomeToBiomeBase(Biome.MUTATED_TAIGA_COLD));
biomeMap.put(ICBiome.DEEP_OCEAN, CraftBlock.biomeToBiomeBase(Biome.DEEP_OCEAN));
biomeMap.put(ICBiome.DESERT, CraftBlock.biomeToBiomeBase(Biome.DESERT));
biomeMap.put(ICBiome.DESERT_HILLS, CraftBlock.biomeToBiomeBase(Biome.DESERT_HILLS));
biomeMap.put(ICBiome.DESERT_M, CraftBlock.biomeToBiomeBase(Biome.MUTATED_DESERT));
biomeMap.put(ICBiome.END, CraftBlock.biomeToBiomeBase(Biome.SKY));
biomeMap.put(ICBiome.EXTREME_HILLS, CraftBlock.biomeToBiomeBase(Biome.EXTREME_HILLS));
biomeMap.put(ICBiome.EXTREME_HILLS_EDGE, CraftBlock.biomeToBiomeBase(Biome.SMALLER_EXTREME_HILLS));
biomeMap.put(ICBiome.EXTREME_HILLS_M, CraftBlock.biomeToBiomeBase(Biome.MUTATED_EXTREME_HILLS));
biomeMap.put(ICBiome.EXTREME_HILLS_PLUS, CraftBlock.biomeToBiomeBase(Biome.EXTREME_HILLS_WITH_TREES));
biomeMap.put(ICBiome.EXTREME_HILLS_PLUS_M, CraftBlock.biomeToBiomeBase(Biome.MUTATED_EXTREME_HILLS_WITH_TREES));
biomeMap.put(ICBiome.FLOWER_FOREST, CraftBlock.biomeToBiomeBase(Biome.MUTATED_FOREST));
biomeMap.put(ICBiome.FOREST, CraftBlock.biomeToBiomeBase(Biome.FOREST));
biomeMap.put(ICBiome.FOREST_HILLS, CraftBlock.biomeToBiomeBase(Biome.FOREST_HILLS));
biomeMap.put(ICBiome.FROZEN_OCEAN, CraftBlock.biomeToBiomeBase(Biome.FROZEN_OCEAN));
biomeMap.put(ICBiome.FROZEN_RIVER, CraftBlock.biomeToBiomeBase(Biome.FROZEN_RIVER));
biomeMap.put(ICBiome.ICE_MOUNTAINS, CraftBlock.biomeToBiomeBase(Biome.ICE_MOUNTAINS));
biomeMap.put(ICBiome.ICE_PLAINS, CraftBlock.biomeToBiomeBase(Biome.ICE_FLATS));
biomeMap.put(ICBiome.ICE_PLAINS_SPIKES, CraftBlock.biomeToBiomeBase(Biome.MUTATED_ICE_FLATS));
biomeMap.put(ICBiome.JUNGLE, CraftBlock.biomeToBiomeBase(Biome.JUNGLE));
biomeMap.put(ICBiome.JUNGLE_EDGE, CraftBlock.biomeToBiomeBase(Biome.JUNGLE_EDGE));
biomeMap.put(ICBiome.JUNGLE_HILLS, CraftBlock.biomeToBiomeBase(Biome.JUNGLE_HILLS));
biomeMap.put(ICBiome.JUNGLE_M, CraftBlock.biomeToBiomeBase(Biome.MUTATED_JUNGLE));
biomeMap.put(ICBiome.JUNGLE_EDGE_M,CraftBlock.biomeToBiomeBase(Biome.MUTATED_JUNGLE_EDGE));
biomeMap.put(ICBiome.MEGA_SPRUCE_TAIGA, CraftBlock.biomeToBiomeBase(Biome.MUTATED_REDWOOD_TAIGA));
biomeMap.put(ICBiome.MEGA_SPRUCE_TAIGA_HILLS, CraftBlock.biomeToBiomeBase(Biome.MUTATED_REDWOOD_TAIGA_HILLS));
biomeMap.put(ICBiome.MEGA_TAIGA, CraftBlock.biomeToBiomeBase(Biome.REDWOOD_TAIGA));
biomeMap.put(ICBiome.MEGA_TAIGA_HILLS, CraftBlock.biomeToBiomeBase(Biome.REDWOOD_TAIGA_HILLS));
biomeMap.put(ICBiome.MESA, CraftBlock.biomeToBiomeBase(Biome.MESA));
biomeMap.put(ICBiome.MESA_BRYCE, CraftBlock.biomeToBiomeBase(Biome.MUTATED_MESA));
biomeMap.put(ICBiome.MESA_PLATEAU, CraftBlock.biomeToBiomeBase(Biome.MESA_CLEAR_ROCK));
biomeMap.put(ICBiome.MESA_PLATEAU_F, CraftBlock.biomeToBiomeBase(Biome.MESA_ROCK));
biomeMap.put(ICBiome.MESA_PLATEAU_F_M, CraftBlock.biomeToBiomeBase(Biome.MUTATED_MESA_ROCK));
biomeMap.put(ICBiome.MESA_PLATEAU_M, CraftBlock.biomeToBiomeBase(Biome.MUTATED_MESA_CLEAR_ROCK));
biomeMap.put(ICBiome.MUSHROOM_ISLAND, CraftBlock.biomeToBiomeBase(Biome.MUSHROOM_ISLAND));
biomeMap.put(ICBiome.MUSHROOM_ISLAND_SHORE, CraftBlock.biomeToBiomeBase(Biome.MUSHROOM_ISLAND_SHORE));
biomeMap.put(ICBiome.NETHER, CraftBlock.biomeToBiomeBase(Biome.HELL));
biomeMap.put(ICBiome.OCEAN, CraftBlock.biomeToBiomeBase(Biome.OCEAN));
biomeMap.put(ICBiome.PLAINS, CraftBlock.biomeToBiomeBase(Biome.PLAINS));
biomeMap.put(ICBiome.RIVER, CraftBlock.biomeToBiomeBase(Biome.RIVER));
biomeMap.put(ICBiome.ROOFED_FOREST, CraftBlock.biomeToBiomeBase(Biome.ROOFED_FOREST));
biomeMap.put(ICBiome.ROOFED_FOREST_M, CraftBlock.biomeToBiomeBase(Biome.MUTATED_ROOFED_FOREST));
biomeMap.put(ICBiome.SAVANNA, CraftBlock.biomeToBiomeBase(Biome.SAVANNA));
biomeMap.put(ICBiome.SAVANNA_M, CraftBlock.biomeToBiomeBase(Biome.MUTATED_SAVANNA));
biomeMap.put(ICBiome.SAVANNA_PLATEAU, CraftBlock.biomeToBiomeBase(Biome.SAVANNA_ROCK));
biomeMap.put(ICBiome.SAVANNA_PLATEAU_M, CraftBlock.biomeToBiomeBase(Biome.MUTATED_SAVANNA_ROCK));
biomeMap.put(ICBiome.STONE_BEACH, CraftBlock.biomeToBiomeBase(Biome.STONE_BEACH));
biomeMap.put(ICBiome.SUNFLOWER_PLAINS, CraftBlock.biomeToBiomeBase(Biome.MUTATED_PLAINS));
biomeMap.put(ICBiome.SWAMPLAND, CraftBlock.biomeToBiomeBase(Biome.SWAMPLAND));
biomeMap.put(ICBiome.SWAMPLAND_M, CraftBlock.biomeToBiomeBase(Biome.MUTATED_SWAMPLAND));
biomeMap.put(ICBiome.TAIGA, CraftBlock.biomeToBiomeBase(Biome.TAIGA));
biomeMap.put(ICBiome.TAIGA_HILLS, CraftBlock.biomeToBiomeBase(Biome.TAIGA_HILLS));
biomeMap.put(ICBiome.TAIGA_M, CraftBlock.biomeToBiomeBase(Biome.MUTATED_TAIGA));
// TODO Biome.VOID -- new end biome???
}

private final BiomeCache biomeCache;
private final BiomeGenerator biomeGenerator;

public CustomWorldChunkManager(final BiomeGenerator biomeGenerator) {
this.biomeGenerator = biomeGenerator;
this.biomeCache = new BiomeCache(this);
}

/** Returns a list of biome's which are valid for spawn */
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public List a() {
return super.a();
}

/** Returns the biome at a position. Used for various things. */
@Override
public BiomeBase getBiome(BlockPosition blockPosition) {
// Get from cache
return this.biomeCache.a(blockPosition.getX(), blockPosition.getZ(), (BiomeBase) null);
}

/** Returns the biome at a position. Used for various things. */
@Override
public BiomeBase getBiome(BlockPosition blockPosition, BiomeBase biomeBase) {
// Get from cache
return this.biomeCache.a(blockPosition.getX(), blockPosition.getZ(), biomeBase);
}

@Override
public float a(float a, int b) {
// TODO work out what this is used for
return super.a(a, b);
}

/** Used for height map and temperature */
@Override
public BiomeBase[] getBiomes(BiomeBase[] result, final int xMin, final int zMin, final int xSize, final int zSize) {
// Create result array if given one is insufficient
if (result == null || result.length < xSize * zSize) {
result = new BiomeBase[xSize * zSize];
}
// 1 in every 4
for (int i = 0; i < xSize * zSize; ++i) {
final int x = (xMin + (i % xSize)) << 2;
final int z = (zMin + (i / xSize)) << 2;
final ICBiome biome = biomeGenerator.generateBiome(x, z);
result[i] = biomeMap.get(biome);
}
return result;
}

/** Used in chunk creation */
@Override
public BiomeBase[] getBiomeBlock(final BiomeBase[] array, final int x, final int z, final int xSize, final int zSize) {
return a(array, x, z, xSize, zSize, true);
}

/** Only used in above method... and getWetness */
@Override
public BiomeBase[] a(BiomeBase[] result, final int xMin, final int zMin, final int xSize, final int zSize, final boolean useCache) {
// Create result array if given one is insufficient
if (result == null || result.length < xSize * zSize) {
// Happens for nether, end, and flat worlds...
result = new BiomeBase[xSize * zSize];
}
// More efficient handling of whole chunk
if (xSize == 16 && zSize == 16 && (xMin & 0xF) == 0 && (zMin & 0xF) == 0) {
if (useCache) {
// Happens most of the time
final BiomeBase[] biomes = this.biomeCache.b(xMin, zMin);
System.arraycopy(biomes, 0, result, 0, xSize * zSize);
return result;
}
// This only happens in getWetness above
final ICBiome[] temp = biomeGenerator.generateChunkBiomes(xMin, zMin);
for (int i = 0; i < xSize * zSize; ++i) {
result[i] = biomeMap.get(temp[i]);
}
return result;
}
// In reality this never happens...
for (int x = 0; x < xSize; ++x) {
for (int z = 0; z < zSize; ++z) {
final ICBiome temp = biomeGenerator.generateBiome(xMin + x, zMin + z);
result[x + z * xSize] = biomeMap.get(temp);
}
}
return result;
}

/**
* Returns true if all biome's in area are in allowedBiomes. x, z and radius
* are in blocks. Used for checking where a village can go.
*/
@Override
public boolean a(final int x, final int z, final int radius, @SuppressWarnings("rawtypes") final List allowedBiomes) {
// Convert center and radius to minimum and size
final int xMin = (x - radius) >> 2;
final int zMin = (z - radius) >> 2;
final int xMax = (x + radius) >> 2;
final int zMax = (z + radius) >> 2;
final int xSize = xMax - xMin + 1;
final int zSize = zMax - zMin + 1;
// Generate biome's
final BiomeBase[] biomes = getBiomes(null, xMin, zMin, xSize, zSize);
// Make sure all biomes are allowed
for (int i = 0; i < xSize * zSize; i++) {
if (!allowedBiomes.contains(biomes[i])) {
return false;
}
}
return true;
}

/**
* Returns random position within biome if it can be found in given area.
* Otherwise null. Used for initial guess at spawn point and stronghold
* locations.
*/
@Override
public BlockPosition a(final int x, final int z, final int radius, @SuppressWarnings("rawtypes") final List allowedBiomes, final Random random) {
// Convert center and radius to minimum and size
final int xMin = (x - radius) >> 2;
final int zMin = (z - radius) >> 2;
final int xMax = (x + radius) >> 2;
final int zMax = (z + radius) >> 2;
final int xSize = xMax - xMin + 1;
final int zSize = zMax - zMin + 1;
// Generate biome's
final BiomeBase[] biomes = getBiomes(null, xMin, zMin, xSize, zSize);
BlockPosition result = null;
int count = 0;
for (int i = 0; i < xSize * zSize; i++) {
final int xPosition = (xMin + (i % xSize)) << 2;
final int zPosition = (zMin + (i / xSize)) << 2;
if (allowedBiomes.contains(biomes[i]) && (result == null || random.nextInt(count + 1) == 0)) {
result = new BlockPosition(xPosition, 0, zPosition);
count++;
}
}
return result;
}

/** Cleans up biomeCache, called in tick */
@Override
public void b() {
// Clean up biomeCache
biomeCache.a();
biomeGenerator.cleanupCache();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.github.hoqhuuep.islandcraft.nms.v1_12_R1;

import java.lang.reflect.Field;

import org.bukkit.World;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;

import net.minecraft.server.v1_12_R1.WorldProvider;

import com.github.hoqhuuep.islandcraft.nms.BiomeGenerator;
import com.github.hoqhuuep.islandcraft.nms.NmsWrapper;

public class NmsHandler extends NmsWrapper {

@Override
public boolean installBiomeGenerator(final World world, final BiomeGenerator biomeGenerator) {
if (!(world instanceof CraftWorld)) {
// Wrong version?
return false;
}
final CraftWorld craftWorld = (CraftWorld) world;
final WorldProvider worldProvider = craftWorld.getHandle().worldProvider;
try {
Field field = getField(worldProvider.getClass(), "c");
field.setAccessible(true);
if (field.get(worldProvider) instanceof CustomWorldChunkManager) {
// Already installed
return false;
}
field.set(worldProvider, new CustomWorldChunkManager(biomeGenerator));
return true;
} catch (NoSuchFieldException e) {
return false;
} catch (IllegalArgumentException e) {
return false;
} catch (IllegalAccessException e) {
return false;
}
}

private static Field getField(Class<?> clazz, String fieldName) throws NoSuchFieldException {
try {
return clazz.getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
Class<?> superClass = clazz.getSuperclass();
if (superClass == null) {
throw e;
} else {
return getField(superClass, fieldName);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.loader.ConfigurationLoader;

@Plugin(id = "islandcraft", name = "IslandCraft", version = "1.0.7")
@Plugin(id = "islandcraft", name = "IslandCraft", version = "1.0.8")
public class IslandCraftPlugin {
@Inject
private Logger logger;
Expand Down
19 changes: 15 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = 'com.github.hoqhuuep'
version = '1.0.7'
version = '1.0.8'

allprojects {
repositories {
Expand Down Expand Up @@ -66,15 +66,16 @@ project(':IslandCraft-Bukkit') {
dependencies {
compile project(':IslandCraft-NMS')
compile project(':IslandCraft-Common')
compile group: 'org.bukkit', name: 'bukkit', version: '1.11-R0.1-SNAPSHOT'
compile group: 'org.bukkit', name: 'bukkit', version: '1.12-R0.1-SNAPSHOT'
compile group: 'org.mcstats.bukkit', name: 'metrics', version: 'R7'
compile group: 'org.avaje', name: 'ebean', version: '2.8.1'
}
}

project(':IslandCraft-NMS') {
dependencies {
compile project(':IslandCraft-API')
compile group: 'org.bukkit', name: 'bukkit', version: '1.11-R0.1-SNAPSHOT'
compile group: 'org.bukkit', name: 'bukkit', version: '1.12-R0.1-SNAPSHOT'
}
}

Expand Down Expand Up @@ -204,6 +205,13 @@ project(':IslandCraft-NMS-v1_11_R1') {
}
}

project(':IslandCraft-NMS-v1_12_R1') {
dependencies {
compile project(':IslandCraft-NMS')
compile group: 'org.bukkit', name: 'craftbukkit', version: '1.12-R0.1-SNAPSHOT'
}
}

configurations {
spongePlugin
bukkitPlugin
Expand Down Expand Up @@ -287,6 +295,9 @@ dependencies {
bukkitPlugin(project(':IslandCraft-NMS-v1_11_R1')) {
exclude group: 'org.bukkit'
}
bukkitPlugin(project(':IslandCraft-NMS-v1_12_R1')) {
exclude group: 'org.bukkit'
}
}

task bukkit(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
Expand All @@ -306,7 +317,7 @@ dependencies {
bukkitLatest (project(':IslandCraft-Bukkit')) {
exclude group: 'org.bukkit'
}
bukkitLatest(project(':IslandCraft-NMS-v1_11_R1')) {
bukkitLatest(project(':IslandCraft-NMS-v1_12_R1')) {
exclude group: 'org.bukkit'
}
}
Expand Down
Loading

0 comments on commit 775fb35

Please sign in to comment.