Search in sources :

Example 1 with DimensionRegistry

use of net.modificationstation.stationapi.api.registry.DimensionRegistry in project StationAPI by ModificationStation.

the class DimensionListener method registerDimensions.

@EventListener
private static void registerDimensions(DimensionRegistryEvent event) {
    DimensionRegistry r = event.registry;
    r.register(of(MODID, "test_dimension"), new DimensionContainer<>(TestDimension::new));
}
Also used : DimensionRegistry(net.modificationstation.stationapi.api.registry.DimensionRegistry) EventListener(net.mine_diver.unsafeevents.listener.EventListener)

Example 2 with DimensionRegistry

use of net.modificationstation.stationapi.api.registry.DimensionRegistry in project StationAPI by ModificationStation.

the class DimensionAPI method registerDimensions.

@EventListener(priority = ListenerPriority.HIGH)
private static void registerDimensions(DimensionRegistryEvent event) {
    DimensionRegistry r = event.registry;
    r.register(THE_NETHER, -1, new DimensionContainer<>(Nether::new));
    r.register(OVERWORLD, 0, new DimensionContainer<>(Overworld::new));
    r.register(SKYLANDS, 1, new DimensionContainer<>(Skylands::new));
}
Also used : DimensionRegistry(net.modificationstation.stationapi.api.registry.DimensionRegistry) EventListener(net.mine_diver.unsafeevents.listener.EventListener)

Example 3 with DimensionRegistry

use of net.modificationstation.stationapi.api.registry.DimensionRegistry in project StationAPI by ModificationStation.

the class DimensionHelperServerImpl method switchDimension.

@Override
public void switchDimension(PlayerBase player, Identifier destination, double scale, class_467 travelAgent) {
    // noinspection deprecation
    MinecraftServer server = (MinecraftServer) FabricLoader.getInstance().getGameInstance();
    ServerPlayer serverPlayer = (ServerPlayer) player;
    ServerLevel var2 = server.getLevel(serverPlayer.dimensionId);
    DimensionRegistry dimensions = DimensionRegistry.INSTANCE;
    int overworldSerial = dimensions.getSerialID(OVERWORLD).orElseThrow(() -> new IllegalStateException("Overworld not found!"));
    int destinationSerial = dimensions.getSerialID(destination).orElseThrow(() -> new IllegalArgumentException("Unknown dimension: " + destination + "!"));
    player.dimensionId = player.dimensionId == destinationSerial ? overworldSerial : destinationSerial;
    ServerLevel var4 = server.getLevel(serverPlayer.dimensionId);
    serverPlayer.packetHandler.send(new Respawn0x9C2SPacket((byte) serverPlayer.dimensionId));
    var2.removeEntityServer(serverPlayer);
    serverPlayer.removed = false;
    double var5 = serverPlayer.x;
    double var7 = serverPlayer.z;
    if (serverPlayer.dimensionId == destinationSerial) {
        var5 *= scale;
        var7 *= scale;
    } else {
        var5 /= scale;
        var7 /= scale;
    }
    serverPlayer.setPositionAndAngles(var5, serverPlayer.y, var7, serverPlayer.yaw, serverPlayer.pitch);
    if (serverPlayer.isAlive())
        var2.method_193(serverPlayer, false);
    if (serverPlayer.isAlive()) {
        var4.spawnEntity(serverPlayer);
        serverPlayer.setPositionAndAngles(var5, serverPlayer.y, var7, serverPlayer.yaw, serverPlayer.pitch);
        var4.method_193(serverPlayer, false);
        var4.serverLevelSource.field_933 = true;
        travelAgent.method_1530(var4, serverPlayer);
        var4.serverLevelSource.field_933 = false;
    }
    server.serverPlayerConnectionManager.method_554(serverPlayer);
    serverPlayer.packetHandler.method_832(serverPlayer.x, serverPlayer.y, serverPlayer.z, serverPlayer.yaw, serverPlayer.pitch);
    serverPlayer.setLevel(var4);
    server.serverPlayerConnectionManager.sendPlayerTime(serverPlayer, var4);
    server.serverPlayerConnectionManager.method_581(serverPlayer);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ServerPlayer(net.minecraft.entity.player.ServerPlayer) Respawn0x9C2SPacket(net.minecraft.packet.play.Respawn0x9C2SPacket) DimensionRegistry(net.modificationstation.stationapi.api.registry.DimensionRegistry) MinecraftServer(net.minecraft.server.MinecraftServer)

Aggregations

DimensionRegistry (net.modificationstation.stationapi.api.registry.DimensionRegistry)3 EventListener (net.mine_diver.unsafeevents.listener.EventListener)2 ServerPlayer (net.minecraft.entity.player.ServerPlayer)1 Respawn0x9C2SPacket (net.minecraft.packet.play.Respawn0x9C2SPacket)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 ServerLevel (net.minecraft.server.level.ServerLevel)1