Skip to content

Commit c8a08a1

Browse files
authored
Updates (#2253)
- Added more blocks and items from 1.21 and below - Added bottle fill dispenser behavior - Added debug shapes - Added zombie/skeleton held items API - Added new records & custom records compatibility - Added some debug messages - Added breeze drops - Added pointed dripstone custom fall damage - Fixed boats on 1.21.130 - Fixed player eating splash potions - Fixed snow layer silk touch and creative pickup - Fixed some deepslate and copper blocks blast resistance - Fixed flower placement on mud - Fixed typo in smooth red sandstone stairs name - Fixed spiders invisibility - Fixed async code during plugin load possibly causing issues with class loader - Patched resource pack traffic amplification - Increased config writer buffer size - Optimized chunk section light compression - Updated recipes, now loading vanilla format - Updated log4j to latest
1 parent f399646 commit c8a08a1

File tree

143 files changed

+98499
-930
lines changed

Some content is hidden

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

143 files changed

+98499
-930
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
22
junit = "5.9.2"
3-
log4j = "2.25.2"
3+
log4j = "2.25.3"
44
jline = "3.30.6"
55
fastutilmaps = "8.5.15-SNAPSHOT"
66

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

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
import com.google.common.base.Strings;
7272
import com.google.common.collect.BiMap;
7373
import com.google.common.collect.HashBiMap;
74-
import io.netty.util.internal.PlatformDependent;
7574
import it.unimi.dsi.fastutil.bytes.ByteOpenHashSet;
7675
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
7776
import it.unimi.dsi.fastutil.ints.IntArrayList;
@@ -171,7 +170,7 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
171170
protected Vector3 newPosition;
172171
protected Vector3 sleeping;
173172
private BlockVector3 lastRightClickPos;
174-
private final Queue<Vector3> clientMovements = PlatformDependent.newMpscQueue(4);
173+
private Queue<Vector3> clientMovements = new ArrayDeque<>();
175174

176175
protected boolean connected = true;
177176
protected final InetSocketAddress socketAddress;
@@ -254,6 +253,10 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
254253
protected Map<Integer, FormWindow> serverSettings = new Int2ObjectOpenHashMap<>();
255254

256255
protected Map<Long, DummyBossBar> dummyBossBars = new Long2ObjectLinkedOpenHashMap<>();
256+
/**
257+
* Requested resource pack chunks
258+
*/
259+
private Map<UUID, IntOpenHashSet> resourceChunksRequested = new HashMap<>();
257260

258261
private AsyncTask preLoginEventTask;
259262
protected boolean shouldLogin;
@@ -872,7 +875,9 @@ public String getDisplayName() {
872875
public void setDisplayName(String displayName) {
873876
if (displayName == null) {
874877
displayName = "";
875-
server.getLogger().debug("Warning: setDisplayName: argument is null", new Throwable(""));
878+
if (Nukkit.DEBUG > 1) {
879+
server.getLogger().debug("Warning: setDisplayName: argument is null", new Throwable(""));
880+
}
876881
}
877882
this.displayName = displayName;
878883
updatePlayerListData(true);
@@ -995,7 +1000,9 @@ public String getButtonText() {
9951000
public void setButtonText(String text) {
9961001
if (text == null) {
9971002
text = "";
998-
server.getLogger().debug("Warning: setButtonText: argument is null", new Throwable(""));
1003+
if (Nukkit.DEBUG > 1) {
1004+
server.getLogger().debug("Warning: setButtonText: argument is null", new Throwable(""));
1005+
}
9991006
}
10001007
if (!text.equals(buttonText)) {
10011008
this.buttonText = text;
@@ -2419,9 +2426,29 @@ public boolean onUpdate(int currentTick) {
24192426
Math.cos(Math.toRadians(this.yaw)) * Math.cos(Math.toRadians(this.pitch)) * multiplier));
24202427
}
24212428

2422-
if (this.age % 5 == 0 && this.isBreakingBlock() && !this.isCreative()) {
2423-
//this.level.addLevelSoundEvent(this.breakingBlock, LevelSoundEventPacket.SOUND_HIT, blockRuntimeId);
2424-
this.level.addParticle(new PunchBlockParticle(this.breakingBlock, this.breakingBlock, this.breakingBlockFace));
2429+
if (this.age % 5 == 0) {
2430+
if (this.isBreakingBlock() && !this.isCreative()) {
2431+
/*if (this.protocol >= ProtocolInfo.v1_20_0_23) {
2432+
this.level.addLevelSoundEvent(this.breakingBlock, LevelSoundEventPacket.SOUND_HIT, blockRuntimeId);
2433+
}*/
2434+
this.level.addParticle(new PunchBlockParticle(this.breakingBlock, this.breakingBlock, this.breakingBlockFace));
2435+
}
2436+
2437+
if (this.isUsingItem()) {
2438+
Item food = this.getInventory().getItemInHandFast();
2439+
2440+
if (food instanceof ItemEdible) {
2441+
EntityEventPacket pk = new EntityEventPacket();
2442+
pk.eid = this.id;
2443+
pk.event = EntityEventPacket.EATING_ITEM;
2444+
pk.data = food.getNetworkId() << 16;
2445+
this.dataPacket(pk);
2446+
2447+
for (Player p : this.getViewers().values()) {
2448+
p.dataPacket(pk);
2449+
}
2450+
}
2451+
}
24252452
}
24262453

24272454
this.checkTeleportPosition();
@@ -3089,12 +3116,21 @@ public void onCompletion(Server server) {
30893116
ResourcePackClientResponsePacket responsePacket = (ResourcePackClientResponsePacket) packet;
30903117
switch (responsePacket.responseStatus) {
30913118
case ResourcePackClientResponsePacket.STATUS_REFUSED:
3119+
server.getLogger().debug(username + ": got ResourcePackClientResponse STATUS_REFUSED");
30923120
this.close("", "disconnectionScreen.noReason");
30933121
return;
30943122
case ResourcePackClientResponsePacket.STATUS_SEND_PACKS:
3123+
Set<UUID> sent = new HashSet<>();
30953124
for (ResourcePackClientResponsePacket.Entry entry : responsePacket.packEntries) {
30963125
ResourcePack resourcePack = this.server.getResourcePackManager().getPackById(entry.uuid);
30973126
if (resourcePack == null) {
3127+
server.getLogger().debug(username + ": resource pack not found with uuid " + entry.uuid);
3128+
this.close("", "disconnectionScreen.resourcePack");
3129+
return;
3130+
}
3131+
3132+
if (!sent.add(entry.uuid)) {
3133+
server.getLogger().debug(username + ": duplicate resource pack found with uuid " + entry.uuid);
30983134
this.close("", "disconnectionScreen.resourcePack");
30993135
return;
31003136
}
@@ -3127,6 +3163,13 @@ public void onCompletion(Server server) {
31273163
ResourcePackChunkRequestPacket requestPacket = (ResourcePackChunkRequestPacket) packet;
31283164
ResourcePack resourcePack = this.server.getResourcePackManager().getPackById(requestPacket.packId);
31293165
if (resourcePack == null) {
3166+
server.getLogger().debug(username + ": resource pack chunk not found with uuid " + requestPacket.packId);
3167+
this.close("", "disconnectionScreen.resourcePack");
3168+
return;
3169+
}
3170+
3171+
if (!resourceChunksRequested.computeIfAbsent(requestPacket.packId, k -> new IntOpenHashSet()).add(requestPacket.chunkIndex)) {
3172+
server.getLogger().debug(username + ": duplicate request for resource chunk " + requestPacket.packId + "/" + requestPacket.chunkIndex);
31303173
this.close("", "disconnectionScreen.resourcePack");
31313174
return;
31323175
}
@@ -3214,12 +3257,6 @@ public void onCompletion(Server server) {
32143257
if (inputX >= -1.001 && inputX <= 1.001 && inputY >= -1.001 && inputY <= 1.001) {
32153258
((EntityControllable) riding).onPlayerInput(this, inputX, inputY);
32163259
}
3217-
} else if (this.riding instanceof EntityBoat && authPacket.getInputData().contains(AuthInputAction.IN_CLIENT_PREDICTED_IN_VEHICLE)) {
3218-
if (this.riding.getId() == authPacket.getPredictedVehicle() && this.riding.isControlling(this)) {
3219-
if (this.temporalVector.setComponents(authPacket.getPosition().getX(), authPacket.getPosition().getY(), authPacket.getPosition().getZ()).distanceSquared(this.riding) < 16) {
3220-
((EntityBoat) this.riding).onInput(authPacket.getPosition().getX(), authPacket.getPosition().getY(), authPacket.getPosition().getZ(), authPacket.getHeadYaw());
3221-
}
3222-
}
32233260
}
32243261

32253262
if (!this.isSpectator() && authPacket.getInputData().contains(AuthInputAction.MISSED_SWING)) {
@@ -3730,8 +3767,7 @@ public void onCompletion(Server server) {
37303767

37313768
AnimatePacket animatePacket = (AnimatePacket) packet;
37323769

3733-
if (animatePacket.action != AnimatePacket.Action.SWING_ARM &&
3734-
!(this.riding != null && (animatePacket.action == AnimatePacket.Action.ROW_LEFT || animatePacket.action == AnimatePacket.Action.ROW_RIGHT))) {
3770+
if (animatePacket.action != AnimatePacket.Action.SWING_ARM) {
37353771
return;
37363772
}
37373773

@@ -3741,17 +3777,6 @@ public void onCompletion(Server server) {
37413777
return;
37423778
}
37433779

3744-
AnimatePacket.Action animation = animationEvent.getAnimationType();
3745-
3746-
switch (animation) {
3747-
case ROW_RIGHT:
3748-
case ROW_LEFT:
3749-
if (this.riding instanceof EntityBoat) {
3750-
((EntityBoat) this.riding).onPaddle(animation, animatePacket.rowingTime);
3751-
}
3752-
break;
3753-
}
3754-
37553780
animatePacket = new AnimatePacket();
37563781
animatePacket.eid = this.getId();
37573782
animatePacket.action = animationEvent.getAnimationType();
@@ -3769,17 +3794,6 @@ public void onCompletion(Server server) {
37693794
}
37703795

37713796
switch (entityEventPacket.event) {
3772-
case EntityEventPacket.EATING_ITEM:
3773-
if (entityEventPacket.data == 0 || entityEventPacket.eid != this.id) {
3774-
this.getServer().getLogger().debug(username + ": entity event eid mismatch");
3775-
return;
3776-
}
3777-
3778-
entityEventPacket.eid = this.id;
3779-
entityEventPacket.isEncoded = false;
3780-
this.dataPacket(entityEventPacket);
3781-
Server.broadcastPacket(this.getViewers().values(), entityEventPacket);
3782-
return;
37833797
case EntityEventPacket.ENCHANT:
37843798
if (entityEventPacket.eid != this.id) {
37853799
this.getServer().getLogger().debug(username + ": entity event eid mismatch");
@@ -4439,7 +4453,7 @@ public void onCompletion(Server server) {
44394453
if (!item.onUse(this, ticksUsed)) {
44404454
this.needSendHeldItem = true;
44414455
}
4442-
} else {
4456+
} else if (!(item instanceof ProjectileItem)) { // Fix newer versions showing player eating splash potions
44434457
this.setUsingItem(true);
44444458
}
44454459
}
@@ -5424,6 +5438,8 @@ public void close(TextContainer message, String reason, boolean notify) {
54245438

54255439
this.inventory = null;
54265440
this.chunk = null;
5441+
this.clientMovements = null;
5442+
this.resourceChunksRequested = null;
54275443

54285444
this.server.removePlayer(this);
54295445

@@ -5433,8 +5449,6 @@ public void close(TextContainer message, String reason, boolean notify) {
54335449
this.server.removeOnlinePlayer(this);
54345450
this.loggedIn = false;
54355451
}
5436-
5437-
this.clientMovements.clear();
54385452
}
54395453

54405454
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ public void sendFullPlayerListData(Player player) {
10951095
}
10961096

10971097
public void sendRecipeList(Player player) {
1098-
player.dataPacket(CraftingManager.packet);
1098+
player.dataPacket(craftingManager.getCachedPacket());
10991099
}
11001100

11011101
private void checkTickUpdates(int currentTick) {

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

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

3+
import cn.nukkit.Player;
4+
import cn.nukkit.blockentity.BlockEntity;
35
import cn.nukkit.item.Item;
46
import cn.nukkit.item.ItemBlock;
57
import cn.nukkit.item.ItemTool;
68
import cn.nukkit.item.enchantment.Enchantment;
9+
import cn.nukkit.math.BlockFace;
710
import cn.nukkit.utils.BlockColor;
811

912
public class BlockChiseledBookshelf extends BlockSolidMeta {
@@ -73,4 +76,13 @@ public boolean canSilkTouch() {
7376
public boolean canBePushed() {
7477
return false; // prevent item loss issue with pistons until a working implementation
7578
}
79+
80+
@Override
81+
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
82+
if (this.getLevel().setBlock(this, this, true, true)) {
83+
BlockEntity.createBlockEntity(BlockEntity.CHISELED_BOOKSHELF, this.getChunk(), BlockEntity.getDefaultCompound(this, BlockEntity.CHISELED_BOOKSHELF));
84+
return true;
85+
}
86+
return false;
87+
}
7688
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package cn.nukkit.block;
2+
3+
public class BlockChiseledTuffBricks extends BlockTuff {
4+
5+
public BlockChiseledTuffBricks() {
6+
// Does Nothing
7+
}
8+
9+
@Override
10+
public String getName() {
11+
return "Chiseled Tuff Bricks";
12+
}
13+
14+
@Override
15+
public int getId() {
16+
return CHISELED_TUFF_BRICKS;
17+
}
18+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public double getHardness() {
1818

1919
@Override
2020
public double getResistance() {
21-
return 6;
21+
return 30;
2222
}
2323

2424
@Override
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package cn.nukkit.block;
2+
3+
import cn.nukkit.block.properties.OxidizationLevel;
4+
import cn.nukkit.utils.BlockColor;
5+
6+
7+
public class BlockCopperBulb extends BlockCopperBase {
8+
9+
public BlockCopperBulb() {
10+
// Does nothing
11+
}
12+
13+
@Override
14+
public String getName() {
15+
return "Copper Bulb";
16+
}
17+
18+
@Override
19+
public int getId() {
20+
return COPPER_BULB;
21+
}
22+
23+
@Override
24+
public BlockColor getColor() {
25+
return BlockColor.ORANGE_BLOCK_COLOR;
26+
}
27+
28+
@Override
29+
public OxidizationLevel getOxidizationLevel() {
30+
return OxidizationLevel.UNAFFECTED;
31+
}
32+
33+
@Override
34+
protected int getCopperId(boolean waxed, OxidizationLevel oxidizationLevel) {
35+
if (oxidizationLevel == null) {
36+
return this.getId();
37+
}
38+
39+
switch (oxidizationLevel) {
40+
case UNAFFECTED:
41+
return waxed ? WAXED_COPPER_BULB : COPPER_BULB;
42+
case EXPOSED:
43+
return waxed ? WAXED_EXPOSED_COPPER_BULB : EXPOSED_COPPER_BULB;
44+
case WEATHERED:
45+
return waxed ? WAXED_WEATHERED_COPPER_BULB : WEATHERED_COPPER_BULB;
46+
case OXIDIZED:
47+
return waxed ? WAXED_OXIDIZED_COPPER_BULB : OXIDIZED_COPPER_BULB;
48+
default:
49+
return this.getId();
50+
}
51+
}
52+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package cn.nukkit.block;
2+
3+
import cn.nukkit.block.properties.OxidizationLevel;
4+
import cn.nukkit.utils.BlockColor;
5+
6+
public class BlockCopperBulbExposed extends BlockCopperBulb {
7+
8+
public BlockCopperBulbExposed() {
9+
// Does nothing
10+
}
11+
12+
@Override
13+
public String getName() {
14+
return "Exposed Copper Bulb";
15+
}
16+
17+
@Override
18+
public int getId() {
19+
return EXPOSED_COPPER_BULB;
20+
}
21+
22+
@Override
23+
public BlockColor getColor() {
24+
return BlockColor.LIGHT_GRAY_TERRACOTA_BLOCK_COLOR;
25+
}
26+
27+
@Override
28+
public OxidizationLevel getOxidizationLevel() {
29+
return OxidizationLevel.EXPOSED;
30+
}
31+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cn.nukkit.block;
2+
3+
public class BlockCopperBulbExposedWaxed extends BlockCopperBulbExposed {
4+
5+
public BlockCopperBulbExposedWaxed() {
6+
// Does nothing
7+
}
8+
9+
@Override
10+
public String getName() {
11+
return "Waxed Exposed Copper Bulb";
12+
}
13+
14+
@Override
15+
public int getId() {
16+
return WAXED_EXPOSED_COPPER_BULB;
17+
}
18+
19+
@Override
20+
public boolean isWaxed() {
21+
return true;
22+
}
23+
}

0 commit comments

Comments
 (0)