Fix disk clipboard initialization

This commit is contained in:
Jesse Boyd 2017-05-10 12:08:27 +10:00
parent d0a0c0360e
commit e03cb44b16
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
3 changed files with 47 additions and 61 deletions

View File

@ -68,7 +68,7 @@ public class NBTStreamer {
public static abstract class ByteReader extends RunnableVal2<Integer, Integer> { public static abstract class ByteReader extends RunnableVal2<Integer, Integer> {
@Override @Override
public void run(Integer index, Integer value) { public void run(Integer index, Integer value) {
run(index, value); run((int) index, (int) value);
} }
public abstract void run(int index, int byteValue); public abstract void run(int index, int byteValue);

View File

@ -61,7 +61,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
private FileChannel fc; private FileChannel fc;
public DiskOptimizedClipboard(int width, int height, int length, UUID uuid) { public DiskOptimizedClipboard(int width, int height, int length, UUID uuid) {
this(width, height, length, MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.CLIPBOARD + File.separator + uuid + ".bd")); this(width, height, length, MainUtil.getFile(Fawe.get() != null ? Fawe.imp().getDirectory() : new File("."), Settings.IMP.PATHS.CLIPBOARD + File.separator + uuid + ".bd"));
} }
public DiskOptimizedClipboard(File file) { public DiskOptimizedClipboard(File file) {
@ -144,6 +144,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
long volume = (long) width * (long) height * (long) length * 2l + (long) HEADER_SIZE; long volume = (long) width * (long) height * (long) length * 2l + (long) HEADER_SIZE;
braf.setLength(0); braf.setLength(0);
braf.setLength(volume); braf.setLength(volume);
if (width * height * length != 0) {
init(); init();
// write length etc // write length etc
mbb.position(2); mbb.position(2);
@ -151,6 +152,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
mbb.putChar((char) width); mbb.putChar((char) width);
mbb.putChar((char) height); mbb.putChar((char) height);
mbb.putChar((char) length); mbb.putChar((char) length);
}
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -419,7 +421,6 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
@Override @Override
public void setId(int i, int id) { public void setId(int i, int id) {
try {
int index; int index;
if (i != last + 1) { if (i != last + 1) {
index = (HEADER_SIZE) + (i << 1); index = (HEADER_SIZE) + (i << 1);
@ -434,26 +435,18 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
mbb.position(index); mbb.position(index);
mbb.put((byte) (id >> 4)); mbb.put((byte) (id >> 4));
mbb.put((byte) (((id & 0xFF) << 4) + (id2 & 0xFF))); mbb.put((byte) (((id & 0xFF) << 4) + (id2 & 0xFF)));
} catch (Exception e) {
MainUtil.handleError(e);
}
} }
public void setCombined(int i, int combined) { public void setCombined(int i, int combined) {
try {
if (i != last + 1) { if (i != last + 1) {
mbb.position((HEADER_SIZE) + (i << 1)); mbb.position((HEADER_SIZE) + (i << 1));
} }
last = i; last = i;
mbb.putChar((char) combined); mbb.putChar((char) combined);
} catch (Exception e) {
MainUtil.handleError(e);
}
} }
@Override @Override
public void setAdd(int i, int add) { public void setAdd(int i, int add) {
try {
last = i; last = i;
int index = (HEADER_SIZE) + (i << 1); int index = (HEADER_SIZE) + (i << 1);
mbb.position(index); mbb.position(index);
@ -462,14 +455,10 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
char combined = mbb.getChar(); char combined = mbb.getChar();
mbb.position(index); mbb.position(index);
mbb.putChar((char) ((combined & 0xFFFF) + (add << 12))); mbb.putChar((char) ((combined & 0xFFFF) + (add << 12)));
} catch (Exception e) {
MainUtil.handleError(e);
}
} }
@Override @Override
public void setData(int i, int data) { public void setData(int i, int data) {
try {
int index; int index;
if (i != last + 1) { if (i != last + 1) {
index = (HEADER_SIZE) + (i << 1) + 1; index = (HEADER_SIZE) + (i << 1) + 1;
@ -481,9 +470,6 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable {
byte id = mbb.get(); byte id = mbb.get();
mbb.position(index); mbb.position(index);
mbb.put((byte) ((id & 0xF0) + data)); mbb.put((byte) ((id & 0xF0) + data));
} catch (Exception e) {
MainUtil.handleError(e);
}
} }
@Override @Override

View File

@ -230,8 +230,8 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
if (typeAndData.length > 1 && !typeAndData[1].isEmpty()) { if (typeAndData.length > 1 && !typeAndData[1].isEmpty()) {
if (MathMan.isInteger(typeAndData[1])) { if (MathMan.isInteger(typeAndData[1])) {
data = Integer.parseInt(typeAndData[1]); data = Integer.parseInt(typeAndData[1]);
} else {
data = -1; // Some invalid value data = -1; // Some invalid value
} else {
BundledBlockData.BlockEntry block = BundledBlockData.getInstance().findById(blockId); BundledBlockData.BlockEntry block = BundledBlockData.getInstance().findById(blockId);
if (block != null && block.states != null) { if (block != null && block.states != null) {
loop: loop: