-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathIntegratedScripting.java
More file actions
197 lines (164 loc) · 8.16 KB
/
Copy pathIntegratedScripting.java
File metadata and controls
197 lines (164 loc) · 8.16 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package org.cyclops.integratedscripting;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.server.ServerStartedEvent;
import net.minecraftforge.event.server.ServerStoppingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.NewRegistryEvent;
import org.apache.logging.log4j.Level;
import org.cyclops.cyclopscore.config.ConfigHandler;
import org.cyclops.cyclopscore.helper.MinecraftHelpers;
import org.cyclops.cyclopscore.infobook.IInfoBookRegistry;
import org.cyclops.cyclopscore.init.ModBaseVersionable;
import org.cyclops.cyclopscore.proxy.IClientProxy;
import org.cyclops.cyclopscore.proxy.ICommonProxy;
import org.cyclops.integrateddynamics.IntegratedDynamics;
import org.cyclops.integrateddynamics.api.item.IVariableFacadeHandlerRegistry;
import org.cyclops.integrateddynamics.infobook.OnTheDynamicsOfIntegrationBook;
import org.cyclops.integratedscripting.api.evaluate.translation.IValueTranslatorRegistry;
import org.cyclops.integratedscripting.api.language.ILanguageHandlerRegistry;
import org.cyclops.integratedscripting.block.BlockMendesiteConfig;
import org.cyclops.integratedscripting.block.BlockScriptingDriveConfig;
import org.cyclops.integratedscripting.blockentity.BlockEntityScriptingDriveConfig;
import org.cyclops.integratedscripting.capability.ScriptingNetworkCapabilityConstructors;
import org.cyclops.integratedscripting.capability.network.ScriptingNetworkConfig;
import org.cyclops.integratedscripting.command.CommandTestScript;
import org.cyclops.integratedscripting.core.client.model.ScriptingVariableModelProviders;
import org.cyclops.integratedscripting.core.evaluate.ScriptVariableFacadeHandler;
import org.cyclops.integratedscripting.core.language.LanguageHandlerRegistry;
import org.cyclops.integratedscripting.core.language.LanguageHandlers;
import org.cyclops.integratedscripting.core.network.ScriptingData;
import org.cyclops.integratedscripting.evaluate.EvaluationExceptionResolutionHelpers;
import org.cyclops.integratedscripting.evaluate.translation.ValueTranslatorRegistry;
import org.cyclops.integratedscripting.evaluate.translation.ValueTranslators;
import org.cyclops.integratedscripting.inventory.container.ContainerScriptingDriveConfig;
import org.cyclops.integratedscripting.inventory.container.ContainerTerminalScriptingConfig;
import org.cyclops.integratedscripting.item.ItemScriptingDiskConfig;
import org.cyclops.integratedscripting.part.PartTypes;
import org.cyclops.integratedscripting.proxy.ClientProxy;
import org.cyclops.integratedscripting.proxy.CommonProxy;
/**
* The main mod class of this mod.
* @author rubensworks (aka kroeserr)
*
*/
@Mod(Reference.MOD_ID)
public class IntegratedScripting extends ModBaseVersionable<IntegratedScripting> {
public static IntegratedScripting _instance;
public ScriptingData scriptingData;
public IntegratedScripting() {
super(Reference.MOD_ID, (instance) -> _instance = instance);
getRegistryManager().addRegistry(IValueTranslatorRegistry.class, ValueTranslatorRegistry.getInstance());
getRegistryManager().addRegistry(ILanguageHandlerRegistry.class, LanguageHandlerRegistry.getInstance());
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onRegistriesCreate);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::afterSetup);
MinecraftForge.EVENT_BUS.addListener(this::onServerStarting);
MinecraftForge.EVENT_BUS.addListener(this::onServerTick);
}
public void onRegistriesCreate(NewRegistryEvent event) {
// Register handlers
IntegratedDynamics._instance.getRegistryManager().getRegistry(IVariableFacadeHandlerRegistry.class)
.registerHandler(ScriptVariableFacadeHandler.getInstance());
// Load client models
if (MinecraftHelpers.isClientSide()) {
ScriptingVariableModelProviders.load();
}
// Load parts
PartTypes.load();
}
@Override
protected LiteralArgumentBuilder<CommandSourceStack> constructBaseCommand() {
LiteralArgumentBuilder<CommandSourceStack> root = super.constructBaseCommand();
root.then(CommandTestScript.make());
return root;
}
@Override
protected void setup(FMLCommonSetupEvent event) {
super.setup(event);
MinecraftForge.EVENT_BUS.register(new ScriptingNetworkCapabilityConstructors());
ValueTranslators.load();
LanguageHandlers.load();
}
@SubscribeEvent
public void onServerStarted(ServerStartedEvent event) {
MinecraftForge.EVENT_BUS.register(this.scriptingData = new ScriptingData(event.getServer().getWorldPath(ScriptingData.LEVEL_RESOURCE)));
}
@Override
protected void onServerStopping(ServerStoppingEvent event) {
if (this.scriptingData != null) {
this.scriptingData.close();
}
this.scriptingData = null;
EvaluationExceptionResolutionHelpers.reset();
}
@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
if(event.phase == TickEvent.Phase.START) {
if (this.scriptingData != null) {
this.scriptingData.tick();
}
}
}
protected void afterSetup(FMLLoadCompleteEvent event) {
// Initialize info book
IntegratedDynamics._instance.getRegistryManager().getRegistry(IInfoBookRegistry.class)
.registerSection(this,
OnTheDynamicsOfIntegrationBook.getInstance(), "info_book.integrateddynamics.manual",
"/data/" + Reference.MOD_ID + "/info/scripting_info.xml");
IntegratedDynamics._instance.getRegistryManager().getRegistry(IInfoBookRegistry.class)
.registerSection(this,
OnTheDynamicsOfIntegrationBook.getInstance(), "info_book.integrateddynamics.tutorials",
"/data/" + Reference.MOD_ID + "/info/scripting_tutorials.xml");
}
@Override
protected CreativeModeTab.Builder constructDefaultCreativeModeTab(CreativeModeTab.Builder builder) {
return super.constructDefaultCreativeModeTab(builder)
.icon(() -> new ItemStack(RegistryEntries.ITEM_SCRIPTING_DISK));
}
@Override
protected void onConfigsRegister(ConfigHandler configHandler) {
super.onConfigsRegister(configHandler);
configHandler.addConfigurable(new GeneralConfig());
configHandler.addConfigurable(new ScriptingNetworkConfig());
configHandler.addConfigurable(new ItemScriptingDiskConfig());
configHandler.addConfigurable(new BlockScriptingDriveConfig());
configHandler.addConfigurable(new BlockMendesiteConfig());
configHandler.addConfigurable(new BlockEntityScriptingDriveConfig());
configHandler.addConfigurable(new ContainerScriptingDriveConfig());
configHandler.addConfigurable(new ContainerTerminalScriptingConfig());
}
@OnlyIn(Dist.CLIENT)
@Override
protected IClientProxy constructClientProxy() {
return new ClientProxy();
}
@Override
protected ICommonProxy constructCommonProxy() {
return new CommonProxy();
}
/**
* Log a new info message for this mod.
* @param message The message to show.
*/
public static void clog(String message) {
clog(Level.INFO, message);
}
/**
* Log a new message of the given level for this mod.
* @param level The level in which the message must be shown.
* @param message The message to show.
*/
public static void clog(Level level, String message) {
IntegratedScripting._instance.getLoggerHelper().log(level, message);
}
}