-
Notifications
You must be signed in to change notification settings - Fork 497
/
TabletBase.java
68 lines (56 loc) · 1.89 KB
/
TabletBase.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
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
package buildcraft.core.tablet;
import java.util.LinkedList;
import net.minecraft.nbt.NBTTagCompound;
import buildcraft.api.core.BCLog;
import buildcraft.api.tablet.ITablet;
import buildcraft.api.tablet.TabletAPI;
import buildcraft.api.tablet.TabletProgram;
import buildcraft.api.tablet.TabletProgramFactory;
public abstract class TabletBase implements ITablet {
protected final LinkedList<TabletProgram> programs = new LinkedList<>();
protected TabletBase() {
}
public void tick(float time) {
if (programs.size() > 0) {
programs.getLast().tick(time);
}
}
@Override
public int getScreenWidth() {
return 244;
}
@Override
public int getScreenHeight() {
return 306;
}
protected boolean launchProgramInternal(String name) {
TabletProgramFactory factory = TabletAPI.getProgram(name);
if (factory == null) {
BCLog.logger.error("Tried to launch non-existent tablet program on side CLIENT: " + name);
return false;
}
TabletProgram program = factory.create(this);
if (program == null) {
BCLog.logger.error("Factory could not create program on side CLIENT: " + name);
return false;
}
programs.add(program);
return true;
}
public abstract void receiveMessage(NBTTagCompound compound);
protected boolean receiveMessageInternal(NBTTagCompound compound) {
if (compound.hasKey("__program")) {
compound.removeTag("__program");
if (programs.getLast() != null) {
programs.getLast().receiveMessage(compound);
}
return true;
} else {
if (compound.hasKey("programToLaunch")) {
launchProgramInternal(compound.getString("programToLaunch"));
return true;
}
}
return false;
}
}