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 public static boolean disableStitchedFileSaving = false; 034 035 public ForgeDummyContainer() 036 { 037 super(new ModMetadata()); 038 ModMetadata meta = getMetadata(); 039 meta.modId = "Forge"; 040 meta.name = "Minecraft Forge"; 041 meta.version = String.format("%d.%d.%d.%d", majorVersion, minorVersion, revisionVersion, buildVersion); 042 meta.credits = "Made possible with help from many people"; 043 meta.authorList = Arrays.asList("LexManos", "Eloraam", "Spacetoad"); 044 meta.description = "Minecraft Forge is a common open source API allowing a broad range of mods " + 045 "to work cooperatively together. It allows many mods to be created without " + 046 "them editing the main Minecraft code."; 047 meta.url = "http://MinecraftForge.net"; 048 meta.updateUrl = "http://MinecraftForge.net/forum/index.php/topic,5.0.html"; 049 meta.screenshots = new String[0]; 050 meta.logoFile = "/forge_logo.png"; 051 052 Configuration config = null; 053 File cfgFile = new File(Loader.instance().getConfigDir(), "forge.cfg"); 054 try 055 { 056 config = new Configuration(cfgFile); 057 } 058 catch (Exception e) 059 { 060 System.out.println("Error loading forge.cfg, deleting file and resetting: "); 061 e.printStackTrace(); 062 063 if (cfgFile.exists()) 064 cfgFile.delete(); 065 066 config = new Configuration(cfgFile); 067 } 068 if (!config.isChild) 069 { 070 config.load(); 071 Property enableGlobalCfg = config.get(Configuration.CATEGORY_GENERAL, "enableGlobalConfig", false); 072 if (enableGlobalCfg.getBoolean(false)) 073 { 074 Configuration.enableGlobalConfig(); 075 } 076 } 077 Property prop; 078 prop = config.get(Configuration.CATEGORY_GENERAL, "clumpingThreshold", 64); 079 prop.comment = "Controls the number threshold at which Packet51 is preferred over Packet52, default and minimum 64, maximum 1024"; 080 clumpingThreshold = prop.getInt(64); 081 if (clumpingThreshold > 1024 || clumpingThreshold < 64) 082 { 083 clumpingThreshold = 64; 084 prop.set(64); 085 } 086 087 prop = config.get(Configuration.CATEGORY_GENERAL, "legacyFurnaceOutput", false); 088 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."; 089 legacyFurnaceSides = prop.getBoolean(false); 090 091 prop = config.get(Configuration.CATEGORY_GENERAL, "removeErroringEntities", false); 092 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."; 093 removeErroringEntities = prop.getBoolean(false); 094 095 if (removeErroringEntities) 096 { 097 FMLLog.warning("Enableing removal of erroring Entities USE AT YOUR OWN RISK"); 098 } 099 100 prop = config.get(Configuration.CATEGORY_GENERAL, "removeErroringTileEntities", false); 101 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."; 102 removeErroringTileEntities = prop.getBoolean(false); 103 104 if (removeErroringTileEntities) 105 { 106 FMLLog.warning("Enableing removal of erroring Tile Entities USE AT YOUR OWN RISK"); 107 } 108 109 prop = config.get(Configuration.CATEGORY_GENERAL, "disableStitchedFileSaving", true); 110 prop.comment = "Set this to just disable the texture stitcher from writing the 'debug.stitched_{name}.png file to disc. Just a small performance tweak. Default: true"; 111 disableStitchedFileSaving = prop.getBoolean(true); 112 113 if (config.hasChanged()) 114 { 115 config.save(); 116 } 117 } 118 119 @Override 120 public boolean registerBus(EventBus bus, LoadController controller) 121 { 122 bus.register(this); 123 return true; 124 } 125 126 @Subscribe 127 public void preInit(FMLPreInitializationEvent evt) 128 { 129 ForgeChunkManager.captureConfig(evt.getModConfigurationDirectory()); 130 } 131 132 @Subscribe 133 public void postInit(FMLPostInitializationEvent evt) 134 { 135 ForgeChunkManager.loadConfiguration(); 136 } 137 138 @Override 139 public NBTTagCompound getDataForWriting(SaveHandler handler, WorldInfo info) 140 { 141 NBTTagCompound forgeData = new NBTTagCompound(); 142 NBTTagCompound dimData = DimensionManager.saveDimensionDataMap(); 143 forgeData.setCompoundTag("DimensionData", dimData); 144 return forgeData; 145 } 146 147 @Override 148 public void readData(SaveHandler handler, WorldInfo info, Map<String, NBTBase> propertyMap, NBTTagCompound tag) 149 { 150 if (tag.hasKey("DimensionData")) 151 { 152 DimensionManager.loadDimensionDataMap(tag.hasKey("DimensionData") ? tag.getCompoundTag("DimensionData") : null); 153 } 154 } 155}