Java Code Examples for net.minecraft.client.Minecraft#isSingleplayer()

The following examples show how to use net.minecraft.client.Minecraft#isSingleplayer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DevUtils.java    From SkyblockAddons with MIT License 6 votes vote down vote up
/**
 * Retrieves the server brand from the Minecraft client.
 *
 * @param mc the Minecraft client
 * @return the server brand if the client is connected to a server, {@code null} otherwise
 */
public static String getServerBrand(Minecraft mc) {
    final Pattern SERVER_BRAND_PATTERN = Pattern.compile("(.+) <- (?:.+)");

    if (!mc.isSingleplayer()) {
        Matcher matcher = SERVER_BRAND_PATTERN.matcher(mc.thePlayer.getClientBrand());

        if (matcher.find()) {
            // Group 1 is the server brand.
            return matcher.group(1);
        }
        else {
            return null;
        }
    }
    else {
        return null;
    }
}
 
Example 2
Source File: Utils.java    From SkyblockAddons with MIT License 6 votes vote down vote up
/**
 * Checks if the player is on the Hypixel Network
 *
 * @return {@code true} if the player is on Hypixel, {@code false} otherwise
 */
public boolean isOnHypixel() {
    final Pattern SERVER_BRAND_PATTERN = Pattern.compile("(.+) <- (?:.+)");
    final String HYPIXEL_SERVER_BRAND = "BungeeCord (Hypixel)";

    Minecraft mc = Minecraft.getMinecraft();

    if (!mc.isSingleplayer() && mc.thePlayer.getClientBrand() != null) {
        Matcher matcher = SERVER_BRAND_PATTERN.matcher(mc.thePlayer.getClientBrand());

        if (matcher.find()) {
            // Group 1 is the server brand.
            return matcher.group(1).equals(HYPIXEL_SERVER_BRAND);
        }
        else {
            return false;
        }
    }
    else {
        return false;
    }
}
 
Example 3
Source File: TaskScheduler.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static TaskScheduler getServerInstanceIfExistsOrClient()
{
    Minecraft mc = Minecraft.getMinecraft();
    // Yes this is actually correct despite the naming - in single player we want to
    // schedule stuff to the integrated server's thread in some cases
    return mc.isSingleplayer() ? INSTANCE_SERVER : INSTANCE_CLIENT;
}
 
Example 4
Source File: ToolUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void updateSelectionVolumes(@Nullable final AreaSelection area, Minecraft mc)
{
    if (mc.player != null && mc.player.capabilities.isCreativeMode && mc.isSingleplayer())
    {
        if (area == null)
        {
            InfoUtils.showGuiOrInGameMessage(MessageType.ERROR, "litematica.message.error.no_area_selected");
            return;
        }

        if (area.getAllSubRegionBoxes().size() > 0)
        {
            SelectionBox currentBox = area.getSelectedSubRegionBox();
            final ImmutableList<SelectionBox> boxes = currentBox != null ? ImmutableList.of(currentBox) : ImmutableList.copyOf(area.getAllSubRegionBoxes());
            TaskUpdateBlocks task = new TaskUpdateBlocks(boxes);
            TaskScheduler.getInstanceServer().scheduleTask(task, 20);

            InfoUtils.showGuiOrInGameMessage(MessageType.INFO, "litematica.message.scheduled_task_added");
        }
        else
        {
            InfoUtils.showGuiOrInGameMessage(MessageType.ERROR, "litematica.message.error.empty_area_selection");
        }
    }
    else
    {
        InfoUtils.showGuiOrInGameMessage(MessageType.ERROR, "litematica.error.generic.creative_mode_only");
    }
}