diff --git a/src/main/java/com/reider745/InnerCoreServer.java b/src/main/java/com/reider745/InnerCoreServer.java index 327008836..e3462ea62 100644 --- a/src/main/java/com/reider745/InnerCoreServer.java +++ b/src/main/java/com/reider745/InnerCoreServer.java @@ -26,7 +26,7 @@ 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.modpack.ModPackStorage; import com.zhekasmirnov.innercore.ui.LoadingUI; import com.zhekasmirnov.innercore.utils.FileTools; import com.zhekasmirnov.mcpe161.InnerCore; @@ -42,6 +42,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.Enumeration; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.function.Consumer; import java.util.stream.Stream; @@ -55,6 +56,7 @@ public enum MethodHandling { public static final int PROTOCOL = 422; public static final int EXIT_CODE_NO_INTERNAL_PACKAGE = 32; + public static final int EXIT_CODE_NO_MODPACK = 33; public static String dataPath; public static InnerCoreServer singleton; @@ -235,8 +237,8 @@ public void preload(Server server) throws Exception { try { System.exit(EXIT_CODE_NO_INTERNAL_PACKAGE); } catch (SecurityException e) { - throw new RuntimeException("EXIT_CODE_NO_INTERNAL_PACKAGE"); } + throw new RuntimeException("EXIT_CODE_NO_INTERNAL_PACKAGE"); } } } @@ -246,10 +248,9 @@ public void preload(Server server) throws Exception { // Required to be called before modpack instantiation FileTools.init(); - ModPack innerCoreModPack = ModPackFactory.getInstance().createFromDirectory(innerCoreDirectory); - ModPackContext.getInstance().setCurrentModPack(innerCoreModPack); + ModPackContext.getInstance().setCurrentModPack(getModpack()); - for (ModPackDirectory directoryWithMods : innerCoreModPack + for (ModPackDirectory directoryWithMods : ModPackContext.getInstance().getCurrentModPack() .getDirectoriesOfType(ModPackDirectory.DirectoryType.MODS)) { directoryWithMods.assureDirectoryRoot(); for (File potentialIcmodFile : directoryWithMods.getLocation().listFiles()) { @@ -357,6 +358,53 @@ public boolean getPropertyBoolean(String variable, Object defaultValue) { } } + private ModPack getModpack() { + String modpackRequirement = getPropertyString("modpack"); + ModPackStorage storage = ModPackContext.getInstance().getStorage(); + storage.rebuildModPackList(); + + if (modpackRequirement == null) { + return storage.getDefaultModPack(); + } + + List modpacks = storage.getAllModPacks(); + for (ModPack modpack : modpacks) { + if (modpackRequirement.equals(modpack.getRootDirectory().getAbsolutePath())) { + return modpack; + } + if (modpackRequirement.equals(modpack.getRootDirectory().getName())) { + return modpack; + } + } + for (ModPack modpack : modpacks) { + if (modpackRequirement.equals(modpack.getManifest().getPackName())) { + return modpack; + } + if (modpackRequirement.equals(modpack.getManifest().getDisplayedName())) { + return modpack; + } + } + + Logger.critical( + "Unable to find specified modpack, please enter modpack name, folder name or relative path instead. " + + "It is possible that your hosting provider dynamically updates paths, preventing you from specifying absolute one."); + if (modpacks.size() > 0) { + StringBuilder builder = new StringBuilder(); + builder.append("Available modpacks: "); + for (ModPack modpack : modpacks) { + builder.append(modpack.getRootDirectory().getName()); + } + builder.append('.'); + Logger.critical(builder.toString()); + } + + try { + System.exit(EXIT_CODE_NO_MODPACK); + } catch (SecurityException e) { + } + throw new RuntimeException("EXIT_CODE_NO_MODPACK"); + } + public static boolean isLegacyWorkbench() { return singleton.getPropertyBoolean("use-legacy-workbench-override", true); } diff --git a/src/main/java/com/reider745/event/EventListener.java b/src/main/java/com/reider745/event/EventListener.java index 8129e39bb..5ae6c9573 100644 --- a/src/main/java/com/reider745/event/EventListener.java +++ b/src/main/java/com/reider745/event/EventListener.java @@ -201,7 +201,8 @@ public void onEntityDeath(EntityDeathEvent event) { final Entity entity = event.getEntity(); final EntityDamageEvent damageEvent = entity.getLastDamageCause(); final Entity attacker = damageEvent instanceof EntityDamageByEntityEvent damageByEntityEvent - ? damageByEntityEvent.getDamager() : null; + ? damageByEntityEvent.getDamager() + : null; NativeCallback.onEntityDied(entity.getId(), attacker != null ? attacker.getId() : -1, convertDamageCauseToEnum(damageEvent != null ? damageEvent.getCause() : DamageCause.CUSTOM)); @@ -212,7 +213,8 @@ public void onPlayerDeath(PlayerDeathEvent event) { final Entity entity = event.getEntity(); final EntityDamageEvent damageEvent = entity.getLastDamageCause(); final Entity attacker = damageEvent instanceof EntityDamageByEntityEvent damageByEntityEvent - ? damageByEntityEvent.getDamager() : null; + ? damageByEntityEvent.getDamager() + : null; consumeEvent(event, () -> NativeCallback.onEntityDied(entity.getId(), attacker != null ? attacker.getId() : -1, convertDamageCauseToEnum(damageEvent != null ? damageEvent.getCause() : DamageCause.CUSTOM))); @@ -223,8 +225,7 @@ public void onBlockExplosion(BlockExplosionPrimeEvent event) { final Location pos = event.getBlock().getLocation(); consumeEvent(event, () -> NativeCallback.onExplode((float) pos.x, (float) pos.y, (float) pos.z, - (float) event.getForce(), -1, event.isIncendiary(), event.isBlockBreaking(), - (float) event.getFireChance())); + (float) event.getForce(), -1, event.isIncendiary(), event.isBlockBreaking(), Float.MAX_VALUE)); } @EventHandler @@ -233,7 +234,7 @@ public void onEntityExplosion(EntityExplosionPrimeEvent event) { final Position pos = entity.getPosition(); consumeEvent(event, () -> NativeCallback.onExplode((float) pos.x, (float) pos.y, (float) pos.z, - (float) event.getForce(), entity.getId(), false, event.isBlockBreaking(), 0f)); + (float) event.getForce(), entity.getId(), false, event.isBlockBreaking(), Float.MAX_VALUE)); } @EventHandler @@ -306,7 +307,8 @@ public void onBlockUpdate(BlockGrowEvent event) { // TODO: onItemDispensed - // TODO: onEnchantPostAttack, onEnchantPostHurt, onEnchantGetDamageBonus, onEnchantGetProtectionBonus + // TODO: onEnchantPostAttack, onEnchantPostHurt, onEnchantGetDamageBonus, + // onEnchantGetProtectionBonus // TODO: onWorkbenchCraft diff --git a/src/main/java/com/reider745/world/BlockSourceMethods.java b/src/main/java/com/reider745/world/BlockSourceMethods.java index d9257a4f4..940d94aca 100644 --- a/src/main/java/com/reider745/world/BlockSourceMethods.java +++ b/src/main/java/com/reider745/world/BlockSourceMethods.java @@ -6,7 +6,7 @@ import cn.nukkit.blockentity.BlockEntity; import cn.nukkit.entity.Entity; import cn.nukkit.entity.item.EntityItem; -import cn.nukkit.event.entity.ExplosionPrimeEvent; +import cn.nukkit.event.block.BlockExplosionPrimeEvent; import cn.nukkit.item.Item; import cn.nukkit.level.Explosion; import cn.nukkit.level.Level; @@ -176,15 +176,19 @@ public static void addToTickingQueue(Level pointer, int x, int y, int z, int run int unknown /* = 0 */) { } - public static void explode(Level pointer, float x, float y, float z, float power, boolean fire) { - ExplosionPrimeEvent event = new ExplosionPrimeEvent(null, power); + public static void explode(Level level, float x, float y, float z, float power, boolean fire) { + final Block block = level.getBlock((int) x, (int) y, (int) z); + final BlockExplosionPrimeEvent event = new BlockExplosionPrimeEvent(block, power, 0d); + event.setIncendiary(fire); Server.getInstance().getPluginManager().callEvent(event); + if (event.isCancelled()) { return; } - Position position = new Position(x, y, z); - position.setLevel(pointer); - Explosion explosion = new Explosion(position, event.getForce(), (Entity) null); + + final Position position = new Position(x, y, z); + position.setLevel(level); + final Explosion explosion = new Explosion(position, event.getForce(), block); if (event.isBlockBreaking()) { explosion.explodeA(); } diff --git a/src/main/java/com/zhekasmirnov/innercore/api/unlimited/FileLoader.java b/src/main/java/com/zhekasmirnov/innercore/api/unlimited/FileLoader.java index c8dc83a2e..66f55354d 100644 --- a/src/main/java/com/zhekasmirnov/innercore/api/unlimited/FileLoader.java +++ b/src/main/java/com/zhekasmirnov/innercore/api/unlimited/FileLoader.java @@ -19,7 +19,9 @@ public FileLoader(File file) { this.file = file; try { - data = FileTools.readJSON(file.getAbsolutePath()); + if (file.exists()) { + data = FileTools.readJSON(file.getAbsolutePath()); + } } catch (Exception e) { e.printStackTrace(); data = new JSONObject(); diff --git a/src/main/java/com/zhekasmirnov/innercore/modpack/ModPack.java b/src/main/java/com/zhekasmirnov/innercore/modpack/ModPack.java index f553c871a..ca2e45871 100644 --- a/src/main/java/com/zhekasmirnov/innercore/modpack/ModPack.java +++ b/src/main/java/com/zhekasmirnov/innercore/modpack/ModPack.java @@ -1,5 +1,6 @@ package com.zhekasmirnov.innercore.modpack; +import com.zhekasmirnov.horizon.runtime.logger.Logger; import com.zhekasmirnov.innercore.modpack.installation.ModPackExtractionTarget; import com.zhekasmirnov.innercore.modpack.installation.ModpackInstallationSource; import com.zhekasmirnov.innercore.modpack.strategy.extract.DirectoryExtractStrategy; @@ -80,12 +81,15 @@ public ModPackJsAdapter getJsAdapter() { public boolean reloadAndValidateManifest() { try { + if (!getManifestFile().exists()) { + return false; + } declaredDirectories.clear(); manifest.loadFile(getManifestFile()); declaredDirectories.addAll(manifest.createDeclaredDirectoriesForModPack(this)); return manifest.getPackName() != null; } catch (IOException | JSONException exception) { - exception.printStackTrace(); + Logger.warning("ModPack.reloadAndValidateManifest()", exception); return false; } } diff --git a/src/main/resources/innercore/config.json b/src/main/resources/innercore/config.json deleted file mode 100644 index 3fbebeb24..000000000 --- a/src/main/resources/innercore/config.json +++ /dev/null @@ -1 +0,0 @@ -{"inventory_tick_send":true,"pack":{"version_name":"2.3.1b115 test","name":"Inner Core Test","version":152},"version":108,"socket_server":false,"network":{"enable_socket_server":true,"local_native_protocol_forced":false,"remote_native_protocol_prioritized":false},"developer_mode":true,"performance":{"max_update_time":40,"max_update_count":128,"time_based_limit":false},"version_name":"2.1.0b71","disable_loading_screen":false,"port":19132,"background":{"auto_save":true,"auto_save_period":40},"inventory_tick_send_time":20,"name":"Inner Core","threading":{"advanced":false,"threshold_fps":45,"additional_thread_count":0,"priority_simple":5,"priority_high":40,"additional_thread_priority":12,"priority_low":1},"create_debug_dump":false,"gameplay":{"use_legacy_workbench_override":false}} \ No newline at end of file diff --git a/src/main/resources/innercore/modpack.json b/src/main/resources/innercore/modpack.json deleted file mode 100644 index 045e41e00..000000000 --- a/src/main/resources/innercore/modpack.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "ZoteCore", - "displayedName": "ZoteCore", - "versionCode": "", - "author": "Reider745", - "description": "", - "versionName": "" -} \ No newline at end of file diff --git a/src/main/resources/zotecore.yml b/src/main/resources/zotecore.yml index 474ed8e7b..de949ff2d 100644 --- a/src/main/resources/zotecore.yml +++ b/src/main/resources/zotecore.yml @@ -4,6 +4,10 @@ pack: Inner Core Test pack-version: 2.3.0b115 test pack-version-code: 152 +# Sets the list of mods and configs to load, you can specify +# folder name of a modpack from /modpacks or a path. +# modpack: StoneBlock + # Use vanilla crafting table interface, instead of custom one. # Attention: currently not supported and custom recipes will not be dislayed. # use-legacy-workbench-override: off