Skip to content

Commit

Permalink
Resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriM1 committed Mar 27, 2024
1 parent 875f43b commit 84d4487
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 25 deletions.
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ dependencies {
exclude(group = "org.iq80.leveldb", module = "leveldb")
}
api(libs.snappy)
api(libs.expiringmap)
api(libs.jwt)
api(libs.bundles.terminal)
api(libs.bundles.log4j)
Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ snakeyaml = { group = "org.yaml", name = "snakeyaml", version = "1.33" }
leveldb = { group = "org.iq80.leveldb", name = "leveldb", version = "0.11-SNAPSHOT" }
leveldbjni = { group = "net.daporkchop", name = "leveldb-mcpe-jni", version = "0.0.10-SNAPSHOT" }
snappy = { group = "org.xerial.snappy", name = "snappy-java", version = "1.1.10.5" }
expiringmap = { group = "net.jodah", name = "expiringmap", version = "0.5.11" }
jwt = { group = "com.nimbusds", name = "nimbus-jose-jwt", version = "9.13" }
jopt-simple = { group = "net.sf.jopt-simple", name = "jopt-simple", version = "5.0.4" }
blockstateupdater = { group = "org.cloudburstmc", name = "block-state-updater", version = "1.20.10-SNAPSHOT" }
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -883,13 +883,12 @@ public Position getNextPosition() {
return this.newPosition != null ? new Position(this.newPosition.x, this.newPosition.y, this.newPosition.z, this.level) : this.getPosition();
}

private static final Vector3 ZERO_VECTOR3 = new Vector3(0, 0, 0);

