Skip to content

Commit 4da37b2

Browse files
authored
Fixes & updates (#2208)
- Fixed players becoming invisible after sleeping - Fixed server hanging when reading corrupted Zlib input - Updated enchanted golden apple regeneration amplifier to match vanilla - Bed/anchor explosions can now create fire - Bamboo from world generator can generate taller - Conduits now give conduit power effect - Froglight now rotates correctly when placed - Using ThreadLocalRandom
1 parent d02928d commit 4da37b2

File tree

76 files changed

+589
-202
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+589
-202
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ leveldbjni = { group = "net.daporkchop", name = "leveldb-mcpe-jni", version = "0
1818
snappy = { group = "org.xerial.snappy", name = "snappy-java", version = "1.1.10.7" }
1919
jwt = { group = "com.nimbusds", name = "nimbus-jose-jwt", version = "9.23" }
2020
jopt-simple = { group = "net.sf.jopt-simple", name = "jopt-simple", version = "5.0.4" }
21-
blockstateupdater = { group = "org.cloudburstmc", name = "block-state-updater", version = "1.21.30-SNAPSHOT" }
21+
blockstateupdater = { group = "org.cloudburstmc", name = "block-state-updater", version = "1.21.40-SNAPSHOT" }
2222
lmbda = { group = "org.lanternpowered", name = "lmbda", version = "2.0.0" }
2323
noise = { group = "net.daporkchop.lib", name = "noise", version = "0.5.6-SNAPSHOT" }
2424
lombok = { group = "org.projectlombok", name = "lombok", version = "1.18.36" }

src/main/java/cn/nukkit/Player.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
import java.util.*;
9595
import java.util.Queue;
9696
import java.util.Map.Entry;
97+
import java.util.concurrent.ThreadLocalRandom;
9798
import java.util.concurrent.TimeUnit;
9899
import java.util.concurrent.atomic.AtomicReference;
99100
import java.util.function.Consumer;
@@ -1477,7 +1478,7 @@ public void stopSleep() {
14771478
this.server.getPluginManager().callEvent(new PlayerBedLeaveEvent(this, this.level.getBlock(this.sleeping)));
14781479

14791480
this.sleeping = null;
1480-
this.setDataProperty(new IntPositionEntityData(DATA_PLAYER_BED_POSITION, 0, 0, 0));
1481+
this.removeDataProperty(DATA_PLAYER_BED_POSITION);
14811482
this.setDataFlag(DATA_PLAYER_FLAGS, DATA_PLAYER_FLAG_SLEEP, false);
14821483

14831484
this.level.sleepTicks = 0;
@@ -2085,7 +2086,7 @@ protected void handleMovement(Vector3 newPos) {
20852086
server.getPluginManager().callEvent(waterFrostEvent);
20862087
if (!waterFrostEvent.isCancelled()) {
20872088
level.setBlockAt((int) block.x, (int) block.y, (int) block.z, Block.ICE_FROSTED, 0);
2088-
level.scheduleUpdate(level.getBlock(this.chunk, block.getFloorX(), block.getFloorY(), block.getFloorZ(), true), Utils.random.nextInt(20, 40));
2089+
level.scheduleUpdate(level.getBlock(this.chunk, block.getFloorX(), block.getFloorY(), block.getFloorZ(), true), ThreadLocalRandom.current().nextInt(20, 40));
20892090
}
20902091
}
20912092
}
@@ -6938,7 +6939,7 @@ public boolean pickupEntity(Entity entity, boolean near) {
69386939
}
69396940

69406941
if (!itemsWithMending.isEmpty()) {
6941-
int itemToRepair = itemsWithMending.getInt(Utils.random.nextInt(itemsWithMending.size()));
6942+
int itemToRepair = itemsWithMending.getInt(ThreadLocalRandom.current().nextInt(itemsWithMending.size()));
69426943
boolean isOffhand = itemToRepair == -1;
69436944

69446945
Item repaired = isOffhand ? offhand : this.inventory.getItem(itemToRepair);

src/main/java/cn/nukkit/Server.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
import java.nio.ByteOrder;
9595
import java.nio.charset.StandardCharsets;
9696
import java.util.*;
97+
import java.util.concurrent.ThreadLocalRandom;
9798
import java.util.concurrent.atomic.AtomicBoolean;
9899
import java.util.regex.Pattern;
99100

@@ -2111,7 +2112,7 @@ public boolean loadLevel(String name) {
21112112
* @return generated
21122113
*/
21132114
public boolean generateLevel(String name) {
2114-
return this.generateLevel(name, Utils.random.nextLong());
2115+
return this.generateLevel(name, ThreadLocalRandom.current().nextLong());
21152116
}
21162117

21172118
/**
@@ -2772,6 +2773,9 @@ private static void registerBlockEntities() {
27722773
BlockEntity.registerBlockEntity(BlockEntity.BLAST_FURNACE, BlockEntityBlastFurnace.class);
27732774
BlockEntity.registerBlockEntity(BlockEntity.SMOKER, BlockEntitySmoker.class);
27742775
BlockEntity.registerBlockEntity(BlockEntity.BELL, BlockEntityBell.class);
2776+
BlockEntity.registerBlockEntity(BlockEntity.CONDUIT, BlockEntityConduit.class);
2777+
2778+
// Persistent container, not on vanilla
27752779
BlockEntity.registerBlockEntity(BlockEntity.PERSISTENT_CONTAINER, PersistentDataContainerBlockEntity.class);
27762780
}
27772781

src/main/java/cn/nukkit/block/BlockBed.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public boolean onActivate(Item item, Player player) {
7575
}
7676

7777
Explosion explosion = new Explosion(this.add(0.5, 0, 0.5), 5, this);
78+
explosion.setFireSpawnChance(0.3333);
7879
explosion.explodeA();
7980
explosion.explodeB();
8081
}

src/main/java/cn/nukkit/block/BlockBeetroot.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package cn.nukkit.block;
22

33
import cn.nukkit.item.Item;
4-
import cn.nukkit.utils.Utils;
4+
5+
import java.util.concurrent.ThreadLocalRandom;
56

67
/**
78
* Created on 2015/11/22 by xtypr.
@@ -36,7 +37,7 @@ public Item[] getDrops(Item item) {
3637
if (this.getDamage() >= 0x07) {
3738
return new Item[]{
3839
Item.get(Item.BEETROOT, 0, 1),
39-
Item.get(Item.BEETROOT_SEEDS, 0, Utils.random.nextInt(0, 4))
40+
Item.get(Item.BEETROOT_SEEDS, 0, ThreadLocalRandom.current().nextInt(0, 4))
4041
};
4142
} else {
4243
return new Item[]{

src/main/java/cn/nukkit/block/BlockCauldron.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public void clearWithFizz(BlockEntityCauldron cauldron) {
434434
cauldron.clearCustomColor();
435435
this.level.setBlock(this, Block.get(CAULDRON_BLOCK), true);
436436
this.level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_FIZZ);
437-
this.getLevel().addParticle(new SmokeParticle(add(Math.random(), 1.2, Math.random())), null, 8);
437+
this.getLevel().addParticle(new SmokeParticle(add(ThreadLocalRandom.current().nextDouble(), 1.2, ThreadLocalRandom.current().nextDouble())), null, 8);
438438
}
439439

440440
@Override

src/main/java/cn/nukkit/block/BlockChorusFlower.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ public int onUpdate(int type) {
131131
}
132132
// Grow Horizontally
133133
} else if (!isFullyAged()) {
134-
for (int i = 0; i < ThreadLocalRandom.current().nextInt(ground ? 5 : 4); i++) {
134+
ThreadLocalRandom random = ThreadLocalRandom.current();
135+
for (int i = 0; i < random.nextInt(ground ? 5 : 4); i++) {
135136
BlockFace face = BlockFace.Plane.HORIZONTAL.random();
136137
Block check = this.getSide(face);
137138
if (check.getId() == AIR && check.down().getId() == AIR && isHorizontalAirExcept(check, face.getOpposite())) {

src/main/java/cn/nukkit/block/BlockCocoa.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import cn.nukkit.utils.Faceable;
1616
import cn.nukkit.utils.Utils;
1717

18+
import java.util.concurrent.ThreadLocalRandom;
19+
1820
/**
1921
* Created by CreeperFace on 27. 10. 2016.
2022
*/
@@ -111,7 +113,7 @@ public int onUpdate(int type) {
111113
return Level.BLOCK_UPDATE_NORMAL;
112114
}
113115
} else if (type == Level.BLOCK_UPDATE_RANDOM) {
114-
if (Utils.random.nextInt(2) == 1) {
116+
if (ThreadLocalRandom.current().nextInt(2) == 1) {
115117
if (this.getDamage() >> 2 < 2) {
116118
BlockCocoa block = (BlockCocoa) this.clone();
117119
block.setDamage(block.getDamage() + 4);

src/main/java/cn/nukkit/block/BlockComposter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
import cn.nukkit.item.*;
77
import cn.nukkit.level.Sound;
88
import cn.nukkit.utils.DyeColor;
9-
import cn.nukkit.utils.Utils;
109
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
1110

11+
import java.util.concurrent.ThreadLocalRandom;
12+
1213
public class BlockComposter extends BlockTransparentMeta implements ItemID {
1314

1415
private static final Int2IntOpenHashMap ITEMS = new Int2IntOpenHashMap();
@@ -109,7 +110,7 @@ public boolean onActivate(Item item, Player player) {
109110
return false;
110111
}
111112

112-
boolean success = Utils.random.nextInt(100) < chance;
113+
boolean success = ThreadLocalRandom.current().nextInt(100) < chance;
113114
ComposterFillEvent event = new ComposterFillEvent(this, player, item, chance, success);
114115
this.level.getServer().getPluginManager().callEvent(event);
115116

src/main/java/cn/nukkit/block/BlockConduit.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package cn.nukkit.block;
22

3+
import cn.nukkit.Player;
4+
import cn.nukkit.blockentity.BlockEntity;
5+
import cn.nukkit.item.Item;
36
import cn.nukkit.item.ItemTool;
7+
import cn.nukkit.math.BlockFace;
48

5-
public class BlockConduit extends BlockSolidMeta {
9+
public class BlockConduit extends BlockTransparentMeta {
610

711
public BlockConduit() {
812
this(0);
@@ -56,4 +60,13 @@ public WaterloggingType getWaterloggingType() {
5660
public boolean alwaysDropsOnExplosion() {
5761
return true;
5862
}
63+
64+
@Override
65+
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
66+
if (this.getLevel().setBlock(this, this, true, true)) {
67+
BlockEntity.createBlockEntity(BlockEntity.CONDUIT, this.getChunk(), BlockEntity.getDefaultCompound(this, BlockEntity.CONDUIT));
68+
return true;
69+
}
70+
return false;
71+
}
5972
}

0 commit comments

Comments
 (0)