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,13 +144,15 @@ 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);
init(); if (width * height * length != 0) {
// write length etc init();
mbb.position(2); // write length etc
last = Integer.MIN_VALUE; mbb.position(2);
mbb.putChar((char) width); last = Integer.MIN_VALUE;
mbb.putChar((char) height); mbb.putChar((char) width);
mbb.putChar((char) length); mbb.putChar((char) height);
mbb.putChar((char) length);
}
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -419,71 +421,55 @@ 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); } else {
} else { index = mbb.position();
index = mbb.position();
}
last = i;
mbb.position(index + 1);
// 00000000 00000000
// [ id ]data
byte id2 = mbb.get();
mbb.position(index);
mbb.put((byte) (id >> 4));
mbb.put((byte) (((id & 0xFF) << 4) + (id2 & 0xFF)));
} catch (Exception e) {
MainUtil.handleError(e);
} }
last = i;
mbb.position(index + 1);
// 00000000 00000000
// [ id ]data
byte id2 = mbb.get();
mbb.position(index);
mbb.put((byte) (id >> 4));
mbb.put((byte) (((id & 0xFF) << 4) + (id2 & 0xFF)));
} }
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;
mbb.putChar((char) combined);
} catch (Exception e) {
MainUtil.handleError(e);
} }
last = i;
mbb.putChar((char) combined);
} }
@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); // 00000000 00000000
// 00000000 00000000 // [ id ]data
// [ id ]data 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; } else {
} else { index = mbb.position() + 1;
index = mbb.position() + 1;
}
mbb.position(index);
last = i;
byte id = mbb.get();
mbb.position(index);
mbb.put((byte) ((id & 0xF0) + data));
} catch (Exception e) {
MainUtil.handleError(e);
} }
mbb.position(index);
last = i;
byte id = mbb.get();
mbb.position(index);
mbb.put((byte) ((id & 0xF0) + data));
} }
@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: