Skip to content

Commit

Permalink
perf: Реализация пакетов innercore.mod, innercore.modpack
Browse files Browse the repository at this point in the history
- Добавлена загрузка, кеширование и компиляция модов из Instant Referrer.
- Загрузка иннера перемещена в соответствующий класс.
- Добавлен метод Level.getSeed, калбеки должны начать использовать его.
- Исправления, которые слишком долго описывать.
  • Loading branch information
MaXFeeD committed Dec 11, 2023
1 parent 3b4accc commit d692bea
Show file tree
Hide file tree
Showing 88 changed files with 6,908 additions and 7,177 deletions.
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package-lock.json
node_modules
.gradle
bin
build
/.gradle
/bin
/build

target/*
!target/README.md
logs
/target/*
!/target/README.md
/logs

.idea
.vscode
Expand Down
83 changes: 35 additions & 48 deletions src/main/java/com/reider745/InnerCoreServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,28 @@

import com.reider745.item.ItemMethod;
import com.reider745.item.NukkitIdConvertor;
import com.zhekasmirnov.apparatus.adapter.innercore.PackInfo;
import com.zhekasmirnov.apparatus.api.container.ItemContainer;
import com.zhekasmirnov.apparatus.api.player.NetworkPlayerRegistry;
import com.zhekasmirnov.apparatus.mcpe.NativeWorkbench;
import com.zhekasmirnov.apparatus.multiplayer.Network;
import com.zhekasmirnov.apparatus.multiplayer.NetworkJsAdapter;
import com.zhekasmirnov.apparatus.multiplayer.mod.IdConversionMap;
import com.zhekasmirnov.apparatus.multiplayer.mod.MultiplayerModList;
import com.zhekasmirnov.apparatus.multiplayer.mod.MultiplayerPackVersionChecker;
import com.zhekasmirnov.apparatus.multiplayer.mod.RuntimeIdDataPacketSender;
import com.zhekasmirnov.apparatus.multiplayer.util.entity.NetworkEntity;
import com.zhekasmirnov.horizon.runtime.logger.Logger;
import com.zhekasmirnov.innercore.api.InnerCoreConfig;
import com.zhekasmirnov.innercore.api.NativeCallback;
import com.zhekasmirnov.innercore.api.NativeFurnaceRegistry;
import com.zhekasmirnov.innercore.api.mod.API;
import com.zhekasmirnov.innercore.api.runtime.AsyncModLauncher;
import com.zhekasmirnov.innercore.api.runtime.Updatable;
import com.zhekasmirnov.innercore.api.runtime.LoadingStage;
import com.zhekasmirnov.innercore.mod.build.ExtractionHelper;
import com.zhekasmirnov.innercore.mod.build.ModLoader;
import com.zhekasmirnov.innercore.modpack.ModPack;
import com.zhekasmirnov.innercore.modpack.ModPackContext;
import com.zhekasmirnov.innercore.modpack.ModPackDirectory;
import com.zhekasmirnov.innercore.modpack.ModPackFactory;
import com.zhekasmirnov.innercore.utils.ColorsPatch;
import com.zhekasmirnov.innercore.ui.LoadingUI;
import com.zhekasmirnov.innercore.utils.FileTools;
import com.zhekasmirnov.innercore.utils.ReflectionPatch;
import com.zhekasmirnov.mcpe161.InnerCore;

import org.json.JSONObject;

import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.*;
import java.nio.file.FileSystem;
import java.util.concurrent.atomic.AtomicReference;
import java.util.Enumeration;
import java.util.HashMap;
Expand Down Expand Up @@ -270,15 +257,13 @@ public void preload(Server server) throws Exception {
}
}

// Rhino JavaMembers.reflect patches
ColorsPatch.init();
ReflectionPatch.init();

MultiplayerModList.loadClass();
NetworkPlayerRegistry.loadClass();
MultiplayerPackVersionChecker.loadClass();
NetworkEntity.loadClass();
IdConversionMap.loadClass();
new InnerCore(new File(PATH)).load();
LoadingStage.setStage(LoadingStage.STAGE_MCPE_STARTING);
InnerCoreConfig.set("gameplay.use_legacy_workbench_override", isLegacyWorkbench());
LoadingStage.setStage(LoadingStage.STAGE_MCPE_INITIALIZING);
LoadingUI.setTextAndProgressBar("Initializing Minecraft...", 0.55f);
NativeCallback.onFinalInitStarted();
NativeCallback.onFinalInitComplete();

JSONObject object = new JSONObject();
object.put("fix", server.getPropertyBoolean("inner_core.legacy_inventory", true));
Expand All @@ -289,23 +274,9 @@ public void preload(Server server) throws Exception {
// for new inner core
});

RuntimeIdDataPacketSender.loadClass();
NetworkJsAdapter.instance = new NetworkJsAdapter(Network.getSingleton());
InnerCoreConfig.set("gameplay.use_legacy_workbench_override", isLegacyWorkbench());

API.loadAllAPIs();
ModLoader.initialize();
ModLoader.loadModsAndSetupEnvViaNewModLoader();
ModLoader.prepareResourcesViaNewModLoader();
new AsyncModLauncher().launchModsInCurrentThread();

Updatable.init();
NativeCallback.onLocalServerStarted();

ItemContainer.loadClass();

Logger.info("INNERCORE", "preloaded in " + (System.currentTimeMillis() - startupMillis) + "ms");
Logger.info("INNERCORE", PackInfo.toInfo());
}

public void afterload() {
Expand Down Expand Up @@ -339,23 +310,39 @@ public static String getName() {
}

public static void useNotSupport(String name) {
if (isRuntimeException())
throw new RuntimeException("Use not support multiplayer method " + name);
String message = "Use not support multiplayer method " + name;
if (isRuntimeException()) {
throw new RuntimeException(message);
} else {
Logger.warning(message);
}
}

public static void useClientMethod(String name) {
if (isRuntimeException())
throw new RuntimeException("Use client method " + name);
String message = "Use client method " + name;
if (isRuntimeException()) {
throw new RuntimeException(message);
} else {
Logger.warning(message);
}
}

public static void useNotCurrentSupport(String name) {
if (isRuntimeException())
throw new RuntimeException("The " + name + " method is currently not supported");
String message = "The " + name + " method is currently not supported";
if (isRuntimeException()) {
throw new RuntimeException(message);
} else {
Logger.warning(message);
}
}

public static void useIncomprehensibleMethod(String name) {
if (isRuntimeException())
throw new RuntimeException("I don't really understand what this method does (" + name
+ "), which is why you're reading this right now");
String message = "I don't really understand what this method does (" + name
+ "), which is why you're reading this right now";
if (isRuntimeException()) {
throw new RuntimeException(message);
} else {
Logger.warning(message);
}
}
}
2 changes: 0 additions & 2 deletions src/main/java/com/reider745/world/GenerationUtilsMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import cn.nukkit.math.Vector3;
import com.reider745.api.CallbackHelper;
import com.zhekasmirnov.apparatus.mcpe.NativeBlockSource;
import org.mozilla.javascript.annotations.JSStaticFunction;

import java.util.ArrayList;

public class GenerationUtilsMethods {
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/com/reider745/world/WorldMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,44 @@
import com.reider745.InnerCoreServer;

public class WorldMethod {
public static long getTime(){
public static long getTime() {
return InnerCoreServer.server.getLevel(0).getTime() % Level.TIME_FULL;
}

public static void setTime(int time){
public static void setTime(int time) {
InnerCoreServer.server.getLevel(0).setTime(time);
}

public static int getGameMode(){
public static int getGameMode() {
return InnerCoreServer.server.getGamemode();
}

public static void setGameMode(int mode){

public static void setGameMode(int mode) {
}

public static int getDifficulty(){
public static int getDifficulty() {
return InnerCoreServer.server.getDifficulty();
}

public static void setDifficulty(int difficulty){
public static void setDifficulty(int difficulty) {
InnerCoreServer.server.setDifficulty(difficulty);
}

public static double getRainLevel(){
public static double getRainLevel() {
return 0;
}

public static void setRainLevel(float v){

public static void setRainLevel(float v) {
}

public static double getLightningLevel(){
public static double getLightningLevel() {
return 0;
}

public static void setLightningLevel(float v){
public static void setLightningLevel(float v) {
}

public static long getSeed() {
return InnerCoreServer.server.getLevel(0).getSeed();
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/zhekasmirnov/apparatus/Apparatus.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
package com.zhekasmirnov.apparatus;

import com.reider745.InnerCoreServer;
import com.zhekasmirnov.apparatus.api.container.ItemContainer;
import com.zhekasmirnov.apparatus.api.player.NetworkPlayerRegistry;
import com.zhekasmirnov.apparatus.multiplayer.mod.IdConversionMap;
import com.zhekasmirnov.apparatus.multiplayer.mod.MultiplayerModList;
import com.zhekasmirnov.apparatus.multiplayer.mod.MultiplayerPackVersionChecker;
import com.zhekasmirnov.apparatus.multiplayer.mod.RuntimeIdDataPacketSender;
import com.zhekasmirnov.apparatus.multiplayer.util.entity.NetworkEntity;

public class Apparatus {
static {
NetworkEntity.loadClass();
NetworkPlayerRegistry.loadClass();
MultiplayerPackVersionChecker.loadClass();
MultiplayerModList.loadClass();
IdConversionMap.loadClass();
RuntimeIdDataPacketSender.loadClass();
ItemContainer.loadClass();
}

public static void loadClasses() {
// forces all api classes to load
}

public static boolean isDevelop() {
return InnerCoreServer.isDevelopMode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public Mod getLegacyModInstance() {
public void init() {
if (legacyModInstance == null) {
ICLog.d("INNERCORE-MOD", "building and importing mod: " + getDirectory().getName());
legacyModInstance = ModBuilder.buildModForDir(getDirectory().getAbsolutePath() + "/", modPack, locationName);
legacyModInstance = ModBuilder.buildModForDir(getDirectory().getAbsolutePath() + "/", modPack,
locationName);
if (legacyModInstance != null) {
legacyModInstance.onImport();
} else {
Expand All @@ -62,46 +63,6 @@ public boolean isEnabledAndAbleToRun() {

@Override
public void onSettingUpEnvironment(EnvironmentSetupProxy proxy, ModLoaderReporter reporter) {
// resource & gui
/*for (BuildConfig.ResourceDir resourceDir : legacyModInstance.buildConfig.resourceDirs) {
if (resourceDir.gameVersion.isCompatible()) {
switch (resourceDir.resourceType) {
case RESOURCE:
//proxy.addResourceDirectory(this, new File(getDirectory(), resourceDir.path));
break;
case GUI:
proxy.addGuiAssetsDirectory(this, new File(getDirectory(), resourceDir.path));
//break;
}
}
}*/

