This repository has been archived by the owner on Aug 1, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package cofh.lib.world; | ||
|
||
import static cofh.lib.world.WorldGenMinableCluster.generateBlock; | ||
|
||
import cofh.lib.util.WeightedRandomBlock; | ||
|
||
import java.util.List; | ||
import java.util.Random; | ||
|
||
import net.minecraft.world.World; | ||
import net.minecraft.world.gen.feature.WorldGenerator; | ||
|
||
public class WorldGenMinablePlate extends WorldGenerator { | ||
|
||
private final List<WeightedRandomBlock> cluster; | ||
private final WeightedRandomBlock[] genBlock; | ||
private final int radius; | ||
public byte height = 1; | ||
public byte variation = 2; | ||
|
||
public WorldGenMinablePlate(List<WeightedRandomBlock> resource, int clusterSize, List<WeightedRandomBlock> block) { | ||
|
||
cluster = resource; | ||
radius = clusterSize; | ||
genBlock = block.toArray(new WeightedRandomBlock[block.size()]); | ||
} | ||
|
||
@Override | ||
public boolean generate(World world, Random rand, int x, int y, int z) { | ||
|
||
int size = radius; | ||
if (radius > variation + 1) | ||
size = rand.nextInt(radius - variation) + variation; | ||
final int dist = size * size; | ||
byte height = this.height; | ||
|
||
boolean r = false; | ||
for (int posX = x - size; posX <= x + size; ++posX) { | ||
int xDist = posX - x; | ||
xDist *= xDist; | ||
for (int posZ = z - size; posZ <= z + size; ++posZ) { | ||
int zSize = posZ - z; | ||
|
||
if (zSize * zSize + xDist <= dist) { | ||
for (int posY = y - height; posY <= y + height; ++posY) { | ||
r |= generateBlock(world, posX, posY, posZ, genBlock, cluster); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return r; | ||
} | ||
|
||
} |