mirror of
https://github.com/chylex/Hardcore-Ender-Expansion.git
synced 2025-04-22 19:15:43 +02:00
Moar populators :3
This commit is contained in:
parent
40340a9898
commit
791ebc0a45
src/main/java/chylex/hee/world/feature/blobs
@ -1,32 +0,0 @@
|
|||||||
package chylex.hee.world.feature.blobs.old;
|
|
||||||
import java.util.Random;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import chylex.hee.world.feature.WorldGenBlobOld;
|
|
||||||
|
|
||||||
public class FlowerPopulator extends Populator{
|
|
||||||
private Block flower;
|
|
||||||
|
|
||||||
public FlowerPopulator(Block flower){
|
|
||||||
this.flower = flower;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void populate(World world, Random rand, int x, int y, int z){
|
|
||||||
int planeAreaSquared = (int)Math.floor(Math.sqrt(size[0]*size[2]))>>1;
|
|
||||||
for(int a = 0; a < planeAreaSquared; a++){
|
|
||||||
int xx = rand.nextInt(maxPos[0]-minPos[0])+minPos[0],
|
|
||||||
zz = rand.nextInt(maxPos[2]-minPos[2])+minPos[2],yy;
|
|
||||||
boolean can = false;
|
|
||||||
|
|
||||||
for(yy = maxPos[1]; yy > minPos[1]; yy--){
|
|
||||||
if (getBlock(world,xx,yy,zz) == WorldGenBlobOld.filler){
|
|
||||||
can = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (can)world.setBlock(xx,yy+1,zz,flower);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
package chylex.hee.world.feature.blobs.old;
|
|
||||||
import java.util.Random;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.init.Blocks;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import chylex.hee.world.feature.WorldGenBlobOld;
|
|
||||||
|
|
||||||
public class LakePopulator extends Populator{
|
|
||||||
private Block liquid;
|
|
||||||
|
|
||||||
public LakePopulator(Block liquid){
|
|
||||||
this.liquid = liquid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void populate(World world, Random rand, int x, int y, int z){
|
|
||||||
for(int attempt = 0; attempt < 3; attempt++){
|
|
||||||
int px = rand.nextInt(maxPos[0]-minPos[0])+minPos[0],
|
|
||||||
pz = rand.nextInt(maxPos[2]-minPos[2])+minPos[2],
|
|
||||||
py = maxPos[1];
|
|
||||||
boolean found = false;
|
|
||||||
|
|
||||||
for(; py > minPos[1]; py--){
|
|
||||||
if (getBlock(world,px,py,pz) == WorldGenBlobOld.filler){
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found)continue;
|
|
||||||
|
|
||||||
for(int xx = minPos[0]; xx <= maxPos[0]; xx++){
|
|
||||||
for(int zz = minPos[2]; zz <= maxPos[2]; zz++){
|
|
||||||
if (isBlockSuitable(world,xx,py,zz))world.setBlock(xx,py,zz,liquid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rand.nextInt(3) != 0)break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isBlockSuitable(World world, int x, int y, int z){
|
|
||||||
if (!(isInRange(x-1,y,z-1) && isInRange(x+1,y,z+1)) || getBlock(world,x,y+1,z) != Blocks.air)return false;
|
|
||||||
return getBlock(world,x+1,y,z) != Blocks.air && getBlock(world,x-1,y,z) != Blocks.air&&
|
|
||||||
getBlock(world,x,y,z+2) != Blocks.air && getBlock(world,x,y,z-1) != Blocks.air;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,52 @@
|
|||||||
|
package chylex.hee.world.feature.blobs.populators;
|
||||||
|
import java.util.Random;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import chylex.hee.world.feature.blobs.BlobPopulator;
|
||||||
|
import chylex.hee.world.feature.util.DecoratorFeatureGenerator;
|
||||||
|
|
||||||
|
public class BlobPopulatorLake extends BlobPopulator{
|
||||||
|
private Block liquid;
|
||||||
|
private double minRadius, maxRadius;
|
||||||
|
|
||||||
|
public BlobPopulatorLake(int weight){
|
||||||
|
super(weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlobPopulatorLake block(Block liquid){
|
||||||
|
this.liquid = liquid;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlobPopulatorLake rad(double minRadius, double maxRadius){
|
||||||
|
this.minRadius = minRadius;
|
||||||
|
this.maxRadius = maxRadius;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generate(DecoratorFeatureGenerator gen, Random rand){
|
||||||
|
double rad = minRadius+rand.nextDouble()*(maxRadius-minRadius);
|
||||||
|
int irad = (int)Math.ceil(rad);
|
||||||
|
|
||||||
|
for(int attempt = 0, x, y, z; attempt < 30; attempt++){
|
||||||
|
x = rand.nextInt(32)-16;
|
||||||
|
y = rand.nextInt(32)-16;
|
||||||
|
z = rand.nextInt(32)-16;
|
||||||
|
|
||||||
|
if (gen.getBlock(x,y,z) == Blocks.end_stone && gen.getBlock(x,y+1,z) == Blocks.air){
|
||||||
|
for(int xx = x-irad; xx <= x+irad; xx++){
|
||||||
|
for(int zz = z-irad; zz <= z+irad; zz++){
|
||||||
|
if (gen.getBlock(xx,y,zz) == Blocks.end_stone && gen.getBlock(xx,y+1,zz) == Blocks.air &&
|
||||||
|
gen.getBlock(xx-1,y,zz) == Blocks.air && gen.getBlock(xx+1,y,zz) == Blocks.air &&
|
||||||
|
gen.getBlock(xx,y,zz-1) == Blocks.air && gen.getBlock(xx,y,zz+1) == Blocks.air){
|
||||||
|
gen.setBlock(xx,y,zz,liquid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package chylex.hee.world.feature.blobs.populators;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import chylex.hee.world.feature.blobs.BlobPopulator;
|
||||||
|
import chylex.hee.world.feature.util.DecoratorFeatureGenerator;
|
||||||
|
import chylex.hee.world.util.BlockLocation;
|
||||||
|
import chylex.hee.world.util.IRandomAmount;
|
||||||
|
|
||||||
|
public class BlobPopulatorPlant extends BlobPopulator{
|
||||||
|
private Block plant;
|
||||||
|
private IRandomAmount amountGen;
|
||||||
|
private int minAttempts, maxAttempts, minPlantAmount, maxPlantAmount;
|
||||||
|
private boolean knownBlockLocations;
|
||||||
|
|
||||||
|
public BlobPopulatorPlant(int weight){
|
||||||
|
super(weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlobPopulatorPlant block(Block plant){
|
||||||
|
this.plant = plant;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlobPopulatorPlant attempts(int minAttempts, int maxAttempts){
|
||||||
|
this.minAttempts = (byte)minAttempts;
|
||||||
|
this.maxAttempts = (byte)maxAttempts;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlobPopulatorPlant blockAmount(IRandomAmount amountGen, int minPlantAmount, int maxPlantAmount){
|
||||||
|
this.amountGen = amountGen;
|
||||||
|
this.minPlantAmount = (byte)minPlantAmount;
|
||||||
|
this.maxPlantAmount = (byte)maxPlantAmount;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populator will know all generated blocks and use those to place ores, attempt amount will have an effect in cases when the random block is not air above End Stone.
|
||||||
|
*/
|
||||||
|
public BlobPopulatorPlant knownBlockLocations(){
|
||||||
|
this.knownBlockLocations = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generate(DecoratorFeatureGenerator gen, Random rand){
|
||||||
|
int blocks = amountGen.generate(rand,minPlantAmount,maxPlantAmount);
|
||||||
|
List<BlockLocation> locs = null;
|
||||||
|
|
||||||
|
for(int attempt = 0, attempts = minAttempts+rand.nextInt(maxAttempts-minAttempts+1), x, y, z; attempt < attempts && blocks > 0; attempt++){
|
||||||
|
if (knownBlockLocations){
|
||||||
|
if (attempt == 0)locs = gen.getUsedLocations();
|
||||||
|
if (locs.isEmpty())return;
|
||||||
|
|
||||||
|
BlockLocation loc = locs.get(rand.nextInt(locs.size()));
|
||||||
|
x = loc.x;
|
||||||
|
y = loc.y;
|
||||||
|
z = loc.z;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
x = rand.nextInt(32)-16;
|
||||||
|
y = rand.nextInt(32)-16;
|
||||||
|
z = rand.nextInt(32)-16;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gen.getBlock(x,y,z) == Blocks.air && gen.getBlock(x,y-1,z) == Blocks.end_stone){
|
||||||
|
gen.setBlock(x,y,z,plant);
|
||||||
|
--blocks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user