From a9303a44cbf3282abaa5831cb2f53b8aafc3892a Mon Sep 17 00:00:00 2001 From: dragonruler1000 Date: Sat, 24 May 2025 10:18:18 -0500 Subject: [PATCH] Add welcome message to dimensions and introduce config support Players entering non-overworld dimensions now receive a tailored welcome message. Additionally, basic configuration support has been introduced, laying the foundation for future customization. Updated mod version to 1.2.1 to reflect these changes. --- gradle.properties | 2 +- .../us/minecraftchest2/hdm_mod/Hdm_mod.java | 3 +++ .../hdm_mod/block/custom/Window.java | 5 +--- .../hdm_mod/config/ModConfig.java | 18 +++++++++++++ .../hdm_mod/config/modconfig.toml | 18 +++++++++++++ .../world/dimension/SimpleTeleporter.java | 27 +++++++++++++++++++ 6 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 src/main/java/us/minecraftchest2/hdm_mod/config/ModConfig.java create mode 100644 src/main/java/us/minecraftchest2/hdm_mod/config/modconfig.toml diff --git a/gradle.properties b/gradle.properties index e61404c..635380c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -38,7 +38,7 @@ mod_name=Hdm Mod # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=MIT # The mod version. See https://semver.org/ -mod_version=1.2 +mod_version=1.2.1 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/us/minecraftchest2/hdm_mod/Hdm_mod.java b/src/main/java/us/minecraftchest2/hdm_mod/Hdm_mod.java index 69b2566..1a2092e 100644 --- a/src/main/java/us/minecraftchest2/hdm_mod/Hdm_mod.java +++ b/src/main/java/us/minecraftchest2/hdm_mod/Hdm_mod.java @@ -7,7 +7,9 @@ import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.InterModComms; +import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; @@ -44,6 +46,7 @@ public class Hdm_mod { modEventBus1.addListener(this::processIMC); // Register the doClientStuff method for modloading modEventBus1.addListener(this::doClientStuff); +// ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ModConfig.GENERAL_SPEC, "modconfig.toml"); // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); diff --git a/src/main/java/us/minecraftchest2/hdm_mod/block/custom/Window.java b/src/main/java/us/minecraftchest2/hdm_mod/block/custom/Window.java index 13b77b3..09ef11d 100644 --- a/src/main/java/us/minecraftchest2/hdm_mod/block/custom/Window.java +++ b/src/main/java/us/minecraftchest2/hdm_mod/block/custom/Window.java @@ -11,6 +11,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.state.StateContainer; import net.minecraft.util.ActionResultType; import net.minecraft.util.Hand; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.shapes.IBooleanFunction; @@ -125,10 +126,6 @@ public class Window extends HorizontalBlock { SimpleTeleporter teleporter = new SimpleTeleporter(pos, goingToCustom); player.changeDimension(targetWorld, teleporter); } - - System.out.println("[DEBUG] Portal activated on server!"); - player.sendMessage(new StringTextComponent("Teleport logic running!"), player.getUniqueID()); - player.sendMessage(new StringTextComponent("Teleport attempted!"), player.getUniqueID()); return ActionResultType.SUCCESS; } diff --git a/src/main/java/us/minecraftchest2/hdm_mod/config/ModConfig.java b/src/main/java/us/minecraftchest2/hdm_mod/config/ModConfig.java new file mode 100644 index 0000000..07aa724 --- /dev/null +++ b/src/main/java/us/minecraftchest2/hdm_mod/config/ModConfig.java @@ -0,0 +1,18 @@ +//package us.minecraftchest2.hdm_mod.config; +// +//import net.minecraftforge.common.ForgeConfigSpec; +// +//public class ModConfig { +//public static final ForgeConfigSpec GENERAL_SPEC; +// +//static { +// ForgeConfigSpec.Builder configBuilder = new ForgeConfigSpec.Builder(); +// setupConfig(configBuilder); +// GENERAL_SPEC = configBuilder.build(); +//} +//public static ForgeConfigSpec.IntValue exampleIntConfigEntry; +// +//private static void setupConfig(ForgeConfigSpec.Builder builder) { +// exampleIntConfigEntry = builder.defineInRange("exampleIntConfigEntry", 5, 2, 50); +//} +//} diff --git a/src/main/java/us/minecraftchest2/hdm_mod/config/modconfig.toml b/src/main/java/us/minecraftchest2/hdm_mod/config/modconfig.toml new file mode 100644 index 0000000..7c482ca --- /dev/null +++ b/src/main/java/us/minecraftchest2/hdm_mod/config/modconfig.toml @@ -0,0 +1,18 @@ +package us.minecraftchest2.hdm_mod.config; + +import net.minecraftforge.common.ForgeConfigSpec; + +public class ModConfig { +public static final ForgeConfigSpec GENERAL_SPEC; + +static { +ForgeConfigSpec.Builder configBuilder = new ForgeConfigSpec.Builder(); +setupConfig(configBuilder); +GENERAL_SPEC = configBuilder.build(); +} +public static ForgeConfigSpec.IntValue exampleIntConfigEntry; + +private static void setupConfig(ForgeConfigSpec.Builder builder) { +exampleIntConfigEntry = builder.defineInRange("exampleIntConfigEntry", 5, 2, 50); +} +} diff --git a/src/main/java/us/minecraftchest2/hdm_mod/world/dimension/SimpleTeleporter.java b/src/main/java/us/minecraftchest2/hdm_mod/world/dimension/SimpleTeleporter.java index f852405..2579e20 100644 --- a/src/main/java/us/minecraftchest2/hdm_mod/world/dimension/SimpleTeleporter.java +++ b/src/main/java/us/minecraftchest2/hdm_mod/world/dimension/SimpleTeleporter.java @@ -5,8 +5,11 @@ package us.minecraftchest2.hdm_mod.world.dimension; import net.minecraft.block.BlockState; import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.fluid.Fluids; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.server.ServerWorld; import net.minecraftforge.common.util.ITeleporter; import us.minecraftchest2.hdm_mod.block.ModBlocks; @@ -114,6 +117,30 @@ public class SimpleTeleporter implements ITeleporter { } } + if (entity instanceof PlayerEntity) { + PlayerEntity player = (PlayerEntity) entity; + ResourceLocation dimensionKey = destinationWorld.getDimensionKey().getLocation(); + // Only send the welcome message if NOT the overworld + if (!dimensionKey.getPath().equals("overworld")) { + // (Same nice formatting as before) + String path = dimensionKey.getPath(); + String dimensionName; + switch (path) { + case "the_nether": + dimensionName = "the Nether"; + break; + case "the_end": + dimensionName = "the End"; + break; + default: + dimensionName = path.replace('_', ' '); + dimensionName = dimensionName.substring(0, 1).toUpperCase() + dimensionName.substring(1); + break; + } + player.sendMessage(new StringTextComponent("Welcome to " + dimensionName + "!"), player.getUniqueID()); + } + } + return entity; } } \ No newline at end of file