Skip to content

Commit 0083c40

Browse files
authored
Merge pull request #104 from dshadowwolf/master-1.12
fix some issues - the issue reported by Morph about blocks from certa…
2 parents eef4099 + 95042d7 commit 0083c40

File tree

6 files changed

+58
-37
lines changed

6 files changed

+58
-37
lines changed

src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java

+35-21
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private boolean spawnOrCache(World world, BlockPos coord, List<IBlockState> bloc
108108
IBlockState targetBlock = world.getBlockState(coord);
109109

110110
if (canReplace(targetBlock, blockReplace)) {
111-
world.setBlockState(coord, oreBlock, 22);
111+
world.setBlockState(coord, oreBlock); // , 22);
112112
return true;
113113
} else {
114114
return false;
@@ -229,33 +229,47 @@ protected int getPoint(int lowerBound, int upperBound, int median) {
229229
return t - median;
230230
}
231231

232-
233-
protected void spawnMunge(FunctionParameterWrapper params, double radius, int count, boolean toPositive) {
234-
int rSqr = (int)(radius * radius);
232+
protected void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double radius,
233+
List<IBlockState> replaceBlock, int count, OreList possibleOres) {
234+
Random prng = this.random;
235235
int quantity = count;
236-
237-
OreList possible = params.getOres();
238-
World world = params.getWorld();
239-
BlockPos blockPos = params.getBlockPos();
240-
List<IBlockState> replace = params.getReplacements();
241-
BiomeLocation biomes = params.getBiomes();
242-
243-
for (int dy = (int)(-1 * radius); dy < radius; dy++) {
244-
for (int dx = getStart(toPositive, radius); endCheck(toPositive, dx, radius); dx = countItem(dx, toPositive)) {
245-
for (int dz = getStart(toPositive, radius); endCheck(toPositive, dz, radius); dz = countItem(dz, toPositive)) {
246-
if (getABC(dx, dy, dz) <= rSqr) {
247-
IBlockState oreBlock = possible.getRandomOre(this.random).getOre();
248-
spawn(oreBlock, world, blockPos.add(dx, dy, dz), world.provider.getDimension(), true, replace, biomes);
249-
250-
if (--quantity <= 0) {
251-
return;
252-
}
236+
for(int dy = (int)(-1 * radius); dy < radius; dy++){
237+
for(int dx = (int)(radius); dx >= (int)(-1 * radius); dx--){
238+
for(int dz = (int)(radius); dz >= (int)(-1 * radius); dz--){
239+
if((dx*dx + dy*dy + dz*dz) <= rSqr){
240+
IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre();
241+
spawnOrCache(world,blockPos.add(dx,dy,dz),replaceBlock, oreBlock, true, world.provider.getDimension());
242+
quantity--;
243+
}
244+
if(quantity <= 0) {
245+
return;
253246
}
254247
}
255248
}
256249
}
257250
}
258251

252+
253+
protected void spawnMungeNE(World world, BlockPos blockPos, int rSqr, double radius,
254+
List<IBlockState> replaceBlock, int count, OreList possibleOres) {
255+
Random prng = this.random;
256+
int quantity = count;
257+
for(int dy = (int)(-1 * radius); dy < radius; dy++){
258+
for(int dz = (int)(-1 * radius); dz < radius; dz++){
259+
for(int dx = (int)(-1 * radius); dx < radius; dx++){
260+
if((dx*dx + dy*dy + dz*dz) <= rSqr){
261+
IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre();
262+
spawnOrCache(world,blockPos.add(dx,dy,dz),replaceBlock, oreBlock, true, world.provider.getDimension());
263+
quantity--;
264+
}
265+
if(quantity <= 0) {
266+
return;
267+
}
268+
}
269+
}
270+
}
271+
}
272+
259273
protected int getABC(int dx, int dy, int dz) {
260274
return (dx * dx + dy * dy + dz * dz);
261275
}

src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,13 @@ private void spawnChunk(FunctionParameterWrapper params, int quantity) {
173173
}
174174

175175
private void doSpawnFill(boolean nextBoolean, int quantity, FunctionParameterWrapper params) {
176-
double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2;
177-
178-
if (nextBoolean) {
179-
spawnMunge(params, radius, quantity, false);
176+
int count = quantity;
177+
double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2;
178+
int rSqr = (int)(radius * radius);
179+
if( nextBoolean ) {
180+
spawnMungeNE( params.getWorld(), params.getBlockPos(), rSqr, radius, params.getReplacements(), count, params.getOres() );
180181
} else {
181-
spawnMunge(params, radius, quantity, true);
182+
spawnMungeSW( params.getWorld(), params.getBlockPos(), rSqr, radius, params.getReplacements(), count, params.getOres() );
182183
}
183184
}
184185

src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Random;
66

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

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

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

125127
private void doSpawnFill(boolean nextBoolean, int quantity, FunctionParameterWrapper params) {
126-
double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2;
127-
128-
if (nextBoolean) {
129-
spawnMunge(params, radius, quantity, false);
128+
int count = quantity;
129+
double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2;
130+
int rSqr = (int)(radius * radius);
131+
if( nextBoolean ) {
132+
spawnMungeNE( params.getWorld(), params.getBlockPos(), rSqr, radius, params.getReplacements(), count, params.getOres() );
130133
} else {
131-
spawnMunge(params, radius, quantity, true);
134+
spawnMungeSW( params.getWorld(), params.getBlockPos(), rSqr, radius, params.getReplacements(), count, params.getOres() );
132135
}
133136
}
134137

src/main/java/com/mcmoddev/orespawn/impl/os3/OreBuilderImpl.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ public OreBuilder setOre(String name, String serializedState) {
4747
@SuppressWarnings("deprecation")
4848
@Override
4949
public OreBuilder setOre(String name, int metaData) {
50-
this.setOre(name);
50+
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(name));
5151

52-
if (this.ore == null) {
52+
if (block == null) {
5353
return this;
5454
}
5555

56-
this.ore = this.ore.getBlock().getStateFromMeta(metaData);
56+
this.ore = block.getStateFromMeta(metaData);
5757
return this;
5858
}
5959

src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private void writeFile(File file, JsonObject wrapper) {
9494
Gson gson = new GsonBuilder().setPrettyPrinting().create();
9595

9696
try {
97-
FileUtils.writeStringToFile(file, gson.toJson(wrapper), Charset.defaultCharset(), false);
97+
FileUtils.writeStringToFile(file, gson.toJson(wrapper), "UTF8", false);
9898
} catch (IOException e) {
9999
CrashReport report = CrashReport.makeCrashReport(e, String.format("Failed in config %s", file.getName()));
100100
report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION);

src/main/java/com/mcmoddev/orespawn/util/StateUtil.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.mcmoddev.orespawn.util;
22

3+
import com.mcmoddev.orespawn.OreSpawn;
4+
35
import net.minecraft.block.Block;
46
import net.minecraft.block.state.IBlockState;
57

@@ -15,7 +17,8 @@ public static String serializeState(IBlockState state) {
1517
if (string.equals(state.getBlock().getRegistryName().toString())) {
1618
string = "normal";
1719
}
18-
20+
21+
OreSpawn.LOGGER.fatal("State is %s (for block %s)", string, state.getBlock().getRegistryName());
1922
return string;
2023
}
2124

0 commit comments

Comments
 (0)