Skip to content

Commit

Permalink
It works well now, I'll test it on all mc versions to figure out what…
Browse files Browse the repository at this point in the history
… I can run this on
  • Loading branch information
RaydanOMGr committed Mar 17, 2024
1 parent 35fe247 commit c50cea8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ dependencies {
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${cca_version}"
include "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${cca_version}"

modImplementation "curse.maven:lazydfu-433518:3821870"

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/me/andreasmelone/glowingeyes/GlowingEyes.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@

import me.andreasmelone.glowingeyes.common.GlowingEyesEvents;
import me.andreasmelone.glowingeyes.common.packet.CapabilityUpdatePacket;
import me.andreasmelone.glowingeyes.common.scheduler.CodeScheduler;
import me.andreasmelone.glowingeyes.common.scheduler.Scheduler;
import net.fabricmc.api.ModInitializer;

import java.awt.*;

public class GlowingEyes implements ModInitializer {
public static final String MOD_ID = "glowingeyes";
public static final Color DEFAULT_COLOR = new Color(255, 10, 10, 210);
private static final Scheduler SERVER_SCHEDULER = new CodeScheduler();

@Override
public void onInitialize() {
CapabilityUpdatePacket.registerHandlers();
GlowingEyesEvents.registerEvents();
}

public static Scheduler getServerScheduler() {
return SERVER_SCHEDULER;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.andreasmelone.glowingeyes.common;

import me.andreasmelone.glowingeyes.GlowingEyes;
import me.andreasmelone.glowingeyes.common.component.eyes.GlowingEyesComponent;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.networking.v1.EntityTrackingEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.server.level.ServerPlayer;
Expand All @@ -14,7 +16,13 @@ public static void registerEvents() {
EntityTrackingEvents.START_TRACKING.register((trackedEntity, playerTracking) -> {
if(!(trackedEntity instanceof ServerPlayer trackedPlayer)) return;

GlowingEyesComponent.sendUpdate(playerTracking, trackedPlayer);
GlowingEyes.getServerScheduler().runLater(() -> {
GlowingEyesComponent.sendUpdate(playerTracking, trackedPlayer);
}, 1L);
});

ServerTickEvents.END_SERVER_TICK.register(server -> {
GlowingEyes.getServerScheduler().tick();
});
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package me.andreasmelone.glowingeyes.common.scheduler;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CodeScheduler implements Scheduler {
// task, ticks
Map<Task, Long> tasksToDelay = new HashMap<>();
Map<Task, Long> tasksToDelay = new ConcurrentHashMap<>();

@Override
public Task runLater(Runnable runnable, long ticks) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depends": {
"fabricloader": ">=${loader_version}",
"fabric": "*",
"minecraft": "${minecraft_version}"
"minecraft": "1.19.*"
},
"custom": {
"cardinal-components": [
Expand Down

0 comments on commit c50cea8

Please sign in to comment.