From 68144334749ab67366f69b8d477942920c15b958 Mon Sep 17 00:00:00 2001 From: direwolf20 <39863894+Direwolf20-MC@users.noreply.github.com> Date: Wed, 5 Feb 2025 14:25:37 -0500 Subject: [PATCH] Added custom dimensions config for time crystals --- .../resources/TimeCrystalBuddingBlock.java | 26 +++++++++++++-- .../justdirethings/setup/Config.java | 33 +++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/direwolf20/justdirethings/common/blocks/resources/TimeCrystalBuddingBlock.java b/src/main/java/com/direwolf20/justdirethings/common/blocks/resources/TimeCrystalBuddingBlock.java index 44d1c167..0a2d0faf 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/blocks/resources/TimeCrystalBuddingBlock.java +++ b/src/main/java/com/direwolf20/justdirethings/common/blocks/resources/TimeCrystalBuddingBlock.java @@ -1,6 +1,7 @@ package com.direwolf20.justdirethings.common.blocks.resources; import com.direwolf20.justdirethings.client.particles.glitterparticle.GlitterParticleData; +import com.direwolf20.justdirethings.setup.Config; import com.direwolf20.justdirethings.setup.Registration; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -19,6 +20,7 @@ import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.material.Fluids; +import java.util.List; import java.util.Random; public class TimeCrystalBuddingBlock extends BuddingAmethystBlock { @@ -46,6 +48,26 @@ public InteractionResult useWithoutItem(BlockState blockState, Level level, Bloc return InteractionResult.SUCCESS; }*/ + public int canAdvanceToCustom(Level level, BlockState state) { + int stage = state.getValue(STAGE); + if (stage == 0) { + List allowedDims = Config.TIME_CRYSTAL_STAGE1_DIMENSIONS.get(); + if (allowedDims.contains(level.dimension().location().toString())) + return 1; + } + if (stage == 1) { + List allowedDims = Config.TIME_CRYSTAL_STAGE2_DIMENSIONS.get(); + if (allowedDims.contains(level.dimension().location().toString())) + return 2; + } + if (stage == 2) { + List allowedDims = Config.TIME_CRYSTAL_STAGE3_DIMENSIONS.get(); + if (allowedDims.contains(level.dimension().location().toString())) + return 3; + } + return -1; + } + public int canAdvanceTo(Level level, BlockState state) { int stage = state.getValue(STAGE); if (stage == 0 && (level.dimension() != Level.NETHER && level.dimension() != Level.END)) @@ -65,7 +87,7 @@ public void advance(Level level, BlockState state, BlockPos pos, int advanceTo) @Override protected void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) { int stage = state.getValue(STAGE); - int advanceTo = canAdvanceTo(level, state); + int advanceTo = Config.TIME_CRYSTAL_CUSTOM_DIMENSIONS.isTrue() ? canAdvanceToCustom(level, state) : canAdvanceTo(level, state); if (advanceTo != -1) { advance(level, state, pos, advanceTo); } @@ -118,7 +140,7 @@ public void animateTick(BlockState state, Level level, BlockPos pos, RandomSourc double d2 = (double) pos.getZ() + 0.5; float r, g, b; - int advanceTo = canAdvanceTo(level, state); + int advanceTo = Config.TIME_CRYSTAL_CUSTOM_DIMENSIONS.isTrue() ? canAdvanceToCustom(level, state) : canAdvanceTo(level, state); if (advanceTo == -1) return; if (advanceTo == 1) { r = 0.25f; diff --git a/src/main/java/com/direwolf20/justdirethings/setup/Config.java b/src/main/java/com/direwolf20/justdirethings/setup/Config.java index 0fd30a2f..e2add0b4 100644 --- a/src/main/java/com/direwolf20/justdirethings/setup/Config.java +++ b/src/main/java/com/direwolf20/justdirethings/setup/Config.java @@ -104,6 +104,12 @@ public class Config { public static ModConfigSpec.IntValue PLAYER_ACCESSOR_VALIDATION_TIME; public static ModConfigSpec.ConfigValue> PLAYER_ACCESSOR_BLACKLISTED_DIMENSIONS; + public static final String CATEGORY_TIME_CRYSTAL = "time_crystal"; + public static ModConfigSpec.BooleanValue TIME_CRYSTAL_CUSTOM_DIMENSIONS; + public static ModConfigSpec.ConfigValue> TIME_CRYSTAL_STAGE1_DIMENSIONS; + public static ModConfigSpec.ConfigValue> TIME_CRYSTAL_STAGE2_DIMENSIONS; + public static ModConfigSpec.ConfigValue> TIME_CRYSTAL_STAGE3_DIMENSIONS; + public static void register(ModContainer container) { //registerServerConfigs(container); registerCommonConfigs(container); @@ -129,6 +135,7 @@ private static void registerCommonConfigs(ModContainer container) { polymorphWandConfig(); paradoxConfig(); playerAccessorConfig(); + timeCrystalConfig(); COMMON_CONFIG = COMMON_BUILDER.build(); container.registerConfig(ModConfig.Type.COMMON, COMMON_CONFIG); } @@ -341,4 +348,30 @@ private static void playerAccessorConfig() { COMMON_BUILDER.pop(); } + + private static void timeCrystalConfig() { + COMMON_BUILDER.comment("Time Crystals").push(CATEGORY_TIME_CRYSTAL); + TIME_CRYSTAL_CUSTOM_DIMENSIONS = COMMON_BUILDER.comment("Do you want to customize Time Crystal Growth Dimensions? If set to true, the following 3 fields MUST be populated. Don't leave any blank! Defaults to false, which means normal growth rules occur - Stage 1 = Overworld (or any other dimension besides Nether/End), Stage 2 = Nether, Stage 3 = End.") + .define("time_crystal_custom_dimensions", false); + TIME_CRYSTAL_STAGE1_DIMENSIONS = COMMON_BUILDER + .comment("A list of dimensions that Time Crystals can Advance to Stage 1 in.") + .defineListAllowEmpty("time_crystal_stage_1_dims", + List.of(), // Default value is an empty list + () -> "", // Supplier for new elements in the UI + obj -> obj instanceof String); // Validate that all entries are strings + TIME_CRYSTAL_STAGE2_DIMENSIONS = COMMON_BUILDER + .comment("A list of dimensions that Time Crystals can Advance to Stage 2 in.") + .defineListAllowEmpty("time_crystal_stage_2_dims", + List.of(), // Default value is an empty list + () -> "", // Supplier for new elements in the UI + obj -> obj instanceof String); // Validate that all entries are strings + TIME_CRYSTAL_STAGE3_DIMENSIONS = COMMON_BUILDER + .comment("A list of dimensions that Time Crystals can Advance to Stage 3 in.") + .defineListAllowEmpty("time_crystal_stage_3_dims", + List.of(), // Default value is an empty list + () -> "", // Supplier for new elements in the UI + obj -> obj instanceof String); // Validate that all entries are strings + + COMMON_BUILDER.pop(); + } }