Skip to content

Commit 066244e

Browse files
committed
Merge branches 'master' and 'redstone' of https://github.com/NukkitX/Nukkit into redstone
� Conflicts: � src/main/java/cn/nukkit/block/BlockPistonBase.java � src/main/java/cn/nukkit/block/BlockPistonHead.java � src/main/java/cn/nukkit/block/BlockUndyedShulkerBox.java � src/main/java/cn/nukkit/blockentity/BlockEntityHopper.java
2 parents ad292d8 + 62e05c7 commit 066244e

File tree

169 files changed

+1082
-667
lines changed

Some content is hidden

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

169 files changed

+1082
-667
lines changed

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

Lines changed: 79 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,8 +1668,8 @@ public boolean onUpdate(int currentTick) {
16681668

16691669
this.lastUpdate = currentTick;
16701670

1671-
if (this.fishing != null) {
1672-
if (this.distance(fishing) > 80) {
1671+
if (this.fishing != null && this.server.getTick() % 20 == 0) {
1672+
if (this.distance(fishing) > 33) {
16731673
this.stopFishing(false);
16741674
}
16751675
}
@@ -1729,7 +1729,7 @@ public boolean onUpdate(int currentTick) {
17291729
boolean ignore = block == Block.LADDER || block == Block.VINES || block == Block.COBWEB;
17301730

17311731
if (!this.hasEffect(Effect.JUMP) && diff > 0.6 && expectedVelocity < this.speed.y && !ignore) {
1732-
if (this.inAirTicks < 100) {
1732+
if (this.inAirTicks < 150) {
17331733
this.setMotion(new Vector3(0, expectedVelocity, 0));
17341734
} else if (this.kick(PlayerKickEvent.Reason.FLYING_DISABLED, "Flying is not enabled on this server")) {
17351735
return false;
@@ -2435,7 +2435,7 @@ public void onCompletion(Server server) {
24352435
}
24362436
Block block = target.getSide(face);
24372437
if (block.getId() == Block.FIRE) {
2438-
this.level.setBlock(block, new BlockAir(), true);
2438+
this.level.setBlock(block, Block.get(BlockID.AIR), true);
24392439
this.level.addLevelSoundEvent(block, LevelSoundEventPacket.SOUND_EXTINGUISH_FIRE);
24402440
break;
24412441
}
@@ -2793,7 +2793,13 @@ public void onCompletion(Server server) {
27932793
TextPacket textPacket = (TextPacket) packet;
27942794

27952795
if (textPacket.type == TextPacket.TYPE_CHAT) {
2796-
this.chat(textPacket.message);
2796+
String chatMessage = textPacket.message;
2797+
int breakLine = chatMessage.indexOf('\n');
2798+
// Chat messages shouldn't contain break lines so ignore text afterwards
2799+
if (breakLine != -1) {
2800+
chatMessage = chatMessage.substring(0, breakLine);
2801+
}
2802+
this.chat(chatMessage);
27972803
}
27982804
break;
27992805
case ProtocolInfo.CONTAINER_CLOSE_PACKET:
@@ -2879,7 +2885,7 @@ public void onCompletion(Server server) {
28792885
if (itemDrop.getId() != Item.AIR) {
28802886
vector3 = this.temporalVector.setComponents(itemFrame.x + 0.5, itemFrame.y, itemFrame.z + 0.5);
28812887
this.level.dropItem(vector3, itemDrop);
2882-
itemFrame.setItem(new ItemBlock(new BlockAir()));
2888+
itemFrame.setItem(new ItemBlock(Block.get(BlockID.AIR)));
28832889
itemFrame.setItemRotation(0);
28842890
this.getLevel().addSound(this, Sound.BLOCK_ITEMFRAME_REMOVE_ITEM);
28852891
}
@@ -3149,13 +3155,13 @@ public void onCompletion(Server server) {
31493155
if (target.onInteract(this, item, useItemOnEntityData.clickPos) && this.isSurvival()) {
31503156
if (item.isTool()) {
31513157
if (item.useOn(target) && item.getDamage() >= item.getMaxDurability()) {
3152-
item = new ItemBlock(new BlockAir());
3158+
item = new ItemBlock(Block.get(BlockID.AIR));
31533159
}
31543160
} else {
31553161
if (item.count > 1) {
31563162
item.count--;
31573163
} else {
3158-
item = new ItemBlock(new BlockAir());
3164+
item = new ItemBlock(Block.get(BlockID.AIR));
31593165
}
31603166
}
31613167

@@ -3201,7 +3207,7 @@ public void onCompletion(Server server) {
32013207

32023208
if (item.isTool() && this.isSurvival()) {
32033209
if (item.useOn(target) && item.getDamage() >= item.getMaxDurability()) {
3204-
this.inventory.setItemInHand(new ItemBlock(new BlockAir()));
3210+
this.inventory.setItemInHand(new ItemBlock(Block.get(BlockID.AIR)));
32053211
} else {
32063212
this.inventory.setItemInHand(item);
32073213
}
@@ -3286,6 +3292,45 @@ public void onCompletion(Server server) {
32863292
respawn1.respawnState = RespawnPacket.STATE_READY_TO_SPAWN;
32873293
this.dataPacket(respawn1);
32883294
}
3295+
break;
3296+
case ProtocolInfo.BOOK_EDIT_PACKET:
3297+
BookEditPacket bookEditPacket = (BookEditPacket) packet;
3298+
Item oldBook = this.inventory.getItem(bookEditPacket.inventorySlot);
3299+
if (oldBook.getId() != Item.BOOK_AND_QUILL) {
3300+
return;
3301+
}
3302+
3303+
Item newBook = oldBook.clone();
3304+
boolean success;
3305+
switch (bookEditPacket.action) {
3306+
case REPLACE_PAGE:
3307+
success = ((ItemBookAndQuill) newBook).setPageText(bookEditPacket.pageNumber, bookEditPacket.text);
3308+
break;
3309+
case ADD_PAGE:
3310+
success = ((ItemBookAndQuill) newBook).insertPage(bookEditPacket.pageNumber, bookEditPacket.text);
3311+
break;
3312+
case DELETE_PAGE:
3313+
success = ((ItemBookAndQuill) newBook).deletePage(bookEditPacket.pageNumber);
3314+
break;
3315+
case SWAP_PAGES:
3316+
success = ((ItemBookAndQuill) newBook).swapPages(bookEditPacket.pageNumber, bookEditPacket.secondaryPageNumber);
3317+
break;
3318+
case SIGN_BOOK:
3319+
newBook = Item.get(Item.WRITTEN_BOOK, 0, 1, oldBook.getCompoundTag());
3320+
success = ((ItemBookWritten) newBook).signBook(bookEditPacket.title, bookEditPacket.author, bookEditPacket.xuid, ItemBookWritten.GENERATION_ORIGINAL);
3321+
break;
3322+
default:
3323+
return;
3324+
}
3325+
3326+
if (success) {
3327+
PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(this, oldBook, newBook, bookEditPacket.action);
3328+
this.server.getPluginManager().callEvent(editBookEvent);
3329+
if (!editBookEvent.isCancelled()) {
3330+
this.inventory.setItem(bookEditPacket.inventorySlot, editBookEvent.getNewBook());
3331+
}
3332+
}
3333+
break;
32893334
default:
32903335
break;
32913336
}
@@ -3818,37 +3863,38 @@ public void kill() {
38183863
PlayerDeathEvent ev = new PlayerDeathEvent(this, this.getDrops(), new TranslationContainer(message, params.toArray(new String[0])), this.expLevel);
38193864
ev.setKeepExperience(this.level.gameRules.getBoolean(GameRule.KEEP_INVENTORY));
38203865
ev.setKeepInventory(ev.getKeepExperience());
3821-
this.server.getPluginManager().callEvent(ev);
38223866

3823-
if (!ev.isCancelled()) {
3824-
if (cause != null && cause.getCause() != DamageCause.VOID) {
3825-
PlayerOffhandInventory offhandInventory = this.getOffhandInventory();
3826-
PlayerInventory playerInventory = this.getInventory();
3827-
if (offhandInventory.getItem(0).getId() == Item.TOTEM || playerInventory.getItemInHand().getId() == Item.TOTEM) {
3828-
this.getLevel().addLevelEvent(this, LevelEventPacket.EVENT_SOUND_TOTEM);
3829-
this.extinguish();
3830-
this.removeAllEffects();
3831-
this.setHealth(1);
3867+
if (cause != null && cause.getCause() != DamageCause.VOID) {
3868+
PlayerOffhandInventory offhandInventory = this.getOffhandInventory();
3869+
PlayerInventory playerInventory = this.getInventory();
3870+
if (offhandInventory.getItem(0).getId() == Item.TOTEM || playerInventory.getItemInHand().getId() == Item.TOTEM) {
3871+
this.getLevel().addLevelEvent(this, LevelEventPacket.EVENT_SOUND_TOTEM);
3872+
this.extinguish();
3873+
this.removeAllEffects();
3874+
this.setHealth(1);
38323875

3833-
this.addEffect(Effect.getEffect(Effect.REGENERATION).setDuration(800).setAmplifier(1));
3834-
this.addEffect(Effect.getEffect(Effect.FIRE_RESISTANCE).setDuration(800).setAmplifier(1));
3835-
this.addEffect(Effect.getEffect(Effect.ABSORPTION).setDuration(100).setAmplifier(1));
3876+
this.addEffect(Effect.getEffect(Effect.REGENERATION).setDuration(800).setAmplifier(1));
3877+
this.addEffect(Effect.getEffect(Effect.FIRE_RESISTANCE).setDuration(800).setAmplifier(1));
3878+
this.addEffect(Effect.getEffect(Effect.ABSORPTION).setDuration(100).setAmplifier(1));
38363879

3837-
EntityEventPacket pk = new EntityEventPacket();
3838-
pk.eid = this.getId();
3839-
pk.event = EntityEventPacket.CONSUME_TOTEM;
3840-
this.dataPacket(pk);
3880+
EntityEventPacket pk = new EntityEventPacket();
3881+
pk.eid = this.getId();
3882+
pk.event = EntityEventPacket.CONSUME_TOTEM;
3883+
this.dataPacket(pk);
38413884

3842-
if (offhandInventory.getItem(0).getId() == Item.TOTEM) {
3843-
offhandInventory.clear(0);
3844-
} else {
3845-
playerInventory.clear(playerInventory.getHeldItemIndex());
3846-
}
3847-
ev.setCancelled(true);
3848-
return;
3885+
if (offhandInventory.getItem(0).getId() == Item.TOTEM) {
3886+
offhandInventory.clear(0);
3887+
} else {
3888+
playerInventory.clear(playerInventory.getHeldItemIndex());
38493889
}
3890+
3891+
ev.setCancelled(true);
38503892
}
3893+
}
38513894

3895+
this.server.getPluginManager().callEvent(ev);
3896+
3897+
if (!ev.isCancelled()) {
38523898
if (this.fishing != null) {
38533899
this.stopFishing(false);
38543900
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ public int tickRate() {
408408
}
409409

410410
public boolean onBreak(Item item) {
411-
return this.getLevel().setBlock(this, new BlockAir(), true, true);
411+
return this.getLevel().setBlock(this, Block.get(BlockID.AIR), true, true);
412412
}
413413

414414
public int onUpdate(int type) {
@@ -627,6 +627,11 @@ public double getBreakTime(Item item, Player player) {
627627
Objects.requireNonNull(item, "getBreakTime: Item can not be null");
628628
Objects.requireNonNull(player, "getBreakTime: Player can not be null");
629629
double blockHardness = getHardness();
630+
631+
if (blockHardness == 0) {
632+
return 0;
633+
}
634+
630635
boolean correctTool = correctTool0(getToolType(), item);
631636
boolean canHarvestWithHand = canHarvestWithHand();
632637
int blockId = getId();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public boolean place(Item item, Block block, Block target, BlockFace face, doubl
7373
this.getLevel().setBlock(block, this, true);
7474
} else {
7575
this.setDamage(face.getIndex());
76-
this.getLevel().setBlock(block, new BlockWallBanner(this.getDamage()), true);
76+
this.getLevel().setBlock(block, Block.get(BlockID.WALL_BANNER, this.getDamage()), true);
7777
}
7878

7979
CompoundTag nbt = BlockEntity.getDefaultCompound(this, BlockEntity.BANNER)

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,27 +139,27 @@ public boolean onBreak(Item item) {
139139

140140
if ((this.getDamage() & 0x08) == 0x08) { //This is the Top part of bed
141141
if (blockNorth.getId() == BED_BLOCK && (blockNorth.getDamage() & 0x08) != 0x08) { //Checks if the block ID&&meta are right
142-
this.getLevel().setBlock(blockNorth, new BlockAir(), true, true);
142+
this.getLevel().setBlock(blockNorth, Block.get(BlockID.AIR), true, true);
143143
} else if (blockSouth.getId() == BED_BLOCK && (blockSouth.getDamage() & 0x08) != 0x08) {
144-
this.getLevel().setBlock(blockSouth, new BlockAir(), true, true);
144+
this.getLevel().setBlock(blockSouth, Block.get(BlockID.AIR), true, true);
145145
} else if (blockEast.getId() == BED_BLOCK && (blockEast.getDamage() & 0x08) != 0x08) {
146-
this.getLevel().setBlock(blockEast, new BlockAir(), true, true);
146+
this.getLevel().setBlock(blockEast, Block.get(BlockID.AIR), true, true);
147147
} else if (blockWest.getId() == BED_BLOCK && (blockWest.getDamage() & 0x08) != 0x08) {
148-
this.getLevel().setBlock(blockWest, new BlockAir(), true, true);
148+
this.getLevel().setBlock(blockWest, Block.get(BlockID.AIR), true, true);
149149
}
150150
} else { //Bottom Part of Bed
151151
if (blockNorth.getId() == this.getId() && (blockNorth.getDamage() & 0x08) == 0x08) {
152-
this.getLevel().setBlock(blockNorth, new BlockAir(), true, true);
152+
this.getLevel().setBlock(blockNorth, Block.get(BlockID.AIR), true, true);
153153
} else if (blockSouth.getId() == this.getId() && (blockSouth.getDamage() & 0x08) == 0x08) {
154-
this.getLevel().setBlock(blockSouth, new BlockAir(), true, true);
154+
this.getLevel().setBlock(blockSouth, Block.get(BlockID.AIR), true, true);
155155
} else if (blockEast.getId() == this.getId() && (blockEast.getDamage() & 0x08) == 0x08) {
156-
this.getLevel().setBlock(blockEast, new BlockAir(), true, true);
156+
this.getLevel().setBlock(blockEast, Block.get(BlockID.AIR), true, true);
157157
} else if (blockWest.getId() == this.getId() && (blockWest.getDamage() & 0x08) == 0x08) {
158-
this.getLevel().setBlock(blockWest, new BlockAir(), true, true);
158+
this.getLevel().setBlock(blockWest, Block.get(BlockID.AIR), true, true);
159159
}
160160
}
161161

162-
this.getLevel().setBlock(this, new BlockAir(), true, false); // Do not update both parts to prevent duplication bug if there is two fallable blocks top of the bed
162+
this.getLevel().setBlock(this, Block.get(BlockID.AIR), true, false); // Do not update both parts to prevent duplication bug if there is two fallable blocks top of the bed
163163

164164
return true;
165165
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ public boolean canBePulled() {
5454

5555
@Override
5656
public Item toItem() {
57-
return new ItemBlock(new BlockAir());
57+
return new ItemBlock(Block.get(BlockID.AIR));
5858
}
5959
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public int onUpdate(int type) {
107107
for (int y = 1; y < 3; ++y) {
108108
Block b = this.getLevel().getBlock(new Vector3(this.x, this.y + y, this.z));
109109
if (b.getId() == AIR) {
110-
BlockGrowEvent event = new BlockGrowEvent(b, new BlockCactus());
110+
BlockGrowEvent event = new BlockGrowEvent(b, Block.get(BlockID.CACTUS));
111111
Server.getInstance().getPluginManager().callEvent(event);
112112
if (!event.isCancelled()) {
113113
this.getLevel().setBlock(b, event.getNewState(), true);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public boolean place(Item item, Block block, Block target, BlockFace face, doubl
9090
public int onUpdate(int type) {
9191
if (type == Level.BLOCK_UPDATE_NORMAL) {
9292
if (down().getId() == Block.AIR) {
93-
getLevel().setBlock(this, new BlockAir(), true);
93+
getLevel().setBlock(this, Block.get(BlockID.AIR), true);
9494

9595
return Level.BLOCK_UPDATE_NORMAL;
9696
}
@@ -114,7 +114,7 @@ public boolean onActivate(Item item, Player player) {
114114
if (player != null && player.getFoodData().getLevel() < player.getFoodData().getMaxLevel()) {
115115
if (getDamage() <= 0x06) setDamage(getDamage() + 1);
116116
if (getDamage() >= 0x06) {
117-
getLevel().setBlock(this, new BlockAir(), true);
117+
getLevel().setBlock(this, Block.get(BlockID.AIR), true);
118118
} else {
119119
Food.getByRelative(this).eatenBy(player);
120120
getLevel().setBlock(this, this, true);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public boolean onActivate(Item item, Player player) {
142142
this.setDamage(0x06);
143143

144144
if (item.getCount() == 1) {
145-
player.getInventory().setItemInHand(new ItemBlock(new BlockAir()));
145+
player.getInventory().setItemInHand(new ItemBlock(Block.get(BlockID.AIR)));
146146
} else if (item.getCount() > 1) {
147147
item.setCount(item.getCount() - 1);
148148
player.getInventory().setItemInHand(item);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public boolean onBreak(Item item) {
153153
if (t instanceof BlockEntityChest) {
154154
((BlockEntityChest) t).unpair();
155155
}
156-
this.getLevel().setBlock(this, new BlockAir(), true, true);
156+
this.getLevel().setBlock(this, Block.get(BlockID.AIR), true, true);
157157

158158
return true;
159159
}

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

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

3-
import cn.nukkit.Player;
43
import cn.nukkit.item.Item;
54
import cn.nukkit.item.ItemBlock;
65
import cn.nukkit.utils.BlockColor;

0 commit comments

Comments
 (0)