Skip to content

Commit

Permalink
Change Ender teleporting to allow teleporting to an unloaded chunk #93
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrbysco committed Jul 15, 2024
1 parent 973b5fa commit d37abad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mrbysco.forcecraft.attachment.forcerod;

import com.mrbysco.forcecraft.util.ForceUtils;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.GlobalPos;
Expand Down Expand Up @@ -74,7 +75,7 @@ public void teleportPlayerToLocation(Player player, GlobalPos globalPos) {
int y = pos.getY() + 1;
int z = pos.getZ();

player.randomTeleport(x, y, z, true);
ForceUtils.teleportToLocation(player, x, y, z, true);
} else {
if (!player.level().isClientSide) {
player.sendSystemMessage(Component.translatable("forcecraft.ender_rod.dimension.text").withStyle(ChatFormatting.YELLOW));
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/mrbysco/forcecraft/util/ForceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@

public class ForceUtils {

/**
* A modified version of LivingEntity#randomTeleport that allows teleporting to unloaded chunks
*
* @param player The entity to teleport
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
* @param broadcast if the teleport should be broadcasted to other players
* @return if the teleport was successful
*/
public static boolean teleportToLocation(Player player, double x, double y, double z, boolean broadcast) {
Level level = player.level();

player.teleportTo(x, y, z);
if (broadcast) {
level.broadcastEntityEvent(player, (byte) 46);
}
return true;
}

public static void removeEnchant(Enchantment enchantment, ItemStack stack) {
Map<Enchantment, Integer> enchantMap = EnchantmentHelper.getEnchantments(stack);
if (enchantMap.containsKey(enchantment)) {
Expand Down

0 comments on commit d37abad

Please sign in to comment.