From 08bdfe2fd9fd5b2c44acd52c2b4cb0dac010b561 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 7 Oct 2017 15:59:18 +1100 Subject: [PATCH] Use BaseItem for item remapping --- .../object/clipboard/ClipboardRemapper.java | 29 ++++++++++--------- .../core/converter/MCAFile2LevelDB.java | 9 +++--- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/com/boydti/fawe/object/clipboard/ClipboardRemapper.java b/core/src/main/java/com/boydti/fawe/object/clipboard/ClipboardRemapper.java index cb4d2d88..dba7a3dd 100644 --- a/core/src/main/java/com/boydti/fawe/object/clipboard/ClipboardRemapper.java +++ b/core/src/main/java/com/boydti/fawe/object/clipboard/ClipboardRemapper.java @@ -8,9 +8,9 @@ import com.google.gson.JsonParser; import com.intellectualcrafters.plot.util.MathMan; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.regions.Region; @@ -50,12 +50,13 @@ public class ClipboardRemapper { return tmp; } - public BaseBlock remapItem(String name, int damage) { - if (name.isEmpty()) return EditSession.nullBlock; + public BaseItem remapItem(String name, int damage) { + if (name.isEmpty()) return new BaseItem(0); if (from == RemapPlatform.PC) { BundledBlockData.BlockEntry state = BundledBlockData.getInstance().findById(name); if (state != null) { - return remap(new BaseBlock(state.legacyId, damage)); + BaseBlock remapped = remap(new BaseBlock(state.legacyId, damage)); + return new BaseItem(remapped.getId(), (short) remapped.getData()); } else { try { name = name.replace("minecraft:", ""); @@ -64,14 +65,14 @@ public class ClipboardRemapper { Map mapTo = scraper.scapeOrCache(from.opposite()); scraper.expand(mapTo); switch (name) { - case "spruce_boat": return new BaseBlock(333, 1); - case "birch_boat": return new BaseBlock(333, 2); - case "jungle_boat": return new BaseBlock(333, 3); - case "acacia_boat": return new BaseBlock(333, 4); - case "dark_oak_boat": return new BaseBlock(333, 5); - case "water_bucket": return new BaseBlock(325, 8); - case "lava_bucket": return new BaseBlock(325, 10); - case "milk_bucket": return new BaseBlock(325, 1); + case "spruce_boat": return new BaseItem(333, (short) 1); + case "birch_boat": return new BaseItem(333, (short) 2); + case "jungle_boat": return new BaseItem(333, (short) 3); + case "acacia_boat": return new BaseItem(333, (short) 4); + case "dark_oak_boat": return new BaseItem(333, (short) 5); + case "water_bucket": return new BaseItem(325, (short) 8); + case "lava_bucket": return new BaseItem(325, (short) 10); + case "milk_bucket": return new BaseItem(325, (short) 1); case "tipped_arrow": case "spectral_arrow": name = "arrow"; // Unsupported @@ -86,13 +87,13 @@ public class ClipboardRemapper { Integer itemId = mapTo.get(name); if (itemId == null) itemId = mapTo.get(name.replace("_", "")); if (itemId == null) itemId = mapFrom.get(name); - if (itemId != null) return new BaseBlock(itemId, damage); + if (itemId != null) return new BaseItem(itemId, (short) damage); } catch (IOException ignore) { ignore.printStackTrace(); } } } - return EditSession.nullBlock; + return new BaseItem(0); } public Map.Entry remapItem(int id, int data) { diff --git a/nukkit/src/main/java/com/boydti/fawe/nukkit/core/converter/MCAFile2LevelDB.java b/nukkit/src/main/java/com/boydti/fawe/nukkit/core/converter/MCAFile2LevelDB.java index f90618d9..75d651fd 100644 --- a/nukkit/src/main/java/com/boydti/fawe/nukkit/core/converter/MCAFile2LevelDB.java +++ b/nukkit/src/main/java/com/boydti/fawe/nukkit/core/converter/MCAFile2LevelDB.java @@ -27,6 +27,7 @@ import com.sk89q.jnbt.NamedTag; import com.sk89q.jnbt.ShortTag; import com.sk89q.jnbt.StringTag; import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.world.registry.BundledBlockData; import java.io.ByteArrayOutputStream; import java.io.DataOutput; @@ -435,9 +436,9 @@ public class MCAFile2LevelDB extends MapConverter { private CompoundTag transformItem(CompoundTag item) { String itemId = item.getString("id"); short damage = item.getShort("Damage"); - BaseBlock remapped = remapper.remapItem(itemId, damage); + BaseItem remapped = remapper.remapItem(itemId, damage); Map map = ReflectionUtils.getMap(item.getValue()); - map.put("id", new ShortTag((short) remapped.getId())); + map.put("id", new ShortTag((short) remapped.getType())); map.put("Damage", new ShortTag((short) remapped.getData())); CompoundTag tag = (CompoundTag) item.getValue().get("tag"); @@ -476,8 +477,8 @@ public class MCAFile2LevelDB extends MapConverter { String item = tag.getString("Item"); if (item != null) { short damage = tag.getShort("Data"); - BaseBlock remapped = remapper.remapItem(item, damage); - map.put("Item", new ShortTag((short) remapped.getId())); + BaseItem remapped = remapper.remapItem(item, damage); + map.put("Item", new ShortTag((short) remapped.getType())); map.put("mData", new IntTag(remapped.getData())); } }