001package net.minecraftforge.common; 002 003import java.io.File; 004import java.util.Arrays; 005import java.util.Map; 006 007import net.minecraft.nbt.NBTBase; 008import net.minecraft.nbt.NBTTagCompound; 009import net.minecraft.server.management.PlayerInstance; 010import net.minecraft.world.storage.SaveHandler; 011import net.minecraft.world.storage.WorldInfo; 012 013import com.google.common.eventbus.EventBus; 014import com.google.common.eventbus.Subscribe; 015 016import cpw.mods.fml.common.DummyModContainer; 017import cpw.mods.fml.common.FMLLog; 018import cpw.mods.fml.common.LoadController; 019import cpw.mods.fml.common.Loader; 020import cpw.mods.fml.common.ModMetadata; 021import cpw.mods.fml.common.WorldAccessContainer; 022import cpw.mods.fml.common.event.FMLPostInitializationEvent; 023import cpw.mods.fml.common.event.FMLPreInitializationEvent; 024 025import static net.minecraftforge.common.ForgeVersion.*; 026 027public class ForgeDummyContainer extends DummyModContainer implements WorldAccessContainer 028{ 029 public static int clumpingThreshold = 64; 030 public static boolean legacyFurnaceSides = false; 031 public static boolean removeErroringEntities = false; 032 public static boolean removeErroringTileEntities = false; 033 034 public ForgeDummyContainer() 035 { 036 super(new ModMetadata()); 037 ModMetadata meta = getMetadata(); 038 meta.modId = "Forge"; 039 meta.name = "Minecraft Forge"; 040 meta.version = String.format("%d.%d.%d.%d", majorVersion, minorVersion, revisionVersion, buildVersion); 041 meta.credits = "Made possible with help from many people"; 042 meta.authorList = Arrays.asList("LexManos", "Eloraam", "Spacetoad"); 043 meta.description = "Minecraft Forge is a common open source API allowing a broad range of mods " + 044 "to work cooperatively together. It allows many mods to be created without " + 045 "them editing the main Minecraft code."; 046 meta.url = "http://MinecraftForge.net"; 047 meta.updateUrl = "http://MinecraftForge.net/forum/index.php/topic,5.0.html"; 048 meta.screenshots = new String[0]; 049 meta.logoFile = "/forge_logo.png"; 050 051 Configuration config = null; 052 File cfgFile = new File(Loader.instance().getConfigDir(), "forge.cfg"); 053 try 054 { 055 config = new Configuration(cfgFile); 056 } 057 catch (Exception e) 058 { 059 System.out.println("Error loading forge.cfg, deleting file and resetting: "); 060 e.printStackTrace(); 061 062 if (cfgFile.exists()) 063 cfgFile.delete(); 064 065 config = new Configuration(cfgFile); 066 } 067 if (!config.isChild) 068 { 069 config.load(); 070 Property enableGlobalCfg = config.get(Configuration.CATEGORY_GENERAL, "enableGlobalConfig", false); 071 if (enableGlobalCfg.getBoolean(false)) 072 { 073 Configuration.enableGlobalConfig(); 074 } 075 } 076 Property prop; 077 prop = config.get(Configuration.CATEGORY_GENERAL, "clumpingThreshold", 64); 078 prop.comment = "Controls the number threshold at which Packet51 is preferred over Packet52, default and minimum 64, maximum 1024"; 079 clumpingThreshold = prop.getInt(64); 080 if (clumpingThreshold > 1024 || clumpingThreshold < 64) 081 { 082 clumpingThreshold = 64; 083 prop.set(64); 084 } 085 086 prop = config.get(Configuration.CATEGORY_GENERAL, "legacyFurnceOutput", false); 087 prop.comment = "Controls the sides of vanilla furnaces for Forge's ISidedInventroy, Vanilla defines the output as the bottom, but mods/Forge define it as the sides. Settings this to true will restore the old side relations."; 088 legacyFurnaceSides = prop.getBoolean(false); 089 090 prop = config.get(Configuration.CATEGORY_GENERAL, "removeErroringEntities", false); 091 prop.comment = "Set this to just remove any TileEntity that throws a error in there update method instead of closing the server and reporting a crash log. BE WARNED THIS COULD SCREW UP EVERYTHING USE SPARINGLY WE ARE NOT RESPONSIBLE FOR DAMAGES."; 092 removeErroringEntities = prop.getBoolean(false); 093 094 if (removeErroringEntities) 095 { 096 FMLLog.warning("Enableing removal of erroring Entities USE AT YOUR OWN RISK"); 097 } 098 099 prop = config.get(Configuration.CATEGORY_GENERAL, "removeErroringTileEntities", false); 100 prop.comment = "Set this to just remove any TileEntity that throws a error in there update method instead of closing the server and reporting a crash log. BE WARNED THIS COULD SCREW UP EVERYTHING USE SPARINGLY WE ARE NOT RESPONSIBLE FOR DAMAGES."; 101 removeErroringTileEntities = prop.getBoolean(false); 102 103 if (removeErroringTileEntities) 104 { 105 FMLLog.warning("Enableing removal of erroring Tile Entities USE AT YOUR OWN RISK"); 106 } 107 108 if (config.hasChanged()) 109 { 110 config.save(); 111 } 112 } 113 114 @Override 115 public boolean registerBus(EventBus bus, LoadController controller) 116 { 117 bus.register(this); 118 return true; 119 } 120 121 @Subscribe 122 public void preInit(FMLPreInitializationEvent evt) 123 { 124 ForgeChunkManager.captureConfig(evt.getModConfigurationDirectory()); 125 } 126 127 @Subscribe 128 public void postInit(FMLPostInitializationEvent evt) 129 { 130 ForgeChunkManager.loadConfiguration(); 131 } 132 133 @Override 134 public NBTTagCompound getDataForWriting(SaveHandler handler, WorldInfo info) 135 { 136 NBTTagCompound forgeData = new NBTTagCompound(); 137 NBTTagCompound dimData = DimensionManager.saveDimensionDataMap(); 138 forgeData.setCompoundTag("DimensionData", dimData); 139 return forgeData; 140 } 141 142 @Override 143 public void readData(SaveHandler handler, WorldInfo info, Map<String, NBTBase> propertyMap, NBTTagCompound tag) 144 { 145 if (tag.hasKey("DimensionData")) 146 { 147 DimensionManager.loadDimensionDataMap(tag.hasKey("DimensionData") ? tag.getCompoundTag("DimensionData") : null); 148 } 149 } 150}