Search in sources :

Example 91 with ChatComponentText

use of v1_8_9.net.minecraft.util.ChatComponentText in project BuildCraft by BuildCraft.

the class BlockTank method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) {
    if (super.onBlockActivated(world, i, j, k, entityplayer, par6, par7, par8, par9)) {
        return true;
    }
    ItemStack current = entityplayer.inventory.getCurrentItem();
    if (current != null) {
        TileEntity tile = world.getTileEntity(i, j, k);
        if (tile instanceof TileTank) {
            TileTank tank = (TileTank) tile;
            // Handle FluidContainerRegistry
            if (FluidContainerRegistry.isContainer(current)) {
                FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current);
                // Handle filled containers
                if (liquid != null) {
                    int qty = tank.fill(ForgeDirection.UNKNOWN, liquid, true);
                    if (qty != 0 && !BuildCraftCore.debugWorldgen && !entityplayer.capabilities.isCreativeMode) {
                        if (current.stackSize > 1) {
                            if (!entityplayer.inventory.addItemStackToInventory(FluidContainerRegistry.drainFluidContainer(current))) {
                                entityplayer.dropPlayerItemWithRandomChoice(FluidContainerRegistry.drainFluidContainer(current), false);
                            }
                            entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, InvUtils.consumeItem(current));
                        } else {
                            entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, FluidContainerRegistry.drainFluidContainer(current));
                        }
                    }
                    return true;
                // Handle empty containers
                } else {
                    FluidStack available = tank.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid;
                    if (available != null) {
                        ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, current);
                        liquid = FluidContainerRegistry.getFluidForFilledItem(filled);
                        if (liquid != null) {
                            if (!BuildCraftCore.debugWorldgen && !entityplayer.capabilities.isCreativeMode) {
                                if (current.stackSize > 1) {
                                    if (!entityplayer.inventory.addItemStackToInventory(filled)) {
                                        return false;
                                    } else {
                                        entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, InvUtils.consumeItem(current));
                                    }
                                } else {
                                    entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, InvUtils.consumeItem(current));
                                    entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, filled);
                                }
                            }
                            tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true);
                            return true;
                        }
                    }
                }
            } else if (current.getItem() instanceof IFluidContainerItem) {
                if (current.stackSize != 1) {
                    return false;
                }
                if (!world.isRemote) {
                    IFluidContainerItem container = (IFluidContainerItem) current.getItem();
                    FluidStack liquid = container.getFluid(current);
                    FluidStack tankLiquid = tank.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid;
                    boolean mustDrain = liquid == null || liquid.amount == 0;
                    boolean mustFill = tankLiquid == null || tankLiquid.amount == 0;
                    if (mustDrain && mustFill) {
                    // Both are empty, do nothing
                    } else if (mustDrain || !entityplayer.isSneaking()) {
                        liquid = tank.drain(ForgeDirection.UNKNOWN, 1000, false);
                        int qtyToFill = container.fill(current, liquid, true);
                        tank.drain(ForgeDirection.UNKNOWN, qtyToFill, true);
                    } else if (mustFill || entityplayer.isSneaking()) {
                        if (liquid.amount > 0) {
                            int qty = tank.fill(ForgeDirection.UNKNOWN, liquid, false);
                            tank.fill(ForgeDirection.UNKNOWN, container.drain(current, qty, true), true);
                        }
                    }
                }
                return true;
            }
        }
    } else if (DEBUG_MODE) {
        TileEntity tile = world.getTileEntity(i, j, k);
        if (tile instanceof TileTank) {
            TileTank tank = (TileTank) tile;
            if (tank.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid != null) {
                entityplayer.addChatComponentMessage(new ChatComponentText("Amount: " + tank.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid.amount + " mB"));
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IFluidContainerItem(net.minecraftforge.fluids.IFluidContainerItem) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 92 with ChatComponentText

use of v1_8_9.net.minecraft.util.ChatComponentText in project DungeonRoomsMod by Quantizr.

the class DungeonRooms method onServerConnect.

/**
 * Modified from Danker's Skyblock Mod under the GNU General Public License v3.0
 * https://github.com/bowser0000/SkyblockMod/blob/master/LICENSE
 * @author bowser0000
 */
@SubscribeEvent
public void onServerConnect(FMLNetworkEvent.ClientConnectedToServerEvent event) {
    if (mc.getCurrentServerData() == null)
        return;
    if (mc.getCurrentServerData().serverIP.toLowerCase().contains("hypixel.")) {
        logger.info("DungeonRooms: Connecting to Hypixel...");
        // Packets are used in this mod solely to detect when the player picks up an item. No packets are modified or created.
        event.manager.channel().pipeline().addBefore("packet_handler", "drm_packet_handler", new PacketHandler());
        logger.info("DungeonRooms: Packet Handler added");
        new Thread(() -> {
            try {
                while (mc.thePlayer == null) {
                    // Yes, I'm too lazy to code something proper so I'm busy-waiting, shut up. no :) -carmel
                    // It usually waits for less than half a second
                    Thread.sleep(100);
                }
                Thread.sleep(3000);
                logger.info("DungeonRooms: Checking for conflicting keybindings...");
                Utils.checkForConflictingHotkeys();
                logger.info("DungeonRooms: Checking for updates...");
                URL url = new URL("https://api.github.com/repos/Quantizr/DungeonRoomsMod/releases/latest");
                URLConnection request = url.openConnection();
                request.connect();
                JsonParser json = new JsonParser();
                JsonObject latestRelease = json.parse(new InputStreamReader((InputStream) request.getContent())).getAsJsonObject();
                String latestTag = latestRelease.get("tag_name").getAsString();
                DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(VERSION);
                DefaultArtifactVersion latestVersion = new DefaultArtifactVersion(latestTag.substring(1));
                if (currentVersion.compareTo(latestVersion) < 0) {
                    String releaseURL = "https://github.com/Quantizr/DungeonRoomsMod/releases/latest";
                    ChatComponentText update = new ChatComponentText(EnumChatFormatting.GREEN + "" + EnumChatFormatting.BOLD + "  [UPDATE]  ");
                    update.setChatStyle(update.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, releaseURL)));
                    mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Dungeon Rooms Mod is outdated. Please update to " + latestTag + ".\n").appendSibling(update));
                } else {
                    logger.info("DungeonRooms: No update found");
                }
                logger.info("DungeonRooms: Getting MOTD...");
                url = new URL("https://gist.githubusercontent.com/Quantizr/01aca53e61cef5dfd08989fec600b204/raw/");
                BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8));
                String line;
                motd = new ArrayList<>();
                while ((line = in.readLine()) != null) {
                    motd.add(line);
                }
                in.close();
                logger.info("DungeonRooms: MOTD has been checked");
            } catch (IOException | InterruptedException e) {
                mc.thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Dungeon Rooms: An error has occured. See logs for more details."));
                e.printStackTrace();
            }
        }).start();
    }
}
Also used : ClickEvent(net.minecraft.event.ClickEvent) DefaultArtifactVersion(net.minecraftforge.fml.common.versioning.DefaultArtifactVersion) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) URL(java.net.URL) URLConnection(java.net.URLConnection) PacketHandler(io.github.quantizr.dungeonrooms.handlers.PacketHandler) ChatComponentText(net.minecraft.util.ChatComponentText) JsonParser(com.google.gson.JsonParser) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 93 with ChatComponentText

