Skip to content

Commit

Permalink
chore: update minestom
Browse files Browse the repository at this point in the history
  • Loading branch information
mworzala committed Dec 22, 2024
1 parent d46f28e commit b8d2a76
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
metadata.format.version = "1.1"

[versions]
minestom = "1_20_5-323c75f8a5"
minestom = "c976f345d1"
logback = "1.4.5" # For tests only

nexuspublish = "1.3.0"
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/net/hollowcube/schem/Schematic.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.minestom.server.instance.batch.BatchOption;
import net.minestom.server.instance.batch.RelativeBlockBatch;
import net.minestom.server.instance.block.Block;
import net.minestom.server.utils.Utils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -18,7 +17,6 @@
/**
* Represents a schematic file which can be manipulated in the world.
*/
@SuppressWarnings("UnstableApiUsage")
public record Schematic(
Point size,
Point offset,
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/net/hollowcube/schem/SchematicBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import net.minestom.server.coordinate.Point;
import net.minestom.server.coordinate.Vec;
import net.minestom.server.instance.block.Block;
import net.minestom.server.utils.Utils;
import org.jetbrains.annotations.NotNull;

import java.nio.ByteBuffer;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

@SuppressWarnings("UnstableApiUsage")
public class SchematicBuilder {

// Point -> Block, a missing value is air
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/net/hollowcube/schem/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.hollowcube.schem;

import java.nio.ByteBuffer;

public class Utils {
public static void writeVarInt(ByteBuffer buf, int value) {
if ((value & (0xFFFFFFFF << 7)) == 0) {
buf.put((byte) value);
} else if ((value & (0xFFFFFFFF << 14)) == 0) {
buf.putShort((short) ((value & 0x7F | 0x80) << 8 | (value >>> 7)));
} else if ((value & (0xFFFFFFFF << 21)) == 0) {
buf.put((byte) (value & 0x7F | 0x80));
buf.put((byte) ((value >>> 7) & 0x7F | 0x80));
buf.put((byte) (value >>> 14));
} else if ((value & (0xFFFFFFFF << 28)) == 0) {
buf.putInt((value & 0x7F | 0x80) << 24 | (((value >>> 7) & 0x7F | 0x80) << 16)
| ((value >>> 14) & 0x7F | 0x80) << 8 | (value >>> 21));
} else {
buf.putInt((value & 0x7F | 0x80) << 24 | ((value >>> 7) & 0x7F | 0x80) << 16
| ((value >>> 14) & 0x7F | 0x80) << 8 | ((value >>> 21) & 0x7F | 0x80));
buf.put((byte) (value >>> 28));
}
}

public static int readVarInt(ByteBuffer buf) {
// https://github.com/jvm-profiling-tools/async-profiler/blob/a38a375dc62b31a8109f3af97366a307abb0fe6f/src/converter/one/jfr/JfrReader.java#L393
int result = 0;
for (int shift = 0; ; shift += 7) {
byte b = buf.get();
result |= (b & 0x7f) << shift;
if (b >= 0) {
return result;
}
}
}
}

0 comments on commit b8d2a76

Please sign in to comment.