Fixed a few more errors, and added legacy support to the item parser.

Dieser Commit ist enthalten in:
Matthew Miller 2018-07-24 17:12:50 +10:00
Ursprung bc2279f2f6
Commit 965e977411
13 geänderte Dateien mit 56 neuen und 101 gelöschten Zeilen

Datei anzeigen

@ -78,7 +78,7 @@ public class LazyBlock extends BaseBlock {
public CompoundTag getNbtData() {
if (!loaded) {
BaseBlock loadedBlock = extent.getFullBlock(position);
super.setNbtData(loadedBlock.getNbtData());
this.nbtData = loadedBlock.getNbtData();
loaded = true;
}
return super.getNbtData();

Datei anzeigen

@ -52,8 +52,7 @@ import javax.annotation.Nullable;
public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
private BlockState blockState;
@Nullable
private CompoundTag nbtData;
@Nullable CompoundTag nbtData;
/**
* Construct a block with a state.

Datei anzeigen

@ -20,10 +20,8 @@
package com.sk89q.worldedit.blocks;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.NbtValued;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.item.ItemType;
import javax.annotation.Nullable;
@ -39,20 +37,6 @@ public class BaseItem implements NbtValued {
@Nullable
private CompoundTag nbtData;
/**
* Construct the object.
*
* @param id ID of the item
*/
@Deprecated
public BaseItem(int id) {
ItemType type = LegacyMapper.getInstance().getItemFromLegacy(id);
if (type == null) {
type = ItemTypes.AIR;
}
this.itemType = type;
}
/**
* Construct the object.
*
@ -73,16 +57,6 @@ public class BaseItem implements NbtValued {
this.nbtData = tag;
}
/**
* Get the type of item.
*
* @return the id
*/
@Deprecated
public int getLegacyId() {
return this.itemType.getLegacyId();
}
/**
* Get the type of item.
*

Datei anzeigen

@ -31,16 +31,6 @@ public class BaseItemStack extends BaseItem {
private int amount = 1;
/**
* Construct the object with default stack size of one, with data value of 0.
*
* @param id with data value of 0.
*/
@Deprecated
public BaseItemStack(int id) {
super(id);
}
/**
* Construct the object with default stack size of one, with damage value of 0.
*
@ -50,18 +40,6 @@ public class BaseItemStack extends BaseItem {
super(itemType);
}
/**
* Construct the object.
*
* @param id type ID
* @param amount amount in the stack
*/
@Deprecated
public BaseItemStack(int id, int amount) {
super(id);
this.amount = amount;
}
/**
* Construct the object.
*
@ -73,19 +51,6 @@ public class BaseItemStack extends BaseItem {
this.amount = amount;
}
/**
* Construct the object.
*
* @param id type ID
* @param amount amount in the stack
* @param data data value
*/
@Deprecated
public BaseItemStack(int id, int amount, short data) {
super(id);
this.amount = amount;
}
/**
* Construct the object.
*

Datei anzeigen

@ -25,6 +25,8 @@ import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.LegacyMapper;
public class DefaultItemParser extends InputParser<BaseItem> {
@ -34,8 +36,26 @@ public class DefaultItemParser extends InputParser<BaseItem> {
@Override
public BaseItem parseFromInput(String input, ParserContext context) throws InputParseException {
BaseItem item = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries().getItemRegistry().createFromId(input);
BaseItem item = null;
// Legacy matcher
if (context.isTryingLegacy()) {
try {
String[] split = input.split(":");
ItemType type;
if (split.length == 1) {
type = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(split[0]));
} else {
type = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
}
item = new BaseItem(type);
} catch (NumberFormatException e) {
}
}
if (item == null) {
item = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries().getItemRegistry().createFromId(input);
}
if (item == null) {
throw new InputParseException("'" + input + "' did not match any item");

Datei anzeigen

@ -42,7 +42,9 @@ import com.sk89q.worldedit.extent.clipboard.io.legacycompat.SignCompatibilityHan
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.entity.EntityTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.storage.NBTConversions;
import java.io.IOException;
@ -196,7 +198,7 @@ public class SchematicReader implements ClipboardReader {
}
int index = y * width * length + z * width + x;
BaseBlock block = new BaseBlock(blocks[index], blockData[index]);
BlockState block = LegacyMapper.getInstance().getBlockFromLegacy(blocks[index], blockData[index]);
for (NBTCompatibilityHandler handler : COMPATIBILITY_HANDLERS) {
if (handler.isAffectedBlock(block)) {
handler.updateNBT(block, values);
@ -218,14 +220,14 @@ public class SchematicReader implements ClipboardReader {
for (int z = 0; z < length; ++z) {
int index = y * width * length + z * width + x;
BlockVector pt = new BlockVector(x, y, z);
BaseBlock block = new BaseBlock(blocks[index], blockData[index]);
if (tileEntitiesMap.containsKey(pt)) {
block.setNbtData(new CompoundTag(tileEntitiesMap.get(pt)));
}
BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(blocks[index], blockData[index]);
try {
clipboard.setBlock(region.getMinimumPoint().add(pt), block);
if (tileEntitiesMap.containsKey(pt)) {
clipboard.setBlock(region.getMinimumPoint().add(pt), new BaseBlock(state, new CompoundTag(tileEntitiesMap.get(pt))));
} else {
clipboard.setBlock(region.getMinimumPoint().add(pt), state);
}
} catch (WorldEditException e) {
switch (failedBlockSets) {
case 0:

Datei anzeigen

@ -21,10 +21,11 @@ package com.sk89q.worldedit.extent.clipboard.io.legacycompat;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import java.util.Map;
public interface NBTCompatibilityHandler {
boolean isAffectedBlock(BaseBlock block);
void updateNBT(BaseBlock block, Map<String, Tag> values);
boolean isAffectedBlock(BlockStateHolder block);
void updateNBT(BlockStateHolder block, Map<String, Tag> values);
}

Datei anzeigen

@ -27,18 +27,19 @@ import com.google.gson.JsonSyntaxException;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Map;
public class SignCompatibilityHandler implements NBTCompatibilityHandler {
@Override
public boolean isAffectedBlock(BaseBlock block) {
public boolean isAffectedBlock(BlockStateHolder block) {
return block.getBlockType() == BlockTypes.SIGN || block.getBlockType() == BlockTypes.WALL_SIGN;
}
@Override
public void updateNBT(BaseBlock block, Map<String, Tag> values) {
public void updateNBT(BlockStateHolder block, Map<String, Tag> values) {
for (int i = 0; i < 4; ++i) {
String key = "Text" + (i + 1);
Tag value = values.get(key);

Datei anzeigen

@ -36,7 +36,7 @@ public interface NbtValued {
*
* @return true if there is NBT data
*/
public boolean hasNbtData();
boolean hasNbtData();
/**
* Get the object's NBT data (tile entity data). The returned tag, if

Datei anzeigen

@ -29,16 +29,18 @@ import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
public class AnvilChunk implements Chunk {
private CompoundTag rootTag;
@ -256,16 +258,11 @@ public class AnvilChunk implements Chunk {
public BaseBlock getBlock(Vector position) throws DataException {
int id = getBlockID(position);
int data = getBlockData(position);
BaseBlock block;
block = new BaseBlock(id, data);
BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(id, data);
CompoundTag tileEntity = getBlockTileEntity(position);
if (tileEntity != null) {
((TileEntityBlock) block).setNbtData(tileEntity);
}
return block;
return new BaseBlock(state, tileEntity);
}
}

Datei anzeigen

@ -28,9 +28,11 @@ import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
import java.util.HashMap;
@ -178,14 +180,10 @@ public class OldChunk implements Chunk {
throw new DataException("Chunk does not contain position " + position);
}
BaseBlock block = new BaseBlock(id, dataVal);
BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(id, dataVal);
CompoundTag tileEntity = getBlockTileEntity(position);
if (tileEntity != null) {
block.setNbtData(tileEntity);
}
return block;
return new BaseBlock(state, tileEntity);
}
}

Datei anzeigen

@ -20,6 +20,7 @@
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import javax.annotation.Nullable;
@ -33,6 +34,7 @@ public class BundledItemRegistry implements ItemRegistry {
@Nullable
@Override
public BaseItem createFromId(String id) {
return new BaseItem(ItemTypes.get(id));
ItemType itemType = ItemTypes.get(id);
return itemType == null ? null : new BaseItem(itemType);
}
}

Datei anzeigen

@ -30,13 +30,14 @@ import com.sk89q.worldedit.world.chunk.AnvilChunk;
import com.sk89q.worldedit.world.chunk.Chunk;
import com.sk89q.worldedit.world.chunk.OldChunk;
import java.io.Closeable;
import java.io.IOException;
import java.util.Map;
/**
* Represents chunk storage mechanisms.
*/
public abstract class ChunkStore {
public abstract class ChunkStore implements Closeable {
/**
* >> to chunk
@ -86,11 +87,6 @@ public abstract class ChunkStore {
return new OldChunk(world, tag);
}
/**
* Close resources.
*
* @throws IOException on I/O error
*/
public void close() throws IOException {
}