Skip to content

Commit d41a460

Browse files
committed
TOASTED. R O A S T E D.
1 parent 6e954f3 commit d41a460

27 files changed

+787
-23
lines changed

src/main/java/com/falsepattern/lib/internal/FalsePatternLib.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.falsepattern.lib.internal.proxy.CommonProxy;
2424

2525
import cpw.mods.fml.common.*;
26+
import cpw.mods.fml.common.event.FMLConstructionEvent;
2627
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
2728
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
2829

@@ -41,7 +42,7 @@
4142
name = Tags.MODNAME,
4243
version = Tags.VERSION,
4344
acceptedMinecraftVersions = "[1.7.10]",
44-
guiFactory = Tags.GROUPNAME + ".internal.LibraryGuiFactory",
45+
guiFactory = Tags.GROUPNAME + ".internal.config.LibraryGuiFactory",
4546
acceptableRemoteVersions = "*")
4647
public class FalsePatternLib {
4748
public static final String UPDATE_URL = "https://falsepattern.com/mc/versions.json";
@@ -58,6 +59,11 @@ public FalsePatternLib() {
5859
log.info("Version " + Tags.VERSION + " initialized!");
5960
}
6061

62+
@Mod.EventHandler
63+
public void construct(FMLConstructionEvent e) {
64+
proxy.construct(e);
65+
}
66+
6167
@Mod.EventHandler
6268
public void preInit(FMLPreInitializationEvent e) {
6369
proxy.preInit(e);

src/main/java/com/falsepattern/lib/internal/LibraryConfig.java renamed to src/main/java/com/falsepattern/lib/internal/config/LibraryConfig.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,24 @@
1818
* You should have received a copy of the GNU Lesser General Public License
1919
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2020
*/
21-
package com.falsepattern.lib.internal;
21+
package com.falsepattern.lib.internal.config;
2222

2323
import com.falsepattern.lib.config.Config;
24+
import com.falsepattern.lib.internal.Tags;
2425

2526
@Config(modid = Tags.MODID)
2627
public class LibraryConfig {
2728
@Config.Comment({"Used to control whether FalsePatternLib should check for outdated mods.",
28-
"If you're building a public modpack, you should turn this off so that your users don't " +
29-
"get nagged about outdated mods."})
29+
"If you're building a public modpack, you should turn this off so that your users don't " +
30+
"get nagged about outdated mods."})
3031
@Config.LangKey("config.falsepatternlib.updatecheck")
31-
public static boolean ENABLE_UPDATE_CHECKER = true;
32+
@Config.DefaultBoolean(true)
33+
public static boolean ENABLE_UPDATE_CHECKER;
3234

3335
@Config.Comment({"Used to control whether FalsePatternLib should be allowed to use the internet.",
34-
"If this is disabled, library downloads will be blocked.",
35-
"Note that if a mod tries to download a library that is not downloaded yet, the game will crash."})
36+
"If this is disabled, library downloads will be blocked.",
37+
"Note that if a mod tries to download a library that is not downloaded yet, the game will crash."})
3638
@Config.LangKey("config.falsepatternlib.disableinternet")
37-
public static boolean ENABLE_LIBRARY_DOWNLOADS = true;
39+
@Config.DefaultBoolean(true)
40+
public static boolean ENABLE_LIBRARY_DOWNLOADS;
3841
}

src/main/java/com/falsepattern/lib/internal/LibraryGuiConfig.java renamed to src/main/java/com/falsepattern/lib/internal/config/LibraryGuiConfig.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@
1818
* You should have received a copy of the GNU Lesser General Public License
1919
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2020
*/
21-
package com.falsepattern.lib.internal;
21+
package com.falsepattern.lib.internal.config;
2222

2323
import com.falsepattern.lib.config.ConfigException;
2424
import com.falsepattern.lib.config.SimpleGuiConfig;
25+
import com.falsepattern.lib.internal.Tags;
26+
2527
import cpw.mods.fml.relauncher.Side;
2628
import cpw.mods.fml.relauncher.SideOnly;
2729
import net.minecraft.client.gui.GuiScreen;
2830

