Skip to content

Commit

Permalink
#43: Prevent players from swimming up waterfalls
Browse files Browse the repository at this point in the history
[Problem]

Players can swim up waterfalls in areas where we want waterfalls as decoration but also need to restrict access.

[Solution]

Handle player position packets by checking if they are in a bubble column, cancel their ability to sprint (fast swim) if so.

[Testing]

This does work partially, however there must be some discrepancy with how a user's position is tracked when they are swimming already. If you load into the given test environment, and start swimming in the normal water, then move to the bubble column, it will sometimes not cancel your swimming. We could also potentially check within a radius of the 8 blocks around the player if that's the issue.

Another potential issue with this solution is players with high ping could navigate around this by not sending a position packet until they've climbed up the waterfall on client side, and then each packet gets sent and processed but won't return them to their original location.
  • Loading branch information
Nixotica committed Sep 27, 2022
1 parent 1aede46 commit 87dcff9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ public static void main(String[] args) {
event.getSpawnInstance().setBlock(11, 47, 5, Block.WATER);
event.getSpawnInstance().setBlock(11, 48, 5, Block.WATER);

event.getSpawnInstance().setBlock(10, 40, 5, Block.BUBBLE_COLUMN);
event.getSpawnInstance().setBlock(10, 41, 5, Block.BUBBLE_COLUMN);
event.getSpawnInstance().setBlock(10, 42, 5, Block.BUBBLE_COLUMN);
event.getSpawnInstance().setBlock(10, 43, 5, Block.BUBBLE_COLUMN);
event.getSpawnInstance().setBlock(10, 44, 5, Block.BUBBLE_COLUMN);
event.getSpawnInstance().setBlock(10, 45, 5, Block.BUBBLE_COLUMN);
event.getSpawnInstance().setBlock(10, 46, 5, Block.BUBBLE_COLUMN);
event.getSpawnInstance().setBlock(10, 47, 5, Block.BUBBLE_COLUMN);
event.getSpawnInstance().setBlock(10, 48, 5, Block.BUBBLE_COLUMN);

event.getSpawnInstance().setBlock(11, 40, 5, Block.WATER);
event.getSpawnInstance().setBlock(11, 41, 5, Block.WATER);
event.getSpawnInstance().setBlock(11, 42, 5, Block.WATER);
event.getSpawnInstance().setBlock(11, 43, 5, Block.WATER);
event.getSpawnInstance().setBlock(11, 44, 5, Block.WATER);
event.getSpawnInstance().setBlock(11, 45, 5, Block.WATER);
event.getSpawnInstance().setBlock(11, 46, 5, Block.WATER);
event.getSpawnInstance().setBlock(11, 47, 5, Block.WATER);
event.getSpawnInstance().setBlock(11, 48, 5, Block.WATER);

//todo this needs to be done elsewhere
player.addEffect(new Potion(PotionEffect.MINING_FATIGUE, (byte) -1, Short.MAX_VALUE, (byte) 0x0));

Expand Down
29 changes: 11 additions & 18 deletions modules/player/src/main/java/net/hollowcube/player/PlayerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import net.hollowcube.modifiers.ModifierList;
import net.hollowcube.modifiers.ModifierOperation;
import net.hollowcube.modifiers.ModifierType;
import net.hollowcube.player.event.PlayerBubbleColumnSinkEvent;
import net.hollowcube.player.event.PlayerLongDiggingStartEvent;
import net.minestom.server.MinecraftServer;
import net.minestom.server.coordinate.Point;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.entity.Player;
import net.minestom.server.event.player.PlayerPacketEvent;
import net.minestom.server.instance.Instance;
Expand Down Expand Up @@ -105,33 +105,26 @@ private void handleDiggingPacket(ClientPlayerDiggingPacket packet) {
}

private void handlePositionPacket(ClientPlayerPositionPacket packet) {
Pos playerPos = this.getPosition();
Block blockAtPlayerPos = this.getInstance().getBlock(playerPos);

if (packet.onGround()) {

}
else {
if (this.getInstance().getBlock(this.getPosition()) == Block.BUBBLE_COLUMN) {
//TODO: I think we want to make this part of a whole PlayerInWaterHandler or something, and on top of that,
// we would have to make a BlockComponentHandler or something to encapsulate it. I wonder if @Matt has a
// suggestion on this.

// PlayerBubbleColumnSinkEvent playerBubbleColumnSinkEvent = new PlayerBubbleColumnSinkEvent(this, this.getFood());
// MinecraftServer.getGlobalEventHandler().call(playerBubbleColumnSinkEvent);

if (blockAtPlayerPos == Block.BUBBLE_COLUMN) {
if (!this.wasLastSeenInBubbleColumn) {
this.wasLastSeenInBubbleColumn = true;
this.bubbleColumnSinkEnergyLevel = this.getFood();
//TODO: This does not work lol it is not implemented in minestom to get rid of the player's
// ability to sprint when they have hunger below 7
this.setFood(6);
}
}
else if (this.wasLastSeenInBubbleColumn) {
if (this.getInstance().getBlock(this.getPosition()) != Block.BUBBLE_COLUMN) {
this.wasLastSeenInBubbleColumn = false;
this.setFood(this.bubbleColumnSinkEnergyLevel);
this.bubbleColumnSinkEnergyLevel = -1;
}
}
}

if ((this.wasLastSeenInBubbleColumn) && (blockAtPlayerPos != Block.BUBBLE_COLUMN)) {
this.wasLastSeenInBubbleColumn = false;
this.setFood(this.bubbleColumnSinkEnergyLevel);
this.bubbleColumnSinkEnergyLevel = -1;
}
}

Expand Down

0 comments on commit 87dcff9

Please sign in to comment.