trying to get a chat message to show in the chat if the portal cant find an aplicable loccation.

Signed-off-by: dragonruler1000 <github@me.minecraftchest2.us>
This commit is contained in:
dragonruler1000 2025-05-14 10:53:39 -05:00
parent cc98e7cd6b
commit 8f94831df0
4 changed files with 35 additions and 12 deletions

View file

@ -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. # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT mod_license=MIT
# The mod version. See https://semver.org/ # 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. # 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. # This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html # See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View file

@ -15,6 +15,7 @@ import net.minecraft.util.math.shapes.IBooleanFunction;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes; import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
@ -81,18 +82,27 @@ public class Window extends HorizontalBlock {
MinecraftServer server = worldIn.getServer(); MinecraftServer server = worldIn.getServer();
if (server != null) { if (server != null) {
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) {
} targetWorld = server.getWorld(ModDimensions.World1);
} else { } else {
ServerWorld kjDim = server.getWorld(ModDimensions.World1); targetWorld = server.getWorld(World.OVERWORLD);
if (kjDim != null) { }
player.changeDimension(kjDim, new SimpleTeleporter(pos, true));
} 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); return super.onBlockActivated(state, worldIn, pos, player, handIn, hit);
} }
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
switch (state.get(HORIZONTAL_FACING)) { switch (state.get(HORIZONTAL_FACING)) {

View file

@ -17,6 +17,12 @@ public class SimpleTeleporter implements ITeleporter {
public static BlockPos thisPos = BlockPos.ZERO; public static BlockPos thisPos = BlockPos.ZERO;
public static boolean insideDimension = true; public static boolean insideDimension = true;
private boolean success = false;
public boolean wasSuccessful() {
return success;
}
public SimpleTeleporter(BlockPos pos, boolean insideDim) { public SimpleTeleporter(BlockPos pos, boolean insideDim) {
thisPos = pos; thisPos = pos;
insideDimension = insideDim; insideDimension = insideDim;
@ -50,7 +56,13 @@ public class SimpleTeleporter implements ITeleporter {
tries++; tries++;
} }
if (tries >= 25) {
this.success = false;
return entity;
}
entity.setPositionAndUpdate(destinationPos.getX(), destinationPos.getY(), destinationPos.getZ()); entity.setPositionAndUpdate(destinationPos.getX(), destinationPos.getY(), destinationPos.getZ());
this.success = true;
if (insideDimension) { if (insideDimension) {
boolean doSetBlock = true; boolean doSetBlock = true;

View file

@ -5,5 +5,5 @@
}, },
"result": "minecraft:red_wool", "result": "minecraft:red_wool",
"experience": 10000000, "experience": 10000000,
"cookingtime": 200 "cookingtime": 100
} }