Skip to content

Commit 86d97f0

Browse files
PetteriM1TTsdzb
authored andcommitted
1.21.70 & updates (CloudburstMC#2231)
- Added support for Minecraft 1.21.70 - Added ElementDivider and ElementHeader for simple and custom forms - Added methods to change player's client side walk/fly/vertical fly speed - Fixed campfire not being breakable by hand - Fixed sculk block hardness and resistance - Fixed hopper minecart pickup area - Fixed hoppers attempting to empty containers from wrong side and non full composters - Fixed target block hit and lectern page change not providing redstone signal - Fixed falling scaffolding drops lead - Fixed flowers not generating - Fixed wither rose not dealing damage - More projectiles can break chorus flower - You can drink honey bottle even when food bar is full - Iron golems can now be repaired using iron ingots - Lectern, jukebox and respawn anchor now work as comparator input - Made fixes for vehicle collisions - Reporting UWP as Windows instead of Windows 10 and WIN32 as Windows x86 - Some cleanup
1 parent 0be85a6 commit 86d97f0

File tree

62 files changed

+10513
-457
lines changed

Some content is hidden

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

62 files changed

+10513
-457
lines changed

src/main/java/cn/nukkit/AdventureSettings.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ void update(boolean reset) {
103103
layer.getAbilityValues().add(PlayerAbility.OPERATOR_COMMANDS);
104104
}
105105

106-
layer.setWalkSpeed(Player.DEFAULT_SPEED);
107-
layer.setFlySpeed(Player.DEFAULT_FLY_SPEED);
108-
layer.setVerticalFlySpeed(1.0f);
106+
layer.setWalkSpeed(player.getWalkSpeed());
107+
layer.setFlySpeed(player.getFlySpeed());
108+
layer.setVerticalFlySpeed(player.getVerticalFlySpeed());
109109
packet.getAbilityLayers().add(layer);
110110

111111
if (player.isSpectator()) {

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

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,15 @@
7171
import com.google.common.base.Strings;
7272
import com.google.common.collect.BiMap;
7373
import com.google.common.collect.HashBiMap;
74-
import com.google.common.collect.Sets;
7574
import io.netty.util.internal.PlatformDependent;
75+
import it.unimi.dsi.fastutil.bytes.ByteOpenHashSet;
7676
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
7777
import it.unimi.dsi.fastutil.ints.IntArrayList;
7878
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
79-
import it.unimi.dsi.fastutil.longs.*;
79+
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
80+
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
81+
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
82+
import it.unimi.dsi.fastutil.longs.LongIterator;
8083
import it.unimi.dsi.fastutil.objects.ObjectIterator;
8184
import lombok.Getter;
8285
import lombok.Setter;
@@ -90,10 +93,10 @@
9093
import java.lang.reflect.Field;
9194
import java.net.InetSocketAddress;
9295
import java.nio.ByteOrder;
93-
import java.util.List;
9496
import java.util.*;
95-
import java.util.Queue;
97+
import java.util.List;
9698
import java.util.Map.Entry;
99+
import java.util.Queue;
97100
import java.util.concurrent.ThreadLocalRandom;
98101
import java.util.concurrent.TimeUnit;
99102
import java.util.concurrent.atomic.AtomicReference;
@@ -125,6 +128,7 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
125128
public static final float DEFAULT_SPEED = 0.1f;
126129
public static final float MAXIMUM_SPEED = 6f; // TODO: Decrease when block collisions are fixed
127130
public static final float DEFAULT_FLY_SPEED = 0.05f;
131+
public static final float DEFAULT_VERTICAL_FLY_SPEED = 1f;
128132

129133
public static final int PERMISSION_CUSTOM = 3;
130134
public static final int PERMISSION_OPERATOR = 2;
@@ -178,7 +182,7 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
178182
protected Vector3 teleportPosition;
179183
protected Vector3 newPosition;
180184
protected Vector3 sleeping;
181-
private Vector3 lastRightClickPos;
185+
private BlockVector3 lastRightClickPos;
182186
private final Queue<Vector3> clientMovements = PlatformDependent.newMpscQueue(4);
183187

184188
protected boolean connected = true;
@@ -215,6 +219,24 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
215219
@Getter
216220
@Setter
217221
private boolean canTickShield = true;
222+
/**
223+
* Player's client-side walk speed. Remember to call getAdventureSettings().update() if changed.
224+
*/
225+
@Getter
226+
@Setter
227+
private float walkSpeed = DEFAULT_SPEED;
228+
/**
229+
* Player's client-side fly speed. Remember to call getAdventureSettings().update() if changed.
230+
*/
231+
@Getter
232+
@Setter
233+
private float flySpeed = DEFAULT_FLY_SPEED;
234+
/**
235+
* Player's client-side vertical fly speed. Remember to call getAdventureSettings().update() if changed.
236+
*/
237+
@Getter
238+
@Setter
239+
private float verticalFlySpeed = DEFAULT_VERTICAL_FLY_SPEED;
218240

219241
private int exp;
220242
private int expLevel;
@@ -296,7 +318,7 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
296318
/**
297319
* Packets that can be received before the player has logged in
298320
*/
299-
private static final Set<Byte> PRE_LOGIN_PACKETS = Sets.newHashSet(ProtocolInfo.BATCH_PACKET, ProtocolInfo.LOGIN_PACKET, ProtocolInfo.REQUEST_NETWORK_SETTINGS_PACKET, ProtocolInfo.REQUEST_CHUNK_RADIUS_PACKET, ProtocolInfo.SET_LOCAL_PLAYER_AS_INITIALIZED_PACKET, ProtocolInfo.RESOURCE_PACK_CHUNK_REQUEST_PACKET, ProtocolInfo.RESOURCE_PACK_CLIENT_RESPONSE_PACKET, ProtocolInfo.CLIENT_CACHE_STATUS_PACKET, ProtocolInfo.PACKET_VIOLATION_WARNING_PACKET, ProtocolInfo.CLIENT_TO_SERVER_HANDSHAKE_PACKET);
321+
private static final ByteOpenHashSet PRE_LOGIN_PACKETS = new ByteOpenHashSet(new byte[]{ProtocolInfo.BATCH_PACKET, ProtocolInfo.LOGIN_PACKET, ProtocolInfo.REQUEST_NETWORK_SETTINGS_PACKET, ProtocolInfo.REQUEST_CHUNK_RADIUS_PACKET, ProtocolInfo.SET_LOCAL_PLAYER_AS_INITIALIZED_PACKET, ProtocolInfo.RESOURCE_PACK_CHUNK_REQUEST_PACKET, ProtocolInfo.RESOURCE_PACK_CLIENT_RESPONSE_PACKET, ProtocolInfo.CLIENT_CACHE_STATUS_PACKET, ProtocolInfo.PACKET_VIOLATION_WARNING_PACKET, ProtocolInfo.CLIENT_TO_SERVER_HANDSHAKE_PACKET});
300322
/**
301323
* Default kick message for flying
302324
*/
@@ -4197,7 +4219,6 @@ public void onCompletion(Server server) {
41974219
UseItemData useItemData = (UseItemData) transactionPacket.transactionData;
41984220
BlockVector3 blockVector = useItemData.blockPos;
41994221
BlockFace face = useItemData.face;
4200-
int type = useItemData.actionType;
42014222

42024223
this.setShieldBlockingDelay(5);
42034224

@@ -4209,14 +4230,14 @@ public void onCompletion(Server server) {
42094230
itemSent = true; // Assume that the item is still correct even if the selected slot is not
42104231
}
42114232

4212-
switch (type) {
4233+
switch (useItemData.actionType) {
42134234
case InventoryTransactionPacket.USE_ITEM_ACTION_CLICK_BLOCK:
42144235
// Hack: Fix client spamming right clicks
42154236
if ((lastRightClickPos != null && this.getInventory().getItemInHandFast().getBlockId() == BlockID.AIR && System.currentTimeMillis() - lastRightClickTime < 200.0 && blockVector.distanceSquared(lastRightClickPos) < 0.00001)) {
42164237
return;
42174238
}
42184239

4219-
lastRightClickPos = blockVector.asVector3();
4240+
lastRightClickPos = blockVector;
42204241
lastRightClickTime = System.currentTimeMillis();
42214242

42224243
this.breakingBlock = null;
@@ -4366,17 +4387,15 @@ public void onCompletion(Server server) {
43664387
return;
43674388
}
43684389

4369-
type = useItemOnEntityData.actionType;
4370-
43714390
if (inventory.getHeldItemIndex() != useItemOnEntityData.hotbarSlot) {
43724391
inventory.equipItem(useItemOnEntityData.hotbarSlot);
43734392
}
43744393

43754394
item = this.inventory.getItemInHand();
43764395

4377-
switch (type) {
4396+
switch (useItemOnEntityData.actionType) {
43784397
case InventoryTransactionPacket.USE_ITEM_ON_ENTITY_ACTION_INTERACT:
4379-
if (this.distanceSquared(target) > 1000) {
4398+
if (this.distanceSquared(target) > 256) { // TODO: Note entity scale
43804399
this.getServer().getLogger().debug(username + ": target entity is too far away");
43814400
return;
43824401
}
@@ -4513,8 +4532,7 @@ public void onCompletion(Server server) {
45134532
ReleaseItemData releaseItemData = (ReleaseItemData) transactionPacket.transactionData;
45144533

45154534
try {
4516-
type = releaseItemData.actionType;
4517-
switch (type) {
4535+
switch (releaseItemData.actionType) {
45184536
case InventoryTransactionPacket.RELEASE_ITEM_ACTION_RELEASE:
45194537
if (this.isUsingItem()) {
45204538
int ticksUsed = this.server.getTick() - this.startAction;
@@ -4529,7 +4547,7 @@ public void onCompletion(Server server) {
45294547
case InventoryTransactionPacket.RELEASE_ITEM_ACTION_CONSUME:
45304548
return;
45314549
default:
4532-
this.getServer().getLogger().debug(username + ": unknown release item action type: " + type);
4550+
this.getServer().getLogger().debug(username + ": unknown release item action type: " + releaseItemData.actionType);
45334551
}
45344552
} finally {
45354553
this.setUsingItem(false);
@@ -4687,12 +4705,11 @@ public void onCompletion(Server server) {
46874705
}
46884706

46894707
LecternUpdatePacket lecternUpdatePacket = (LecternUpdatePacket) packet;
4690-
Vector3 lecternPos = lecternUpdatePacket.blockPosition.asVector3();
4691-
if (lecternPos.distanceSquared(this) > 4096) {
4708+
if (lecternUpdatePacket.blockPosition.distanceSquared(this) > 4096) {
46924709
return;
46934710
}
46944711
if (!lecternUpdatePacket.dropBook) {
4695-
BlockEntity blockEntityLectern = this.level.getBlockEntityIfLoaded(this.chunk, lecternPos);
4712+
BlockEntity blockEntityLectern = this.level.getBlockEntityIfLoaded(this.chunk, lecternUpdatePacket.blockPosition.asVector3());
46964713
if (blockEntityLectern instanceof BlockEntityLectern) {
46974714
BlockEntityLectern lectern = (BlockEntityLectern) blockEntityLectern;
46984715
if (lectern.getRawPage() != lecternUpdatePacket.page) {
@@ -4917,8 +4934,9 @@ private void onBlockBreakComplete(BlockVector3 blockPos, BlockFace face) { // Fr
49174934
}
49184935
this.needSendHeldItem = true;
49194936
if (blockPos.distanceSquared(this) < 10000) {
4920-
this.level.sendBlocks(this, new Block[]{this.level.getBlock(blockPos.asVector3(), false)}, UpdateBlockPacket.FLAG_ALL_PRIORITY);
4921-
BlockEntity blockEntity = this.level.getBlockEntityIfLoaded(this.chunk, blockPos.asVector3());
4937+
Vector3 pos = blockPos.asVector3();
4938+
this.level.sendBlocks(this, new Block[]{this.level.getBlock(pos, false)}, UpdateBlockPacket.FLAG_ALL_PRIORITY);
4939+
BlockEntity blockEntity = this.level.getBlockEntityIfLoaded(this.chunk, pos);
49224940
if (blockEntity instanceof BlockEntitySpawnable) {
49234941
((BlockEntitySpawnable) blockEntity).spawnTo(this);
49244942
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ public Block getSide(BlockLayer layer, BlockFace face, int step) {
640640
if (this.isValid()) {
641641
return this.getLevel().getBlock(super.getSide(face, step), layer, true);
642642
}
643-
return Block.get(AIR, 0, Position.fromObject(new Vector3(this.x, this.y, this.z).getSide(face, step)), layer);
643+
return Block.get(AIR, 0, Position.fromObject(this.getSideVec(face, step)), layer);
644644
}
645645

646646
protected Block getSideIfLoaded(BlockFace face) {
@@ -649,7 +649,7 @@ protected Block getSideIfLoaded(BlockFace face) {
649649
(int) this.x + face.getXOffset(), (int) this.y + face.getYOffset(), (int) this.z + face.getZOffset(),
650650
BlockLayer.NORMAL, false);
651651
}
652-
return Block.get(AIR, 0, Position.fromObject(new Vector3(this.x, this.y, this.z).getSide(face, 1)), BlockLayer.NORMAL);
652+
return Block.get(AIR, 0, Position.fromObject(this.getSideVec(face, 1)), BlockLayer.NORMAL);
653653
}
654654

655655
protected Block getSideIfLoadedOrNull(BlockFace face) {
@@ -667,7 +667,7 @@ protected Block getSideIfLoadedOrNull(BlockFace face) {
667667
BlockLayer.NORMAL, false);
668668
}
669669

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

673673
public Block up() {

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import cn.nukkit.item.Item;
1010
import cn.nukkit.level.Level;
1111
import cn.nukkit.level.format.FullChunk;
12+
import cn.nukkit.math.AxisAlignedBB;
1213
import cn.nukkit.math.BlockFace;
14+
import cn.nukkit.math.SimpleAxisAlignedBB;
1315
import cn.nukkit.utils.BlockColor;
1416

1517
/**
@@ -45,7 +47,7 @@ public boolean hasEntityCollision() {
4547
return true;
4648
}
4749

48-
/*@Override
50+
@Override
4951
public double getMinX() {
5052
return this.x + 0.0625;
5153
}
@@ -63,11 +65,12 @@ public double getMaxX() {
6365
@Override
6466
public double getMaxZ() {
6567
return this.z + 0.9375;
66-
}*/
68+
}
6769

68-
// Hack: Fix entity collisions
69-
// No need for separate collision box
70-
// Y-collisions need another fix anyway
70+
@Override
71+
protected AxisAlignedBB recalculateCollisionBoundingBox() {
72+
return new SimpleAxisAlignedBB(x, y, z, x + 1, y + 1, z + 1);
73+
}
7174

7275
@Override
7376
public double getMaxY() {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ public int getToolType() {
6262
return ItemTool.TYPE_AXE;
6363
}
6464

65-
@Override
66-
public boolean canHarvestWithHand() {
67-
return false;
68-
}
69-
7065
@Override
7166
public Item[] getDrops(Item item) {
7267
return new Item[] {Item.get(ItemID.COAL, 0, 1 + ThreadLocalRandom.current().nextInt(1))};

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
import cn.nukkit.Player;
44
import cn.nukkit.Server;
55
import cn.nukkit.entity.Entity;
6+
import cn.nukkit.entity.item.EntityFirework;
67
import cn.nukkit.entity.projectile.EntityArrow;
8+
import cn.nukkit.entity.projectile.EntityEgg;
79
import cn.nukkit.entity.projectile.EntitySnowball;
10+
import cn.nukkit.entity.projectile.EntityThrownTrident;
811
import cn.nukkit.event.block.BlockGrowEvent;
912
import cn.nukkit.item.Item;
1013
import cn.nukkit.item.ItemBlock;
@@ -194,9 +197,15 @@ public Item toItem() {
194197
return new ItemBlock(Block.get(this.getId(), 0), 0);
195198
}
196199

200+
@Override
201+
public boolean hasEntityCollision() {
202+
return true;
203+
}
204+
197205
@Override
198206
public void onEntityCollide(Entity entity) {
199-
if (entity instanceof EntityArrow || entity instanceof EntitySnowball) {
207+
int e = entity.getNetworkId();
208+
if (e == EntityArrow.NETWORK_ID || e == EntityThrownTrident.NETWORK_ID || e == EntityFirework.NETWORK_ID || e == EntitySnowball.NETWORK_ID || e == EntityEgg.NETWORK_ID || e == 85 || e == 94 || e == 79 || e == 89) {
200209
entity.close();
201210
this.getLevel().useBreakOn(this);
202211
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,15 @@ public BlockColor getColor() {
109109
public boolean canBePushed() {
110110
return false;
111111
}
112+
113+
@Override
114+
public boolean hasComparatorInputOverride() {
115+
return true;
116+
}
117+
118+
@Override
119+
public int getComparatorInputOverride() {
120+
BlockEntity blockEntity = this.getLevel().getBlockEntityIfLoaded(this);
121+
return blockEntity instanceof BlockEntityJukebox ? ((BlockEntityJukebox) blockEntity).getComparatorSignal() : 0;
122+
}
112123
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public Item[] getDrops(Item item) {
116116
@Override
117117
public int onUpdate(int type) {
118118
if (type == Level.BLOCK_UPDATE_NORMAL && !isPersistent() && !isCheckDecay()) {
119+
if (this.level.getBlockIdAt((int) this.x, (int) this.y, (int) this.z) != this.getId()) {
120+
return 0;
121+
}
122+
119123
setCheckDecay(true);
120124
getLevel().setBlock((int) this.x, (int) this.y, (int) this.z, BlockLayer.NORMAL, this, false, false, false); // No need to send this to client
121125

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

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import cn.nukkit.item.Item;
88
import cn.nukkit.item.ItemID;
99
import cn.nukkit.item.ItemTool;
10+
import cn.nukkit.level.Level;
1011
import cn.nukkit.math.BlockFace;
12+
import cn.nukkit.math.NukkitMath;
1113
import cn.nukkit.nbt.tag.CompoundTag;
1214
import cn.nukkit.network.protocol.ContainerOpenPacket;
1315
import cn.nukkit.network.protocol.LevelSoundEventPacket;
@@ -80,21 +82,6 @@ public BlockFace getBlockFace() {
8082
return BlockFace.fromHorizontalIndex(getDamage() & 0b11);
8183
}
8284

83-
public boolean dropBook() {
84-
BlockEntity blockEntity = this.getLevel().getBlockEntity(this);
85-
if (blockEntity instanceof BlockEntityLectern) {
86-
BlockEntityLectern lectern = (BlockEntityLectern) blockEntity;
87-
Item book = lectern.getBook();
88-
if (book.getId() != BlockID.AIR) {
89-
lectern.setBook(Item.get(BlockID.AIR));
90-
lectern.spawnToAll();
91-
this.level.dropItem(lectern.add(0.5f, 1, 0.5f), book);
92-
return true;
93-
}
94-
}
95-
return false;
96-
}
97-
9885
@Override
9986
public boolean isPowerSource() {
10087
return true;
@@ -167,4 +154,41 @@ public boolean onActivate(Item item, Player player) {
167154
public boolean canBePushed() {
168155
return false; // prevent item loss issue with pistons until a working implementation
169156
}
157+
158+
@Override
159+
public boolean hasComparatorInputOverride() {
160+
return true;
161+
}
162+
163+
@Override
164+
public int getComparatorInputOverride() {
165+
int power = 0;
166+
BlockEntity lectern = level.getBlockEntityIfLoaded(this);
167+
if (lectern instanceof BlockEntityLectern && ((BlockEntityLectern) lectern).hasBook()) {
168+
int currentPage = ((BlockEntityLectern) lectern).getLeftPage();
169+
int totalPages = ((BlockEntityLectern) lectern).getTotalPages();
170+
power = NukkitMath.floorDouble(1 + ((double) (currentPage - 1) / (totalPages - 1)) * 14);
171+
}
172+
return power;
173+
}
174+
175+
public void onPageChange(boolean active) {
176+
if (isActivated() != active) {
177+
setActivated(active);
178+
level.setBlock((int) this.x, (int) this.y, (int) this.z, BlockLayer.NORMAL, this, false, false, false); // No need to send this to client
179+
level.updateAroundRedstone(this, null);
180+
if (active) {
181+
level.scheduleUpdate(this, 1);
182+
}
183+
}
184+
}
185+
186+
@Override
187+
public int onUpdate(int type) {
188+
if (type == Level.BLOCK_UPDATE_SCHEDULED || type == Level.BLOCK_UPDATE_NORMAL) {
189+
onPageChange(false);
190+
}
191+
192+
return 0;
193+
}
170194
}

0 commit comments

Comments
 (0)