├── README.md └── me └── superblaubeere27 └── client └── notifications ├── NotificationType.java ├── NotificationManager.java └── Notification.java /README.md: -------------------------------------------------------------------------------- 1 | # NotificationSystem 2 | 3 | ## Video: 4 | [![Video](https://img.youtube.com/vi/26f1WrsE7mk/0.jpg)](https://www.youtube.com/watch?v=26f1WrsE7mk) 5 | -------------------------------------------------------------------------------- /me/superblaubeere27/client/notifications/NotificationType.java: -------------------------------------------------------------------------------- 1 | package me.superblaubeere27.client.notifications; 2 | 3 | public enum NotificationType { 4 | INFO, WARNING, ERROR; 5 | } 6 | -------------------------------------------------------------------------------- /me/superblaubeere27/client/notifications/NotificationManager.java: -------------------------------------------------------------------------------- 1 | package me.superblaubeere27.client.notifications; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.LinkedBlockingQueue; 5 | 6 | public class NotificationManager { 7 | private static LinkedBlockingQueue pendingNotifications = new LinkedBlockingQueue<>(); 8 | private static Notification currentNotification = null; 9 | 10 | public static void show(Notification notification) { 11 | pendingNotifications.add(notification); 12 | } 13 | 14 | public static void update() { 15 | if (currentNotification != null && !currentNotification.isShown()) { 16 | currentNotification = null; 17 | } 18 | 19 | if (currentNotification == null && !pendingNotifications.isEmpty()) { 20 | currentNotification = pendingNotifications.poll(); 21 | currentNotification.show(); 22 | } 23 | 24 | } 25 | 26 | public static void render() { 27 | update(); 28 | 29 | if (currentNotification != null) 30 | currentNotification.render(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /me/superblaubeere27/client/notifications/Notification.java: -------------------------------------------------------------------------------- 1 | package me.superblaubeere27.client.notifications; 2 | 3 | import net.minecraft.client.Minecraft; 4 | import net.minecraft.client.gui.FontRenderer; 5 | import net.minecraft.client.gui.Gui; 6 | import net.minecraft.client.gui.GuiScreen; 7 | import net.minecraft.client.renderer.GlStateManager; 8 | import net.minecraft.client.renderer.Tessellator; 9 | import net.minecraft.client.renderer.WorldRenderer; 10 | import net.minecraft.client.renderer.vertex.DefaultVertexFormats; 11 | 12 | import java.awt.Color; 13 | 14 | import org.lwjgl.opengl.GL11; 15 | 16 | public class Notification { 17 | private NotificationType type; 18 | private String title; 19 | private String messsage; 20 | private long start; 21 | 22 | private long fadedIn; 23 | private long fadeOut; 24 | private long end; 25 | 26 | 27 | public Notification(NotificationType type, String title, String messsage, int length) { 28 | this.type = type; 29 | this.title = title; 30 | this.messsage = messsage; 31 | 32 | fadedIn = 200 * length; 33 | fadeOut = fadedIn + 500 * length; 34 | end = fadeOut + fadedIn; 35 | } 36 | 37 | public void show() { 38 | start = System.currentTimeMillis(); 39 | } 40 | 41 | public boolean isShown() { 42 | return getTime() <= end; 43 | } 44 | 45 | private long getTime() { 46 | return System.currentTimeMillis() - start; 47 | } 48 | 49 | public void render() { 50 | double offset = 0; 51 | int width = 120; 52 | int height = 30; 53 | long time = getTime(); 54 | 55 | if (time < fadedIn) { 56 | offset = Math.tanh(time / (double) (fadedIn) * 3.0) * width; 57 | } else if (time > fadeOut) { 58 | offset = (Math.tanh(3.0 - (time - fadeOut) / (double) (end - fadeOut) * 3.0) * width); 59 | } else { 60 | offset = width; 61 | } 62 | 63 | Color color = new Color(0, 0, 0, 220); 64 | Color color1; 65 | 66 | if (type == NotificationType.INFO) 67 | color1 = new Color(0, 26, 169); 68 | else if (type == NotificationType.WARNING) 69 | color1 = new Color(204, 193, 0); 70 | else { 71 | color1 = new Color(204, 0, 18); 72 | int i = Math.max(0, Math.min(255, (int) (Math.sin(time / 100.0) * 255.0 / 2 + 127.5))); 73 | color = new Color(i, 0, 0, 220); 74 | } 75 | 76 | FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; 77 | 78 | drawRect(GuiScreen.width - offset, GuiScreen.height - 5 - height, GuiScreen.width, GuiScreen.height - 5, color.getRGB()); 79 | drawRect(GuiScreen.width - offset, GuiScreen.height - 5 - height, GuiScreen.width - offset + 4, GuiScreen.height - 5, color1.getRGB()); 80 | 81 | fontRenderer.drawString(title, (int) (GuiScreen.width - offset + 8), GuiScreen.height - 2 - height, -1); 82 | fontRenderer.drawString(messsage, (int) (GuiScreen.width - offset + 8), GuiScreen.height - 15, -1); 83 | } 84 | 85 | public static void drawRect(double left, double top, double right, double bottom, int color) { 86 | if (left < right) { 87 | double i = left; 88 | left = right; 89 | right = i; 90 | } 91 | 92 | if (top < bottom) { 93 | double j = top; 94 | top = bottom; 95 | bottom = j; 96 | } 97 | 98 | float f3 = (float) (color >> 24 & 255) / 255.0F; 99 | float f = (float) (color >> 16 & 255) / 255.0F; 100 | float f1 = (float) (color >> 8 & 255) / 255.0F; 101 | float f2 = (float) (color & 255) / 255.0F; 102 | Tessellator tessellator = Tessellator.getInstance(); 103 | WorldRenderer worldrenderer = tessellator.getWorldRenderer(); 104 | GlStateManager.enableBlend(); 105 | GlStateManager.disableTexture2D(); 106 | GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); 107 | GlStateManager.color(f, f1, f2, f3); 108 | worldrenderer.begin(7, DefaultVertexFormats.POSITION); 109 | worldrenderer.pos(left, bottom, 0.0D).endVertex(); 110 | worldrenderer.pos(right, bottom, 0.0D).endVertex(); 111 | worldrenderer.pos(right, top, 0.0D).endVertex(); 112 | worldrenderer.pos(left, top, 0.0D).endVertex(); 113 | tessellator.draw(); 114 | GlStateManager.enableTexture2D(); 115 | GlStateManager.disableBlend(); 116 | } 117 | 118 | public static void drawRect(int mode, double left, double top, double right, double bottom, int color) { 119 | if (left < right) { 120 | double i = left; 121 | left = right; 122 | right = i; 123 | } 124 | 125 | if (top < bottom) { 126 | double j = top; 127 | top = bottom; 128 | bottom = j; 129 | } 130 | 131 | float f3 = (float) (color >> 24 & 255) / 255.0F; 132 | float f = (float) (color >> 16 & 255) / 255.0F; 133 | float f1 = (float) (color >> 8 & 255) / 255.0F; 134 | float f2 = (float) (color & 255) / 255.0F; 135 | Tessellator tessellator = Tessellator.getInstance(); 136 | WorldRenderer worldrenderer = tessellator.getWorldRenderer(); 137 | GlStateManager.enableBlend(); 138 | GlStateManager.disableTexture2D(); 139 | GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); 140 | GlStateManager.color(f, f1, f2, f3); 141 | worldrenderer.begin(mode, DefaultVertexFormats.POSITION); 142 | worldrenderer.pos(left, bottom, 0.0D).endVertex(); 143 | worldrenderer.pos(right, bottom, 0.0D).endVertex(); 144 | worldrenderer.pos(right, top, 0.0D).endVertex(); 145 | worldrenderer.pos(left, top, 0.0D).endVertex(); 146 | tessellator.draw(); 147 | GlStateManager.enableTexture2D(); 148 | GlStateManager.disableBlend(); 149 | } 150 | 151 | 152 | } 153 | --------------------------------------------------------------------------------