Skip to content

Commit 6814433

Browse files
committed
Added custom dimensions config for time crystals
1 parent 9d5fb49 commit 6814433

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

src/main/java/com/direwolf20/justdirethings/common/blocks/resources/TimeCrystalBuddingBlock.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.direwolf20.justdirethings.common.blocks.resources;
22

33
import com.direwolf20.justdirethings.client.particles.glitterparticle.GlitterParticleData;
4+
import com.direwolf20.justdirethings.setup.Config;
45
import com.direwolf20.justdirethings.setup.Registration;
56
import net.minecraft.core.BlockPos;
67
import net.minecraft.core.Direction;
@@ -19,6 +20,7 @@
1920
import net.minecraft.world.level.block.state.properties.IntegerProperty;
2021
import net.minecraft.world.level.material.Fluids;
2122

23+
import java.util.List;
2224
import java.util.Random;
2325

2426
public class TimeCrystalBuddingBlock extends BuddingAmethystBlock {
@@ -46,6 +48,26 @@ public InteractionResult useWithoutItem(BlockState blockState, Level level, Bloc
4648
return InteractionResult.SUCCESS;
4749
}*/
4850

51+
public int canAdvanceToCustom(Level level, BlockState state) {
52+
int stage = state.getValue(STAGE);
53+
if (stage == 0) {
54+
List<? extends String> allowedDims = Config.TIME_CRYSTAL_STAGE1_DIMENSIONS.get();
55+
if (allowedDims.contains(level.dimension().location().toString()))
56+
return 1;
57+
}
58+
if (stage == 1) {
59+
List<? extends String> allowedDims = Config.TIME_CRYSTAL_STAGE2_DIMENSIONS.get();
60+
if (allowedDims.contains(level.dimension().location().toString()))
61+
return 2;
62+
}
63+
if (stage == 2) {
64+
List<? extends String> allowedDims = Config.TIME_CRYSTAL_STAGE3_DIMENSIONS.get();
65+
if (allowedDims.contains(level.dimension().location().toString()))
66+
return 3;
67+
}
68+
return -1;
69+
}
70+
4971
public int canAdvanceTo(Level level, BlockState state) {
5072
int stage = state.getValue(STAGE);
5173
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)
6587
@Override
6688
protected void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
6789
int stage = state.getValue(STAGE);
68-
int advanceTo = canAdvanceTo(level, state);
90+
int advanceTo = Config.TIME_CRYSTAL_CUSTOM_DIMENSIONS.isTrue() ? canAdvanceToCustom(level, state) : canAdvanceTo(level, state);
6991
if (advanceTo != -1) {
7092
advance(level, state, pos, advanceTo);
7193
}
@@ -118,7 +140,7 @@ public void animateTick(BlockState state, Level level, BlockPos pos, RandomSourc
118140
double d2 = (double) pos.getZ() + 0.5;
119141

120142
float r, g, b;
121-
int advanceTo = canAdvanceTo(level, state);
143+
int advanceTo = Config.TIME_CRYSTAL_CUSTOM_DIMENSIONS.isTrue() ? canAdvanceToCustom(level, state) : canAdvanceTo(level, state);
122144
if (advanceTo == -1) return;
123145
if (advanceTo == 1) {
124146
r = 0.25f;

src/main/java/com/direwolf20/justdirethings/setup/Config.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ public class Config {
104104
public static ModConfigSpec.IntValue PLAYER_ACCESSOR_VALIDATION_TIME;
105105
public static ModConfigSpec.ConfigValue<List<? extends String>> PLAYER_ACCESSOR_BLACKLISTED_DIMENSIONS;
106106

107+
public static final String CATEGORY_TIME_CRYSTAL = "time_crystal";
108+
public static ModConfigSpec.BooleanValue TIME_CRYSTAL_CUSTOM_DIMENSIONS;
109+
public static ModConfigSpec.ConfigValue<List<? extends String>> TIME_CRYSTAL_STAGE1_DIMENSIONS;
110+
public static ModConfigSpec.ConfigValue<List<? extends String>> TIME_CRYSTAL_STAGE2_DIMENSIONS;
111+
public static ModConfigSpec.ConfigValue<List<? extends String>> TIME_CRYSTAL_STAGE3_DIMENSIONS;
112+
107113
public static void register(ModContainer container) {
108114
//registerServerConfigs(container);
109115
registerCommonConfigs(container);
@@ -129,6 +135,7 @@ private static void registerCommonConfigs(ModContainer container) {
129135
polymorphWandConfig();
130136
paradoxConfig();
131137
playerAccessorConfig();
138+
timeCrystalConfig();
132139
COMMON_CONFIG = COMMON_BUILDER.build();
133140
container.registerConfig(ModConfig.Type.COMMON, COMMON_CONFIG);
134141
}
@@ -341,4 +348,30 @@ private static void playerAccessorConfig() {
341348

342349
COMMON_BUILDER.pop();
343350
}
351+
352+
private static void timeCrystalConfig() {
353+
COMMON_BUILDER.comment("Time Crystals").push(CATEGORY_TIME_CRYSTAL);
354+
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.")
355+
.define("time_crystal_custom_dimensions", false);
356+
TIME_CRYSTAL_STAGE1_DIMENSIONS = COMMON_BUILDER
357+
.comment("A list of dimensions that Time Crystals can Advance to Stage 1 in.")
358+
.defineListAllowEmpty("time_crystal_stage_1_dims",
359+
List.of(), // Default value is an empty list
360+
() -> "", // Supplier for new elements in the UI
361+
obj -> obj instanceof String); // Validate that all entries are strings
362+
TIME_CRYSTAL_STAGE2_DIMENSIONS = COMMON_BUILDER
363+
.comment("A list of dimensions that Time Crystals can Advance to Stage 2 in.")
364+
.defineListAllowEmpty("time_crystal_stage_2_dims",
365+
List.of(), // Default value is an empty list
366+
() -> "", // Supplier for new elements in the UI
367+
obj -> obj instanceof String); // Validate that all entries are strings
368+
TIME_CRYSTAL_STAGE3_DIMENSIONS = COMMON_BUILDER
369+
.comment("A list of dimensions that Time Crystals can Advance to Stage 3 in.")
370+
.defineListAllowEmpty("time_crystal_stage_3_dims",
371+
List.of(), // Default value is an empty list
372+
() -> "", // Supplier for new elements in the UI
373+
obj -> obj instanceof String); // Validate that all entries are strings
374+
375+
COMMON_BUILDER.pop();
376+
}
344377
}

0 commit comments

Comments
 (0)