Search in sources :

Example 1 with ChatScreen

use of net.minecraft.client.gui.screen.ChatScreen in project BleachHack by BleachDrinker420.

the class Vector2 method onClose.

public void onClose() {
    cursorMode(GLFW.GLFW_CURSOR_NORMAL);
    // This makes the magic
    if (focusedString != null) {
        DecimalFormat coordFormat = new DecimalFormat("#.##");
        String message = ModuleManager.getModule(EntityMenu.class).interactions.getValue(focusedString).replaceAll("%name%", entity.getDisplayName().getString()).replaceAll("%uuid%", entity.getEntityName()).replaceAll("%health%", String.valueOf((int) entity.getHealth())).replaceAll("%x%", coordFormat.format(entity.getX())).replaceAll("%y%", coordFormat.format(entity.getY())).replaceAll("%z%", coordFormat.format(entity.getZ()));
        if (message.startsWith(">suggest ")) {
            client.setScreen(new ChatScreen(message.substring(9)));
        } else if (message.startsWith(">url ")) {
            try {
                Util.getOperatingSystem().open(new URI(message.substring(5)));
            } catch (Exception e) {
                BleachLogger.error("Invalid url \"" + message.substring(5) + "\"");
            }
            client.setScreen(null);
        } else {
            client.player.sendChatMessage(message);
            client.setScreen(null);
        }
    } else {
        client.setScreen(null);
    }
}
Also used : ChatScreen(net.minecraft.client.gui.screen.ChatScreen) DecimalFormat(java.text.DecimalFormat) URI(java.net.URI)

Example 2 with ChatScreen

use of net.minecraft.client.gui.screen.ChatScreen in project ImmersivePortalsMod by qouteall.

the class ClientWorldLoader method createFakedClientWorld.

// fool minecraft using the faked world
private ClientWorld createFakedClientWorld(DimensionType dimension) {
    assert mc.world.dimension.getType() == mc.player.dimension;
    assert (mc.player.dimension != dimension);
    isLoadingFakedWorld = true;
    // TODO get load distance
    int chunkLoadDistance = 3;
    WorldRenderer worldRenderer = new WorldRenderer(mc);
    ClientWorld newWorld;
    try {
        ClientPlayNetworkHandler newNetworkHandler = new ClientPlayNetworkHandler(mc, new ChatScreen("You should not be seeing me. I'm just a faked screen."), new ClientConnection(NetworkSide.CLIENTBOUND), new GameProfile(null, "faked_profiler_id"));
        // multiple net handlers share the same playerListEntries object
        ((IEClientPlayNetworkHandler) newNetworkHandler).setPlayerListEntries(((IEClientPlayNetworkHandler) mc.player.networkHandler).getPlayerListEntries());
        newWorld = new ClientWorld(newNetworkHandler, new LevelInfo(0L, GameMode.CREATIVE, true, isHardCore, LevelGeneratorType.FLAT), dimension, chunkLoadDistance, mc.getProfiler(), worldRenderer);
    } catch (Exception e) {
        throw new IllegalStateException("Creating Faked World " + dimension + " " + clientWorldMap.keySet(), e);
    }
    worldRenderer.setWorld(newWorld);
    worldRenderer.apply(mc.getResourceManager());
    ((IEClientPlayNetworkHandler) ((IEClientWorld) newWorld).getNetHandler()).setWorld(newWorld);
    clientWorldMap.put(dimension, newWorld);
    worldRendererMap.put(dimension, worldRenderer);
    Helper.log("Faked World Created " + dimension);
    isLoadingFakedWorld = false;
    return newWorld;
}
Also used : ChatScreen(net.minecraft.client.gui.screen.ChatScreen) IEClientPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler) GameProfile(com.mojang.authlib.GameProfile) LevelInfo(net.minecraft.world.level.LevelInfo) ClientConnection(net.minecraft.network.ClientConnection) IEClientWorld(com.qouteall.immersive_portals.ducks.IEClientWorld) ClientWorld(net.minecraft.client.world.ClientWorld) WorldRenderer(net.minecraft.client.render.WorldRenderer) IEClientPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler)

Example 3 with ChatScreen

use of net.minecraft.client.gui.screen.ChatScreen in project BleachHack by BleachDrinker420.

the class CommandSuggestor method onDrawOverlay.

