Made a few schematic related fixes. Made the deprecation error more obvious.

Dieser Commit ist enthalten in:
Matthew Miller 2018-07-24 11:21:29 +10:00
Ursprung 9f9fda72b7
Commit 3f1f52d1f1
4 geänderte Dateien mit 27 neuen und 104 gelöschten Zeilen

Datei anzeigen

@ -22,8 +22,6 @@ package com.sk89q.worldedit;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.command.ClipboardCommands; import com.sk89q.worldedit.command.ClipboardCommands;
import com.sk89q.worldedit.command.SchematicCommands; import com.sk89q.worldedit.command.SchematicCommands;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
@ -32,11 +30,9 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.schematic.SchematicFormat; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.block.BlockTypes;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -83,7 +79,7 @@ public class CuboidClipboard {
checkNotNull(size); checkNotNull(size);
this.size = size; this.size = size;
data = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()]; data = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
origin = new Vector(); origin = new Vector();
offset = new Vector(); offset = new Vector();
} }
@ -100,7 +96,7 @@ public class CuboidClipboard {
checkNotNull(origin); checkNotNull(origin);
this.size = size; this.size = size;
data = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()]; data = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
this.origin = origin; this.origin = origin;
offset = new Vector(); offset = new Vector();
} }
@ -119,7 +115,7 @@ public class CuboidClipboard {
checkNotNull(offset); checkNotNull(offset);
this.size = size; this.size = size;
data = new BaseBlock[size.getBlockX()][size.getBlockY()][size.getBlockZ()]; data = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
this.origin = origin; this.origin = origin;
this.offset = offset; this.offset = offset;
} }
@ -160,8 +156,12 @@ public class CuboidClipboard {
for (int x = 0; x < size.getBlockX(); ++x) { for (int x = 0; x < size.getBlockX(); ++x) {
for (int y = 0; y < size.getBlockY(); ++y) { for (int y = 0; y < size.getBlockY(); ++y) {
for (int z = 0; z < size.getBlockZ(); ++z) { for (int z = 0; z < size.getBlockZ(); ++z) {
data[x][y][z] = BaseBlock fullBlock = editSession.getFullBlock(new Vector(x, y, z).add(getOrigin()));
editSession.getBlock(new Vector(x, y, z).add(getOrigin())); if (fullBlock.getNbtData() != null) {
data[x][y][z] = fullBlock;
} else {
data[x][y][z] = fullBlock.toImmutableState();
}
} }
} }
} }
@ -179,7 +179,12 @@ public class CuboidClipboard {
for (int z = 0; z < size.getBlockZ(); ++z) { for (int z = 0; z < size.getBlockZ(); ++z) {
final Vector pt = new Vector(x, y, z).add(getOrigin()); final Vector pt = new Vector(x, y, z).add(getOrigin());
if (region.contains(pt)) { if (region.contains(pt)) {
data[x][y][z] = editSession.getBlock(pt); BaseBlock fullBlock = editSession.getFullBlock(pt);
if (fullBlock.getNbtData() != null) {
data[x][y][z] = fullBlock;
} else {
data[x][y][z] = fullBlock.toImmutableState();
}
} else { } else {
data[x][y][z] = null; data[x][y][z] = null;
} }
@ -287,26 +292,6 @@ public class CuboidClipboard {
this.entities.add(new CopiedEntity(entity)); this.entities.add(new CopiedEntity(entity));
} }
/**
* Get the block at the given position.
*
* <p>If the position is out of bounds, air will be returned.</p>
*
* @param position the point, relative to the origin of the copy (0, 0, 0) and not to the actual copy origin
* @return air, if this block was outside the (non-cuboid) selection while copying
* @throws ArrayIndexOutOfBoundsException if the position is outside the bounds of the CuboidClipboard
* @deprecated use {@link #getBlock(Vector)} instead
*/
@Deprecated
public BlockStateHolder getPoint(Vector position) throws ArrayIndexOutOfBoundsException {
final BlockStateHolder block = getBlock(position);
if (block == null) {
return BlockTypes.AIR.getDefaultState();
}
return block;
}
/** /**
* Get the block at the given position. * Get the block at the given position.
* *
@ -327,7 +312,7 @@ public class CuboidClipboard {
* @param block the block to set * @param block the block to set
* @throws ArrayIndexOutOfBoundsException if the position is outside the bounds of the CuboidClipboard * @throws ArrayIndexOutOfBoundsException if the position is outside the bounds of the CuboidClipboard
*/ */
public void setBlock(Vector position, BaseBlock block) { public void setBlock(Vector position, BlockStateHolder block) {
data[position.getBlockX()][position.getBlockY()][position.getBlockZ()] = block; data[position.getBlockX()][position.getBlockY()][position.getBlockZ()] = block;
} }
@ -340,35 +325,6 @@ public class CuboidClipboard {
return size; return size;
} }
/**
* Saves the clipboard data to a .schematic-format file.
*
* @param path the path to the file to save
* @throws IOException thrown on I/O error
* @throws DataException thrown on error writing the data for other reasons
* @deprecated use {@link SchematicFormat#MCEDIT}
*/
@Deprecated
public void saveSchematic(File path) throws IOException, DataException {
checkNotNull(path);
SchematicFormat.MCEDIT.save(this, path);
}
/**
* Load a .schematic file into a clipboard.
*
* @param path the path to the file to load
* @return a clipboard
* @throws IOException thrown on I/O error
* @throws DataException thrown on error writing the data for other reasons
* @deprecated use {@link SchematicFormat#MCEDIT}
*/
@Deprecated
public static CuboidClipboard loadSchematic(File path) throws DataException, IOException {
checkNotNull(path);
return SchematicFormat.MCEDIT.load(path);
}
/** /**
* Get the origin point, which corresponds to where the copy was * Get the origin point, which corresponds to where the copy was
* originally copied from. The origin is the lowest possible X, Y, and * originally copied from. The origin is the lowest possible X, Y, and

Datei anzeigen

@ -57,7 +57,7 @@ public enum ClipboardFormat {
@Override @Override
public ClipboardWriter getWriter(OutputStream outputStream) throws IOException { public ClipboardWriter getWriter(OutputStream outputStream) throws IOException {
throw new UnsupportedOperationException("This clipboard format is deprecated."); throw new IOException("This clipboard format no longer supports saving.");
} }
@Override @Override
@ -85,7 +85,7 @@ public enum ClipboardFormat {
* *
* @param aliases an array of aliases by which this format may be referred to * @param aliases an array of aliases by which this format may be referred to
*/ */
private ClipboardFormat(String ... aliases) { ClipboardFormat(String... aliases) {
this.aliases = aliases; this.aliases = aliases;
} }

Datei anzeigen

@ -34,6 +34,8 @@ import com.sk89q.worldedit.CuboidClipboard;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.File; import java.io.File;
@ -181,12 +183,13 @@ public class MCEditSchematicFormat extends SchematicFormat {
for (int z = 0; z < length; ++z) { for (int z = 0; z < length; ++z) {
int index = y * width * length + z * width + x; int index = y * width * length + z * width + x;
BlockVector pt = new BlockVector(x, y, z); BlockVector pt = new BlockVector(x, y, z);
BaseBlock block = getBlockForId(blocks[index], blockData[index]); BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(blocks[index], blockData[index]);
if (tileEntitiesMap.containsKey(pt)) { if (tileEntitiesMap.containsKey(pt)) {
block.setNbtData(new CompoundTag(tileEntitiesMap.get(pt))); clipboard.setBlock(pt, new BaseBlock(state, new CompoundTag(tileEntitiesMap.get(pt))));
} else {
clipboard.setBlock(pt, state);
} }
clipboard.setBlock(pt, block);
} }
} }
} }
@ -201,7 +204,7 @@ public class MCEditSchematicFormat extends SchematicFormat {
@Override @Override
public void save(CuboidClipboard clipboard, File file) throws IOException, DataException { public void save(CuboidClipboard clipboard, File file) throws IOException, DataException {
throw new UnsupportedOperationException("Saving is deprecated"); throw new DataException("This clipboard format no longer supports saving.");
} }
@Override @Override

Datei anzeigen

@ -83,42 +83,6 @@ public abstract class SchematicFormat {
return lookupNames; return lookupNames;
} }
public BaseBlock getBlockForId(int id, short data) {
BaseBlock block;
switch (id) {
/*case BlockID.WALL_SIGN:
case BlockID.SIGN_POST:
block = new SignBlock(id, data);
break;
case BlockID.CHEST:
block = new ChestBlock(data);
break;
case BlockID.FURNACE:
case BlockID.BURNING_FURNACE:
block = new FurnaceBlock(id, data);
break;
case BlockID.DISPENSER:
block = new DispenserBlock(data);
break;
case BlockID.MOB_SPAWNER:
block = new MobSpawnerBlock(id);
break;
case BlockID.NOTE_BLOCK:
block = new NoteBlock(data);
break;*/
default:
block = new BaseBlock(id, data);
break;
}
return block;
}
/** /**
* Loads a schematic from the given file into a CuboidClipboard * Loads a schematic from the given file into a CuboidClipboard
* @param file The file to load from * @param file The file to load from