Skip to content

Commit

Permalink
- Removed: Always enabled debug messages
Browse files Browse the repository at this point in the history
- Added: Config option for enabling debug messages.
- Added: Mod now able to tell when on server, will automatically enable alwaysOn mode for the duration.

A bunch of misc improvements to the core code.
  • Loading branch information
Forecaster committed Oct 5, 2014
1 parent ab6fd66 commit 76da8c4
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/build/
/.gradle/
/eclipse/
/testClient/

*.iws
*.iml
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ buildscript {

apply plugin: 'forge'

version = "1.7.10-1.1"
version = "1.7.10-1.1.1"
group= "com.forecaster.runup" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "runUp"

minecraft {
version = "1.7.10-10.13.1.1217"
runDir = "eclipse"
runDir = "testClient"
}

dependencies {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/forecaster/runup/ConfigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ public class ConfigHandler
static boolean enabled = true;
static int checkInterval = 2;
static boolean alwaysOn = false;
static boolean tempAlwaysOn = false;
static boolean rotationMatters = true;
static boolean blacklist = false;
static String[] blocklist = new String[] {};
static boolean debug = false;

public static void init(File configFile)
{
Expand All @@ -29,6 +31,7 @@ public static void init(File configFile)
rotationMatters = configuration.get(Configuration.CATEGORY_GENERAL, "rotationMatters", true, "Enables also checking the block in front of you, allowing for improved control. Default: true").getBoolean();
blacklist = configuration.get(Configuration.CATEGORY_GENERAL, "blacklist", false, "Turn the whitelist below into a blacklist. Default: false").getBoolean();
blocklist = configuration.get(Configuration.CATEGORY_GENERAL, "blocklist", new String[]{"minecraft:stone", "minecraft:grass", "minecraft:sand", "minecraft:gravel", "minecraft:snow_layer", "minecraft:ice", "minecraft:snow", "minecraft:netherrack", "minecraft:soul_sand", "minecraft:mycelium", "minecraft:end_stone"}, "The blocks that will cause your step height to be set by default, or which will not if blacklist is true. Default: minecraft:stone, minecraft:grass, minecraft:sand, minecraft:gravel, minecraft:snow_layer, minecraft:ice, minecraft:snow, minecraft:netherrack, minecraft:soul_sand, minecraft:mycelium, minecraft:end_stone").getStringList();
debug = configuration.get("Debug", "debug", false, "Enable debug output").getBoolean();
}
catch (Exception e)
{
Expand All @@ -39,6 +42,6 @@ public static void init(File configFile)
configuration.save();
}

RunUp.modLogOut(Level.INFO, "Config loaded!");
Util.modLogOut(Level.INFO, "Config loaded!");
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/forecaster/runup/ConnectionHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.forecaster.runup;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;

/**
* Created by Forecaster on 2014-10-05 for runUp.
*/
public class ConnectionHandler
{
}
21 changes: 21 additions & 0 deletions src/main/java/com/forecaster/runup/ConstructingHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.forecaster.runup;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.entity.EntityEvent;

@SideOnly(Side.CLIENT)
public class ConstructingHandler
{
@SubscribeEvent
public void onEntityConstructing(EntityEvent.EntityConstructing event)
{
if (event.entity instanceof EntityPlayer)
{
TickHandler.worldIsRemoteTicks = 0;
ConfigHandler.tempAlwaysOn = false;
}
}
}
31 changes: 25 additions & 6 deletions src/main/java/com/forecaster/runup/RunUp.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.forecaster.runup;

import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLEvent;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import cpw.mods.fml.server.FMLServerHandler;
import net.minecraftforge.common.MinecraftForge;
import org.apache.logging.log4j.Level;

@Mod(modid = References.MODID, name = References.MODNAME, version = References.VERSION)
Expand All @@ -19,22 +26,34 @@ public class RunUp
public void preInit(FMLPreInitializationEvent event)
{
ConfigHandler.init(event.getSuggestedConfigurationFile());
if (ConfigHandler.debug)
Util.modLogOut(Level.INFO, "Debug mode enabled");
if (ConfigHandler.enabled && ConfigHandler.debug)
Util.modLogOut(Level.INFO, "Mod is enabled!");
else
Util.modLogOut(Level.INFO, "Mod is disabled!");
if (ConfigHandler.alwaysOn && ConfigHandler.debug)
Util.modLogOut(Level.INFO, "AlwaysOn mode is enabled! Whitelist/blacklist will be ignored. StepHeight will be maintained at 1.");
if (ConfigHandler.blacklist && ConfigHandler.debug)
Util.modLogOut(Level.INFO, "Blacklist mode enabled!");
if (ConfigHandler.rotationMatters && ConfigHandler.debug)
//TODO Change this message once rotation mode has been implemented
Util.modLogOut(Level.INFO, "RotationMatters mode is enabled! However this has no effect at the moment!");
}

@Mod.EventHandler
@SideOnly(Side.CLIENT)
public void init(FMLInitializationEvent event)
{
FMLCommonHandler.instance().bus().register(new TickHandler());
MinecraftForge.EVENT_BUS.register(new ConstructingHandler());
//SimpleNetworkWrapper channel = NetworkRegistry.INSTANCE.newSimpleChannel("ConnectionHandler");
//channel.
}

@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event)
{

}

public static void modLogOut(Level level, String message)
{
FMLLog.log(level, "[" + References.MODNAME + "] " + message);
}
}
133 changes: 93 additions & 40 deletions src/main/java/com/forecaster/runup/TickHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,87 +8,139 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;