2931
@SideOnly(Side.CLIENT)
3032
public class LibraryGuiConfig extends SimpleGuiConfig {
3133
public LibraryGuiConfig(GuiScreen parent) throws ConfigException {
32-
super(parent, LibraryConfig.class, Tags.MODID, Tags.MODNAME);
34+
super(parent, new Class[]{LibraryConfig.class, ToastConfig.class}, Tags.MODID, Tags.MODNAME);
3335
}
3436
}

src/main/java/com/falsepattern/lib/internal/LibraryGuiFactory.java renamed to src/main/java/com/falsepattern/lib/internal/config/LibraryGuiFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* You should have received a copy of the GNU Lesser General Public License
1919
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2020
*/
21-
package com.falsepattern.lib.internal;
21+
package com.falsepattern.lib.internal.config;
2222

2323
import com.falsepattern.lib.config.SimpleGuiFactory;
2424
import cpw.mods.fml.relauncher.Side;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright (C) 2022 FalsePattern
3+
* All Rights Reserved
4+
*
5+
* The above copyright notice, this permission notice and the word "SNEED"
6+
* shall be included in all copies or substantial portions of the Software.
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
package com.falsepattern.lib.internal.config;
22+
23+
import com.falsepattern.lib.config.Config;
24+
import com.falsepattern.lib.internal.Tags;
25+
26+
@Config(modid = Tags.MODID,
27+
category = "toasts")
28+
public class ToastConfig {
29+
@Config.Comment("The maximum amount of toasts to show on the screen")
30+
@Config.LangKey("config.falsepatternlib.maxtoasts")
31+
@Config.DefaultInt(5)
32+
@Config.RangeInt(min = 1,
33+
max = 10)
34+
public static int MAX_VISIBLE;
35+
36+
@Config.Comment("The amount of empty space from the top of the screen in pixels")
37+
@Config.LangKey("config.falsepatternlib.toastoffset")
38+
@Config.DefaultInt(0)
39+
@Config.RangeInt(min = 0,
40+
max = 10000)
41+
public static int Y_OFFSET;
42+
43+
@Config.Comment("Which side of the screen should toasts show up on")
44+
@Config.LangKey("config.falsepatternlib.toastalign")
45+
@Config.DefaultEnum("Right")
46+
public static Side ALIGN;
47+
48+
public static boolean leftAlign() {
49+
return ALIGN == Side.Left;
50+
}
51+
52+
public enum Side {
53+
Left, Right
54+
}
55+
}

