Add interval property for configurable tick rate in LagoonAddons

This commit is contained in:
2026-05-13 07:38:02 +02:00
parent 227c8a7c70
commit 48276881ea
4 changed files with 7 additions and 5 deletions

View File

@@ -2,7 +2,7 @@ import { system, world } from "@minecraft/server";
import utils from "utils"; import utils from "utils";
import { websocket } from "@minecraft/server-net"; import { websocket } from "@minecraft/server-net";
import { InitPlayer } from "entities/player"; import { InitPlayer } from "entities/player";
import { roomCode } from "properties"; import { interval, roomCode } from "properties";
class LagoonAddons { class LagoonAddons {
constructor() { constructor() {
this.timer = 0; this.timer = 0;
@@ -42,7 +42,7 @@ class LagoonAddons {
async clock() { async clock() {
this.timer++; this.timer++;
// 1 seconde // 1 seconde
if (this.timer % 20 === 0) { if (this.timer % interval === 0) {
if (this.ws.isOpen) { if (this.ws.isOpen) {
const players = world.getAllPlayers().map((p) => { const players = world.getAllPlayers().map((p) => {
return { return {

View File

@@ -1 +1,2 @@
export const roomCode = 'ROOM_CODE'; export const roomCode = 'ROOM_CODE';
export const interval = 20; // Interval in ticks at which positions will be sent to the server. (Min: 10)

View File

@@ -2,7 +2,7 @@ import { system, world } from "@minecraft/server";
import utils from "utils"; import utils from "utils";
import { websocket, WebSocketClient } from "@minecraft/server-net"; import { websocket, WebSocketClient } from "@minecraft/server-net";
import { InitPlayer } from "entities/player"; import { InitPlayer } from "entities/player";
import { roomCode } from "properties"; import { interval, roomCode } from "properties";
class LagoonAddons { class LagoonAddons {
@@ -53,7 +53,7 @@ class LagoonAddons {
this.timer++; this.timer++;
// 1 seconde // 1 seconde
if (this.timer % 20 === 0) { if (this.timer % interval === 0) {
if (this.ws.isOpen) { if (this.ws.isOpen) {
const players: {x: number, y: number, z: number, code: string, muted: boolean}[] = world.getAllPlayers().map((p) => { const players: {x: number, y: number, z: number, code: string, muted: boolean}[] = world.getAllPlayers().map((p) => {

View File

@@ -1 +1,2 @@
export const roomCode = 'ROOM_CODE'; export const roomCode = 'ROOM_CODE';
export const interval = 20; // Interval in ticks at which positions will be sent to the server. (Min: 10)