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
56 changes: 35 additions & 21 deletions src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private boolean spawnOrCache(World world, BlockPos coord, List<IBlockState> bloc
IBlockState targetBlock = world.getBlockState(coord);

if (canReplace(targetBlock, blockReplace)) {
world.setBlockState(coord, oreBlock, 22);
world.setBlockState(coord, oreBlock); // , 22);
return true;
} else {
return false;
Expand Down Expand Up @@ -229,33 +229,47 @@ protected int getPoint(int lowerBound, int upperBound, int median) {
return t - median;
}


protected void spawnMunge(FunctionParameterWrapper params, double radius, int count, boolean toPositive) {
int rSqr = (int)(radius * radius);
protected void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double radius,
List<IBlockState> replaceBlock, int count, OreList possibleOres) {
Random prng = this.random;
int quantity = count;

OreList possible = params.getOres();
World world = params.getWorld();
BlockPos blockPos = params.getBlockPos();
List<IBlockState> replace = params.getReplacements();
BiomeLocation biomes = params.getBiomes();

for (int dy = (int)(-1 * radius); dy < radius; dy++) {
for (int dx = getStart(toPositive, radius); endCheck(toPositive, dx, radius); dx = countItem(dx, toPositive)) {
for (int dz = getStart(toPositive, radius); endCheck(toPositive, dz, radius); dz = countItem(dz, toPositive)) {
if (getABC(dx, dy, dz) <= rSqr) {
IBlockState oreBlock = possible.getRandomOre(this.random).getOre();
spawn(oreBlock, world, blockPos.add(dx, dy, dz), world.provider.getDimension(), true, replace, biomes);

if (--quantity <= 0) {
return;
}
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){
IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre();
spawnOrCache(world,blockPos.add(dx,dy,dz),replaceBlock, oreBlock, true, world.provider.getDimension());
quantity--;
}
if(quantity <= 0) {
return;
}
}
}
}
}


protected void spawnMungeNE(World world, BlockPos blockPos, int rSqr, double radius,
List<IBlockState> replaceBlock, int count, OreList possibleOres) {
Random prng = this.random;
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){
IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre();
spawnOrCache(world,blockPos.add(dx,dy,dz),replaceBlock, oreBlock, true, world.provider.getDimension());
quantity--;
}
if(quantity <= 0) {
return;
}
}
}
}
}

protected int getABC(int dx, int dy, int dz) {
return (dx * dx + dy * dy + dz * dz);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,13 @@ private void spawnChunk(FunctionParameterWrapper params, int quantity) {
}

private void doSpawnFill(boolean nextBoolean, int quantity, FunctionParameterWrapper params) {
double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2;

if (nextBoolean) {
spawnMunge(params, radius, quantity, false);
int count = quantity;
double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2;
int rSqr = (int)(radius * radius);
if( nextBoolean ) {
spawnMungeNE( params.getWorld(), params.getBlockPos(), rSqr, radius, params.getReplacements(), count, params.getOres() );
} else {
spawnMunge(params, radius, quantity, true);
spawnMungeSW( params.getWorld(), params.getBlockPos(), rSqr, radius, params.getReplacements(), count, params.getOres() );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Random;

import com.google.gson.JsonObject;
import com.mcmoddev.orespawn.OreSpawn;
import com.mcmoddev.orespawn.api.BiomeLocation;
import com.mcmoddev.orespawn.api.FeatureBase;
import com.mcmoddev.orespawn.api.GeneratorParameters;
Expand Down Expand Up @@ -112,7 +113,8 @@ private void spawnOre(FunctionParameterWrapper params, int quantity) {

while (count > 0) {
IBlockState oreBlock = params.getOres().getRandomOre(this.random).getOre();
spawn(oreBlock, params.getWorld(), params.getBlockPos().add(offs[scrambledLUT[--count]]),
BlockPos target = params.getBlockPos().add(offs[scrambledLUT[--count]]);
spawn(oreBlock, params.getWorld(), target,
params.getWorld().provider.getDimension(), true, params.getReplacements(), params.getBiomes());
}

Expand All @@ -123,12 +125,13 @@ private void spawnOre(FunctionParameterWrapper params, int quantity) {
}

private void doSpawnFill(boolean nextBoolean, int quantity, FunctionParameterWrapper params) {
double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2;

if (nextBoolean) {
spawnMunge(params, radius, quantity, false);
int count = quantity;
double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2;
int rSqr = (int)(radius * radius);
if( nextBoolean ) {
spawnMungeNE( params.getWorld(), params.getBlockPos(), rSqr, radius, params.getReplacements(), count, params.getOres() );
} else {
spawnMunge(params, radius, quantity, true);
spawnMungeSW( params.getWorld(), params.getBlockPos(), rSqr, radius, params.getReplacements(), count, params.getOres() );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public OreBuilder setOre(String name, String serializedState) {
@SuppressWarnings("deprecation")
@Override
public OreBuilder setOre(String name, int metaData) {
this.setOre(name);
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(name));

if (this.ore == null) {
if (block == null) {
return this;
}

this.ore = this.ore.getBlock().getStateFromMeta(metaData);
this.ore = block.getStateFromMeta(metaData);
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void writeFile(File file, JsonObject wrapper) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();

try {
FileUtils.writeStringToFile(file, gson.toJson(wrapper), Charset.defaultCharset(), false);
FileUtils.writeStringToFile(file, gson.toJson(wrapper), "UTF8", false);
} catch (IOException e) {
CrashReport report = CrashReport.makeCrashReport(e, String.format("Failed in config %s", file.getName()));
report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/mcmoddev/orespawn/util/StateUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.mcmoddev.orespawn.util;

import com.mcmoddev.orespawn.OreSpawn;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;

Expand All @@ -15,7 +17,8 @@ public static String serializeState(IBlockState state) {
if (string.equals(state.getBlock().getRegistryName().toString())) {
string = "normal";
}


OreSpawn.LOGGER.fatal("State is %s (for block %s)", string, state.getBlock().getRegistryName());
return string;
}

Expand Down