src/main/java/com/falsepattern/lib/internal/impl/dependencies/DependencyLoaderImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.falsepattern.lib.dependencies.Version;
2525
import com.falsepattern.lib.internal.FalsePatternLib;
2626
import com.falsepattern.lib.internal.Internet;
27-
import com.falsepattern.lib.internal.LibraryConfig;
27+
import com.falsepattern.lib.internal.config.LibraryConfig;
2828
import com.falsepattern.lib.internal.Tags;
2929
import com.falsepattern.lib.util.FileUtil;
3030
import lombok.NonNull;
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/**
2+
* Copyright (C) 2022 FalsePattern
3+
* All Rights Reserved
4+
* <p>
5+
* The above copyright notice, this permission notice and the word "SNEED"
6+
* shall be included in all copies or substantial portions of the Software.
7+
* <p>
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
* <p>
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
* <p>
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
package com.falsepattern.lib.internal.impl.toast;
22+
23+
import com.falsepattern.lib.internal.config.LibraryConfig;
24+
import com.falsepattern.lib.internal.config.ToastConfig;
25+
import com.falsepattern.lib.toasts.IToast;
26+
import com.falsepattern.lib.util.MathUtil;
27+
import com.google.common.collect.Queues;
28+
import lombok.val;
29+
import lombok.var;
30+
import org.lwjgl.opengl.GL11;
31+
32+
import net.minecraft.client.Minecraft;
33+
import net.minecraft.client.gui.Gui;
34+
import net.minecraft.client.gui.ScaledResolution;
35+
import net.minecraft.client.renderer.RenderHelper;
36+
import cpw.mods.fml.common.FMLCommonHandler;
37+
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
38+
import cpw.mods.fml.common.gameevent.TickEvent;
39+
import cpw.mods.fml.relauncher.Side;
40+
import cpw.mods.fml.relauncher.SideOnly;
41+
42+
import javax.annotation.Nullable;
43+
import java.util.Arrays;
44+
import java.util.Deque;
45+
46+
@SideOnly(Side.CLIENT)
47+
public class GuiToastImpl extends Gui {
48+
private final Minecraft mc;
49+
private final Deque<IToast> toastsQueue = Queues.newArrayDeque();
50+
private ToastInstance<?>[] visible = new ToastInstance[0];
51+
private static GuiToastImpl instance;
52+
53+
public static void initialize(Minecraft mc) {
54+
if (instance != null) {
55+
return;
56+
}
57+
instance = new GuiToastImpl(mc);
58+
FMLCommonHandler.instance().bus().register(instance);
59+
}
60+
61+
public static GuiToastImpl getInstance() {
62+
return instance;
63+
}
64+
65+
@SubscribeEvent
66+
public void updateToasts(TickEvent.RenderTickEvent event) {
67+
if ( event.phase != TickEvent.Phase.END) {
68+
return;
69+
}
70+
mc.mcProfiler.startSection("toasts");
71+
drawToast(new ScaledResolution(mc, mc.displayWidth, mc.displayHeight));
72+
mc.mcProfiler.endSection();
73+
}
74+
75+
76+
public GuiToastImpl(Minecraft mcIn) {
77+
this.mc = mcIn;
78+
}
79+
80+
public void drawToast(ScaledResolution resolution) {
81+
if (!this.mc.gameSettings.hideGUI) {
82+
RenderHelper.disableStandardItemLighting();
83+
if (ToastConfig.MAX_VISIBLE != visible.length) {
84+
visible = Arrays.copyOf(visible, ToastConfig.MAX_VISIBLE);
85+
}
86+
87+
for (int i = 0; i < this.visible.length; ++i) {
88+
val toast = this.visible[i];
89+
90+
if (toast != null && toast.render(ToastConfig.leftAlign() ? 0 : resolution.getScaledWidth(), i)) {
91+
this.visible[i] = null;
92+
}
93+
94+
if (this.visible[i] == null && !this.toastsQueue.isEmpty()) {
95+
this.visible[i] = new ToastInstance<>(this.toastsQueue.removeFirst());
96+
}
97+
}
98+
}
99+
}
100+
101+
@Nullable
102+
public <T extends IToast> T getToast(Class<? extends T> toastClass, Object type) {
103+
for (val toast : this.visible) {
104+
if (toast != null && toastClass.isAssignableFrom(toast.getToast().getClass()) &&
105+
toast.getToast().getType().equals(type)) {
106+
return toastClass.cast(toast);
107+
}
108+
}
109+
110+
for (val toast : this.toastsQueue) {
111+
if (toastClass.isAssignableFrom(toast.getClass()) && toast.getType().equals(type)) {
112+
return toastClass.cast(toast);
113+
}
114+
}
115+
116+
return null;
117+
}
118+
119+
public void clear() {
120+
Arrays.fill(this.visible, null);
121+
this.toastsQueue.clear();
122+
}
123+
124+
public void add(IToast toastIn) {
125+
this.toastsQueue.add(toastIn);
126+
}
127+
128+
public Minecraft getMinecraft() {
129+
return this.mc;
130+
}
131+
132+
@SideOnly(Side.CLIENT)
133+
class ToastInstance<T extends IToast> {
134+
private final T toast;
135+
private long animationTime;
136+
private long visibleTime;
137+
private IToast.Visibility visibility;
138+
139+
private ToastInstance(T toastIn) {
140+
this.animationTime = -1L;
141+
this.visibleTime = -1L;
142+
this.visibility = IToast.Visibility.SHOW;
143+
this.toast = toastIn;
144+
}
145+
146+
public T getToast() {
147+
return this.toast;
148+
}
149+
150+
private float getVisibility(long currentTime) {
151+
var visibility = MathUtil.clamp((float) (currentTime - this.animationTime) / 600.0F, 0.0F, 1.0F);
152+
visibility = visibility * visibility;
153+
return this.visibility == IToast.Visibility.HIDE ? 1.0F - visibility : visibility;
154+
}
155+
156+
public boolean render(int x, int y) {
157+
val sysTime = Minecraft.getSystemTime();
158+
159+
if (this.animationTime == -1L) {
160+
this.animationTime = sysTime;
161+
this.visibility.playSound(GuiToastImpl.this.mc.getSoundHandler());
162+
}
163+
164+
if (this.visibility == IToast.Visibility.SHOW && sysTime - this.animationTime <= 600L) {
165+
this.visibleTime = sysTime;
166+
}
167+
168+
GL11.glPushMatrix();
169+
val shift = toast.width() * getVisibility(sysTime);
170+
val X = ToastConfig.leftAlign() ? shift - toast.width() : x - shift;
171+
GL11.glTranslatef(X,
172+
(float) (y * 32) + ToastConfig.Y_OFFSET,
173+
(float) (500 + y));
174+
val visibility = this.toast.draw(GuiToastImpl.this, sysTime - this.visibleTime);
175+
GL11.glPopMatrix();
176+
177+
if (visibility != this.visibility) {
178+
this.animationTime = sysTime - (long) ((int) ((1.0F - this.getVisibility(sysTime)) * 600.0F));
179+
this.visibility = visibility;
180+
this.visibility.playSound(GuiToastImpl.this.mc.getSoundHandler());
181+
}
182+
183+
return this.visibility == IToast.Visibility.HIDE && sysTime - this.animationTime > 600L;
184+
}
185+
}
186+
}

src/main/java/com/falsepattern/lib/internal/proxy/ClientProxy.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,21 @@
2222

2323
import com.falsepattern.lib.internal.FalsePatternLib;
2424
import com.falsepattern.lib.internal.Tags;
25+
import com.falsepattern.lib.internal.impl.toast.GuiToastImpl;
2526
import com.falsepattern.lib.updates.UpdateChecker;
26-
import cpw.mods.fml.client.IModGuiFactory;
27-
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
28-
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
29-
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
30-
import cpw.mods.fml.relauncher.Side;
31-
import cpw.mods.fml.relauncher.SideOnly;
3227
import lombok.val;
28+
29+
import net.minecraft.client.Minecraft;
3330
import net.minecraft.client.entity.EntityPlayerSP;
3431
import net.minecraft.util.IChatComponent;
3532
import net.minecraftforge.common.MinecraftForge;
3633
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
34+
import cpw.mods.fml.common.event.FMLConstructionEvent;
35+
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
36+
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
37+
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
38+
import cpw.mods.fml.relauncher.Side;
39+
import cpw.mods.fml.relauncher.SideOnly;
3740

3841
import java.util.Collections;
3942
import java.util.List;
@@ -43,6 +46,12 @@
4346
public class ClientProxy extends CommonProxy {
4447
private CompletableFuture<List<IChatComponent>> chatFuture;
4548

49+
@Override
50+
public void construct(FMLConstructionEvent e) {
51+
super.construct(e);
52+
GuiToastImpl.initialize(Minecraft.getMinecraft());
53+
}
54+
4655
@Override
4756
public void preInit(FMLPreInitializationEvent e) {
4857
super.preInit(e);

0 commit comments

Comments
 (0)