@BleachSubscribe
public void onDrawOverlay(EventRenderInGameHud event) {
    if (!Option.CHAT_SHOW_SUGGESTIONS.getValue())
        return;
    Screen screen = MinecraftClient.getInstance().currentScreen;
    if (screen instanceof ChatScreen) {
        TextFieldWidget field = ((AccessorChatScreen) screen).getChatField();
        String text = field.getText();
        if (!text.equals(curText)) {
            suggestions.clear();
            curText = text;
            if (text.startsWith(Command.getPrefix())) {
                suggestions.addAll(CommandManager.getSuggestionProvider().getSuggestions(text.substring(Command.getPrefix().length()).split(" ", -1)));
            }
            selected = 0;
            scroll = 0;
        }
        if (selected >= 0 && selected < suggestions.size()) {
            String[] split = field.getText().split(" ", -1);
            int offset = split[split.length - 1].length() - (split.length == 1 ? Command.getPrefix().length() : 0);
            if (offset > suggestions.get(selected).length()) {
                field.setSuggestion("");
            } else {
                field.setSuggestion(suggestions.get(selected).substring(offset));
            }
        }
        if (!suggestions.isEmpty()) {
            event.getMatrix().push();
            event.getMatrix().translate(0, 0, 200);
            int length = suggestions.stream().map(s -> MinecraftClient.getInstance().textRenderer.getWidth(s)).min(Comparator.reverseOrder()).orElse(0);
            int startX = MinecraftClient.getInstance().textRenderer.getWidth(field.getText().replaceFirst("[^ ]*$", "") + (!field.getText().contains(" ") ? Command.getPrefix() : "")) + 3;
            int startY = screen.height - Math.min(suggestions.size(), 10) * 12 - 15;
            for (int i = scroll; i < suggestions.size() && i < scroll + 10; i++) {
                String suggestion = suggestions.get(i);
                DrawableHelper.fill(event.getMatrix(), startX, startY, startX + length + 2, startY + 12, 0xd0000000);
                MinecraftClient.getInstance().textRenderer.drawWithShadow(event.getMatrix(), suggestion, startX + 1, startY + 2, i == selected ? 0xffff00 : 0xb0b0b0);
                startY += 12;
            }
            event.getMatrix().pop();
        }
    }
}
Also used : AccessorChatScreen(org.bleachhack.mixin.AccessorChatScreen) ChatScreen(net.minecraft.client.gui.screen.ChatScreen) EventOpenScreen(org.bleachhack.event.events.EventOpenScreen) Screen(net.minecraft.client.gui.screen.Screen) AccessorChatScreen(org.bleachhack.mixin.AccessorChatScreen) ChatScreen(net.minecraft.client.gui.screen.ChatScreen) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) AccessorChatScreen(org.bleachhack.mixin.AccessorChatScreen) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 4 with ChatScreen

use of net.minecraft.client.gui.screen.ChatScreen in project BleachHack by BleachDrinker420.

the class MixinKeyboard method onKeyEvent_1.

@Inject(method = "onKey", at = @At(value = "INVOKE", target = "net/minecraft/client/util/InputUtil.isKeyPressed(JI)Z", ordinal = 5), cancellable = true)
private void onKeyEvent_1(long windowPointer, int key, int scanCode, int action, int modifiers, CallbackInfo callbackInfo) {
    if (Option.CHAT_QUICK_PREFIX.getValue() && Command.getPrefix().length() == 1 && key == Command.getPrefix().charAt(0)) {
        MinecraftClient.getInstance().setScreen(new ChatScreen(Command.getPrefix()));
    }
    ModuleManager.handleKey(key);
    if (key >= 0) {
        EventKeyPress.InWorld event = new EventKeyPress.InWorld(key, scanCode);
        BleachHack.eventBus.post(event);
        if (event.isCancelled()) {
            callbackInfo.cancel();
        }
    }
}
Also used : ChatScreen(net.minecraft.client.gui.screen.ChatScreen) EventKeyPress(org.bleachhack.event.events.EventKeyPress) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with ChatScreen

use of net.minecraft.client.gui.screen.ChatScreen in project Hypnotic-Client by Hypnotic-Development.

the class KeyboardMixin method onKey.

@Inject(method = "onKey", at = @At("HEAD"), cancellable = true)
public void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo info) {
    if (key != GLFW.GLFW_KEY_UNKNOWN) {
        /*
        	 * action == GLFW.GLFW_PRESS is important
        	 * so the module does not toggle twice
        	 */
        KeyUtils.setKeyState(key, action != GLFW.GLFW_RELEASE);
        for (Mod mod : ModuleManager.INSTANCE.modules) {
            if (mod.getKey() == key && action == GLFW.GLFW_PRESS && MinecraftClient.getInstance().currentScreen == null)
                mod.toggle();
        }
        EventKeyPress event = new EventKeyPress(key, scancode, action);
        event.call();
        if (event.isCancelled())
            info.cancel();
        if (client.currentScreen == null && key == KeyUtils.getKey(CommandManager.INSTANCE.getPrefix()) && action == GLFW.GLFW_PRESS)
            client.setScreen(new ChatScreen(""));
    }
}
Also used : ChatScreen(net.minecraft.client.gui.screen.ChatScreen) Mod(dev.hypnotic.module.Mod) EventKeyPress(dev.hypnotic.event.events.EventKeyPress) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ChatScreen (net.minecraft.client.gui.screen.ChatScreen)5 Inject (org.spongepowered.asm.mixin.injection.Inject)2 GameProfile (com.mojang.authlib.GameProfile)1 IEClientPlayNetworkHandler (com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler)1 IEClientWorld (com.qouteall.immersive_portals.ducks.IEClientWorld)1 EventKeyPress (dev.hypnotic.event.events.EventKeyPress)1 Mod (dev.hypnotic.module.Mod)1 URI (java.net.URI)1 DecimalFormat (java.text.DecimalFormat)1 Screen (net.minecraft.client.gui.screen.Screen)1 TextFieldWidget (net.minecraft.client.gui.widget.TextFieldWidget)1 ClientPlayNetworkHandler (net.minecraft.client.network.ClientPlayNetworkHandler)1 WorldRenderer (net.minecraft.client.render.WorldRenderer)1 ClientWorld (net.minecraft.client.world.ClientWorld)1 ClientConnection (net.minecraft.network.ClientConnection)1 LevelInfo (net.minecraft.world.level.LevelInfo)1 EventKeyPress (org.bleachhack.event.events.EventKeyPress)1 EventOpenScreen (org.bleachhack.event.events.EventOpenScreen)1 BleachSubscribe (org.bleachhack.eventbus.BleachSubscribe)1 AccessorChatScreen (org.bleachhack.mixin.AccessorChatScreen)1