-
Notifications
You must be signed in to change notification settings - Fork 497
/
RobotRegistryProvider.java
42 lines (28 loc) · 1.17 KB
/
RobotRegistryProvider.java
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
package buildcraft.robotics;
import java.util.HashMap;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import buildcraft.api.robots.DockingStation;
import buildcraft.api.robots.IRobotRegistryProvider;
public class RobotRegistryProvider implements IRobotRegistryProvider {
private static HashMap<Integer, RobotRegistry> registries = new HashMap<Integer, RobotRegistry>();
@Override
public synchronized RobotRegistry getRegistry(World world) {
if (!registries.containsKey(world.provider.dimensionId)
|| registries.get(world.provider.dimensionId).world != world) {
RobotRegistry newRegistry = (RobotRegistry) world.perWorldStorage.loadData(RobotRegistry.class, "robotRegistry");
if (newRegistry == null) {
newRegistry = new RobotRegistry("robotRegistry");
world.perWorldStorage.setData("robotRegistry", newRegistry);
}
newRegistry.world = world;
for (DockingStation d : newRegistry.stations.values()) {
d.world = world;
}
MinecraftForge.EVENT_BUS.register(newRegistry);
registries.put(world.provider.dimensionId, newRegistry);
return newRegistry;
}
return registries.get(world.provider.dimensionId);
}
}