0% found this document useful (0 votes)
17 views2 pages

Server Tick Event Handling in Minecraft

Uploaded by

brunoisbest124
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Server Tick Event Handling in Minecraft

Uploaded by

brunoisbest124
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

package net.voidedmc85.

outofbounds;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class OutOfBounds implements ModInitializer {


public static final String MOD_ID = "outofbounds";
public static final Logger LOGGER = [Link](MOD_ID);
private final Random random = new Random();

@Override
public void onInitialize() {
[Link]();

ServerTickEvents.END_SERVER_TICK.register(server -> {
// Create a copy of the players list to avoid
ConcurrentModificationException
List<ServerPlayerEntity> players =
[Link]().getPlayerList();
for (ServerPlayerEntity player : players) {
// Check if player is sprinting and not in the Nether
if ([Link]() &&
[Link]().getRegistryKey() != [Link]([Link], new
Identifier("minecraft", "the_nether"))) {
handleSprinting(player);
}
}
});
}

private void handleSprinting(ServerPlayerEntity player) {


// 99% chance to teleport
if ([Link](100) < 99) { // 99% chance
teleportPlayer(player);
}
}

private void teleportPlayer(ServerPlayerEntity player) {


// Define the Nether dimension
RegistryKey<World> netherKey = [Link]([Link], new
Identifier("minecraft", "the_nether"));
ServerWorld targetWorld = [Link]().getWorld(netherKey);

// If the target world exists, teleport the player


if (targetWorld != null) {
// Set target coordinates
int targetX = 0;
int targetZ = 0;
// Define height limits
int maxHeight = 100; // Max height to search
int minHeight = 20; // Min height to search
int targetY = maxHeight; // Start from the max height
BlockPos targetPos;

// Search from max height to min height


while (targetY >= minHeight) {
targetPos = new BlockPos(targetX, targetY, targetZ);
if (![Link](targetPos)) { // Check if it's not
air
// If we found a solid block, teleport the player
there
[Link](targetWorld, targetX, targetY + 1,
targetZ, [Link](), [Link]()); // Offset Y by +1 to avoid
suffocation
return;
}
targetY--;
}

// If no solid block found within limits, log an error


[Link]("No solid block found at coordinates (0,0) in the
Nether between heights " + minHeight + " and " + maxHeight + "!");
} else {
[Link]("Target world does not exist!");
}
}
}

You might also like