TOASTED. R O A S T E D.

This commit is contained in:
FalsePattern committed 2022-07-30 23:26:25 +02:00
1 parent 6e954f3129
commit d41a460589
27 files changed
+787 -23

No files matched your search

@@ -23,6 +23,7 @@ package com.falsepattern.lib.internal;
import com.falsepattern.lib.internal.proxy.CommonProxy;
import cpw.mods.fml.common.*;
import cpw.mods.fml.common.event.FMLConstructionEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
@@ -41,7 +42,7 @@ import org.apache.logging.log4j.Logger;
name = Tags.MODNAME,
version = Tags.VERSION,
acceptedMinecraftVersions = "[1.7.10]",
guiFactory = Tags.GROUPNAME + ".internal.LibraryGuiFactory",
guiFactory = Tags.GROUPNAME + ".internal.config.LibraryGuiFactory",
acceptableRemoteVersions = "*")
public class FalsePatternLib {
public static final String UPDATE_URL = "https://falsepattern.com/mc/versions.json";
@@ -58,6 +59,11 @@ public class FalsePatternLib {
log.info("Version " + Tags.VERSION + " initialized!");
}
@Mod.EventHandler
public void construct(FMLConstructionEvent e) {
proxy.construct(e);
}
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent e) {
proxy.preInit(e);
@@ -18,21 +18,24 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.internal;
package com.falsepattern.lib.internal.config;
import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.internal.Tags;
@Config(modid = Tags.MODID)
public class LibraryConfig {
@Config.Comment({"Used to control whether FalsePatternLib should check for outdated mods.",
"If you're building a public modpack, you should turn this off so that your users don't " +
"get nagged about outdated mods."})
"If you're building a public modpack, you should turn this off so that your users don't " +
"get nagged about outdated mods."})
@Config.LangKey("config.falsepatternlib.updatecheck")
public static boolean ENABLE_UPDATE_CHECKER = true;
@Config.DefaultBoolean(true)
public static boolean ENABLE_UPDATE_CHECKER;
@Config.Comment({"Used to control whether FalsePatternLib should be allowed to use the internet.",
"If this is disabled, library downloads will be blocked.",
"Note that if a mod tries to download a library that is not downloaded yet, the game will crash."})
"If this is disabled, library downloads will be blocked.",
"Note that if a mod tries to download a library that is not downloaded yet, the game will crash."})
@Config.LangKey("config.falsepatternlib.disableinternet")
public static boolean ENABLE_LIBRARY_DOWNLOADS = true;
@Config.DefaultBoolean(true)
public static boolean ENABLE_LIBRARY_DOWNLOADS;
}
@@ -18,10 +18,12 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.internal;
package com.falsepattern.lib.internal.config;
import com.falsepattern.lib.config.ConfigException;
import com.falsepattern.lib.config.SimpleGuiConfig;
import com.falsepattern.lib.internal.Tags;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.GuiScreen;
@@ -29,6 +31,6 @@ import net.minecraft.client.gui.GuiScreen;
@SideOnly(Side.CLIENT)
public class LibraryGuiConfig extends SimpleGuiConfig {
public LibraryGuiConfig(GuiScreen parent) throws ConfigException {
super(parent, LibraryConfig.class, Tags.MODID, Tags.MODNAME);
super(parent, new Class[]{LibraryConfig.class, ToastConfig.class}, Tags.MODID, Tags.MODNAME);
}
}
@@ -18,7 +18,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.internal;
package com.falsepattern.lib.internal.config;
import com.falsepattern.lib.config.SimpleGuiFactory;
import cpw.mods.fml.relauncher.Side;
@@ -0,0 +1,55 @@
/**
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
* The above copyright notice, this permission notice and the word "SNEED"
* shall be included in all copies or substantial portions of the Software.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.internal.config;
import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.internal.Tags;
@Config(modid = Tags.MODID,
category = "toasts")
public class ToastConfig {
@Config.Comment("The maximum amount of toasts to show on the screen")
@Config.LangKey("config.falsepatternlib.maxtoasts")
@Config.DefaultInt(5)
@Config.RangeInt(min = 1,
max = 10)
public static int MAX_VISIBLE;
@Config.Comment("The amount of empty space from the top of the screen in pixels")
@Config.LangKey("config.falsepatternlib.toastoffset")
@Config.DefaultInt(0)
@Config.RangeInt(min = 0,
max = 10000)
public static int Y_OFFSET;
@Config.Comment("Which side of the screen should toasts show up on")
@Config.LangKey("config.falsepatternlib.toastalign")
@Config.DefaultEnum("Right")
public static Side ALIGN;
public static boolean leftAlign() {
return ALIGN == Side.Left;
}
public enum Side {
Left, Right
}
}
@@ -24,7 +24,7 @@ import com.falsepattern.lib.dependencies.DependencyLoader;
import com.falsepattern.lib.dependencies.Version;
import com.falsepattern.lib.internal.FalsePatternLib;
import com.falsepattern.lib.internal.Internet;
import com.falsepattern.lib.internal.LibraryConfig;
import com.falsepattern.lib.internal.config.LibraryConfig;
import com.falsepattern.lib.internal.Tags;
import com.falsepattern.lib.util.FileUtil;
import lombok.NonNull;
@@ -0,0 +1,186 @@
/**
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
* <p>
* The above copyright notice, this permission notice and the word "SNEED"
* shall be included in all copies or substantial portions of the Software.
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.internal.impl.toast;
import com.falsepattern.lib.internal.config.LibraryConfig;
import com.falsepattern.lib.internal.config.ToastConfig;
import com.falsepattern.lib.toasts.IToast;
import com.falsepattern.lib.util.MathUtil;
import com.google.common.collect.Queues;
import lombok.val;
import lombok.var;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.RenderHelper;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Deque;
@SideOnly(Side.CLIENT)
public class GuiToastImpl extends Gui {
private final Minecraft mc;
private final Deque<IToast> toastsQueue = Queues.newArrayDeque();
private ToastInstance<?>[] visible = new ToastInstance[0];
private static GuiToastImpl instance;
public static void initialize(Minecraft mc) {
if (instance != null) {
return;
}
instance = new GuiToastImpl(mc);
FMLCommonHandler.instance().bus().register(instance);
}
public static GuiToastImpl getInstance() {
return instance;
}
@SubscribeEvent
public void updateToasts(TickEvent.RenderTickEvent event) {
if ( event.phase != TickEvent.Phase.END) {
return;
}
mc.mcProfiler.startSection("toasts");
drawToast(new ScaledResolution(mc, mc.displayWidth, mc.displayHeight));
mc.mcProfiler.endSection();
}
public GuiToastImpl(Minecraft mcIn) {
this.mc = mcIn;
}
public void drawToast(ScaledResolution resolution) {
if (!this.mc.gameSettings.hideGUI) {
RenderHelper.disableStandardItemLighting();
if (ToastConfig.MAX_VISIBLE != visible.length) {
visible = Arrays.copyOf(visible, ToastConfig.MAX_VISIBLE);
}
for (int i = 0; i < this.visible.length; ++i) {
val toast = this.visible[i];
if (toast != null && toast.render(ToastConfig.leftAlign() ? 0 : resolution.getScaledWidth(), i)) {
this.visible[i] = null;
}
if (this.visible[i] == null && !this.toastsQueue.isEmpty()) {
this.visible[i] = new ToastInstance<>(this.toastsQueue.removeFirst());
}
}
}
}
@Nullable
public <T extends IToast> T getToast(Class<? extends T> toastClass, Object type) {
for (val toast : this.visible) {
if (toast != null && toastClass.isAssignableFrom(toast.getToast().getClass()) &&
toast.getToast().getType().equals(type)) {
return toastClass.cast(toast);
}
}
for (val toast : this.toastsQueue) {
if (toastClass.isAssignableFrom(toast.getClass()) && toast.getType().equals(type)) {
return toastClass.cast(toast);
}
}
return null;
}
public void clear() {
Arrays.fill(this.visible, null);
this.toastsQueue.clear();
}
public void add(IToast toastIn) {
this.toastsQueue.add(toastIn);
}
public Minecraft getMinecraft() {
return this.mc;
}
@SideOnly(Side.CLIENT)
class ToastInstance<T extends IToast> {
private final T toast;
private long animationTime;
private long visibleTime;
private IToast.Visibility visibility;
private ToastInstance(T toastIn) {
this.animationTime = -1L;
this.visibleTime = -1L;
this.visibility = IToast.Visibility.SHOW;
this.toast = toastIn;
}
public T getToast() {
return this.toast;
}
private float getVisibility(long currentTime) {
var visibility = MathUtil.clamp((float) (currentTime - this.animationTime) / 600.0F, 0.0F, 1.0F);
visibility = visibility * visibility;
return this.visibility == IToast.Visibility.HIDE ? 1.0F - visibility : visibility;
}
public boolean render(int x, int y) {
val sysTime = Minecraft.getSystemTime();
if (this.animationTime == -1L) {
this.animationTime = sysTime;
this.visibility.playSound(GuiToastImpl.this.mc.getSoundHandler());
}
if (this.visibility == IToast.Visibility.SHOW && sysTime - this.animationTime <= 600L) {
this.visibleTime = sysTime;
}
GL11.glPushMatrix();
val shift = toast.width() * getVisibility(sysTime);
val X = ToastConfig.leftAlign() ? shift - toast.width() : x - shift;
GL11.glTranslatef(X,
(float) (y * 32) + ToastConfig.Y_OFFSET,
(float) (500 + y));
val visibility = this.toast.draw(GuiToastImpl.this, sysTime - this.visibleTime);
GL11.glPopMatrix();
if (visibility != this.visibility) {
this.animationTime = sysTime - (long) ((int) ((1.0F - this.getVisibility(sysTime)) * 600.0F));
this.visibility = visibility;
this.visibility.playSound(GuiToastImpl.this.mc.getSoundHandler());
}
return this.visibility == IToast.Visibility.HIDE && sysTime - this.animationTime > 600L;
}
}
}
@@ -22,18 +22,21 @@ package com.falsepattern.lib.internal.proxy;
import com.falsepattern.lib.internal.FalsePatternLib;
import com.falsepattern.lib.internal.Tags;
import com.falsepattern.lib.internal.impl.toast.GuiToastImpl;
import com.falsepattern.lib.updates.UpdateChecker;
import cpw.mods.fml.client.IModGuiFactory;
import lombok.val;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import cpw.mods.fml.common.event.FMLConstructionEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import lombok.val;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import java.util.Collections;
import java.util.List;
@@ -43,6 +46,12 @@ import java.util.concurrent.CompletableFuture;
public class ClientProxy extends CommonProxy {
private CompletableFuture<List<IChatComponent>> chatFuture;
@Override
public void construct(FMLConstructionEvent e) {
super.construct(e);
GuiToastImpl.initialize(Minecraft.getMinecraft());
}
@Override
public void preInit(FMLPreInitializationEvent e) {
super.preInit(e);
@@ -23,10 +23,13 @@ package com.falsepattern.lib.internal.proxy;
import com.falsepattern.lib.config.ConfigException;
import com.falsepattern.lib.config.ConfigurationManager;
import com.falsepattern.lib.internal.FalsePatternLib;
import com.falsepattern.lib.internal.LibraryConfig;
import com.falsepattern.lib.internal.config.LibraryConfig;
import com.falsepattern.lib.internal.config.ToastConfig;
import com.falsepattern.lib.internal.impl.config.ConfigurationManagerImpl;
import com.falsepattern.lib.updates.ModUpdateInfo;
import com.falsepattern.lib.updates.UpdateChecker;
import cpw.mods.fml.common.event.FMLConstructionEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import lombok.val;
@@ -39,10 +42,14 @@ public class CommonProxy {
protected CompletableFuture<List<ModUpdateInfo>> updatesFuture;
public void construct(FMLConstructionEvent e) {
}
public void preInit(FMLPreInitializationEvent e) {
ConfigurationManagerImpl.registerBus();
try {
ConfigurationManager.registerConfig(LibraryConfig.class);
ConfigurationManager.registerConfig(ToastConfig.class);
} catch (ConfigException ex) {
FalsePatternLib.getLog().error("Failed to register config!", ex);
}