|
|
|
@ -2,6 +2,7 @@ package com.thebrokenrail.energonrelics.block.portal;
|
|
|
|
|
|
|
|
|
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
|
|
|
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
|
|
|
|
|
import com.thebrokenrail.energonrelics.mixin.ServerPlayerEntityAccessor;
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
|
import net.minecraft.block.Blocks;
|
|
|
|
@ -19,13 +20,19 @@ import net.minecraft.world.Heightmap;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
class EnergyTeleporter {
|
|
|
|
|
private static void teleport(Entity entity, ServerWorld to, Vec3d pos) {
|
|
|
|
|
if (entity instanceof ServerPlayerEntity) {
|
|
|
|
|
((ServerPlayerEntityAccessor) entity).setInTeleportationState(true);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
TeleportCommand.teleport(null, entity, to, pos.getX(), pos.getY(), pos.getZ(), EnumSet.noneOf(PlayerPositionLookS2CPacket.Flag.class), entity.yaw, entity.pitch, null);
|
|
|
|
|
} catch (CommandSyntaxException ignored) {
|
|
|
|
|
} catch (CommandSyntaxException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
if (entity instanceof ServerPlayerEntity) {
|
|
|
|
|
((ServerPlayerEntity) entity).networkHandler.syncWithPlayerPosition();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -33,8 +40,6 @@ class EnergyTeleporter {
|
|
|
|
|
BlockPos center = EnergyPortalBlock.getCenterPos(world, blockPos);
|
|
|
|
|
Vec3d offset = pos.subtract(Vec3d.ofBottomCenter(center));
|
|
|
|
|
|
|
|
|
|
UUID uuid = entity.getUuid();
|
|
|
|
|
|
|
|
|
|
RegistryKey<World> worldKey = world.getRegistryKey();
|
|
|
|
|
if (worldKey == World.OVERWORLD) {
|
|
|
|
|
teleportWithMultiplier(world, entity, center, offset, World.NETHER, 1d / HardcodedConfig.ENERGY_PORTAL_MULTIPLIER);
|
|
|
|
@ -45,15 +50,12 @@ class EnergyTeleporter {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entity instanceof ServerPlayerEntity) {
|
|
|
|
|
ServerPlayerEntity player = world.getServer().getPlayerManager().getPlayer(uuid);
|
|
|
|
|
if (player != null) {
|
|
|
|
|
player.playSound(SoundEvents.BLOCK_PORTAL_TRAVEL, SoundCategory.PLAYERS, 0.25f, world.random.nextFloat() * 0.4f + 0.8f);
|
|
|
|
|
}
|
|
|
|
|
((ServerPlayerEntity) entity).playSound(SoundEvents.BLOCK_PORTAL_TRAVEL, SoundCategory.PLAYERS, 0.25f, world.random.nextFloat() * 0.4f + 0.8f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int convertY(int y, int oldHeight, int newHeight) {
|
|
|
|
|
int newY = (int) (((float) y / (float) oldHeight) * (float) newHeight);
|
|
|
|
|
int newY = (int) (((float) newHeight / (float) oldHeight) * (float) y);
|
|
|
|
|
|
|
|
|
|
int bottomY = HardcodedConfig.ENERGY_PORTAL_Y_PADDING;
|
|
|
|
|
int topY = newHeight - (bottomY + HardcodedConfig.ENERGY_PORTAL_Y_PADDING_EXTRA_TOP);
|
|
|
|
|