mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Merge remote-tracking branch 'origin/tectonic' into tectonic
This commit is contained in:
@@ -2,14 +2,16 @@ package com.dfsek.terra.generation.items.ores;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class DeformedSphereOre extends Ore {
|
||||
public DeformedSphereOre(Range height, Range amount, BlockData material) {
|
||||
super(height, amount, material);
|
||||
public DeformedSphereOre(Range height, Range amount, BlockData material, Set<Material> replaceable, boolean applyGravity) {
|
||||
super(height, amount, material, replaceable, applyGravity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,33 +2,47 @@ package com.dfsek.terra.generation.items.ores;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class Ore {
|
||||
private final Range height;
|
||||
private final Range amount;
|
||||
private final BlockData material;
|
||||
private final Set<Material> replaceable;
|
||||
private final boolean applyGravity;
|
||||
|
||||
public Ore(Range height, Range amount, BlockData material) {
|
||||
public Ore(Range height, Range amount, BlockData material, Set<Material> replaceable, boolean applyGravity) {
|
||||
this.height = height;
|
||||
this.amount = amount;
|
||||
this.material = material;
|
||||
this.replaceable = replaceable;
|
||||
this.applyGravity = applyGravity;
|
||||
}
|
||||
|
||||
public BlockData getMaterial() {
|
||||
return material;
|
||||
public abstract void generate(Location origin, Chunk c, Random r);
|
||||
|
||||
public Range getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public Range getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public Range getHeight() {
|
||||
return height;
|
||||
public BlockData getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public abstract void generate(Location origin, Chunk c, Random r);
|
||||
public Set<Material> getReplaceable() {
|
||||
return replaceable;
|
||||
}
|
||||
|
||||
public boolean isApplyGravity() {
|
||||
return applyGravity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.dfsek.terra.generation.items.ores;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class VanillaOre extends Ore {
|
||||
private final double size;
|
||||
|
||||
public VanillaOre(Range height, Range amount, BlockData material, Set<Material> replaceable, boolean applyGravity, double size) {
|
||||
super(height, amount, material, replaceable, applyGravity);
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
|
||||
public void generate(Location location, Chunk chunk, Random random) {
|
||||
int chunkBoundx1 = chunk.getX() << 4;
|
||||
int chunkBoundx2 = chunk.getX() << 4 + 15;
|
||||
int chunkBoundz1 = chunk.getZ() << 4;
|
||||
int chunkBoundz2 = chunk.getZ() << 4 + 15;
|
||||
|
||||
int centerX = location.getBlockX();
|
||||
int centerZ = location.getBlockZ();
|
||||
int centerY = location.getBlockY();
|
||||
|
||||
|
||||
float f = random.nextFloat() * (float) Math.PI;
|
||||
|
||||
double d1 = centerX + 8 + FastMath.sin(f) * size / 8.0F;
|
||||
double d2 = centerX + 8 - FastMath.sin(f) * size / 8.0F;
|
||||
double d3 = centerZ + 8 + FastMath.cos(f) * size / 8.0F;
|
||||
double d4 = centerZ + 8 - FastMath.cos(f) * size / 8.0F;
|
||||
|
||||
double d5 = centerY + random.nextInt(3) - 2D;
|
||||
double d6 = centerY + random.nextInt(3) - 2D;
|
||||
|
||||
for(int i = 0; i < size; i++) {
|
||||
float iFactor = (float) i / (float) size;
|
||||
|
||||
double d10 = random.nextDouble() * size / 16.0D;
|
||||
double d11 = (FastMath.sin(Math.PI * iFactor) + 1.0) * d10 + 1.0;
|
||||
double d12 = (FastMath.sin(Math.PI * iFactor) + 1.0) * d10 + 1.0;
|
||||
|
||||
int xStart = FastMath.roundToInt(FastMath.floor(d1 + (d2 - d1) * iFactor - d11 / 2.0D));
|
||||
int yStart = FastMath.roundToInt(FastMath.floor(d5 + (d6 - d5) * iFactor - d12 / 2.0D));
|
||||
int zStart = FastMath.roundToInt(FastMath.floor(d3 + (d4 - d3) * iFactor - d11 / 2.0D));
|
||||
|
||||
int xEnd = FastMath.roundToInt(FastMath.floor(d1 + (d2 - d1) * iFactor + d11 / 2.0D));
|
||||
int yEnd = FastMath.roundToInt(FastMath.floor(d5 + (d6 - d5) * iFactor + d12 / 2.0D));
|
||||
int zEnd = FastMath.roundToInt(FastMath.floor(d3 + (d4 - d3) * iFactor + d11 / 2.0D));
|
||||
|
||||
for(int x = xStart; x <= xEnd; x++) {
|
||||
double d13 = (x + 0.5D - (d1 + (d2 - d1) * iFactor)) / (d11 / 2.0D);
|
||||
|
||||
if(d13 * d13 < 1.0D) {
|
||||
for(int y = yStart; y <= yEnd; y++) {
|
||||
double d14 = (y + 0.5D - (d5 + (d6 - d5) * iFactor)) / (d12 / 2.0D);
|
||||
if(d13 * d13 + d14 * d14 < 1.0D) {
|
||||
for(int z = zStart; z <= zEnd; z++) {
|
||||
double d15 = (z + 0.5D - (d3 + (d4 - d3) * iFactor)) / (d11 / 2.0D);
|
||||
Block block = chunk.getBlock(x, y, z);
|
||||
if((block.getX() <= chunkBoundx1 || block.getX() >= chunkBoundx2) &&
|
||||
(block.getZ() <= chunkBoundz1 || block.getZ() >= chunkBoundz2) &&
|
||||
block.getY() <= 255)
|
||||
continue;
|
||||
if((d13 * d13 + d14 * d14 + d15 * d15 < 1.0D) && getReplaceable().contains(block.getType())) {
|
||||
block.setBlockData(getMaterial(), isApplyGravity());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user