Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/GeyserMC/Geyser into feat…
Browse files Browse the repository at this point in the history
…ure/1.20.5
  • Loading branch information
Camotoy committed Apr 24, 2024
2 parents 8041ae2 + 2471de1 commit a28c890
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 41 deletions.
58 changes: 19 additions & 39 deletions core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import java.util.UUID;
import java.util.concurrent.TimeUnit;

public class BoatEntity extends Entity {
public class BoatEntity extends Entity implements Tickable {

/**
* Required when IS_BUOYANT is sent in order for boats to work in the water. <br>
Expand All @@ -58,6 +58,7 @@ public class BoatEntity extends Entity {
private float paddleTimeLeft;
private boolean isPaddlingRight;
private float paddleTimeRight;
private boolean doTick;

/**
* Saved for using the "pick" functionality on a boat.
Expand Down Expand Up @@ -133,34 +134,16 @@ public void setVariant(IntEntityMetadata entityMetadata) {

public void setPaddlingLeft(BooleanEntityMetadata entityMetadata) {
isPaddlingLeft = entityMetadata.getPrimitiveValue();
if (isPaddlingLeft) {
// Java sends simply "true" and "false" (is_paddling_left), Bedrock keeps sending packets as you're rowing
// This is an asynchronous method that emulates Bedrock rowing until "false" is sent.
paddleTimeLeft = 0f;
if (!this.passengers.isEmpty()) {
// Get the entity by the first stored passenger and convey motion in this manner
Entity entity = this.passengers.get(0);
if (entity != null) {
updateLeftPaddle(session, entity);
}
}
} else {
// Indicate that the row position should be reset
if (!isPaddlingLeft) {
paddleTimeLeft = 0.0f;
dirtyMetadata.put(EntityDataTypes.ROW_TIME_LEFT, 0.0f);
}
}

public void setPaddlingRight(BooleanEntityMetadata entityMetadata) {
isPaddlingRight = entityMetadata.getPrimitiveValue();
if (isPaddlingRight) {
paddleTimeRight = 0f;
if (!this.passengers.isEmpty()) {
Entity entity = this.passengers.get(0);
if (entity != null) {
updateRightPaddle(session, entity);
}
}
} else {
if (!isPaddlingRight) {
paddleTimeRight = 0.0f;
dirtyMetadata.put(EntityDataTypes.ROW_TIME_RIGHT, 0.0f);
}
}
Expand All @@ -186,29 +169,26 @@ public InteractionResult interact(Hand hand) {
}
}

private void updateLeftPaddle(GeyserSession session, Entity rower) {
@Override
public void tick() {
// Java sends simply "true" and "false" (is_paddling_left), Bedrock keeps sending packets as you're rowing
doTick = !doTick; // Run every 100 ms
if (!doTick || passengers.isEmpty()) {
return;
}

Entity rower = passengers.get(0);
if (rower == null) {
return;
}

if (isPaddlingLeft) {
paddleTimeLeft += ROWING_SPEED;
sendAnimationPacket(session, rower, AnimatePacket.Action.ROW_LEFT, paddleTimeLeft);

session.scheduleInEventLoop(() ->
updateLeftPaddle(session, rower),
100,
TimeUnit.MILLISECONDS
);
}
}

private void updateRightPaddle(GeyserSession session, Entity rower) {
if (isPaddlingRight) {
paddleTimeRight += ROWING_SPEED;
sendAnimationPacket(session, rower, AnimatePacket.Action.ROW_RIGHT, paddleTimeRight);

session.scheduleInEventLoop(() ->
updateRightPaddle(session, rower),
100,
TimeUnit.MILLISECONDS
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,17 @@ private ServerBootstrap createBootstrap() {
int rakGlobalPacketLimit = positivePropOrDefault("Geyser.RakGlobalPacketLimit", DEFAULT_GLOBAL_PACKET_LIMIT);
this.geyser.getLogger().debug("Setting RakNet global packet limit to " + rakGlobalPacketLimit);

boolean rakSendCookie = Boolean.parseBoolean(System.getProperty("Geyser.RakSendCookie", "true"));
this.geyser.getLogger().debug("Setting RakNet send cookie to " + rakSendCookie);

return new ServerBootstrap()
.channelFactory(RakChannelFactory.server(TRANSPORT.datagramChannel()))
.group(group, childGroup)
.option(RakChannelOption.RAK_HANDLE_PING, true)
.option(RakChannelOption.RAK_MAX_MTU, this.geyser.getConfig().getMtu())
.option(RakChannelOption.RAK_PACKET_LIMIT, rakPacketLimit)
.option(RakChannelOption.RAK_GLOBAL_PACKET_LIMIT, rakGlobalPacketLimit)
.option(RakChannelOption.RAK_SEND_COOKIE, true)
.option(RakChannelOption.RAK_SEND_COOKIE, rakSendCookie)
.childHandler(serverInitializer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,11 +1136,15 @@ public void executeInEventLoop(Runnable runnable) {

/**
* Schedules a task and prints a stack trace if an error occurs.
* <p>
* The task will not run if the session is closed.
*/
public ScheduledFuture<?> scheduleInEventLoop(Runnable runnable, long duration, TimeUnit timeUnit) {
return eventLoop.schedule(() -> {
try {
runnable.run();
if (!closed) {
runnable.run();
}
} catch (Throwable e) {
geyser.getLogger().error("Error thrown in " + this.bedrockUsername() + "'s event loop!", e);
}
Expand Down

0 comments on commit a28c890

Please sign in to comment.