@SideOnly(Side.CLIENT)
public class TickHandler
{
int clock = 0;
Float targetHeight = 0.5F;
boolean enabledWarningSent = false;
boolean worldIsRemoteWarningSent = false;
static int worldIsRemoteTicks = 0;
String state;

@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent event)
{
Boolean blockMatch;
EntityPlayer player = event.player;

if (ConfigHandler.alwaysOn)

if (ConfigHandler.alwaysOn || ConfigHandler.tempAlwaysOn) //AlwaysOn mode
{
if (ConfigHandler.enabled)
{
if (player.stepHeight != 1F)
{
setStepHeight(player, 1F);
System.out.println("Set stepheight to 1");
if (ConfigHandler.debug)
System.out.println("Set stepheight to 1");
}
}
System.out.println(player.stepHeight);
else if (!enabledWarningSent)
{
Util.sendChatMessage(player, "The mod is disabled! It will do nothing until enabled in the config.");
enabledWarningSent = true;
}
}
else
else //Normal mode
{
if (ConfigHandler.enabled)
if (clock % ConfigHandler.checkInterval == 0)
{
if (clock % ConfigHandler.checkInterval == 0)
if (ConfigHandler.enabled)
{
World world = player.getEntityWorld();

int x = (int) Math.floor(player.posX);
int y = (int) Math.floor(player.posY);
int z = (int) Math.floor(player.posZ);

Block block = world.getBlock(x, y - 1, z);
if (world.isRemote)
state = "Remote";
else
state = "Local";

if (block != null && block != Block.getBlockFromName("minecraft:air"))
if (world.isRemote)
{
//int id = Block.getIdFromBlock(block);

//Block testBlock = Block.getBlockFromName("minecraft:stone");

String[] blockList = ConfigHandler.blocklist;
blockMatch = false;
int i = 0;

System.out.println("Block test started!");
while (!blockMatch && i < blockList.length)
if (worldIsRemoteTicks > 10)
{
Block testBlock = Block.getBlockFromName(blockList[i]);

if (block == testBlock)
if (!worldIsRemoteWarningSent)
{
blockMatch = true;
Util.sendChatMessage(player, "The world is remote. This means you are likely playing on a server, which means I can't get the block you are standing on from the server at the moment. Sorry! Because of this I've enabled \"AlwaysOn\" mode for this session for you! This functionality will come soon!");
ConfigHandler.tempAlwaysOn = true;
worldIsRemoteWarningSent = true;
}

i++;
}
else if (worldIsRemoteTicks != -1)
worldIsRemoteTicks++;
}

if (!ConfigHandler.blacklist)
if (!world.isRemote)
{
if (worldIsRemoteTicks != -1)
{
if (blockMatch)
targetHeight = 1F;
else
targetHeight = 0.5F;
if (ConfigHandler.debug) System.out.println("Recieved local world in " + worldIsRemoteTicks + " ticks!");
worldIsRemoteTicks = -1;
}

int x = (int) Math.floor(player.posX);
int y = (int) Math.floor(player.posY);
int z = (int) Math.floor(player.posZ);

Block block = world.getBlock(x, y - 1, z);

if (block == null)
if (ConfigHandler.debug)
System.out.println("Block is null");
else
if (ConfigHandler.debug)
System.out.println(block.getLocalizedName());

if (block != null && block != Block.getBlockFromName("minecraft:air"))
{
if (!blockMatch)
targetHeight = 1F;
else
targetHeight = 0.5F;
//int id = Block.getIdFromBlock(block);

//Block testBlock = Block.getBlockFromName("minecraft:stone");

String[] blockList = ConfigHandler.blocklist;
blockMatch = false;
int i = 0;

while (!blockMatch && i < blockList.length)
{
Block testBlock = Block.getBlockFromName(blockList[i]);

if (block == testBlock)
{
blockMatch = true;
}

i++;
}

if (!ConfigHandler.blacklist)
{
if (blockMatch)
targetHeight = 1F;
else
targetHeight = 0.5F;
} else
{
if (!blockMatch)
targetHeight = 1F;
else
targetHeight = 0.5F;
}
}
}
if (world.isRemote)
setStepHeight(player, targetHeight);
}
else if (!enabledWarningSent)
{
Util.sendChatMessage(player, "The mod is disabled! It will do nothing until enabled in the config.");
enabledWarningSent = true;
}
setStepHeight(player, targetHeight);
clock++;
}
clock++;
}
}

Expand All @@ -97,7 +149,8 @@ public boolean setStepHeight(EntityPlayer player, Float height)
if (player.stepHeight != height)
{
player.stepHeight = height;
player.addChatComponentMessage(new ChatComponentText("[" + References.MODNAME + "]: StepHeight was set to " + height));
if (ConfigHandler.debug)
Util.sendChatMessage(player, "[" + this.state + "] StepHeight was set to " + height);
return true;
}
else
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/forecaster/runup/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.forecaster.runup;

import cpw.mods.fml.common.FMLLog;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentText;
import org.apache.logging.log4j.Level;

public class Util
{
public static void modLogOut(Level level, String message)
{
FMLLog.log(level, "[" + References.MODNAME + "] " + message);
}

public static void sendChatMessage(EntityPlayer player, String message)
{
player.addChatComponentMessage(new ChatComponentText("[" + References.MODNAME + "]: " + message));
}
}

0 comments on commit 76da8c4

Please sign in to comment.