use of v1_8_9.net.minecraft.util.ChatComponentText in project DungeonRoomsMod by Quantizr.

the class DungeonManager method onTick.

@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent event) {
    if (event.phase != TickEvent.Phase.START)
        return;
    EntityPlayerSP player = mc.thePlayer;
    // From this point forward, everything assumes that Utils.inCatacombs == true
    if (!Utils.inCatacombs)
        return;
    tickAmount++;
    if ((gameStage == 0 || gameStage == 1) && tickAmount % 20 == 0) {
        if (DungeonRooms.firstLogin) {
            DungeonRooms.firstLogin = false;
            mc.thePlayer.addChatMessage(new ChatComponentText("§d§l--- Dungeon Rooms Mod ---\n" + "§e This appears to be your first time using DRM v" + DungeonRooms.VERSION + ".\n" + "§e Press \"" + GameSettings.getKeyDisplayString(DungeonRooms.keyBindings[1].getKeyCode()) + "\" to configure Secret Waypoint settings, If you do not wish to use Waypoints, you can instead press \"" + GameSettings.getKeyDisplayString(DungeonRooms.keyBindings[0].getKeyCode()) + "\" while inside a dungeon room to view images of the secrets for that room.\n" + "§r (If you need help, join the Discord! Run \"/room discord\" to open the Discord invite.)\n" + "§d§l------------------------"));
        }
        if (gameStage == 0) {
            Utils.checkForConflictingHotkeys();
            gameStage = 1;
            DungeonRooms.logger.info("DungeonRooms: gameStage set to " + gameStage);
        }
        Integer[][] map = MapUtils.updatedMap();
        if (map != null) {
            DungeonRooms.logger.warn("DungeonRooms: Run started but gameStage is not on 2");
            gameStage = 2;
            DungeonRooms.logger.info("DungeonRooms: gameStage set to " + gameStage);
            return;
        }
        if (gameStage == 1 && entrancePhysicalNWCorner == null) {
            if (!player.getPositionVector().equals(new Vec3(0.0D, 0.0D, 0.0D))) {
                // this point is calculated using math, not scanning, which may cause issues when reconnecting to a run
                entrancePhysicalNWCorner = MapUtils.getClosestNWPhysicalCorner(player.getPositionVector());
                DungeonRooms.logger.info("DungeonRooms: entrancePhysicalNWCorner has been set to " + entrancePhysicalNWCorner);
            }
        }
        if (DungeonRooms.textToDisplay == null && motdToggled) {
            DungeonRooms.logger.info("DungeonRooms: Updating MOTD on screen");
            if (oddRun || !guiToggled) {
                // load MOTD on odd runs
                if (DungeonRooms.motd != null) {
                    if (!DungeonRooms.motd.isEmpty()) {
                        DungeonRooms.textToDisplay = DungeonRooms.motd;
                    }
                }
            }
            if (DungeonRooms.textToDisplay == null && guiToggled) {
                // if MOTD is empty or not odd run load default text
                DungeonRooms.textToDisplay = new ArrayList<>(Arrays.asList("Dungeon Rooms: " + EnumChatFormatting.GREEN + "Press the hotkey \"" + GameSettings.getKeyDisplayString(DungeonRooms.keyBindings[1].getKeyCode()) + "\" to configure", EnumChatFormatting.GREEN + " waypoint settings. Alternatively, press \"" + GameSettings.getKeyDisplayString(DungeonRooms.keyBindings[0].getKeyCode()) + "\" while in a room", EnumChatFormatting.GREEN + "to view images of secret locations for that room.", "(You can change the keybinds in Minecraft controls menu)"));
            }
            oddRun = !oddRun;
        }
        tickAmount = 0;
    }
}
Also used : Vec3(net.minecraft.util.Vec3) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ChatComponentText(net.minecraft.util.ChatComponentText) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 94 with ChatComponentText