// addon behavior packs
/* String behaviorPackDirName = legacyModInstance.buildConfig.defaultConfig.behaviorPacksDir;
if (behaviorPackDirName != null) {
File[] behaviorPacks = new File(getDirectory(), behaviorPackDirName).listFiles();
if (behaviorPacks != null) {
for (File behaviorPack : behaviorPacks) {
if (new ResourceGameVersion(new File(behaviorPack, "game_version.json")).isCompatible()) {
proxy.addBehaviorPackDirectory(this, behaviorPack);
}
}
}
}
// addon resource packs
String resourcePackDirName = legacyModInstance.buildConfig.defaultConfig.resourcePacksDir;
if (resourcePackDirName != null) {
File[] resourcePacks = new File(getDirectory(), resourcePackDirName).listFiles();
if (resourcePacks != null) {
for (File resourcePack : resourcePacks) {
if (new ResourceGameVersion(new File(resourcePack, "game_version.json")).isCompatible()) {
proxy.addResourcePackDirectory(this, resourcePack);
}
}
}
}*/

// java directories
for (BuildConfig.DeclaredDirectory directory : legacyModInstance.buildConfig.javaDirectories) {
if (directory.version.isCompatible()) {
Expand All @@ -124,14 +85,11 @@ public void onPrepareResources(ModLoaderReporter reporter) {

@Override
public void onRunningMod(ModLoaderReporter reporter) {
legacyModInstance.loadModInfo();
legacyModInstance.RunLauncherScripts();
// update properties, after multiplayer info is set by launcher scripts
getInfo().pullLegacyModProperties(legacyModInstance);
}



@Override
public void onShuttingDown(ModLoaderReporter reporter) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

public class NetworkJsAdapter {
private final Network network;
public static NetworkJsAdapter instance;

public NetworkJsAdapter(Network network) {
this.network = network;
Expand Down Expand Up @@ -48,12 +47,13 @@ public NetworkPlayerHandler getHandlerForPlayer(long player) {
return NetworkPlayerRegistry.getSingleton().getHandlerFor(player);
}


public void addClientInitializationPacket(String name, Network.ClientInitializationPacketSender sender, ConnectedClient.InitializationPacketListener receiver) {
public void addClientInitializationPacket(String name, Network.ClientInitializationPacketSender sender,
ConnectedClient.InitializationPacketListener receiver) {
network.addClientInitializationPacket(name, sender, receiver);
}

public void addServerInitializationPacket(String name, Network.ServerInitializationPacketSender sender, ModdedClient.OnPacketReceivedListener receiver) {
public void addServerInitializationPacket(String name, Network.ServerInitializationPacketSender sender,
ModdedClient.OnPacketReceivedListener receiver) {
network.addServerInitializationPacket(name, sender, receiver);
}

Expand All @@ -73,7 +73,6 @@ public void addServerPacket(String name, ModdedServer.OnPacketReceivedListener l
network.addServerPacket(name, listener);
}


public void sendToAllClients(String packetName, Object data) {
ThreadTypeMarker.assertServerThread();
network.getServer().sendToAll(packetName, data);
Expand All @@ -89,7 +88,6 @@ public void sendServerMessage(String message) {
network.getServer().sendMessageToAll(message);
}


public int serverToLocalId(int id) {
return IdConversionMap.serverToLocal(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public synchronized void close() {
}
closeImpl();
} catch (IOException e) {
e.printStackTrace();
Logger.info(e.getMessage());
}
}
}
Expand Down
Loading

0 comments on commit d692bea

Please sign in to comment.