-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mixins for block palettes in Cubic Chunks save nbt
- Loading branch information
Showing
7 changed files
with
174 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,9 @@ classes | |
*.iml | ||
.idea | ||
|
||
# vscode | ||
.vscode | ||
|
||
# gradle | ||
build | ||
.gradle | ||
|
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
48 changes: 48 additions & 0 deletions
48
src/main/java/org/dimdev/jeid/mixin/modsupport/cubicchunks/MixinCubePrimer.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,48 @@ | ||
package org.dimdev.jeid.mixin.modsupport.cubicchunks; | ||
|
||
import io.github.opencubicchunks.cubicchunks.api.worldgen.CubePrimer; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.state.IBlockState; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Pseudo; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
@Pseudo | ||
@Mixin(CubePrimer.class) | ||
@SuppressWarnings("deprecation") | ||
public class MixinCubePrimer { | ||
@Shadow private static int getBlockIndex(int x, int y, int z) { return 0; } | ||
@Shadow @Final private static IBlockState DEFAULT_STATE; | ||
private int[] intData = new int[65536]; | ||
|
||
/** | ||
* Get the block state at the given location | ||
* | ||
* @param x cube local x | ||
* @param y cube local y | ||
* @param z cube local z | ||
* @return the block state | ||
*/ | ||
@Overwrite(remap = false) | ||
public IBlockState getBlockState(int x, int y, int z) { | ||
IBlockState state = Block.BLOCK_STATE_IDS.getByValue(intData[getBlockIndex(x, y, z)]); | ||
return state == null ? DEFAULT_STATE : state; | ||
} | ||
|
||
/** | ||
* Set the block state at the given location | ||
* | ||
* @param x cube local x | ||
* @param y cube local y | ||
* @param z cube local z | ||
* @param state the block state | ||
*/ | ||
@Overwrite(remap = false) | ||
public void setBlockState(int x, int y, int z, @Nonnull IBlockState state) { | ||
intData[getBlockIndex(x, y, z)] = Block.BLOCK_STATE_IDS.get(state); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/org/dimdev/jeid/mixin/modsupport/cubicchunks/MixinIONbtReader.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,51 @@ | ||
package org.dimdev.jeid.mixin.modsupport.cubicchunks; | ||
|
||
import io.github.opencubicchunks.cubicchunks.api.util.Coords; | ||
import io.github.opencubicchunks.cubicchunks.core.server.chunkio.IONbtReader; | ||
import io.github.opencubicchunks.cubicchunks.core.world.cube.Cube; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.nbt.NBTTagList; | ||
import net.minecraft.world.chunk.NibbleArray; | ||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage; | ||
import net.minecraft.world.World; | ||
import org.dimdev.jeid.INewBlockStateContainer; | ||
import org.dimdev.jeid.Utils; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Pseudo; | ||
|
||
@Pseudo | ||
@Mixin(IONbtReader.class) | ||
public class MixinIONbtReader { | ||
|
||
@Overwrite | ||
private static void readBlocks(NBTTagCompound nbt, World world, Cube cube) { | ||
boolean isEmpty = !nbt.hasKey("Sections");// is this an empty cube? | ||
if (!isEmpty) { | ||
NBTTagList sectionList = nbt.getTagList("Sections", 10); | ||
nbt = sectionList.getCompoundTagAt(0); | ||
|
||
ExtendedBlockStorage ebs = new ExtendedBlockStorage(Coords.cubeToMinBlock(cube.getY()), cube.getWorld().provider.hasSkyLight()); | ||
|
||
int[] palette = nbt.hasKey("Palette", 11) ? nbt.getIntArray("Palette") : null; | ||
//Utils.LOGGER.info("cube at {}, {} palette size {}", cube.getCoords().getX(), cube.getCoords().getZ(), palette.length); | ||
((INewBlockStateContainer) ebs.getData()).setTemporaryPalette(palette); | ||
|
||
byte[] abyte = nbt.getByteArray("Blocks"); | ||
NibbleArray data = new NibbleArray(nbt.getByteArray("Data")); | ||
NibbleArray add = nbt.hasKey("Add", 7) ? new NibbleArray(nbt.getByteArray("Add")) : null; | ||
|
||
ebs.getData().setDataFromNBT(abyte, data, add); | ||
|
||
ebs.setBlockLight(new NibbleArray(nbt.getByteArray("BlockLight"))); | ||
|
||
if (world.provider.hasSkyLight()) { | ||
ebs.setSkyLight(new NibbleArray(nbt.getByteArray("SkyLight"))); | ||
} | ||
|
||
ebs.recalculateRefCounts(); | ||
cube.setStorage(ebs); | ||
} | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/org/dimdev/jeid/mixin/modsupport/cubicchunks/MixinIONbtWriter.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,66 @@ | ||
package org.dimdev.jeid.mixin.modsupport.cubicchunks; | ||
|
||
//import io.github.opencubicchunks.cubicchunks.core.server.chunkio.IONbtWriter; | ||
import io.github.opencubicchunks.cubicchunks.core.world.cube.Cube; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.nbt.NBTTagList; | ||
import net.minecraft.world.chunk.Chunk; | ||
import net.minecraft.world.chunk.NibbleArray; | ||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage; | ||
import org.dimdev.jeid.INewBlockStateContainer; | ||
import org.dimdev.jeid.INewChunk; | ||
import org.dimdev.jeid.Utils; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Pseudo; | ||
|
||
@Pseudo | ||
@Mixin(targets = "io.github.opencubicchunks.cubicchunks.core.server.chunkio.IONbtWriter") | ||
public class MixinIONbtWriter { | ||
|
||
// @Overwrite | ||
// private static void writeBiomes(Chunk column, NBTTagCompound nbt) {// biomes | ||
// INewChunk newChunk = (INewChunk) column; | ||
// nbt.setIntArray("Biomes", newChunk.getIntBiomeArray()); | ||
// } | ||
|
||
// @Overwrite | ||
// private static void writeBiomes(Cube cube, NBTTagCompound nbt) {// biomes | ||
// byte[] biomes = cube.getBiomeArray(); | ||
// if (biomes != null) | ||
// nbt.setByteArray("Biomes", biomes); | ||
// } | ||
|
||
@Overwrite | ||
private static void writeBlocks(Cube cube, NBTTagCompound cubeNbt) { | ||
ExtendedBlockStorage ebs = cube.getStorage(); | ||
if (ebs == null) { | ||
return; // no data to save anyway | ||
} | ||
NBTTagList sectionList = new NBTTagList(); | ||
NBTTagCompound section = new NBTTagCompound(); | ||
sectionList.appendTag(section); | ||
cubeNbt.setTag("Sections", sectionList); | ||
byte[] abyte = new byte[Cube.SIZE * Cube.SIZE * Cube.SIZE]; | ||
NibbleArray data = new NibbleArray(); | ||
NibbleArray add = ebs.getData().getDataForNBT(abyte, data); | ||
|
||
int[] palette = ((INewBlockStateContainer) ebs.getData()).getTemporaryPalette(); | ||
//Utils.LOGGER.info("cube at {}, {} palette size {}", cube.getCoords().getX(), cube.getCoords().getZ(), palette.length); | ||
if (palette != null) section.setIntArray("Palette", palette); | ||
|
||
section.setByteArray("Blocks", abyte); | ||
section.setByteArray("Data", data.getData()); | ||
|
||
if (add != null) { | ||
section.setByteArray("Add", add.getData()); | ||
} | ||
|
||
section.setByteArray("BlockLight", ebs.getBlockLight().getData()); | ||
|
||
if (cube.getWorld().provider.hasSkyLight()) { | ||
section.setByteArray("SkyLight", ebs.getSkyLight().getData()); | ||
} | ||
} | ||
|
||
} |
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