From 54f62e689b00a12e79166c0c5c696bd37a053b21 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 14 Nov 2019 19:20:35 +0000 Subject: [PATCH] WIP level dat for MCAWorld --- .../com/boydti/fawe/jnbt/anvil/LevelDat.java | 46 +++++++++++ .../com/boydti/fawe/jnbt/anvil/MCAWorld.java | 82 +++++++++++++++++-- 2 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/LevelDat.java diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/LevelDat.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/LevelDat.java new file mode 100644 index 000000000..d4cd3329d --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/LevelDat.java @@ -0,0 +1,46 @@ +package com.boydti.fawe.jnbt.anvil; + +import com.boydti.fawe.object.io.PGZIPOutputStream; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.NBTInputStream; +import com.sk89q.jnbt.NBTOutputStream; +import it.unimi.dsi.fastutil.io.FastBufferedInputStream; +import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; + +import static com.google.common.base.Preconditions.checkArgument; + +public class LevelDat { + private final File file; + private CompoundTag tag; + + public LevelDat(File file) { + checkArgument(file.exists()); + this.file = file; + } + + public void load() throws IOException { + try (NBTInputStream nis = new NBTInputStream(new FastBufferedInputStream(new GZIPInputStream(new FastBufferedInputStream(new FileInputStream(file)))))) { + this.tag = (CompoundTag) nis.readNamedTag().getTag(); + } + } + + public void save() throws IOException { + if (this.tag != null) { + try (NBTOutputStream nos = new NBTOutputStream(new FastBufferedOutputStream(new GZIPOutputStream(new FastBufferedOutputStream(new FileOutputStream(file)))))) { + nos.writeNamedTag("", tag); + } + } + } + + public CompoundTag getTag() { + return tag; + } +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAWorld.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAWorld.java index 6c13f45e1..a13cd75b6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAWorld.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAWorld.java @@ -1,23 +1,93 @@ package com.boydti.fawe.jnbt.anvil; +import com.boydti.fawe.beta.IChunkGet; +import com.boydti.fawe.beta.implementation.packet.ChunkPacket; +import com.google.common.base.Preconditions; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.blocks.BaseItemStack; +import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; +import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.util.TreeGenerator; +import com.sk89q.worldedit.world.AbstractWorld; +import com.sk89q.worldedit.world.block.BlockState; -public class MCAWorld implements Extent { - @Override - public BlockVector3 getMinimumPoint() { - return null; +import javax.annotation.Nullable; +import java.io.File; + +import static com.google.common.base.Preconditions.checkArgument; + +public class MCAWorld extends AbstractWorld { + private final File path; + + public MCAWorld(File path) { + checkArgument(path.isDirectory()); + this.path = path; } @Override - public BlockVector3 getMaximumPoint() { - return null; + public String getName() { + return path.getName(); } + @Override public boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException { return false; } + + @Override + public boolean notifyAndLightBlock(BlockVector3 position, BlockState previousType) throws WorldEditException { + return false; + } + + @Override + public boolean clearContainerBlockContents(BlockVector3 position) { + return false; + } + + @Override + public void dropItem(Vector3 position, BaseItemStack item) { + + } + + @Override + public void simulateBlockMine(BlockVector3 position) { + + } + + @Override + public boolean regenerate(Region region, EditSession editSession) { + return false; + } + + @Override + public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 position) throws MaxChangedBlocksException { + return false; + } + + @Override + public BlockVector3 getSpawnPosition() { + return null; + } + + @Override + public void refreshChunk(int chunkX, int chunkZ) { + + } + + @Override + public IChunkGet get(int x, int z) { + return null; + } + + @Override + public void sendFakeChunk(@Nullable Player player, ChunkPacket packet) { + + } }