-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #373 from mircokroon/chunk-fix
Fixed issues with savings chunks in some situations
- Loading branch information
Showing
12 changed files
with
249 additions
and
31 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
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
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
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
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
61 changes: 61 additions & 0 deletions
61
src/main/java/game/data/chunk/palette/PaletteTransformer.java
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,61 @@ | ||
package game.data.chunk.palette; | ||
|
||
import game.data.chunk.version.ChunkSection_1_16; | ||
import game.data.chunk.version.encoder.BlockLocationEncoder; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* Transforms a direct palette to a real palette. | ||
*/ | ||
public class PaletteTransformer { | ||
BlockLocationEncoder locationEncoder; | ||
Palette oldPalette; | ||
Palette newPalette; | ||
|
||
public PaletteTransformer(BlockLocationEncoder locationEncoder, DirectPalette oldPalette) { | ||
this.locationEncoder = locationEncoder; | ||
this.oldPalette = oldPalette; | ||
this.newPalette = new Palette(new int[] { }); | ||
|
||
if (oldPalette.type == PaletteType.BIOMES) { | ||
newPalette.biomePalette(); | ||
} | ||
} | ||
|
||
public long[] transform(long[] data) { | ||
if (data.length == 0) { | ||
return data; | ||
} | ||
|
||
// first add every block in the chunk to the new palette | ||
for (int z = 0; z < 16; z++) { | ||
for (int x = 0; x < 16; x++) { | ||
for (int y = 0; y < 16; y++) { | ||
locationEncoder.setTo(x, y, z, oldPalette.getBitsPerBlock()); | ||
newPalette.getIndexFor(null, locationEncoder.fetch(data)); | ||
} | ||
} | ||
} | ||
|
||
newPalette.recomputeBitsPerBlock(); | ||
|
||
// copy all blocks to the new palette | ||
long[] newData = new long[ChunkSection_1_16.longsRequired(newPalette.getBitsPerBlock())]; | ||
for (int z = 0; z < 16; z++) { | ||
for (int x = 0; x < 16; x++) { | ||
for (int y = 0; y < 16; y++) { | ||
locationEncoder.setTo(x, y, z, oldPalette.getBitsPerBlock()); | ||
int index = newPalette.getIndexFor(null, locationEncoder.fetch(data)); | ||
|
||
locationEncoder.setTo(x, y, z, newPalette.getBitsPerBlock()); | ||
locationEncoder.write(newData, index); | ||
} | ||
} | ||
} | ||
return newData; | ||
} | ||
|
||
public Palette getNewPalette() { | ||
return newPalette; | ||
} | ||
} |
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,21 @@ | ||
package game.data.chunk.palette; | ||
|
||
public enum PaletteType { | ||
BLOCKS(4, 8), | ||
BIOMES(1, 3); | ||
|
||
private final int minBitsPerBlock, maxBitsPerBlock; | ||
|
||
PaletteType(int minBitsPerBlock, int maxBitsPerBlock) { | ||
this.minBitsPerBlock = minBitsPerBlock; | ||
this.maxBitsPerBlock = maxBitsPerBlock; | ||
} | ||
|
||
public int getMinBitsPerBlock() { | ||
return minBitsPerBlock; | ||
} | ||
|
||
public int getMaxBitsPerBlock() { | ||
return maxBitsPerBlock; | ||
} | ||
} |
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
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
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
Oops, something went wrong.