Skip to content

Commit 4d205e4

Browse files
committed
fix a corner-case and an issue where I got a bit too... happy with deleting duplicated code - this solves the issue (#57) reported by @DraKay on github
1 parent db25704 commit 4d205e4

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

src/main/java/com/mcmoddev/orespawn/EventHandlers.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public EventHandlers() {
3737

3838
@SubscribeEvent
3939
public void onGenerateMinable(OreGenEvent.GenerateMinable event) {
40-
event.setResult(Event.Result.DENY);
40+
if( Config.getBoolean(Constants.RETROGEN_KEY) ) {
41+
event.setResult(Event.Result.DENY);
42+
}
4143
}
4244

4345
@SubscribeEvent

src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
3939
for (int z = chunkPos.getZStart(); z <= chunkPos.getZEnd(); z++) {
4040
BlockPos pos = new BlockPos(x, y, z);
4141
Block block = player.world.getBlockState(pos).getBlock();
42-
42+
4343
if (OreSpawnWorldGen.getSpawnBlocks().contains(block)) {
4444
player.world.setBlockToAir(pos);
4545
}

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

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@ public void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator,
4444
int chunkZ = pos.z;
4545
Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension());
4646
Map<BlockPos,IBlockState> cache = retrieveCache(chunkCoord);
47-
for(Entry<BlockPos,IBlockState> ent : cache.entrySet()){
48-
spawn(cache.get(ent.getKey()),world,ent.getKey(),world.provider.getDimension(),false,replaceBlock);
47+
48+
if( !cache.isEmpty() ) { // if there is something in the cache, try to spawn it
49+
for(Entry<BlockPos,IBlockState> ent : cache.entrySet()){
50+
spawn(cache.get(ent.getKey()),world,ent.getKey(),world.provider.getDimension(),false,replaceBlock);
51+
}
4952
}
53+
5054
// now to ore spawn
5155

5256
int blockX = chunkX * 16 + 8;
@@ -94,20 +98,38 @@ public void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator,
9498
new Vec3i( 0, 0, 1),new Vec3i( 1, 0, 1),
9599
new Vec3i( 0, 1, 1),new Vec3i( 1, 1, 1)
96100
};
101+
102+
private static final Vec3i[] offsets = {
103+
new Vec3i(-1,-1,-1),new Vec3i( 0,-1,-1),new Vec3i( 1,-1,-1),
104+
new Vec3i(-1, 0,-1),new Vec3i( 0, 0,-1),new Vec3i( 1, 0,-1),
105+
new Vec3i(-1, 1,-1),new Vec3i( 0, 1,-1),new Vec3i( 1, 1,-1),
106+
107+
new Vec3i(-1,-1, 0),new Vec3i( 0,-1, 0),new Vec3i( 1,-1, 0),
108+
new Vec3i(-1, 0, 0),new Vec3i( 0, 0, 0),new Vec3i( 1, 0, 0),
109+
new Vec3i(-1, 1, 0),new Vec3i( 0, 1, 0),new Vec3i( 1, 1, 0),
110+
111+
new Vec3i(-1,-1, 1),new Vec3i( 0,-1, 1),new Vec3i( 1,-1, 1),
112+
new Vec3i(-1, 0, 1),new Vec3i( 0, 0, 1),new Vec3i( 1, 0, 1),
113+
new Vec3i(-1, 1, 1),new Vec3i( 0, 1, 1),new Vec3i( 1, 1, 1)
114+
};
115+
97116
private static final int[] offsetIndexRef = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26};
98117
private static final int[] offsetIndexRef_small = {0,1,2,3,4,5,6,7};
99118

100119
public static void spawnOre( BlockPos blockPos, IBlockState oreBlock, int quantity, World world, Random prng, IBlockState replaceBlock) {
101120
int count = quantity;
102-
int lutType = quantity <= 8?offsetIndexRef_small.length:offsetIndexRef.length;
103-
int[] lut = quantity <= 8?offsetIndexRef_small:offsetIndexRef;
121+
int lutType = (quantity < 8)?offsetIndexRef_small.length:offsetIndexRef.length;
122+
int[] lut = (quantity < 8)?offsetIndexRef_small:offsetIndexRef;
123+
Vec3i[] offs = new Vec3i[lutType];
124+
125+
System.arraycopy((quantity < 8)?offsets_small:offsets, 0, offs, 0, lutType);
104126

105127
if( quantity < 27 ) {
106128
int[] scrambledLUT = new int[lutType];
107129
System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length);
108130
scramble(scrambledLUT,prng);
109131
while(count > 0){
110-
spawn(oreBlock,world,blockPos.add(offsets_small[scrambledLUT[--count]]),world.provider.getDimension(),true,replaceBlock);
132+
spawn(oreBlock,world,blockPos.add(offs[scrambledLUT[--count]]),world.provider.getDimension(),true,replaceBlock);
111133
}
112134
return;
113135
}

0 commit comments

Comments
 (0)