Skip to content

Commit

Permalink
Fixed compatibility with 1.14.x
Browse files Browse the repository at this point in the history
#19

Makes chests a bit more generous.

Version up.
  • Loading branch information
tastybento committed Jul 4, 2019
1 parent 106ee59 commit 0958d79
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 206 deletions.
21 changes: 10 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>world.bentobox</groupId>
<artifactId>skygrid</artifactId>
<version>1.5.0</version>
<version>1.6.0-SNAPSHOT</version>

<description>Skygrid is an add-on for BentoBox, an expandable Minecraft Bukkit plugin for island-type games like BSkyBlock or AcidIsland.</description>
<url>https://github.com/BentoBoxWorld/SkyGrid</url>
Expand Down Expand Up @@ -52,9 +52,13 @@
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots</url>
</repository>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public</url>
</repository>
<id>codemc</id>
<url>https://repo.codemc.org/repository/maven-snapshots/</url>
</repository>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
Expand All @@ -65,7 +69,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14.1-R0.1-SNAPSHOT</version>
<version>1.14.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -86,15 +90,10 @@
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>bentobox</artifactId>
<version>1.5.0</version>
<version>1.6.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- Vault -->
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/world/bentobox/skygrid/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ public class Settings implements WorldSettings {
@ConfigEntry(path = "world.end-frame-probability")
private double endFrameProb = 0.1;

@ConfigComment("Allow saplings to grow into trees sometimes.")
@ConfigEntry(path = "world.grow-trees")
private boolean growTrees = true;

/* WORLD */
@ConfigComment("Friendly name for this world. Used in admin commands. Must be a single word")
@ConfigEntry(path = "world.friendly-name")
Expand Down Expand Up @@ -358,20 +354,6 @@ public void setEndFrameProb(double endFrameProb) {
this.endFrameProb = endFrameProb;
}

/**
* @return the growTrees
*/
public boolean isGrowTrees() {
return growTrees;
}

/**
* @param growTrees the growTrees to set
*/
public void setGrowTrees(boolean growTrees) {
this.growTrees = growTrees;
}

/**
* @return the friendlyName
*/
Expand Down
44 changes: 28 additions & 16 deletions src/main/java/world/bentobox/skygrid/generators/BiomeGenerator.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
package world.bentobox.skygrid.generators;

import java.util.HashMap;
import java.util.Objects;

import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.util.noise.PerlinOctaveGenerator;

public class BiomeGenerator {

private final PerlinOctaveGenerator temperatureGen, rainfallGen;

public BiomeGenerator(World world) {
// I used a scale of 1/300 instead of something like 1/600 or 1/1000
// to make the biome edges easier to see
temperatureGen = new PerlinOctaveGenerator(world.getSeed(), 16);
temperatureGen.setScale(1.0/100.0);

rainfallGen = new PerlinOctaveGenerator(world.getSeed() + 1, 15);
rainfallGen.setScale(1.0/100.0);
}

public HashMap<Biomes, Double> getBiomes(int realX, int realZ) {
return Biomes.getBiomes(Math.abs(temperatureGen.noise(realX, realZ, 0.5, 0.5)*100.0), Math.abs(rainfallGen.noise(realX, realZ, 0.5, 0.5)*100.0));
}

private final PerlinOctaveGenerator temperatureGen, rainfallGen;

public BiomeGenerator(World world) {
temperatureGen = new PerlinOctaveGenerator(world.getSeed(), 16);
temperatureGen.setScale(1.0/100.0);

rainfallGen = new PerlinOctaveGenerator(world.getSeed() + 1, 15);
rainfallGen.setScale(1.0/100.0);
}

public Biome getDominantBiome(int realX, int realZ) {
//We get the 3 closest biome's to the temperature and rainfall at this block
HashMap<Biomes, Double> biomes = Biomes.getBiomes(Math.abs(temperatureGen.noise(realX, realZ, 0.5, 0.5)*100.0), Math.abs(rainfallGen.noise(realX, realZ, 0.5, 0.5)*100.0));
//And tell bukkit (who tells the client) what the biggest biome here is
double maxNoiz = 0.0;
Biomes maxBiome = null;

for (Biomes biome : biomes.keySet()) {
if (biomes.get(biome) >= maxNoiz) {
maxNoiz = biomes.get(biome);
maxBiome = biome;
}
}
return Objects.requireNonNull(maxBiome).biome;
}

}
63 changes: 24 additions & 39 deletions src/main/java/world/bentobox/skygrid/generators/SkyGridGen.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package world.bentobox.skygrid.generators;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Random;

import org.bukkit.Location;
Expand Down Expand Up @@ -58,47 +56,49 @@ public class SkyGridGen extends ChunkGenerator {
// TODO add all the other plants that need to go on dirt
);

private BiomeGenerator biomeGenerator;

private BlockPopulator populator;

/**
* @param addon - addon
*/
public SkyGridGen(SkyGrid addon) {
this.addon = addon;
this.populator = new SkyGridPop(addon);
}

@Override
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, ChunkGenerator.BiomeGrid biomeGrid) {

BiomeGenerator biomeGenerator = new BiomeGenerator(world);

// This gets all the blocks that can be picked and their probabilities
BlockProbability prob = addon.getWorldStyles().get(world.getEnvironment()).getProb();

// The chunk we are making
ChunkData result = createChunkData(world);
for (int x = 0; x < 16; x ++) {
for (int z = 0; z < 16; z ++) {
// Set biome
if (addon.getSettings().isCreateBiomes() && world.getEnvironment().equals(Environment.NORMAL)) {
for (int x = 1; x < 16; x += 4) {
for (int z = 1; z < 16; z += 4) {
for (int y = 0; y <= addon.getSettings().getIslandHeight(); y += 4) {
setBlock(prob, x, y, z, biomeGrid, random, result);
}
}
}
// Set biome
if (addon.getSettings().isCreateBiomes() && world.getEnvironment().equals(Environment.NORMAL)) {
if (biomeGenerator == null) {
biomeGenerator = new BiomeGenerator(world);
}
for (int x = 0; x < 16; x ++) {
for (int z = 0; z < 16; z ++) {
int realX = x + chunkX * 16; //used so that the noise function gives us
int realZ = z + chunkZ * 16; //different values each chunk
//We get the 3 closest biome's to the temperature and rainfall at this block
HashMap<Biomes, Double> biomes = biomeGenerator.getBiomes(realX, realZ);
//And tell bukkit (who tells the client) what the biggest biome here is
biomeGrid.setBiome(x, z, getDominantBiome(biomes));
}
if (x % 4 == 0 && z % 4 == 0) {
for (int y = 0; y <= addon.getSettings().getIslandHeight(); y += 4) {
setBlock(prob, x, y, z, result, biomeGrid, random);
}
biomeGrid.setBiome(x, z, biomeGenerator.getDominantBiome(realX, realZ));
}
}
}
return result;
}

private void setBlock(BlockProbability prob, int x, int y, int z, ChunkData result, BiomeGrid biomeGrid, Random random) {
private void setBlock(BlockProbability prob, int x, int y, int z, BiomeGrid biomeGrid, Random random, ChunkData result) {
// Get a random block and feed in the last block (true if cactus or cane)
Material blockMat = prob.getBlock(random, y == 0, false);
// If blockMat is not "a block" then cannot be generated
Expand All @@ -121,7 +121,8 @@ private void setBlock(BlockProbability prob, int x, int y, int z, ChunkData resu
result.setBlock( x, y, z, Material.DIRT);
result.setBlock( x, y+1, z, blockMat);
if (blockMat.equals(Material.SUGAR_CANE)) {
result.setBlock( x+1, y, z, Material.WATER);
// x will never be more than 12
result.setBlock(x+1, y, z, Material.WATER);
}
}
} else {
Expand Down Expand Up @@ -180,31 +181,15 @@ private void setBlock(BlockProbability prob, int x, int y, int z, ChunkData resu

@Override
public List<BlockPopulator> getDefaultPopulators(World world) {
List<BlockPopulator> list = new ArrayList<>(1);
list.add(new SkyGridPop(addon));
return list;
//return Collections.emptyList();
return Collections.singletonList(populator);
}



@Override
public Location getFixedSpawnLocation(World world, Random random) {
return new Location(world, 0, addon.getSettings().getIslandHeight() + 2, 0);
}

//We get the closest biome to send to the client (using the biomegrid)
private Biome getDominantBiome(HashMap<Biomes, Double> biomes) {
double maxNoiz = 0.0;
Biomes maxBiome = null;

for (Biomes biome : biomes.keySet()) {
if (biomes.get(biome) >= maxNoiz) {
maxNoiz = biomes.get(biome);
maxBiome = biome;
}
}
return Objects.requireNonNull(maxBiome).biome;
}


}

0 comments on commit 0958d79

Please sign in to comment.