Skip to content

Commit

Permalink
1.21.50 & fixes (#2205)
Browse files Browse the repository at this point in the history
- Updated for Minecraft 1.21.50
- Fixed double chest placement in certain rotations
- Fixed some block updates possibly loading chunks
- Fixed some leaves decaying even when wood is nearby
- Fixed some chunks not being saved on server restart
- Fixed lightning ignoring BlockIgniteEvent result
- Fixed barrel inventory saving
- Fixed ItemSignBirch name
- Fixed PlayerMoveEvent not being called when only rotation changes
  • Loading branch information
PetteriM1 authored Dec 4, 2024
1 parent 047d00a commit 2efad49
Show file tree
Hide file tree
Showing 45 changed files with 261 additions and 158 deletions.
10 changes: 10 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ tasks {
archiveClassifier.set("")

exclude("javax/annotation/**")

// These platforms are not popular, make the jar a bit smaller by not including optional Snappy support
exclude("org/xerial/snappy/native/AIX/**")
exclude("org/xerial/snappy/native/FreeBSD/**")
exclude("org/xerial/snappy/native/SunOS/**")
exclude("org/xerial/snappy/native/Linux/loongarch64/**")
exclude("org/xerial/snappy/native/Linux/ppc/**")
exclude("org/xerial/snappy/native/Linux/ppc64/**")
exclude("org/xerial/snappy/native/Linux/ppc64le/**")
exclude("org/xerial/snappy/native/Linux/s390x/**")
}

runShadow {
Expand Down
12 changes: 5 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
junit = "5.9.2"
log4j = "2.20.0"
jline = "3.22.0"
fastutilmaps = "8.5.13-SNAPSHOT"
fastutilmaps = "8.5.15-SNAPSHOT"

[libraries]
network = { group = "org.cloudburstmc.netty", name = "netty-transport-raknet", version = "1.0.0.CR3-SNAPSHOT" }
epoll = { group = "io.netty", name = "netty-transport-native-epoll", version = "4.1.101.Final" }
fastutil = { group = "com.nukkitx", name = "fastutil-lite", version = "8.1.1" }
fastutil-long-long-maps = { group = "org.cloudburstmc.fastutil.maps", name = "long-long-maps", version.ref = "fastutilmaps" }
fastutil = { group = "it.unimi.dsi", name = "fastutil-core", version = "8.5.15" }
fastutil-int-short-maps = { group = "org.cloudburstmc.fastutil.maps", name = "int-short-maps", version.ref = "fastutilmaps" }
fastutil-object-int-maps = { group = "org.cloudburstmc.fastutil.maps", name = "object-int-maps", version.ref = "fastutilmaps" }
fastutil-object-object-maps = { group = "org.cloudburstmc.fastutil.maps", name = "object-object-maps", version.ref = "fastutilmaps" }
fastutil-long-byte-maps = { group = "org.cloudburstmc.fastutil.maps", name = "long-byte-maps", version.ref = "fastutilmaps" }
guava = { group = "com.google.guava", name = "guava", version = "33.2.1-jre" }
gson = { group = "com.google.code.gson", name = "gson", version = "2.10.1" }
snakeyaml = { group = "org.yaml", name = "snakeyaml", version = "1.33" }
Expand All @@ -23,7 +21,7 @@ jopt-simple = { group = "net.sf.jopt-simple", name = "jopt-simple", version = "5
blockstateupdater = { group = "org.cloudburstmc", name = "block-state-updater", version = "1.21.30-SNAPSHOT" }
lmbda = { group = "org.lanternpowered", name = "lmbda", version = "2.0.0" }
noise = { group = "net.daporkchop.lib", name = "noise", version = "0.5.6-SNAPSHOT" }
lombok = { group = "org.projectlombok", name = "lombok", version = "1.18.34" }
lombok = { group = "org.projectlombok", name = "lombok", version = "1.18.36" }

# Logging dependencies
log4j-api = { group = "org.apache.logging.log4j", name = "log4j-api", version.ref = "log4j" }
Expand All @@ -43,7 +41,7 @@ junit-jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engi
log4j = [ "log4j-api", "log4j-core" ]
terminal = [ "jline-terminal", "jline-terminal-jna", "jline-reader", "terminal-console" ]
junit = [ "junit-jupiter-api", "junit-jupiter-engine" ]
fastutilmaps = [ "fastutil-long-long-maps", "fastutil-int-short-maps", "fastutil-object-int-maps", "fastutil-object-object-maps" ]
fastutilmaps = [ "fastutil-int-short-maps", "fastutil-long-byte-maps" ]

[plugins]
shadow = { id = "com.github.johnrengelman.shadow", version = "8.0.0" }
Expand Down
41 changes: 29 additions & 12 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -1901,9 +1901,32 @@ protected void handleMovement(Vector3 newPos) {
double distanceSquared = newPos.distanceSquared(this);
if (distanceSquared == 0) {
if (this.lastYaw != this.yaw || this.lastPitch != this.pitch) {
this.lastYaw = this.yaw;
this.lastPitch = this.pitch;
this.needSendRotation = true;
if (!this.firstMove) {
Location from = new Location(this.x, this.y, this.z, this.lastYaw, this.lastPitch, this.level);
Location to = this.getLocation();

PlayerMoveEvent moveEvent = new PlayerMoveEvent(this, from, to);
this.server.getPluginManager().callEvent(moveEvent);

if (moveEvent.isCancelled()) {
this.teleport(from, null);
return;
}

this.lastYaw = to.yaw;
this.lastPitch = to.pitch;

if (!to.equals(moveEvent.getTo())) { // If plugins modify the destination
this.teleport(moveEvent.getTo(), null);
} else {
this.needSendRotation = true;
}
} else {
this.lastYaw = this.yaw;
this.lastPitch = this.pitch;
this.needSendRotation = true;
this.firstMove = false;
}
}

if (this.speed == null) speed = new Vector3(0, 0, 0);
Expand Down Expand Up @@ -1987,13 +2010,7 @@ protected void handleMovement(Vector3 newPos) {
this.updateFallState(this.onGround);
// Replacement for this.fastMove(dx, dy, dz) end

Location from = new Location(
this.lastX,
this.lastY,
this.lastZ,
this.lastYaw,
this.lastPitch,
this.level);
Location from = new Location(this.lastX, this.lastY, this.lastZ, this.lastYaw, this.lastPitch, this.level);
Location to = this.getLocation();

if (!this.firstMove) {
Expand Down Expand Up @@ -2027,9 +2044,9 @@ protected void handleMovement(Vector3 newPos) {

this.lastYaw = to.yaw;
this.lastPitch = to.pitch;
}

this.firstMove = false;
this.firstMove = false;
}

if (this.speed == null) speed = new Vector3(from.x - to.x, from.y - to.y, from.z - to.z);
else this.speed.setComponents(from.x - to.x, from.y - to.y, from.z - to.z);
Expand Down
32 changes: 29 additions & 3 deletions src/main/java/cn/nukkit/block/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import cn.nukkit.level.Level;
import cn.nukkit.level.MovingObjectPosition;
import cn.nukkit.level.Position;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.level.persistence.PersistentDataContainer;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.BlockFace;
Expand Down Expand Up @@ -639,9 +640,34 @@ public Block getSide(BlockLayer layer, BlockFace face, int step) {
if (this.isValid()) {
return this.getLevel().getBlock(super.getSide(face, step), layer, true);
}
Block block = Block.get(Item.AIR, 0, Position.fromObject(new Vector3(this.x, this.y, this.z).getSide(face, step)));
block.layer = layer;
return block;
return Block.get(AIR, 0, Position.fromObject(new Vector3(this.x, this.y, this.z).getSide(face, step)), layer);
}

protected Block getSideIfLoaded(BlockFace face) {
if (this.isValid()) {
return this.level.getBlock(null,
(int) this.x + face.getXOffset(), (int) this.y + face.getYOffset(), (int) this.z + face.getZOffset(),
BlockLayer.NORMAL, false);
}
return Block.get(AIR, 0, Position.fromObject(new Vector3(this.x, this.y, this.z).getSide(face, 1)), BlockLayer.NORMAL);
}

protected Block getSideIfLoadedOrNull(BlockFace face) {
if (this.isValid()) {
int cx = ((int) this.x + face.getXOffset()) >> 4;
int cz = ((int) this.z + face.getZOffset()) >> 4;

FullChunk chunk = this.level.getChunkIfLoaded(cx, cz);
if (chunk == null) {
return null;
}

return this.level.getBlock(chunk,
(int) this.x + face.getXOffset(), (int) this.y + face.getYOffset(), (int) this.z + face.getZOffset(),
BlockLayer.NORMAL, false);
}

return Block.get(AIR, 0, Position.fromObject(new Vector3(this.x, this.y, this.z).getSide(face, 1)), BlockLayer.NORMAL);
}

public Block up() {
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/cn/nukkit/block/BlockAzaleaLeaves.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ public Item[] getDrops(Item item) {
}
}

@Override
protected void setOnDecayDamage() {
this.setCheckDecay(false);
}

@Override
protected boolean canDropApple() {
return false;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/cn/nukkit/block/BlockCactus.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ public int onUpdate(int type) {
if (down.getId() != SAND && down.getId() != CACTUS) {
this.getLevel().useBreakOn(this);
} else {
for (int side = 2; side <= 5; ++side) {
Block block = getSide(BlockFace.fromIndex(side));
if (!block.canBeFlowedInto()) {
for (BlockFace side : BlockFace.Plane.HORIZONTAL) {
if (!getSide(side).canBeFlowedInto()) {
this.getLevel().useBreakOn(this);
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/cn/nukkit/block/BlockChest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ public boolean place(Item item, Block block, Block target, BlockFace face, doubl
BlockEntityChest chest = null;
this.setDamage(Block.FACES2534[player != null ? player.getDirection().getHorizontalIndex() : 0]);

for (int side = 2; side <= 5; ++side) {
if ((this.getDamage() == 4 || this.getDamage() == 5) && (side == 4 || side == 5)) {
for (BlockFace side : BlockFace.Plane.HORIZONTAL) {
if ((this.getDamage() == 4 || this.getDamage() == 5) && (side == BlockFace.WEST || side == BlockFace.EAST)) {
continue;
} else if ((this.getDamage() == 3 || this.getDamage() == 2) && (side == 2 || side == 3)) {
} else if ((this.getDamage() == 3 || this.getDamage() == 2) && (side == BlockFace.NORTH || side == BlockFace.SOUTH)) {
continue;
}
Block c = this.getSide(BlockFace.fromIndex(side));
if (c instanceof BlockChest && c.getDamage() == this.getDamage()) {
Block c = this.getSide(side);
if (c instanceof BlockChest &&
(c.getDamage() == this.getDamage() || (c.getDamage() == 0 && this.getDamage() == 2))) { // leveldb states, idk

BlockEntity blockEntity = this.getLevel().getBlockEntity(c);
if (blockEntity instanceof BlockEntityChest && !((BlockEntityChest) blockEntity).isPaired()) {
chest = (BlockEntityChest) blockEntity;
Expand Down
44 changes: 28 additions & 16 deletions src/main/java/cn/nukkit/block/BlockFire.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import cn.nukkit.item.ItemBlock;
import cn.nukkit.level.GameRule;
import cn.nukkit.level.Level;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.BlockFace;
import cn.nukkit.potion.Effect;
Expand Down Expand Up @@ -126,7 +127,7 @@ public int onUpdate(int type) {
this.getLevel().canBlockSeeSky(this.west()) ||
this.getLevel().canBlockSeeSky(this.south()) ||
this.getLevel().canBlockSeeSky(this.north()))
) {
) {

this.getLevel().setBlock(this, Block.get(BlockID.AIR), true);
}
Expand Down Expand Up @@ -158,12 +159,14 @@ public int onUpdate(int type) {

//TODO: decrease the o if the rainfall values are high

this.tryToCatchBlockOnFire(this.east(), 300 + o, meta);
this.tryToCatchBlockOnFire(this.west(), 300 + o, meta);
this.tryToCatchBlockOnFire(this.down(), 250 + o, meta);
this.tryToCatchBlockOnFire(this.up(), 250 + o, meta);
this.tryToCatchBlockOnFire(this.south(), 300 + o, meta);
this.tryToCatchBlockOnFire(this.north(), 300 + o, meta);
this.tryToCatchBlockOnFire(this.getSideIfLoaded(BlockFace.EAST), 300 + o, meta);
this.tryToCatchBlockOnFire(this.getSideIfLoaded(BlockFace.WEST), 300 + o, meta);
this.tryToCatchBlockOnFire(this.getSideIfLoaded(BlockFace.DOWN), 250 + o, meta);
this.tryToCatchBlockOnFire(this.getSideIfLoaded(BlockFace.UP), 250 + o, meta);
this.tryToCatchBlockOnFire(this.getSideIfLoaded(BlockFace.SOUTH), 300 + o, meta);
this.tryToCatchBlockOnFire(this.getSideIfLoaded(BlockFace.NORTH), 300 + o, meta);

int dif = 40 + this.getLevel().getServer().getDifficulty() * 7;

for (int x = (int) (this.x - 1); x <= (int) (this.x + 1); ++x) {
for (int z = (int) (this.z - 1); z <= (int) (this.z + 1); ++z) {
Expand All @@ -175,11 +178,16 @@ public int onUpdate(int type) {
k += (y - (this.y + 1)) * 100;
}

Block block = this.getLevel().getBlock(x, y, z);
FullChunk chunk = this.getLevel().getChunkIfLoaded(x >> 4, z >> 4);
if (chunk == null) {
continue;
}

Block block = this.getLevel().getBlock(chunk, x, y, z, false);
int chance = getChanceOfNeighborsEncouragingFire(block);

if (chance > 0) {
int t = (chance + 40 + this.getLevel().getServer().getDifficulty() * 7) / (meta + 30);
int t = (chance + dif) / (meta + 30);

//TODO: decrease the t if the rainfall values are high

Expand Down Expand Up @@ -210,8 +218,12 @@ public int onUpdate(int type) {
}

private void tryToCatchBlockOnFire(Block block, int bound, int damage) {
if (Utils.random.nextInt(bound) < block.getBurnAbility()) {
int burnAbility = block.getBurnAbility();
if (burnAbility == 0) {
return;
}

if (Utils.random.nextInt(bound) < burnAbility) {
if (Utils.random.nextInt(damage + 10) < 5) {
int meta = damage + (Utils.random.nextInt(5) >> 2);

Expand Down Expand Up @@ -246,12 +258,12 @@ private static int getChanceOfNeighborsEncouragingFire(Block block) {
return 0;
} else {
int chance = 0;
chance = Math.max(chance, block.east().getBurnChance());
chance = Math.max(chance, block.west().getBurnChance());
chance = Math.max(chance, block.down().getBurnChance());
chance = Math.max(chance, block.up().getBurnChance());
chance = Math.max(chance, block.south().getBurnChance());
chance = Math.max(chance, block.north().getBurnChance());
chance = Math.max(chance, block.getSideIfLoaded(BlockFace.EAST).getBurnChance());
chance = Math.max(chance, block.getSideIfLoaded(BlockFace.WEST).getBurnChance());
chance = Math.max(chance, block.getSideIfLoaded(BlockFace.DOWN).getBurnChance());
chance = Math.max(chance, block.getSideIfLoaded(BlockFace.UP).getBurnChance());
chance = Math.max(chance, block.getSideIfLoaded(BlockFace.SOUTH).getBurnChance());
chance = Math.max(chance, block.getSideIfLoaded(BlockFace.NORTH).getBurnChance());
return chance;
}
}
Expand Down
Loading

0 comments on commit 2efad49

Please sign in to comment.