use of v1_8_9.net.minecraft.util.ChatComponentText in project DungeonRoomsMod by Quantizr.

the class WaypointsGUI method actionPerformed.

@Override
public void actionPerformed(GuiButton button) {
    EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    if (button == waypointsEnabled) {
        Waypoints.enabled = !Waypoints.enabled;
        ConfigHandler.writeBooleanConfig("toggles", "waypointsToggled", Waypoints.enabled);
        waypointsEnabled.displayString = waypointBtnText();
        if (Waypoints.enabled) {
            player.addChatMessage(new ChatComponentText("§eDungeon Rooms: Waypoints will now automatically show up when you enter a new dungeon room."));
        }
    } else if (button == practiceModeEnabled) {
        Waypoints.practiceModeOn = !Waypoints.practiceModeOn;
        ConfigHandler.writeBooleanConfig("waypoint", "practiceModeOn", Waypoints.practiceModeOn);
        practiceModeEnabled.displayString = "Practice Mode: " + getOnOff(Waypoints.practiceModeOn);
        if (Waypoints.practiceModeOn) {
            player.addChatMessage(new ChatComponentText("§eDungeon Rooms: Practice Mode has been enabled.\n" + "§e Waypoints will ONLY show up while you are pressing \"" + GameSettings.getKeyDisplayString(DungeonRooms.keyBindings[2].getKeyCode()) + "\".\n" + "§r (Hotkey is configurable in Minecraft Controls menu)"));
        }
    } else if (button == showEntrance) {
        Waypoints.showEntrance = !Waypoints.showEntrance;
        ConfigHandler.writeBooleanConfig("waypoint", "showEntrance", Waypoints.showEntrance);
        showEntrance.displayString = "Show Entrance Waypoints: " + getOnOff(Waypoints.showEntrance);
    } else if (button == showSuperboom) {
        Waypoints.showSuperboom = !Waypoints.showSuperboom;
        ConfigHandler.writeBooleanConfig("waypoint", "showSuperboom", Waypoints.showSuperboom);
        showSuperboom.displayString = "Show Superboom Waypoints: " + getOnOff(Waypoints.showSuperboom);
    } else if (button == showSecrets) {
        Waypoints.showSecrets = !Waypoints.showSecrets;
        ConfigHandler.writeBooleanConfig("waypoint", "showSecrets", Waypoints.showSecrets);
        showSecrets.displayString = "Show Secret Waypoints: " + getOnOff(Waypoints.showSecrets);
    } else if (button == showFairySouls) {
        Waypoints.showFairySouls = !Waypoints.showFairySouls;
        ConfigHandler.writeBooleanConfig("waypoint", "showFairySouls", Waypoints.showFairySouls);
        showFairySouls.displayString = "Show Fairy Soul Waypoints: " + getOnOff(Waypoints.showFairySouls);
    } else if (button == showStonk) {
        Waypoints.showStonk = !Waypoints.showStonk;
        ConfigHandler.writeBooleanConfig("waypoint", "showStonk", Waypoints.showStonk);
        showStonk.displayString = "Show Stonk Waypoints: " + getOnOff(Waypoints.showStonk);
    } else if (button == sneakToDisable) {
        Waypoints.sneakToDisable = !Waypoints.sneakToDisable;
        ConfigHandler.writeBooleanConfig("waypoint", "sneakToDisable", Waypoints.sneakToDisable);
        sneakToDisable.displayString = "Double-Tap Sneak to Hide Nearby: " + getOnOff(Waypoints.sneakToDisable);
    } else if (button == disableWhenAllFound) {
        Waypoints.disableWhenAllFound = !Waypoints.disableWhenAllFound;
        ConfigHandler.writeBooleanConfig("waypoint", "disableWhenAllFound", Waypoints.disableWhenAllFound);
        disableWhenAllFound.displayString = "Disable when all secrets found: " + getOnOff(Waypoints.disableWhenAllFound);
    } else if (button == close) {
        player.closeScreen();
    }
    if (Utils.inCatacombs) {
        if (Waypoints.secretNum > 0) {
            for (int i = 1; i <= Waypoints.secretNum; i++) {
                if (button == secretButtonList.get(i - 1)) {
                    Waypoints.secretsList.set(i - 1, !Waypoints.secretsList.get(i - 1));
                    if (!RoomDetection.roomName.equals("undefined")) {
                        Waypoints.allSecretsMap.replace(RoomDetection.roomName, Waypoints.secretsList);
                    }
                    secretButtonList.get(i - 1).displayString = i + ": " + getOnOff(Waypoints.secretsList.get(i - 1));
                    break;
                }
            }
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 95 with ChatComponentText

use of v1_8_9.net.minecraft.util.ChatComponentText in project DungeonRoomsMod by Quantizr.

the class OpenLink method checkForLink.

public static void checkForLink(String type) {
    Minecraft mc = Minecraft.getMinecraft();
    EntityPlayerSP player = mc.thePlayer;
    if (RoomDetection.roomName.equals("undefined") || DungeonRooms.roomsJson.get(RoomDetection.roomName) == null) {
        player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Dungeon Rooms: You do not appear to be in a detected Dungeon room right now."));
        return;
    }
    JsonObject roomJson = DungeonRooms.roomsJson.get(RoomDetection.roomName).getAsJsonObject();
    if (roomJson.get("dsg").getAsString().equals("null") && roomJson.get("sbp") == null) {
        player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Dungeon Rooms: There are no channels/images for this room."));
        return;
    }
    switch(type) {
        case "gui":
            mc.addScheduledTask(() -> mc.displayGuiScreen(new LinkGUI()));
            break;
        case "dsg":
            OpenLink.openDiscord("client");
            break;
        case "sbp":
            if (DungeonRooms.usingSBPSecrets) {
                OpenLink.openSBPSecrets();
            } else {
                String sbpURL = "https://discord.gg/2UjaFqfPwJ";
                ChatComponentText sbp = new ChatComponentText(EnumChatFormatting.YELLOW + "" + EnumChatFormatting.UNDERLINE + sbpURL);
                sbp.setChatStyle(sbp.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, sbpURL)));
                player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Dungeon Rooms: You need the SkyblockPersonalized (SBP) Mod for this feature, get it from ").appendSibling(sbp));
            }
            break;
    }
}
Also used : LinkGUI(io.github.quantizr.dungeonrooms.gui.LinkGUI) ClickEvent(net.minecraft.event.ClickEvent) JsonObject(com.google.gson.JsonObject) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) Minecraft(net.minecraft.client.Minecraft) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

ChatComponentText (net.minecraft.util.ChatComponentText)383 IChatComponent (net.minecraft.util.IChatComponent)55 EntityPlayer (net.minecraft.entity.player.EntityPlayer)43 ChatStyle (net.minecraft.util.ChatStyle)39 ItemStack (net.minecraft.item.ItemStack)36 ClickEvent (net.minecraft.event.ClickEvent)31 World (net.minecraft.world.World)28 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)26 TileEntity (net.minecraft.tileentity.TileEntity)25 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)25 HoverEvent (net.minecraft.event.HoverEvent)23 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)21 ArrayList (java.util.ArrayList)17 RfToolsDimensionManager (mcjty.rftools.dimension.RfToolsDimensionManager)16 Block (net.minecraft.block.Block)15 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)15 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)14 Entity (net.minecraft.entity.Entity)14 DimensionInformation (mcjty.rftools.dimension.DimensionInformation)13 File (java.io.File)12