Skip to content

Commit 136c99a

Browse files
authored
1.21.120 & updates (#2242)
- Added support for Minecraft 1.21.120 - Fixed BlockDoubleSlabStone3 hardness and resistance - Fixed lever and button redstone update on break - Candles now stay in air even if support block is broken matching vanilla behavior - Made EntityHuman use getSkin internally allowing it to be overridden more easily
1 parent 9ab10a6 commit 136c99a

File tree

16 files changed

+74
-47
lines changed

16 files changed

+74
-47
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,7 +2585,7 @@ protected void processPreLogin() {
25852585

25862586
@Override
25872587
public void onRun() {
2588-
this.event = new PlayerAsyncPreLoginEvent(username, uuid, loginChainData, skin, playerInstance.getAddress(), playerInstance.getPort());
2588+
this.event = new PlayerAsyncPreLoginEvent(username, uuid, loginChainData, playerInstance.getSkin(), playerInstance.getAddress(), playerInstance.getPort());
25892589
server.getPluginManager().callEvent(this.event);
25902590
}
25912591

@@ -3954,7 +3954,7 @@ public void onCompletion(Server server) {
39543954
BlockEntityItemFrame itemFrame1 = (BlockEntityItemFrame) be;
39553955

39563956
if (itemFrame1.getItem() instanceof ItemMap && ((ItemMap) itemFrame1.getItem()).getMapId() == pk.mapId) {
3957-
((ItemMap) itemFrame1.getItem()).sendImage(this);
3957+
((ItemMap) itemFrame1.getItem()).trySendImage(this);
39583958
return;
39593959
}
39603960
}
@@ -4006,7 +4006,7 @@ public void onCompletion(Server server) {
40064006
}
40074007

40084008
map.setImage(image);
4009-
map.sendImage(this);
4009+
map.trySendImage(this);
40104010
} catch (Exception ex) {
40114011
this.getServer().getLogger().debug(username + ": there was an error while generating map image", ex);
40124012
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,18 @@ public BlockFace getFacing() {
124124

125125
@Override
126126
public boolean onBreak(Item item) {
127+
if (!super.onBreak(item)) {
128+
return false;
129+
}
130+
127131
if (isActivated()) {
128132
this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 15, 0));
133+
134+
this.level.updateAroundRedstone(this, null);
135+
this.level.updateAroundRedstone(getSideVec(getFacing().getOpposite()), null);
129136
}
130137

131-
return super.onBreak(item);
138+
return true;
132139
}
133140

134141
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public boolean breakWhenPushed() {
5656
@Override
5757
public int onUpdate(int type) {
5858
if (type == Level.BLOCK_UPDATE_NORMAL) {
59-
if (!isSupportValidBelow()) {
59+
if (false && !isSupportValidBelow()) { // Follow vanilla behavior even if it's broken
6060
this.getLevel().useBreakOn(this);
6161
return Level.BLOCK_UPDATE_NORMAL;
6262
}

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

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

3+
import cn.nukkit.item.ItemTool;
34
import cn.nukkit.utils.BlockColor;
45

56
public class BlockDoubleSlabStone3 extends BlockDoubleSlabBase {
@@ -47,6 +48,21 @@ public int getSingleSlabId() {
4748
return STONE_SLAB3;
4849
}
4950

51+
@Override
52+
public double getResistance() {
53+
return this.getToolType() > ItemTool.TIER_WOODEN ? 30 : 15;
54+
}
55+
56+
@Override
57+
public double getHardness() {
58+
return 2;
59+
}
60+
61+
@Override
62+
public int getToolType() {
63+
return ItemTool.TYPE_PICKAXE;
64+
}
65+
5066
@Override
5167
public int getItemDamage() {
5268
return this.getDamage() & 0x07;

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,19 @@ public boolean place(Item item, Block block, Block target, BlockFace face, doubl
105105

106106
@Override
107107
public boolean onBreak(Item item) {
108-
this.getLevel().setBlock(this, Block.get(BlockID.AIR), true, true);
108+
if (!super.onBreak(item)) {
109+
return false;
110+
}
109111

110112
if (isPowerOn()) {
111-
BlockFace face = LeverOrientation.byMetadata(this.getDamage() ^ 0x08).getFacing();
112-
this.level.updateAround(this.getSideVec(face.getOpposite()));
113+
this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 15, 0));
114+
115+
LeverOrientation orientation = LeverOrientation.byMetadata(this.getDamage() ^ 0x08);
116+
BlockFace face = orientation.getFacing();
117+
this.level.updateAroundRedstone(this, null);
118+
this.level.updateAroundRedstone(this.getSideVec(face.getOpposite()), face);
113119
}
120+
114121
return true;
115122
}
116123

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
import cn.nukkit.item.enchantment.Enchantment;
99
import cn.nukkit.level.Level;
1010
import cn.nukkit.level.Sound;
11-
import cn.nukkit.math.NukkitRandom;
1211
import cn.nukkit.nbt.tag.CompoundTag;
1312
import cn.nukkit.nbt.tag.DoubleTag;
1413
import cn.nukkit.nbt.tag.FloatTag;
1514
import cn.nukkit.nbt.tag.ListTag;
1615
import cn.nukkit.utils.BlockColor;
1716

17+
import java.util.concurrent.ThreadLocalRandom;
18+
1819
/**
1920
* Created on 2015/12/8 by xtypr.
2021
* Package cn.nukkit.block in project Nukkit .
@@ -64,11 +65,9 @@ public void prime(int fuse) {
6465
prime(fuse, null);
6566
}
6667

67-
private static final NukkitRandom RANDOM = new NukkitRandom();
68-
6968
public void prime(int fuse, Entity source) {
7069
this.getLevel().setBlock(this, Block.get(BlockID.AIR), true);
71-
double mot = RANDOM.nextSignedFloat() * 6.283185307179586;
70+
double mot = (ThreadLocalRandom.current().nextFloat() * 2 - 1) * 6.283185307179586;
7271
CompoundTag nbt = new CompoundTag()
7372
.putList(new ListTag<DoubleTag>("Pos")
7473
.add(new DoubleTag("", this.x + 0.5))
@@ -120,12 +119,12 @@ public boolean onActivate(Item item, Player player) {
120119
public BlockColor getColor() {
121120
return BlockColor.TNT_BLOCK_COLOR;
122121
}
123-
122+
124123
@Override
125124
public boolean hasEntityCollision() {
126125
return true;
127126
}
128-
127+
129128
@Override
130129
public void onEntityCollide(Entity entity) {
131130
if (entity instanceof EntityArrow && entity.isOnFire()) {

src/main/java/cn/nukkit/entity/Entity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,9 @@ protected final void init(FullChunk chunk, CompoundTag nbt) {
570570
ListTag<FloatTag> rotationList = this.namedTag.getList("Rotation", FloatTag.class);
571571
ListTag<DoubleTag> motionList = this.namedTag.getList("Motion", DoubleTag.class);
572572
float correctedYaw = rotationList.get(0).data;
573-
if (!(correctedYaw >= 0 && correctedYaw <= 360)) correctedYaw = 0;
573+
if (!(correctedYaw >= -360 && correctedYaw <= 360)) correctedYaw = 0;
574574
float correctedPitch = rotationList.get(1).data;
575-
if (!(correctedPitch >= 0 && correctedPitch <= 360)) correctedPitch = 0;
575+
if (!(correctedPitch >= -360 && correctedPitch <= 360)) correctedPitch = 0;
576576
this.setPositionAndRotation(
577577
this.temporalVector.setComponents(
578578
posList.get(0).data,

src/main/java/cn/nukkit/entity/EntityHuman.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ protected void initEntity() {
196196
this.setSkin(newSkin);
197197
}
198198

199-
this.uuid = Utils.dataToUUID(String.valueOf(this.getId()).getBytes(StandardCharsets.UTF_8), this.skin
199+
this.uuid = Utils.dataToUUID(String.valueOf(this.getId()).getBytes(StandardCharsets.UTF_8), this.getSkin()
200200
.getSkinData().data, this.getNameTag().getBytes(StandardCharsets.UTF_8));
201201
}
202202

@@ -212,18 +212,18 @@ public String getName() {
212212
public void saveNBT() {
213213
super.saveNBT();
214214

215-
if (skin != null) {
215+
if (this.getSkin() != null) {
216216
CompoundTag skinTag = new CompoundTag()
217217
.putByteArray("Data", this.getSkin().getSkinData().data)
218218
.putInt("SkinImageWidth", this.getSkin().getSkinData().width)
219219
.putInt("SkinImageHeight", this.getSkin().getSkinData().height)
220-
.putString("ModelId", this.skin.getSkinId())
220+
.putString("ModelId", this.getSkin().getSkinId())
221221
.putString("CapeId", this.getSkin().getCapeId())
222222
.putByteArray("CapeData", this.getSkin().getCapeData().data)
223223
.putInt("CapeImageWidth", this.getSkin().getCapeData().width)
224224
.putInt("CapeImageHeight", this.getSkin().getCapeData().height)
225225
.putByteArray("SkinResourcePatch", this.getSkin().getSkinResourcePatch().getBytes(StandardCharsets.UTF_8))
226-
.putByteArray("GeometryData", this.skin.getGeometryData().getBytes(StandardCharsets.UTF_8))
226+
.putByteArray("GeometryData", this.getSkin().getGeometryData().getBytes(StandardCharsets.UTF_8))
227227
.putByteArray("SkinAnimationData", this.getSkin().getAnimationData().getBytes(StandardCharsets.UTF_8))
228228
.putBoolean("PremiumSkin", this.getSkin().isPremium())
229229
.putBoolean("PersonaSkin", this.getSkin().isPersona())
@@ -289,16 +289,16 @@ public void spawnTo(Player player) {
289289
if (this != player && !this.hasSpawned.containsKey(player.getLoaderId())) {
290290
this.hasSpawned.put(player.getLoaderId(), player);
291291

292-
if (!this.skin.isValid()) {
292+
if (!this.getSkin().isValid()) {
293293
throw new IllegalStateException(this.getClass().getSimpleName() + " must have a valid skin set");
294294
}
295295

296296
if (this instanceof Player) {
297297
this.server.updatePlayerListData(
298-
new PlayerListPacket.Entry(this.uuid, this.getId(), ((Player) this).getDisplayName(), this.skin, ((Player) this).getLoginChainData().getXUID(), ((Player) this).getLocatorBarColor()),
298+
new PlayerListPacket.Entry(this.uuid, this.getId(), ((Player) this).getDisplayName(), this.getSkin(), ((Player) this).getLoginChainData().getXUID(), ((Player) this).getLocatorBarColor()),
299299
new Player[]{player});
300300
} else {
301-
this.server.updatePlayerListData(this.uuid, this.getId(), this.getName(), this.skin, new Player[]{player});
301+
this.server.updatePlayerListData(this.uuid, this.getId(), this.getName(), this.getSkin(), new Player[]{player});
302302
}
303303

304304
AddPlayerPacket pk = new AddPlayerPacket();

src/main/java/cn/nukkit/item/ItemMap.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
import cn.nukkit.Player;
44
import cn.nukkit.Server;
5+
import cn.nukkit.nbt.stream.FastByteArrayOutputStream;
56
import cn.nukkit.nbt.tag.CompoundTag;
67
import cn.nukkit.network.protocol.ClientboundMapItemDataPacket;
78
import cn.nukkit.utils.MainLogger;
9+
import cn.nukkit.utils.ThreadCache;
810

911
import javax.imageio.ImageIO;
1012
import java.awt.*;
1113
import java.awt.image.BufferedImage;
1214
import java.io.ByteArrayInputStream;
13-
import java.io.ByteArrayOutputStream;
1415
import java.io.File;
1516
import java.io.IOException;
1617

@@ -55,19 +56,20 @@ public void setImage(BufferedImage image) {
5556
this.image = image;
5657
}
5758

58-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
59+
FastByteArrayOutputStream baos = ThreadCache.fbaos.get().reset();
5960
ImageIO.write(this.image, "png", baos);
6061

6162
this.setNamedTag(this.getNamedTag().putByteArray("Colors", baos.toByteArray()));
62-
baos.close();
6363
} catch (IOException e) {
6464
MainLogger.getLogger().logException(e);
6565
}
6666
}
6767

6868
protected BufferedImage loadImageFromNBT() {
6969
try {
70-
byte[] data = getNamedTag().getByteArray("Colors");
70+
CompoundTag tag = this.getNamedTag();
71+
if (tag == null) return null;
72+
byte[] data = tag.getByteArray("Colors");
7173
image = ImageIO.read(new ByteArrayInputStream(data));
7274
return image;
7375
} catch (IOException e) {
@@ -83,22 +85,9 @@ public long getMapId() {
8385
return tag.getLong("map_uuid");
8486
}
8587

88+
@Deprecated
8689
public void sendImage(Player p) {
87-
// Don't load the image from NBT if it has been done before
88-
BufferedImage image = this.image != null ? this.image : loadImageFromNBT();
89-
90-
ClientboundMapItemDataPacket pk = new ClientboundMapItemDataPacket();
91-
pk.mapId = getMapId();
92-
pk.update = ClientboundMapItemDataPacket.TEXTURE_UPDATE;
93-
pk.scale = 0;
94-
pk.width = 128;
95-
pk.height = 128;
96-
pk.offsetX = 0;
97-
pk.offsetZ = 0;
98-
pk.image = image;
99-
pk.eids = new long[]{pk.mapId};
100-
101-
p.dataPacket(pk);
90+
this.trySendImage(p);
10291
}
10392

10493
public boolean trySendImage(Player p) {

src/main/java/cn/nukkit/level/format/generic/BaseFullChunk.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cn.nukkit.level.format.generic;
22

33
import cn.nukkit.Player;
4+
import cn.nukkit.block.BlockID;
45
import cn.nukkit.block.BlockLayer;
56
import cn.nukkit.blockentity.BlockEntity;
67
import cn.nukkit.blockentity.PersistentDataContainerBlockEntity;
@@ -326,7 +327,7 @@ public int getHighestBlockAt(int x, int z, boolean cache) {
326327
}
327328

328329
for (int y = maxY; y >= minY; --y) {
329-
if (getBlockId(x, y, z) != 0x00) {
330+
if (getBlockId(x, y, z) != BlockID.AIR) {
330331
if (cache) {
331332
this.setHeightMap(x, z, y);
332333
}

0 commit comments

Comments
 (0)