Skip to content

Commit

Permalink
update for core
Browse files Browse the repository at this point in the history
  • Loading branch information
dries007 committed Aug 18, 2014
1 parent aa4d433 commit 5d214c1
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 180 deletions.
13 changes: 12 additions & 1 deletion build.gradle
Expand Up @@ -28,7 +28,7 @@ apply plugin: "maven"
apply plugin: "idea-utils"

group = "net.doubledoordev.craycrafting"
version = "1.2.0"
version = "1.3.0"

targetCompatibility = 1.7
sourceCompatibility = 1.7
Expand All @@ -41,6 +41,17 @@ minecraft {
runDir = "jars"
}

repositories {
maven {
name "DDD repo"
url "http://doubledoordev.net/maven/"
}
}

dependencies {
compile "net.doubledoordev.d3core:D3Core:" + project.minecraft.version + "-+:dev"
}

if (System.getenv().BUILD_NUMBER != null) version += "." + System.getenv().BUILD_NUMBER
def builder = new groovy.json.JsonBuilder()
builder (version: version, mcversion: project.minecraft.version, apiversion: project.minecraft.apiVersion)
Expand Down
57 changes: 42 additions & 15 deletions src/main/java/net/doubledoordev/craycrafting/CrayCrafting.java
Expand Up @@ -31,6 +31,7 @@
package net.doubledoordev.craycrafting;

import com.google.common.base.Strings;
import cpw.mods.fml.client.config.IConfigElement;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
Expand All @@ -45,15 +46,18 @@
import net.doubledoordev.craycrafting.network.RecipeMessage;
import net.doubledoordev.craycrafting.network.ResetMessage;
import net.doubledoordev.craycrafting.recipes.*;
import net.doubledoordev.craycrafting.util.Config;
import net.doubledoordev.d3core.util.ID3Mod;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

Expand All @@ -62,35 +66,36 @@
/**
* @author Dries007
*/
@Mod(modid = MODID)
public class CrayCrafting
@Mod(modid = MODID, canBeDeactivated = false)
public class CrayCrafting implements ID3Mod
{
@Mod.Instance(MODID)
public static CrayCrafting instance;

public Logger logger;
private SimpleNetworkWrapper snw;
private Config config;
private File recipeFile;
private Configuration configuration;

public int timer = 0;
public String timermessage = "[CrayCrafting] Recipes have been rotated!";
public boolean listType = false;
public Integer[] list = new Integer[0];

public static SimpleNetworkWrapper getSnw()
{
return instance.snw;
}

public static Config getConfig()
{
return instance.config;
}

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event)
{
logger = event.getModLog();
MinecraftForge.EVENT_BUS.register(this);
FMLCommonHandler.instance().bus().register(this);

config = new Config(event.getSuggestedConfigurationFile());
configuration = new Configuration(event.getSuggestedConfigurationFile());
syncConfig();

new ShapedRecipesType();
new ShapelessRecipesType();
Expand All @@ -113,7 +118,7 @@ public void eventHandler(FMLServerStoppingEvent event)
@Mod.EventHandler()
public void eventHandler(FMLServerStartingEvent event)
{
RecipeRegistry.setConfigFromServer(config.listType, config.list);
RecipeRegistry.setConfigFromServer(listType, list);

recipeFile = new File(DimensionManager.getCurrentSaveRootDirectory(), MODID + ".dat");
if (recipeFile.exists())
Expand All @@ -132,12 +137,12 @@ public void eventHandler(FMLServerStartingEvent event)
RecipeRegistry.randomizeRecipes(recipeFile);
}

if (config.timer > 0) setupTimer();
if (timer > 0) setupTimer();
}

public void setupTimer()
{
if (config.timer >= 1)
if (timer >= 1)
{
new Timer(MODID + "-Timer").schedule(new TimerTask()
{
Expand All @@ -149,11 +154,11 @@ public void run()
RecipeRegistry.randomizeRecipes(recipeFile);
if (MinecraftServer.getServer().isDedicatedServer()) RecipeRegistry.sendPacketToAll();

if (!Strings.isNullOrEmpty(config.timermessage)) MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentText(config.timermessage));
if (!Strings.isNullOrEmpty(timermessage)) MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentText(timermessage));

setupTimer();
}
}, 1000 * 60 * config.timer);
}, 1000 * 60 * timer);
}
}

Expand All @@ -162,4 +167,26 @@ public void loginEvent(PlayerEvent.PlayerLoggedInEvent event)
{
if (MinecraftServer.getServer().isDedicatedServer()) RecipeRegistry.sendPacketTo(event.player);
}

