Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,6 @@ public void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator,

}

private static final Vec3i[] offsets = {
new Vec3i(-1,-1,-1),new Vec3i( 0,-1,-1),new Vec3i( 1,-1,-1),
new Vec3i(-1, 0,-1),new Vec3i( 0, 0,-1),new Vec3i( 1, 0,-1),
new Vec3i(-1, 1,-1),new Vec3i( 0, 1,-1),new Vec3i( 1, 1,-1),

new Vec3i(-1,-1, 0),new Vec3i( 0,-1, 0),new Vec3i( 1,-1, 0),
new Vec3i(-1, 0, 0),new Vec3i( 0, 0, 0),new Vec3i( 1, 0, 0),
new Vec3i(-1, 1, 0),new Vec3i( 0, 1, 0),new Vec3i( 1, 1, 0),

new Vec3i(-1,-1, 1),new Vec3i( 0,-1, 1),new Vec3i( 1,-1, 1),
new Vec3i(-1, 0, 1),new Vec3i( 0, 0, 1),new Vec3i( 1, 0, 1),
new Vec3i(-1, 1, 1),new Vec3i( 0, 1, 1),new Vec3i( 1, 1, 1)
};

private static final Vec3i[] offsets_small = {
new Vec3i( 0, 0, 0),new Vec3i( 1, 0, 0),
new Vec3i( 0, 1, 0),new Vec3i( 1, 1, 0),
Expand All @@ -113,62 +99,72 @@ public void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator,

public static void spawnOre( BlockPos blockPos, IBlockState oreBlock, int quantity, World world, Random prng, IBlockState replaceBlock) {
int count = quantity;
if(quantity <= 8){
int[] scrambledLUT = new int[offsetIndexRef_small.length];
System.arraycopy(offsetIndexRef_small, 0, scrambledLUT, 0, scrambledLUT.length);
int lutType = quantity <= 8?offsetIndexRef_small.length:offsetIndexRef.length;
int[] lut = quantity <= 8?offsetIndexRef_small:offsetIndexRef;

if( quantity < 27 ) {
int[] scrambledLUT = new int[lutType];
System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length);
scramble(scrambledLUT,prng);
while(count > 0){
spawn(oreBlock,world,blockPos.add(offsets_small[scrambledLUT[--count]]),world.provider.getDimension(),true,replaceBlock);
}
return;
}
if(quantity < 27){
int[] scrambledLUT = new int[offsetIndexRef.length];
System.arraycopy(offsetIndexRef, 0, scrambledLUT, 0, scrambledLUT.length);
scramble(scrambledLUT,prng);
while(count > 0){
spawn(oreBlock,world,blockPos.add(offsets[scrambledLUT[--count]]),world.provider.getDimension(),true,replaceBlock);
}
return;
}

doSpawnFill( prng.nextBoolean(), world, blockPos, count, replaceBlock, oreBlock );

return;
}

private static void doSpawnFill(boolean nextBoolean, World world, BlockPos blockPos, int quantity, IBlockState replaceBlock, IBlockState oreBlock ) {
int count = quantity;
double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2;
int rSqr = (int)(radius * radius);
fill:{
if(prng.nextBoolean()){ // switch-up the direction of fill to reduce predictability
// fill from north-east
for(int dy = (int)(-1 * radius); dy < radius; dy++){
for(int dz = (int)(-1 * radius); dz < radius; dz++){
for(int dx = (int)(-1 * radius); dx < radius; dx++){
if((dx*dx + dy*dy + dz*dz) <= rSqr){
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,replaceBlock);
count--;
}
if(count <= 0) {
break fill;
}
}
if( nextBoolean ) {
spawnMungeNE( world, blockPos, rSqr, radius, replaceBlock, count, oreBlock );
} else {
spawnMungeSW( world, blockPos, rSqr, radius, replaceBlock, count, oreBlock );
}
}


private static void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double radius,
IBlockState replaceBlock, int count, IBlockState oreBlock) {
int quantity = count;
for(int dy = (int)(-1 * radius); dy < radius; dy++){
for(int dx = (int)(radius); dx >= (int)(-1 * radius); dx--){
for(int dz = (int)(radius); dz >= (int)(-1 * radius); dz--){
if((dx*dx + dy*dy + dz*dz) <= rSqr){
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,replaceBlock);
quantity--;
}
}
} else {
// fill from south-west
for(int dy = (int)(-1 * radius); dy < radius; dy++){
for(int dx = (int)(radius); dx >= (int)(-1 * radius); dx--){
for(int dz = (int)(radius); dz >= (int)(-1 * radius); dz--){
if((dx*dx + dy*dy + dz*dz) <= rSqr){
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,replaceBlock);
count--;
}
if(count <= 0) {
break fill;
}
}
if(quantity <= 0) {
return;
}
}
}
}
return;
}


private static void spawnMungeNE(World world, BlockPos blockPos, int rSqr, double radius, IBlockState replaceBlock, int count, IBlockState oreBlock) {
int quantity = count;
for(int dy = (int)(-1 * radius); dy < radius; dy++){
for(int dz = (int)(-1 * radius); dz < radius; dz++){
for(int dx = (int)(-1 * radius); dx < radius; dx++){
if((dx*dx + dy*dy + dz*dz) <= rSqr){
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,replaceBlock);
quantity--;
}
if(quantity <= 0) {
return;
}
}
}
}
}

private static void scramble(int[] target, Random prng) {
for(int i = target.length - 1; i > 0; i--){
int n = prng.nextInt(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ public SpawnBuilder newSpawnBuilder( @Nullable String name) {

@Override
public DimensionBuilder create(SpawnBuilder... addedSpawns) {
/* if( !spawns.containsKey(UNNAMED) ) {
spawns.put(UNNAMED, new ArrayList<>() );
}
spawns.get(UNNAMED).addAll(Arrays.asList(addedSpawns).stream().collect(Collectors.<SpawnBuilder>toList()));
*/ return this;
return this;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ public SpawnBuilderImpl() {

@Override
public FeatureBuilder newFeatureBuilder(@Nullable String featureName) {
String featName;
this.featureGen = new FeatureBuilderImpl();
if( OreSpawn.FEATURES.getFeature(featureName) == null ) {
this.featureGen.setGenerator("default");
return this.featureGen;
if( OreSpawn.FEATURES.getFeature(featureName) == null || featureName == null) {
featName = "default";
} else {
featName = featureName;
}

this.featureGen.setGenerator(featureName);
this.featureGen.setGenerator(featName);
return this.featureGen;
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/mcmoddev/orespawn/util/StateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
import net.minecraft.block.state.IBlockState;

public class StateUtil {
private StateUtil() {
throw new InstantiationError("This class cannot be instantiated!");
}

public static String serializeState(IBlockState state) {
String string = state.toString();
string = string.substring(string.indexOf("[") + 1, string.length() - (string.endsWith("]") ? 1 : 0));
string = string.substring(string.indexOf('[') + 1, string.length() - (string.endsWith("]") ? 1 : 0));
if (string.equals(state.getBlock().getRegistryName().toString())) {
string = "normal";
}
Expand All @@ -16,7 +20,7 @@ public static String serializeState(IBlockState state) {
public static IBlockState deserializeState(Block block, String state) {
for (IBlockState validState : block.getBlockState().getValidStates()) {
String string = validState.toString();
string = string.substring(string.indexOf("[") + 1, string.length() - (string.endsWith("]") ? 1 : 0));
string = string.substring(string.indexOf('[') + 1, string.length() - (string.endsWith("]") ? 1 : 0));
if (string.equals(block.getRegistryName().toString())) {
string = "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG

for( SpawnBuilder sE : entries ) {
Biome biome = world.getBiomeProvider().getBiome(new BlockPos(chunkX*16, 64,chunkZ*16));
if( sE.getBiomes().matches(biome) || sE.getBiomes().getBiomes().size() == 0 ) {
if( sE.getBiomes().matches(biome) || sE.getBiomes().getBiomes().isEmpty() ) {
IFeature currentFeatureGen = sE.getFeatureGen().getGenerator();
IBlockState replacement = sE.getReplacementBlocks().get(0);
if( replacement == null ) {
Expand Down