mirror of
https://github.com/LegacyModdingMC/ChunkAPI.git
synced 2026-11-17 19:05:17 +00:00
Implement AnvilChunkLoader coupling
This commit is contained in:
13 files changed
+477
-92
No files matched your search
@@ -1,13 +1,16 @@
|
||||
package com.falsepattern.chunk.internal.vanilla;
|
||||
|
||||
import com.falsepattern.chunk.api.ChunkDataManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class BiomeManager extends VanillaManager {
|
||||
public class BiomeManager extends VanillaManager implements ChunkDataManager.PacketDataManager, ChunkDataManager.ChunkNBTDataManager {
|
||||
public static final int BYTES_PER_CHUNK = 256;
|
||||
|
||||
@Override
|
||||
@@ -21,26 +24,34 @@ public class BiomeManager extends VanillaManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToBuffer(Chunk chunk, int ebsMask, boolean forceUpdate, ByteBuffer data) {
|
||||
public void writeToBuffer(@NotNull Chunk chunk, int ebsMask, boolean forceUpdate, @NotNull ByteBuffer data) {
|
||||
if (forceUpdate) {
|
||||
data.put(chunk.getBiomeArray());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromBuffer(Chunk chunk, int ebsMask, boolean forceUpdate, ByteBuffer buffer) {
|
||||
public void readFromBuffer(@NotNull Chunk chunk, int ebsMask, boolean forceUpdate, @NotNull ByteBuffer buffer) {
|
||||
if (forceUpdate) {
|
||||
buffer.get(chunk.getBiomeArray());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(Chunk chunk, @NotNull NBTTagCompound tag) {
|
||||
public boolean chunkPrivilegedAccess() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeChunkToNBT(@NotNull Chunk chunk, @NotNull NBTTagCompound nbt) {
|
||||
nbt.setByteArray("Biomes", chunk.getBiomeArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(Chunk chunk, @NotNull NBTTagCompound tag) {
|
||||
|
||||
public void readChunkFromNBT(@NotNull Chunk chunk, @NotNull NBTTagCompound nbt) {
|
||||
if (nbt.hasKey("Biomes", 7)) {
|
||||
chunk.setBiomeArray(nbt.getByteArray("Biomes"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,21 @@
|
||||
package com.falsepattern.chunk.internal.vanilla;
|
||||
|
||||
import com.falsepattern.chunk.api.ChunkDataManager;
|
||||
import lombok.val;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.NibbleArray;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static com.falsepattern.chunk.internal.Common.BLOCKS_PER_EBS;
|
||||
import static com.falsepattern.chunk.internal.Common.EBS_PER_CHUNK;
|
||||
|
||||
public class BlockIDManager extends VanillaManager {
|
||||
public class BlockIDManager extends VanillaManager implements ChunkDataManager.PacketDataManager, ChunkDataManager.SectionNBTDataManager {
|
||||
private static final int LSB_BYTES_PER_EBS = BLOCKS_PER_EBS;
|
||||
private static final int MSB_BYTES_PER_EBS = BLOCKS_PER_EBS / 2;
|
||||
private static final int HEADER_SIZE = 2;
|
||||
@@ -72,12 +76,25 @@ public class BlockIDManager extends VanillaManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(Chunk chunk, @NotNull NBTTagCompound tag) {
|
||||
|
||||
public boolean sectionPrivilegedAccess() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(Chunk chunk, @NotNull NBTTagCompound tag) {
|
||||
public void writeSectionToNBT(Chunk chunk, ExtendedBlockStorage ebs, NBTTagCompound section) {
|
||||
section.setByteArray("Blocks", ebs.getBlockLSBArray());
|
||||
|
||||
if (ebs.getBlockMSBArray() != null) {
|
||||
section.setByteArray("Add", ebs.getBlockMSBArray().data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSectionFromNBT(Chunk chunk, ExtendedBlockStorage ebs, NBTTagCompound section) {
|
||||
ebs.setBlockLSBArray(section.getByteArray("Blocks"));
|
||||
|
||||
if (section.hasKey("Add", 7)) {
|
||||
ebs.setBlockMSBArray(new NibbleArray(section.getByteArray("Add"), 4));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.falsepattern.chunk.internal.vanilla;
|
||||
|
||||
import com.falsepattern.chunk.api.ChunkDataManager;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.NibbleArray;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
|
||||
public class BlocklightManager extends NibbleManager {
|
||||
public class BlocklightManager extends NibbleManager implements ChunkDataManager.SectionNBTDataManager {
|
||||
@Override
|
||||
protected NibbleArray getNibbleArray(ExtendedBlockStorage ebs) {
|
||||
return ebs.getBlocklightArray();
|
||||
@@ -13,4 +17,19 @@ public class BlocklightManager extends NibbleManager {
|
||||
public String id() {
|
||||
return "blocklight";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sectionPrivilegedAccess() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSectionToNBT(Chunk chunk, ExtendedBlockStorage ebs, NBTTagCompound section) {
|
||||
section.setByteArray("BlockLight", ebs.getBlocklightArray().data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSectionFromNBT(Chunk chunk, ExtendedBlockStorage ebs, NBTTagCompound section) {
|
||||
ebs.setBlocklightArray(new NibbleArray(section.getByteArray("BlockLight"), 4));
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.falsepattern.chunk.internal.vanilla;
|
||||
|
||||
import com.falsepattern.chunk.api.ChunkDataManager;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.NibbleArray;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
|
||||
public class MetadataManager extends NibbleManager {
|
||||
public class MetadataManager extends NibbleManager implements ChunkDataManager.SectionNBTDataManager {
|
||||
@Override
|
||||
protected NibbleArray getNibbleArray(ExtendedBlockStorage ebs) {
|
||||
return ebs.getMetadataArray();
|
||||
@@ -13,4 +17,19 @@ public class MetadataManager extends NibbleManager {
|
||||
public String id() {
|
||||
return "metadata";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sectionPrivilegedAccess() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSectionToNBT(Chunk chunk, ExtendedBlockStorage ebs, NBTTagCompound section) {
|
||||
section.setByteArray("Data", ebs.getMetadataArray().data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSectionFromNBT(Chunk chunk, ExtendedBlockStorage ebs, NBTTagCompound section) {
|
||||
ebs.setBlockMetadataArray(new NibbleArray(section.getByteArray("Data"), 4));
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
package com.falsepattern.chunk.internal.vanilla;
|
||||
|
||||
import com.falsepattern.chunk.api.ChunkDataManager;
|
||||
import com.falsepattern.chunk.internal.Common;
|
||||
import lombok.val;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.NibbleArray;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public abstract class NibbleManager extends VanillaManager {
|
||||
public abstract class NibbleManager extends VanillaManager implements ChunkDataManager.PacketDataManager {
|
||||
public static final int BYTES_PER_EBS = Common.BLOCKS_PER_EBS / 2;
|
||||
|
||||
protected abstract NibbleArray getNibbleArray(ExtendedBlockStorage ebs);
|
||||
@@ -46,14 +45,4 @@ public abstract class NibbleManager extends VanillaManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(Chunk chunk, @NotNull NBTTagCompound tag) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(Chunk chunk, @NotNull NBTTagCompound tag) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
package com.falsepattern.chunk.internal.vanilla;
|
||||
|
||||
import com.falsepattern.chunk.api.ChunkDataManager;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.NibbleArray;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class SkylightManager extends NibbleManager {
|
||||
public class SkylightManager extends NibbleManager implements ChunkDataManager.SectionNBTDataManager {
|
||||
@Override
|
||||
public String id() {
|
||||
return "skylight";
|
||||
@@ -30,4 +33,25 @@ public class SkylightManager extends NibbleManager {
|
||||
super.readFromBuffer(chunk, ebsMask, forceUpdate, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sectionPrivilegedAccess() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSectionToNBT(Chunk chunk, ExtendedBlockStorage ebs, NBTTagCompound section) {
|
||||
if (!chunk.worldObj.provider.hasNoSky) {
|
||||
section.setByteArray("SkyLight", ebs.getSkylightArray().data);
|
||||
} else {
|
||||
section.setByteArray("SkyLight", new byte[ebs.getBlocklightArray().data.length]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSectionFromNBT(Chunk chunk, ExtendedBlockStorage ebs, NBTTagCompound section) {
|
||||
if (!chunk.worldObj.provider.hasNoSky) {
|
||||
ebs.setSkylightArray(new NibbleArray(section.getByteArray("SkyLight"), 4));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,9 @@ package com.falsepattern.chunk.internal.vanilla;
|
||||
|
||||
import com.falsepattern.chunk.api.ChunkDataManager;
|
||||
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
public abstract class VanillaManager implements ChunkDataManager<Chunk> {
|
||||
public abstract class VanillaManager implements ChunkDataManager {
|
||||
@Override
|
||||
public String domain() {
|
||||
return "minecraft";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Chunk chunk) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user