From 912ea44cc8c04ab8667f43a34226b6fd8dad44c9 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 25 Apr 2016 04:54:32 +1000 Subject: [PATCH] Fixes Fixes #51 Fixes #49 --- .../object/changeset/DiskStorageHistory.java | 4 +- .../clipboard/DiskOptimizedClipboard.java | 52 ++++++++++++++++++- .../clipboard/MemoryOptimizedClipboard.java | 9 +++- .../java/com/sk89q/worldedit/EditSession.java | 6 ++- .../extent/clipboard/BlockArrayClipboard.java | 2 - 5 files changed, 64 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index aa06ec12..d64a86aa 100644 --- a/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -458,9 +458,7 @@ public class DiskStorageHistory implements ChangeSet, FaweChangeSet { try { NamedTag nt = stream.readNamedTag(); return nt != null ? ((CompoundTag) nt.getTag()) : null; - } catch (IOException e) { - e.printStackTrace(); - } + } catch (IOException ignore) {} } return null; } diff --git a/core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java b/core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java index fecfd8f5..a441138f 100644 --- a/core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java +++ b/core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java @@ -1,4 +1,54 @@ package com.boydti.fawe.object.clipboard; -public class DiskOptimizedClipboard { +import com.boydti.fawe.object.IntegerTrio; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.entity.BaseEntity; +import com.sk89q.worldedit.entity.Entity; +import com.sk89q.worldedit.extent.Extent; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; + +/** + * // TODO + * A clipboard with disk backed storage. (lower memory + loads on crash) + * - Uses an auto closable RandomAccessFile for getting / setting id / data + * - I don't know how to reduce nbt / entities to O(1) complexity, so it is stored in memory. + */ +public class DiskOptimizedClipboard extends FaweClipboard { + + private final HashMap nbtMap; + private final HashSet entities; + + public DiskOptimizedClipboard(int width, int height, int length) { + super(width, height, length); + nbtMap = new HashMap<>(); + entities = new HashSet(); + } + + @Override + public BaseBlock getBlock(int x, int y, int z) { + throw new UnsupportedOperationException("NOT IMPLEMENTED / WIP"); + } + + @Override + public boolean setBlock(int x, int y, int z, BaseBlock block) { + throw new UnsupportedOperationException("NOT IMPLEMENTED / WIP"); + } + + @Override + public Entity createEntity(Extent world, double x, double y, double z, float yaw, float pitch, BaseEntity entity) { + throw new UnsupportedOperationException("NOT IMPLEMENTED / WIP"); + } + + @Override + public List getEntities() { + throw new UnsupportedOperationException("NOT IMPLEMENTED / WIP"); + } + + @Override + public boolean remove(ClipboardEntity clipboardEntity) { + throw new UnsupportedOperationException("NOT IMPLEMENTED / WIP"); + } } diff --git a/core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java b/core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java index d618b3cd..9e8cddb5 100644 --- a/core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java +++ b/core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java @@ -61,8 +61,15 @@ public class MemoryOptimizedClipboard extends FaweClipboard { public boolean setBlock(int x, int y, int z, BaseBlock block) { final int id = block.getId(); switch (id) { - case 0: + case 0: { + int i = x + z * width + (y >> 4) * area; + byte[] idArray = ids[i]; + if (idArray != null) { + int y2 = y & 0xF; + idArray[y2] = 0; + } return true; + } case 54: case 130: case 142: diff --git a/core/src/main/java/com/sk89q/worldedit/EditSession.java b/core/src/main/java/com/sk89q/worldedit/EditSession.java index f16cb1e6..d8eb6512 100644 --- a/core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -605,8 +605,10 @@ public class EditSession implements Extent { return FaweCache.CACHE_BLOCK[combinedId4Data]; } try { - return this.world.getLazyBlock(new Vector(x, y, z)); + BaseBlock block = this.world.getBlock(new Vector(x, y, z)); + return block; } catch (Throwable e) { + e.printStackTrace(); return FaweCache.CACHE_BLOCK[combinedId4Data]; } } @@ -1464,7 +1466,7 @@ public class EditSession implements Extent { EditSession.this.flushQueue(); } }, true); - return this.changes = visitor.getAffected(); + return this.changes = copy.getAffected(); } /** diff --git a/core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index 3c18f839..fad2b2d5 100644 --- a/core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -78,8 +78,6 @@ public class BlockArrayClipboard implements Clipboard { this.mx = origin.getBlockX(); this.my = origin.getBlockY(); this.mz = origin.getBlockZ(); - - } @Override