From 8f94831df07053bb807a2bdf7f6dc96860c76d59 Mon Sep 17 00:00:00 2001 From: dragonruler1000 Date: Wed, 14 May 2025 10:53:39 -0500 Subject: [PATCH 1/2] trying to get a chat message to show in the chat if the portal cant find an aplicable loccation. Signed-off-by: dragonruler1000 --- gradle.properties | 2 +- .../hdm_mod/block/custom/Window.java | 31 +++++++++++++------ .../world/dimension/SimpleTeleporter.java | 12 +++++++ .../resources/data/hdm_mod/recipes/joke.json | 2 +- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/gradle.properties b/gradle.properties index e005d87..e02d200 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.1 +mod_version=1.2 # 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/block/custom/Window.java b/src/main/java/us/minecraftchest2/hdm_mod/block/custom/Window.java index e96f191..3a30043 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 @@ -15,6 +15,7 @@ import net.minecraft.util.math.shapes.IBooleanFunction; import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; @@ -81,18 +82,27 @@ public class Window extends HorizontalBlock { MinecraftServer server = worldIn.getServer(); if (server != null) { - if (worldIn.getDimensionKey() == ModDimensions.World1) { - ServerWorld overWorld = server.getWorld(World.OVERWORLD); - if (overWorld != null) { - player.changeDimension(overWorld, new SimpleTeleporter(pos, false)); - } + ServerWorld targetWorld; + boolean goingToCustom = worldIn.getDimensionKey() != ModDimensions.World1; + + if (goingToCustom) { + targetWorld = server.getWorld(ModDimensions.World1); } else { - ServerWorld kjDim = server.getWorld(ModDimensions.World1); - if (kjDim != null) { - player.changeDimension(kjDim, new SimpleTeleporter(pos, true)); - } + targetWorld = server.getWorld(World.OVERWORLD); + } + + if (targetWorld != null) { + SimpleTeleporter teleporter = new SimpleTeleporter(pos, goingToCustom); + player.changeDimension(targetWorld, teleporter); + + if (teleporter.wasSuccessful()) { + player.sendMessage(new StringTextComponent("Teleportation successful!"), player.getUniqueID()); + } else { + player.sendMessage(new StringTextComponent("Teleportation failed: no safe location found."), player.getUniqueID()); + } + + return ActionResultType.SUCCESS; } - return ActionResultType.SUCCESS; } } } @@ -100,6 +110,7 @@ public class Window extends HorizontalBlock { return super.onBlockActivated(state, worldIn, pos, player, handIn, hit); } + @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { switch (state.get(HORIZONTAL_FACING)) { 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 e2b1537..a9f8992 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 @@ -17,6 +17,12 @@ public class SimpleTeleporter implements ITeleporter { public static BlockPos thisPos = BlockPos.ZERO; public static boolean insideDimension = true; + private boolean success = false; + + public boolean wasSuccessful() { + return success; + } + public SimpleTeleporter(BlockPos pos, boolean insideDim) { thisPos = pos; insideDimension = insideDim; @@ -50,7 +56,13 @@ public class SimpleTeleporter implements ITeleporter { tries++; } + if (tries >= 25) { + this.success = false; + return entity; + } + entity.setPositionAndUpdate(destinationPos.getX(), destinationPos.getY(), destinationPos.getZ()); + this.success = true; if (insideDimension) { boolean doSetBlock = true; diff --git a/src/main/resources/data/hdm_mod/recipes/joke.json b/src/main/resources/data/hdm_mod/recipes/joke.json index 6047652..f66f1a8 100644 --- a/src/main/resources/data/hdm_mod/recipes/joke.json +++ b/src/main/resources/data/hdm_mod/recipes/joke.json @@ -5,5 +5,5 @@ }, "result": "minecraft:red_wool", "experience": 10000000, - "cookingtime": 200 + "cookingtime": 100 } \ No newline at end of file From c06d73ebff4404fa9af9abd2442d213f3063ca71 Mon Sep 17 00:00:00 2001 From: dragonruler1000 Date: Wed, 14 May 2025 20:57:28 -0500 Subject: [PATCH 2/2] readded stuff that was accidently removed. Signed-off-by: dragonruler1000 --- .../minecraftchest2/hdm_mod/block/custom/Window.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 3a30043..f3fa412 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 @@ -82,12 +82,22 @@ public class Window extends HorizontalBlock { MinecraftServer server = worldIn.getServer(); if (server != null) { + if (worldIn.getDimensionKey() == ModDimensions.World1) { + ServerWorld overWorld = server.getWorld(World.OVERWORLD); + if (overWorld != null) { + player.changeDimension(overWorld, new SimpleTeleporter(pos, false)); + } + } ServerWorld targetWorld; boolean goingToCustom = worldIn.getDimensionKey() != ModDimensions.World1; if (goingToCustom) { targetWorld = server.getWorld(ModDimensions.World1); } else { + ServerWorld world1 = server.getWorld(ModDimensions.World1); + if (world1 != null) { + player.changeDimension(world1, new SimpleTeleporter(pos, true)); + } targetWorld = server.getWorld(World.OVERWORLD); }