Skip to content

Commit 030cc24

Browse files
Merge pull request CloudburstMC#1073 from PowerNukkit/v1.4/bed/waterlogged
Fixes CloudburstMC#29 Incorrect behaviour when trying to sleep on waterlogged bed
2 parents 120a66c + d0a9287 commit 030cc24

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import cn.nukkit.math.BlockFace;
2222
import cn.nukkit.math.SimpleAxisAlignedBB;
2323
import cn.nukkit.nbt.tag.CompoundTag;
24+
import cn.nukkit.potion.Effect;
2425
import cn.nukkit.utils.BlockColor;
2526
import cn.nukkit.utils.DyeColor;
2627
import cn.nukkit.utils.Faceable;
@@ -173,33 +174,35 @@ public boolean onActivate(@Nonnull Item item, Player player) {
173174
explosion.explodeB();
174175
return true;
175176
}
176-
177-
if (player != null) {
178-
AxisAlignedBB accessArea = new SimpleAxisAlignedBB(head.x - 2, head.y - 5.5, head.z - 2, head.x + 3, head.y + 2.5, head.z + 3)
179-
.addCoord(footPart.getXOffset(), 0, footPart.getZOffset());
180-
181-
if (!accessArea.isVectorInside(player)) {
182-
player.sendMessage(new TranslationContainer(TextFormat.GRAY + "%tile.bed.tooFar"));
183-
return true;
184-
}
185-
186-
Location spawn = Location.fromObject(head.add(0.5, 0.5, 0.5), player.getLevel(), player.getYaw(), player.getPitch());
187-
if (!player.getSpawn().equals(spawn)) {
188-
player.setSpawn(spawn);
189-
}
190-
player.sendMessage(new TranslationContainer(TextFormat.GRAY + "%tile.bed.respawnSet"));
177+
178+
if (player == null || !player.hasEffect(Effect.CONDUIT_POWER) && getLevelBlockAtLayer(1) instanceof BlockWater) {
179+
return true;
180+
}
181+
182+
AxisAlignedBB accessArea = new SimpleAxisAlignedBB(head.x - 2, head.y - 5.5, head.z - 2, head.x + 3, head.y + 2.5, head.z + 3)
183+
.addCoord(footPart.getXOffset(), 0, footPart.getZOffset());
184+
185+
if (!accessArea.isVectorInside(player)) {
186+
player.sendMessage(new TranslationContainer(TextFormat.GRAY + "%tile.bed.tooFar"));
187+
return true;
188+
}
189+
190+
Location spawn = Location.fromObject(head.add(0.5, 0.5, 0.5), player.getLevel(), player.getYaw(), player.getPitch());
191+
if (!player.getSpawn().equals(spawn)) {
192+
player.setSpawn(spawn);
191193
}
194+
player.sendMessage(new TranslationContainer(TextFormat.GRAY + "%tile.bed.respawnSet"));
192195

193196
int time = this.getLevel().getTime() % Level.TIME_FULL;
194197

195198
boolean isNight = (time >= Level.TIME_NIGHT && time < Level.TIME_SUNRISE);
196199

197-
if (player != null && !isNight) {
200+
if (!isNight) {
198201
player.sendMessage(new TranslationContainer(TextFormat.GRAY + "%tile.bed.noSleep"));
199202
return true;
200203
}
201204

202-
if (player != null && !player.isCreative()) {
205+
if (!player.isCreative()) {
203206
AxisAlignedBB checkMonsterArea = new SimpleAxisAlignedBB(head.x - 8, head.y - 6.5, head.z - 8, head.x + 9, head.y + 5.5, head.z + 9)
204207
.addCoord(footPart.getXOffset(), 0, footPart.getZOffset());
205208

@@ -212,11 +215,10 @@ public boolean onActivate(@Nonnull Item item, Player player) {
212215
}
213216
}
214217

215-
if (player != null && !player.sleepOn(head)) {
218+
if (!player.sleepOn(head)) {
216219
player.sendMessage(new TranslationContainer(TextFormat.GRAY + "%tile.bed.occupied"));
217220
}
218221

219-
220222
return true;
221223
}
222224

0 commit comments

Comments
 (0)