mirror of
https://github.com/dragonruler1000/hdm-mod.git
synced 2025-06-29 08:29:33 -05:00
Refactor teleportation logic and add custom dimension config
Simplified portal activation logic to improve readability and efficiency, removing redundant checks and consolidating teleport code paths. Added configuration file for the "world1" custom dimension, defining its properties and behavior and fixing the bug I was having.
This commit is contained in:
parent
79949bc13b
commit
02d4df7c55
2 changed files with 38 additions and 44 deletions
|
@ -104,56 +104,35 @@ public class Window extends HorizontalBlock {
|
||||||
Hand handIn,
|
Hand handIn,
|
||||||
BlockRayTraceResult hit
|
BlockRayTraceResult hit
|
||||||
) {
|
) {
|
||||||
// Only process on the server side, avoid duplicating logic on client
|
if (!worldIn.isRemote() && !player.isCrouching()) {
|
||||||
if (worldIn.isRemote()) return super.onBlockActivated(state, worldIn, pos, player, handIn, hit);
|
MinecraftServer server = worldIn.getServer();
|
||||||
// Do nothing if the player is crouching (commonly used for alternative interactions)
|
if (server == null) return ActionResultType.PASS;
|
||||||
if (player.isCrouching()) return super.onBlockActivated(state, worldIn, pos, player, handIn, hit);
|
|
||||||
|
|
||||||
// Get the server instance safely
|
boolean goingToCustom = worldIn.getDimensionKey() != ModDimensions.World1;
|
||||||
if (worldIn.getServer() == null) return super.onBlockActivated(state, worldIn, pos, player, handIn, hit);
|
|
||||||
MinecraftServer server = worldIn.getServer();
|
|
||||||
|
|
||||||
// Check if in custom dimension; if so, teleport to Overworld
|
ServerWorld targetWorld = (worldIn.getDimensionKey() == ModDimensions.World1)
|
||||||
if (worldIn.getDimensionKey() == ModDimensions.World1) {
|
? server.getWorld(World.OVERWORLD)
|
||||||
ServerWorld overWorld = server.getWorld(World.OVERWORLD);
|
: server.getWorld(ModDimensions.World1);
|
||||||
if (overWorld != null) {
|
|
||||||
player.changeDimension(overWorld, new SimpleTeleporter(pos, false));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up for teleportation based on current dimension
|
if (worldIn.getDimensionKey() == ModDimensions.World1) {
|
||||||
ServerWorld targetWorld;
|
ServerWorld overWorld = server.getWorld(World.OVERWORLD);
|
||||||
boolean goingToCustom = worldIn.getDimensionKey() != ModDimensions.World1;
|
if (overWorld != null) {
|
||||||
|
player.changeDimension(overWorld, new SimpleTeleporter(pos, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (goingToCustom) {
|
if (targetWorld != null) {
|
||||||
// Teleporting from Overworld to custom dimension
|
SimpleTeleporter teleporter = new SimpleTeleporter(pos, goingToCustom);
|
||||||
targetWorld = server.getWorld(ModDimensions.World1);
|
player.changeDimension(targetWorld, teleporter);
|
||||||
} else {
|
}
|
||||||
// From custom dimension, teleport to Overworld
|
|
||||||
ServerWorld world1 = server.getWorld(ModDimensions.World1);
|
|
||||||
if (world1 != null) {
|
|
||||||
player.changeDimension(world1, new SimpleTeleporter(pos, true));
|
|
||||||
}
|
|
||||||
targetWorld = server.getWorld(World.OVERWORLD);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt teleport if a valid world was found
|
System.out.println("[DEBUG] Portal activated on server!");
|
||||||
if (targetWorld != null) {
|
player.sendMessage(new StringTextComponent("Teleport logic running!"), player.getUniqueID());
|
||||||
SimpleTeleporter teleporter = new SimpleTeleporter(pos, goingToCustom);
|
player.sendMessage(new StringTextComponent("Teleport attempted!"), player.getUniqueID());
|
||||||
player.changeDimension(targetWorld, teleporter);
|
return ActionResultType.SUCCESS;
|
||||||
|
|
||||||
// Notify the player about the result
|
}
|
||||||
if (teleporter.wasSuccessful()) {
|
return super.onBlockActivated(state, worldIn, pos, player, handIn, hit);
|
||||||
player.sendMessage(new StringTextComponent("Teleportation successful!"), player.getUniqueID());
|
|
||||||
} else {
|
|
||||||
player.sendMessage(new StringTextComponent("Teleportation failed: no safe location found."), player.getUniqueID());
|
|
||||||
}
|
|
||||||
|
|
||||||
return ActionResultType.SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fall back to default processing if teleportation did not occur
|
|
||||||
return super.onBlockActivated(state, worldIn, pos, player, handIn, hit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
15
src/main/resources/data/hdm_mod/dimension_type/world1.json
Normal file
15
src/main/resources/data/hdm_mod/dimension_type/world1.json
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"logical_height": 256,
|
||||||
|
"infiniburn": "minecraft:infiniburn_overworld",
|
||||||
|
"effects": "minecraft:overworld",
|
||||||
|
"ambient_light": 0,
|
||||||
|
"bed_works": true,
|
||||||
|
"respawn_anchor_works": false,
|
||||||
|
"has_raids": true,
|
||||||
|
"ultrawarm": false,
|
||||||
|
"natural": true,
|
||||||
|
"coordinate_scale": 1,
|
||||||
|
"piglin_safe": false,
|
||||||
|
"has_skylight": true,
|
||||||
|
"has_ceiling": false
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue