Skip to content

Commit

Permalink
Added custom dimensions config for time crystals
Browse files Browse the repository at this point in the history
  • Loading branch information
Direwolf20-MC committed Feb 5, 2025
1 parent 9d5fb49 commit 6814433
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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<? extends String> allowedDims = Config.TIME_CRYSTAL_STAGE1_DIMENSIONS.get();
if (allowedDims.contains(level.dimension().location().toString()))
return 1;
}
if (stage == 1) {
List<? extends String> allowedDims = Config.TIME_CRYSTAL_STAGE2_DIMENSIONS.get();
if (allowedDims.contains(level.dimension().location().toString()))
return 2;
}
if (stage == 2) {
List<? extends String> 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))
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/direwolf20/justdirethings/setup/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public class Config {
public static ModConfigSpec.IntValue PLAYER_ACCESSOR_VALIDATION_TIME;
public static ModConfigSpec.ConfigValue<List<? extends String>> 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<List<? extends String>> TIME_CRYSTAL_STAGE1_DIMENSIONS;
public static ModConfigSpec.ConfigValue<List<? extends String>> TIME_CRYSTAL_STAGE2_DIMENSIONS;
public static ModConfigSpec.ConfigValue<List<? extends String>> TIME_CRYSTAL_STAGE3_DIMENSIONS;

public static void register(ModContainer container) {
//registerServerConfigs(container);
registerCommonConfigs(container);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 6814433

Please sign in to comment.