-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRootComponent.java
More file actions
78 lines (60 loc) · 1.96 KB
/
RootComponent.java
File metadata and controls
78 lines (60 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package dev.amble.lib.api.sync;
import java.util.UUID;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.server.MinecraftServer;
import dev.amble.lib.AmbleKit;
import dev.amble.lib.api.sync.handler.ComponentManager;
import dev.amble.lib.api.sync.handler.SyncComponent;
import dev.amble.lib.api.sync.handler.TickingComponent;
import dev.amble.lib.api.sync.manager.SyncManager;
public abstract class RootComponent extends Initializable<SyncComponent.InitContext> implements Disposable, TickingComponent {
private UUID uuid;
protected ComponentManager manager;
protected RootComponent(UUID uuid) {
this.uuid = uuid;
this.manager = new ComponentManager(getSyncManager().getHandlersId(), getSyncManager().getRegistry());
}
@Override
protected void onInit(SyncComponent.InitContext ctx) {
super.onInit(ctx);
SyncComponent.init(manager, this, ctx);
SyncComponent.postInit(manager, ctx);
}
public UUID getUuid() {
return uuid;
}
@Override
public String toString() {
return uuid.toString();
}
@Override
public int hashCode() {
return uuid.hashCode();
}
public <T extends SyncComponent> T handler(SyncComponent.IdLike type) {
if (this.manager == null) {
AmbleKit.LOGGER.error("Asked for a handler too early on {}", this);
return null;
}
return this.manager.get(type);
}
public ComponentManager getHandlers() {
return manager;
}
public abstract SyncManager<?, ?> getSyncManager();
@Override
public void dispose() {
this.getHandlers().dispose();
}
@Override
public void tick(MinecraftServer server) {
this.getHandlers().tick(server);
}
@Environment(EnvType.CLIENT)
@Override
public void tick(MinecraftClient client) {
this.getHandlers().tick(client) ;
}
}