From bd69188d6435e89f316b071bc5871277d0236315 Mon Sep 17 00:00:00 2001 From: Andrew Haskell <32055840+WardenDrew@users.noreply.github.com> Date: Wed, 22 Nov 2023 15:15:36 -0800 Subject: [PATCH] Add capability to trigger the ancient node automatically --- .../common/block/SculkAncientNodeBlock.java | 6 ++++++ .../blockentity/SculkAncientNodeBlockEntity.java | 14 ++++++++++++++ .../java/com/github/sculkhorde/core/ModConfig.java | 13 +++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/main/java/com/github/sculkhorde/common/block/SculkAncientNodeBlock.java b/src/main/java/com/github/sculkhorde/common/block/SculkAncientNodeBlock.java index a6e36d87..ea9ca942 100644 --- a/src/main/java/com/github/sculkhorde/common/block/SculkAncientNodeBlock.java +++ b/src/main/java/com/github/sculkhorde/common/block/SculkAncientNodeBlock.java @@ -184,6 +184,12 @@ public BlockEntityTicker getTicker(Level level, Block SculkAncientNodeBlockEntity::tickAwake); } + if (ModConfig.SERVER.trigger_ancient_node_automatically.get()) { + return BaseEntityBlock.createTickerHelper(blockEntityType, + ModBlockEntities.SCULK_ANCIENT_NODE_BLOCK_ENTITY.get(), + SculkAncientNodeBlockEntity::tickTriggerAutomatically); + } + return BaseEntityBlock.createTickerHelper(blockEntityType, ModBlockEntities.SCULK_ANCIENT_NODE_BLOCK_ENTITY.get(), (level1, pos, state, entity) -> { VibrationSystem.Ticker.tick(level1, entity.getVibrationData(), entity.getVibrationUser()); }); diff --git a/src/main/java/com/github/sculkhorde/common/blockentity/SculkAncientNodeBlockEntity.java b/src/main/java/com/github/sculkhorde/common/blockentity/SculkAncientNodeBlockEntity.java index 33be88e9..a8ffed55 100644 --- a/src/main/java/com/github/sculkhorde/common/blockentity/SculkAncientNodeBlockEntity.java +++ b/src/main/java/com/github/sculkhorde/common/blockentity/SculkAncientNodeBlockEntity.java @@ -275,6 +275,20 @@ public static void tickAwake(Level level, BlockPos blockPos, BlockState blockSta BlockEntityChunkLoaderHelper.getChunkLoaderHelper().createChunkLoadRequestSquare((ServerLevel) level, blockPos, ModConfig.SERVER.sculk_node_chunkload_radius.get(), 1, TickUnits.convertMinutesToTicks(30)); } + public static void tickTriggerAutomatically(Level level, BlockPos blockPos, BlockState blockState, SculkAncientNodeBlockEntity blockEntity) + { + // Should never get here but for safety's sake double verify + if (!ModConfig.SERVER.trigger_ancient_node_automatically.get()) { return; } + + // Check elapsed days + if (level.getDayTime() < (ModConfig.SERVER.trigger_ancient_node_wait_days.get() * 24000)) { return; } + + // Check time of current day + if ((level.getDayTime() % 24000) < (long)(ModConfig.SERVER.trigger_ancient_node_time_of_day.get())) { return; } + + tryInitializeHorde(level, blockEntity.getBlockPos(), blockEntity.getBlockState(), blockEntity); + } + private static boolean areAnyPlayersInRange(ServerLevel level, BlockPos blockPos, int range) { return level.players().stream().anyMatch((player) -> diff --git a/src/main/java/com/github/sculkhorde/core/ModConfig.java b/src/main/java/com/github/sculkhorde/core/ModConfig.java index cd0051db..af70cb0b 100644 --- a/src/main/java/com/github/sculkhorde/core/ModConfig.java +++ b/src/main/java/com/github/sculkhorde/core/ModConfig.java @@ -1,5 +1,6 @@ package com.github.sculkhorde.core; +import com.electronwill.nightconfig.core.Config; import com.electronwill.nightconfig.core.file.CommentedFileConfig; import com.electronwill.nightconfig.core.io.WritingMode; import net.minecraftforge.common.ForgeConfigSpec; @@ -23,6 +24,10 @@ public static class Server { public final ForgeConfigSpec.ConfigValue block_infestation_enabled; public final ForgeConfigSpec.ConfigValue chunk_loading_enabled; + public final ForgeConfigSpec.ConfigValue trigger_ancient_node_automatically; + public final ForgeConfigSpec.ConfigValue trigger_ancient_node_wait_days; + public final ForgeConfigSpec.ConfigValue trigger_ancient_node_time_of_day; + public final ForgeConfigSpec.ConfigValue gravemind_mass_goal_for_immature_stage; public final ForgeConfigSpec.ConfigValue gravemind_mass_goal_for_mature_stage; @@ -48,6 +53,8 @@ public static class Server { public Server(ForgeConfigSpec.Builder builder) { + Config.setInsertionOrderPreserved(true); + builder.push("Mod Compatability"); target_faw_entities = builder.comment("Should the Sculk Horde attack mobs from the mod 'From Another World'? (Default false)").define("target_faw_entities",false); target_spore_entities = builder.comment("Should the Sculk Horde attack mobs from the mod 'Fungal Infection:Spore'? (Default false)").define("target_spore_entities",false); @@ -58,6 +65,12 @@ public Server(ForgeConfigSpec.Builder builder) { chunk_loading_enabled = builder.comment("Should the Sculk Horde load chunks? If disabled, and will ruin the intended experience. For example, raids wont work properly (Default true)").define("chunk_loading_enabled",true); builder.pop(); + builder.push("Trigger Automatically Variables"); + trigger_ancient_node_automatically = builder.comment("Should the Sculk Horde start automatically? Requires that chunk loading is enabled to work reliably, otherwise will only trigger if the ancient node's chunk is loaded. If enabled on a save where previously disabled, the node will trigger automatically if the time conditions are met. (Default false)").define("trigger_ancient_node_automatically", false); + trigger_ancient_node_wait_days = builder.comment("How many days to wait before triggering the ancient node? (Default 0)").defineInRange("trigger_ancient_node_wait_days", 0, 0, Integer.MAX_VALUE); + trigger_ancient_node_time_of_day = builder.comment("What time of day in ticks must pass before triggering the ancient node after the wait days have elapsed? If wait days is set to 0, set time of day to a time greater than 1000 ticks to allow for world startup and lag to finish (Default 2000)").defineInRange("trigger_ancient_node_time_of_day", 2000, 0, 23999); + builder.pop(); + builder.push("Infestation / Purification Variables"); infestation_speed_multiplier = builder.comment("How much faster or slower should infestation spread? (Default 0)").defineInRange("infestation_speed_multiplier",0f, -10f, 10f); purification_speed_multiplier = builder.comment("How much faster or slower should purification spread? (Default 0)").defineInRange("purification_speed_multiplier",0f, -10f, 10f);