public Vector3 getPositionOffset() {
public AxisAlignedBB getNextPositionBB() {
if (this.newPosition == null) {
return ZERO_VECTOR3;
return this.boundingBox;
}
return this.newPosition.subtract(this);
Vector3 diff = this.newPosition.subtract(this);
return this.boundingBox.getOffsetBoundingBox(diff.x, diff.y, diff.z);
}

/**
Expand Down Expand Up @@ -2249,7 +2248,7 @@ public boolean onUpdate(int currentTick) {

this.resetFallDistance();
} else {
if (this.checkMovement && this.riptideTicks < 1 && !this.isGliding() && !server.getAllowFlight() && this.inAirTicks > 20 && !this.getAllowFlight() && !this.isSleeping() && !this.isImmobile() && !this.isSwimming() && this.riding == null && !this.hasEffect(Effect.LEVITATION) && !this.hasEffect(Effect.SLOW_FALLING) && this.speed != null && !ZERO_VECTOR3.equals(this.speed)) {
if (this.checkMovement && this.riptideTicks < 1 && !this.isGliding() && !server.getAllowFlight() && this.inAirTicks > 20 && !this.getAllowFlight() && !this.isSleeping() && !this.isImmobile() && !this.isSwimming() && this.riding == null && !this.hasEffect(Effect.LEVITATION) && !this.hasEffect(Effect.SLOW_FALLING) && this.speed != null && !(this.speed.x == 0 && this.speed.y == 0 && this.speed.z == 0)) {
double expectedVelocity = (-this.getGravity()) / ((double) this.getDrag()) - ((-this.getGravity()) / ((double) this.getDrag())) * Math.exp(-((double) this.getDrag()) * ((double) (this.inAirTicks - this.startAirTicks)));
double diff = Math.abs(Math.abs(expectedVelocity) - Math.abs(this.speed.y));

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/cn/nukkit/block/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
*/
public abstract class Block extends Position implements Metadatable, Cloneable, AxisAlignedBB, BlockID {

public static final int MAX_BLOCK_ID = 1024;
@SuppressWarnings("UnnecessaryBoxing")
public static final int MAX_BLOCK_ID = Integer.valueOf("1024");
public static final int DATA_BITS = 6;
public static final int DATA_SIZE = 1 << DATA_BITS;
public static final int DATA_MASK = DATA_SIZE - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)

sender.sendMessage(TextFormat.GOLD + "TPS / Average: " + tpsColor + NukkitMath.round(tps, 2) + " / " + NukkitMath.round(server.getTicksPerSecondAverage(), 2));

sender.sendMessage(TextFormat.GOLD + "Load / Average: " + tpsColor + server.getTickUsage() + "% / " + server.getTickUsageAverage() + '%');
sender.sendMessage(TextFormat.GOLD + "Load / Average: " + tpsColor + server.getTickUsage() + "% / " + server.getTickUsageAverage() * 100 + '%');

//sender.sendMessage(TextFormat.GOLD + "Network upload: " + TextFormat.GREEN + NukkitMath.round((server.getNetwork().getUpload() / 1024 * 1000), 2) + " kB/s");

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/cn/nukkit/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -2415,8 +2415,7 @@ public Item useItemOn(Vector3 vector, Item item, BlockFace face, float fx, float
}

if (player != null) {
Vector3 diff = player.getPositionOffset();
if (hand.getBoundingBox().intersectsWith(player.getBoundingBox().getOffsetBoundingBox(diff.x, diff.y, diff.z))) {
if (hand.getBoundingBox().intersectsWith(player.getNextPositionBB())) {
this.sendBlocks(player, new Block[]{block, target}, UpdateBlockPacket.FLAG_NONE); // Prevent ghost blocks
return null; // Player in block
}
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/cn/nukkit/level/format/leveldb/BlockStateMapping.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
package cn.nukkit.level.format.leveldb;

import cn.nukkit.level.format.leveldb.structure.BlockStateSnapshot;
import cn.nukkit.level.format.leveldb.updater.BlockStateUpdaterChunker;
import cn.nukkit.level.format.leveldb.updater.BlockStateUpdaterVanilla;
import cn.nukkit.level.format.leveldb.structure.BlockStateSnapshot;
import cn.nukkit.utils.MainLogger;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;
import org.cloudburstmc.blockstateupdater.*;
import org.cloudburstmc.blockstateupdater.util.tagupdater.CompoundTagUpdaterContext;
import org.cloudburstmc.nbt.NbtMap;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.nukkitx.network.util.Preconditions;
import it.unimi.dsi.fastutil.Hash;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.*;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.cloudburstmc.blockstateupdater.*;
import org.cloudburstmc.blockstateupdater.util.tagupdater.CompoundTagUpdaterContext;
import org.cloudburstmc.nbt.NbtMap;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

import static cn.nukkit.level.format.leveldb.LevelDBConstants.*;
import static cn.nukkit.level.format.leveldb.LevelDBConstants.PALETTE_VERSION;

public class BlockStateMapping {
private static final Logger log = LogManager.getLogger("LevelDB-Logger");
Expand All @@ -33,10 +34,9 @@ public class BlockStateMapping {
private static final int LATEST_UPDATER_VERSION;
private static final BlockStateMapping INSTANCE = new BlockStateMapping(PALETTE_VERSION);

private static final ExpiringMap<NbtMap, NbtMap> BLOCK_UPDATE_CACHE = ExpiringMap.builder()
.maxSize(1024)
.expiration(60, TimeUnit.SECONDS)
.expirationPolicy(ExpirationPolicy.ACCESSED)
private static final Cache<NbtMap, NbtMap> BLOCK_UPDATE_CACHE = CacheBuilder.newBuilder()
.maximumSize(1024)
.expireAfterAccess(60, TimeUnit.SECONDS)
.build();

static {
Expand Down Expand Up @@ -243,7 +243,7 @@ public BlockStateSnapshot getUpdatedState(NbtMap state) {
}

public NbtMap updateVanillaState(NbtMap state) {
NbtMap cached = BLOCK_UPDATE_CACHE.get(state);
NbtMap cached = BLOCK_UPDATE_CACHE.getIfPresent(state);
if (cached == null) {
int version = state.getInt("version"); // TODO: validate this when updating next time
cached = CONTEXT.update(state, LATEST_UPDATER_VERSION == version ? version - 1 : version);
Expand Down

0 comments on commit 84d4487

Please sign in to comment.