Use BaseItem for item remapping
This commit is contained in:
parent
76cfbeb4d0
commit
08bdfe2fd9
@ -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<String, Integer> 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<String, Integer> remapItem(int id, int data) {
|
||||
|
@ -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<String, com.sk89q.jnbt.Tag> 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()));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user