-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathIntegratedScripting.java
More file actions
211 lines (176 loc) · 8.57 KB
/
Copy pathIntegratedScripting.java
File metadata and controls
211 lines (176 loc) · 8.57 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package org.cyclops.integratedscripting;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.server.ServerStartedEvent;
import net.neoforged.neoforge.event.server.ServerStoppingEvent;
import net.neoforged.neoforge.event.tick.ServerTickEvent;
import net.neoforged.neoforge.registries.NewRegistryEvent;
import org.apache.logging.log4j.Level;
import org.cyclops.cyclopscore.config.ConfigHandlerCommon;
import org.cyclops.cyclopscore.infobook.IInfoBookRegistry;
import org.cyclops.cyclopscore.init.ModBaseNeoForge;
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.command.CommandTestScript;
import org.cyclops.integratedscripting.component.DataComponentDiskIdConfig;
import org.cyclops.integratedscripting.core.client.model.ScriptingVariableModelProviders;
import org.cyclops.integratedscripting.core.evaluate.ScriptVariableFacadeHandler;
import org.cyclops.integratedscripting.core.packageddependencies.PackagedDependenciesLoader;
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.gametest.GameTestsAdvancements;
import org.cyclops.integratedscripting.gametest.GameTestsScripts;
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;
import java.io.IOException;
/**
* The main mod class of this mod.
* @author rubensworks (aka kroeserr)
*
*/
@Mod(Reference.MOD_ID)
public class IntegratedScripting extends ModBaseNeoForge<IntegratedScripting> {
public static IntegratedScripting _instance;
public ScriptingData scriptingData;
public IntegratedScripting(IEventBus modEventBus) {
super(Reference.MOD_ID, (instance) -> _instance = instance, modEventBus);
try {
PackagedDependenciesLoader.load();
} catch (IOException e) {
throw new RuntimeException(e);
}
getRegistryManager().addRegistry(IValueTranslatorRegistry.class, ValueTranslatorRegistry.getInstance());
getRegistryManager().addRegistry(ILanguageHandlerRegistry.class, LanguageHandlerRegistry.getInstance());
modEventBus.addListener(this::onRegistriesCreate);
modEventBus.addListener(this::afterSetup);
modEventBus.register(new ScriptingNetworkCapabilityConstructors());
NeoForge.EVENT_BUS.addListener(this::onServerStarting);
NeoForge.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 (getModHelpers().getMinecraftHelpers().isClientSide()) {
ScriptingVariableModelProviders.load();
}
// Load parts
PartTypes.load();
}
@Override
protected LiteralArgumentBuilder<CommandSourceStack> constructBaseCommand(Commands.CommandSelection selection, CommandBuildContext context) {
LiteralArgumentBuilder<CommandSourceStack> root = super.constructBaseCommand(selection, context);
root.then(CommandTestScript.make());
return root;
}
@Override
protected void setup(FMLCommonSetupEvent event) {
super.setup(event);
ValueTranslators.load();
LanguageHandlers.load();
}
@SubscribeEvent
public void onServerStarted(ServerStartedEvent event) {
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(ServerTickEvent.Pre event) {
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(ConfigHandlerCommon configHandler) {
super.onConfigsRegister(configHandler);
configHandler.addConfigurable(new GeneralConfig());
configHandler.addConfigurable(new ItemScriptingDiskConfig());
configHandler.addConfigurable(new BlockScriptingDriveConfig());
configHandler.addConfigurable(new BlockMendesiteConfig());
configHandler.addConfigurable(new BlockEntityScriptingDriveConfig());
configHandler.addConfigurable(new ContainerScriptingDriveConfig());
configHandler.addConfigurable(new ContainerTerminalScriptingConfig());
configHandler.addConfigurable(new DataComponentDiskIdConfig());
}
@Override
protected IClientProxy constructClientProxy() {
return new ClientProxy();
}
@Override
protected ICommonProxy constructCommonProxy() {
return new CommonProxy();
}
@Override
public Class<?>[] getGameTestClasses() {
return new Class<?>[]{
GameTestsAdvancements.class,
GameTestsScripts.class
};
}
/**
* 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);
}
}