@Override
public void syncConfig()
{
configuration.setCategoryLanguageKey(MODID, "d3.craycrafting.config.craycrafting");
configuration.setCategoryRequiresWorldRestart(MODID, true);

timer = configuration.get(MODID, "resetTimer", timer, "For extra evil, this timer rotates the crafting every X minutes. 0 for disable.").getInt();
timermessage = configuration.get(MODID, "timermessage", timermessage, "Message to be send to all players on timer. Empty = no message").getString();

listType = configuration.getBoolean("listType", MODID, listType, "True means that the list is a whitelist. Craycrafting only applies in the dimensions in the list.\nFalse means that the list is a blacklist. Craycrafting applies in all dimensions except the ones in the list");
int[] templist = configuration.get(MODID, "list", new int[0], "The black/whitelist. See listType.").getIntList();
list = new Integer[templist.length];
for (int i = 0; i < templist.length; i++) list[i] = templist[i];
if (configuration.hasChanged()) configuration.save();
}

@Override
public void addConfigElements(List<IConfigElement> configElements)
{
configElements.add(new ConfigElement(configuration.getCategory(MODID.toLowerCase())));
}
}
Expand Up @@ -111,7 +111,7 @@ public static boolean doesCrayApplyTo(World world)
public static void sendPacketTo(EntityPlayer player)
{
CrayCrafting.getSnw().sendTo(new ResetMessage(), (EntityPlayerMP) player);
CrayCrafting.getSnw().sendTo(new ConfigSyncMessage(CrayCrafting.getConfig().listType, CrayCrafting.getConfig().list), (EntityPlayerMP) player);
CrayCrafting.getSnw().sendTo(new ConfigSyncMessage(CrayCrafting.instance.listType, CrayCrafting.instance.list), (EntityPlayerMP) player);
for (BaseType<IRecipe> baseType : typeList)
{
NBTTagCompound nbtTagCompound = new NBTTagCompound();
Expand All @@ -125,7 +125,7 @@ public static void sendPacketTo(EntityPlayer player)
public static void sendPacketToAll()
{
CrayCrafting.getSnw().sendToAll(new ResetMessage());
CrayCrafting.getSnw().sendToAll(new ConfigSyncMessage(CrayCrafting.getConfig().listType, CrayCrafting.getConfig().list));
CrayCrafting.getSnw().sendToAll(new ConfigSyncMessage(CrayCrafting.instance.listType, CrayCrafting.instance.list));
for (BaseType<IRecipe> baseType : typeList)
{
NBTTagCompound nbtTagCompound = new NBTTagCompound();
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/net/doubledoordev/craycrafting/util/Config.java
Expand Up @@ -30,8 +30,6 @@

package net.doubledoordev.craycrafting.util;

import net.doubledoordev.lib.DevPerks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;

import java.io.File;
Expand All @@ -45,7 +43,6 @@ public class Config
{
private final File file;
private Configuration configuration;
public boolean debug = false;
public int timer = 0;
public String timermessage = "[CrayCrafting] Recipes have been rotated!";
public boolean listType = false;
Expand All @@ -56,9 +53,6 @@ public Config(File file)
this.file = file;
configuration = new Configuration(file);

debug = configuration.getBoolean("debug", MODID, debug, "Enable extra debug output.");
if (configuration.getBoolean("sillyness", MODID, true, "Disable sillyness only if you want to piss off the developers XD")) MinecraftForge.EVENT_BUS.register(new DevPerks(debug));

timer = configuration.get(MODID, "resetTimer", timer, "For extra evil, this timer rotates the crafting every X minutes. 0 for disable.").getInt();
timermessage = configuration.get(MODID, "timermessage", timermessage, "Message to be send to all players on timer. Empty = no message").getString();

Expand Down
147 changes: 0 additions & 147 deletions src/main/java/net/doubledoordev/lib/DevPerks.java

This file was deleted.

2 changes: 2 additions & 0 deletions src/main/resources/assets/craycrafting/lang/en_US.lang
@@ -0,0 +1,2 @@
d3.craycrafting.config.craycrafting=CrayCrafting
d3.craycrafting.config.craycrafting.tooltip=Settings for CrayCrafting
20 changes: 11 additions & 9 deletions src/main/resources/mcmod.info
@@ -1,19 +1,21 @@
[
{
{
"modListVersion": 2,
"modList": [{
"modid": "${modid}",
"name": "${modid}",
"description": "${description}",
"version": "${version}",
"mcversion": "${mcversion}",
"url": "https://github.com/${githuborg}/${modid}",
"updateUrl": "",
"authors": [
"Dries007",
"Doubledoor team"
],
"authorList": [ "Dries007", "Doubledoor team" ],
"credits": "",
"logoFile": "",
"screenshots": [],
"dependencies": []
}
]
"parent": "D3Core",
"requiredMods": [ "Forge", "D3Core" ],
"dependencies": [ "D3Core" ],
"dependants": [ ],
"useDependencyInformation": true
}]
}

0 comments on commit 5d214c1

Please sign in to comment.