Skip to content

Commit

Permalink
A gift for the friendly people at FTB
Browse files Browse the repository at this point in the history
  • Loading branch information
CovertJaguar committed Mar 23, 2019
1 parent 6414155 commit b765959
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*------------------------------------------------------------------------------
Copyright (c) CovertJaguar, 2011-2019
http://railcraft.info
This code is the property of CovertJaguar
and may only be used with explicit written
permission unless otherwise specified on the
license page at http://railcraft.info/wiki/info:license.
-----------------------------------------------------------------------------*/

package mods.railcraft.common.core;

import mods.railcraft.common.plugins.forge.ChatPlugin;
import mods.railcraft.common.util.misc.Game;
import mods.railcraft.common.util.misc.MiscTools;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;

/**
* Created by CovertJaguar on 3/22/2019 for Railcraft.
*
* @author CovertJaguar <http://www.railcraft.info>
*/
public enum BetaMessageTickHandler {
INSTANCE;
private static final String[] lines = {
"You are using a development version of Railcraft.",
"There is no guarantee that your server or worlds are safe.",
"There is no guarantee that game breaking bugs will be fixed prior to the next stable build.",
"There is no guarantee when the next build will be available.",
"There is no guarantee that the next build will be on CurseForge.",
"You use this at your own risk, as is. Bugs and all.",
"This build should not be used in modpacks.",
"You can thank the friendly people at FTB for making this message necessary.",
"Have a nice day and enjoy the mod!",
"- CovertJaguar"

This comment has been minimized.

Copy link
@liach

liach Mar 23, 2019

Contributor

Ahhh! Translations! 😡

This comment has been minimized.

Copy link
@CovertJaguar

CovertJaguar Mar 23, 2019

Author Member

I was lazy yes 😋

};
private static final int DELAY = 2;
private static final int INTERVAL = 64;
private static final float CHANCE = 0.25F;
private int lineCounter;
private int startCounter;

@SubscribeEvent
public void login(PlayerEvent.PlayerLoggedInEvent event) {
lineCounter = 0;
startCounter = 0;
}

@SubscribeEvent
public void tick(LivingEvent.LivingUpdateEvent event) {
if (Game.DEVELOPMENT_VERSION
&& lineCounter < lines.length
&& event.getEntity().world.getWorldTime() % INTERVAL == 0
&& Game.isClient(event.getEntity().world)
&& event.getEntity() instanceof EntityPlayer) {
startCounter++;
if (startCounter > DELAY && (lineCounter > 0 || MiscTools.RANDOM.nextFloat() < CHANCE)) {
sendMessage((EntityPlayer) event.getEntity(), lines[lineCounter]);
lineCounter++;
}
}
}

private void sendMessage(EntityPlayer player, String msg) {
player.sendMessage(ChatPlugin.makeMessage(msg).setStyle(new Style().setColor(TextFormatting.RED)));
}
}
1 change: 1 addition & 0 deletions src/main/java/mods/railcraft/common/core/Railcraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public void init(FMLInitializationEvent event) {
HostEffects.init();

MinecraftForge.EVENT_BUS.register(new BlinkTick());
MinecraftForge.EVENT_BUS.register(BetaMessageTickHandler.INSTANCE);
}

@Mod.EventHandler
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mods/railcraft/common/util/misc/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public final class Game {
static {
Object obj = Launch.blackboard.get("fml.deobfuscatedEnvironment");
OBFUSCATED = !(obj instanceof Boolean && ((Boolean) obj));
DEVELOPMENT_VERSION = Railcraft.getVersion().matches(".*(alpha|beta).*") || !OBFUSCATED;
DEVELOPMENT_VERSION = Railcraft.getVersion().matches(".*(alpha|beta|rc).*") || !OBFUSCATED;
boolean foundBukkit = false;
try {
foundBukkit = Class.forName("org.spigotmc.SpigotConfig") != null;
Expand Down

1 comment on commit b765959

@Dockter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love stuff like this.

Please sign in to comment.