diff options
16 files changed, 1644 insertions, 1934 deletions
diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java index d18af57173..ad9686b809 100644 --- a/src/main/java/gregtech/GT_Mod.java +++ b/src/main/java/gregtech/GT_Mod.java @@ -1,12 +1,10 @@ package gregtech; import com.google.common.base.Stopwatch; -import com.gtnewhorizon.structurelib.StructureLib; import cpw.mods.fml.common.*; import cpw.mods.fml.common.event.*; import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.GregTech_API; import gregtech.api.enchants.Enchantment_EnderDamage; import gregtech.api.enchants.Enchantment_Radioactivity; @@ -24,12 +22,7 @@ import gregtech.common.GT_Proxy; import gregtech.common.GT_RecipeAdder; import gregtech.common.entities.GT_Entity_Arrow; import gregtech.common.entities.GT_Entity_Arrow_Potion; -import gregtech.common.items.GT_MetaGenerated_Tool_01; -import gregtech.common.items.behaviors.Behaviour_DataOrb; import gregtech.common.misc.GT_Command; -import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Massfabricator; -import gregtech.common.tileentities.machines.long_distance.GT_MetaTileEntity_LongDistancePipelineBase; -import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_Cleanroom; import gregtech.common.tileentities.storage.GT_MetaTileEntity_DigitalChestBase; import gregtech.loaders.ExtraIcons; import gregtech.loaders.load.GT_CoverBehaviorLoader; @@ -43,37 +36,24 @@ import gregtech.loaders.postload.*; import gregtech.loaders.preload.*; import ic2.api.recipe.IRecipeInput; import ic2.api.recipe.RecipeOutput; -import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.WeightedRandomChestContent; import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.common.ChestGenHooks; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.oredict.OreDictionary; -import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.io.*; -import java.lang.reflect.InvocationTargetException; import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import static gregtech.api.enums.GT_Values.MOD_ID_AE; import static gregtech.api.enums.GT_Values.MOD_ID_FR; @SuppressWarnings("ALL") @@ -127,8 +107,8 @@ public class GT_Mod implements IGT_Mod { public static GT_Proxy gregtechproxy; public static int MAX_IC2 = 2147483647; public static GT_Achievements achievements; - private final String aTextGeneral = "general"; - private final String aTextIC2 = "ic2_"; + public static final String aTextGeneral = "general"; + public static final String aTextIC2 = "ic2_"; public static final Logger GT_FML_LOGGER = LogManager.getLogger("GregTech GTNH"); @@ -141,16 +121,13 @@ public class GT_Mod implements IGT_Mod { public GT_Mod() { try { Class.forName("ic2.core.IC2").getField("enableOreDictCircuit").set(null, Boolean.FALSE); - } catch (Throwable ignored) { - } + } catch (Throwable ignored) {} try { Class.forName("ic2.core.IC2").getField("enableCraftingBucket").set(null, Boolean.FALSE); - } catch (Throwable ignored) { - } + } catch (Throwable ignored) {} try { Class.forName("ic2.core.IC2").getField("enableEnergyInStorageBlockItems").set(null, Boolean.FALSE); - } catch (Throwable ignored) { - } + } catch (Throwable ignored) {} GT_Values.GT = this; GT_Values.DW = new GT_DummyWorld(); GT_Values.NW = new GT_Network(); @@ -166,7 +143,6 @@ public class GT_Mod implements IGT_Mod { public static int calculateTotalGTVersion(int majorVersion, int minorVersion) { return majorVersion * 1000 + minorVersion; - } @Mod.EventHandler @@ -188,438 +164,31 @@ public class GT_Mod implements IGT_Mod { MinecraftForge.EVENT_BUS.register(new ExtraIcons()); } - File tFile = new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "GregTech.cfg"); - Configuration tMainConfig = new Configuration(tFile); - tMainConfig.load(); - tFile = new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "IDs.cfg"); - GT_Config.sConfigFileIDs = new Configuration(tFile); - GT_Config.sConfigFileIDs.load(); - GT_Config.sConfigFileIDs.save(); - GregTech_API.sRecipeFile = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "Recipes.cfg"))); - GregTech_API.sMachineFile = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "MachineStats.cfg"))); - GregTech_API.sWorldgenFile = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "WorldGeneration.cfg"))); - GregTech_API.sMaterialProperties = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "MaterialProperties.cfg"))); - GregTech_API.sMaterialComponents = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "MaterialComponents.cfg"))); - GregTech_API.sUnification = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "Unification.cfg"))); - GregTech_API.sSpecialFile = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "Other.cfg"))); - GregTech_API.sOPStuff = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "OverpoweredStuff.cfg"))); - - GregTech_API.sClientDataFile = new GT_Config(new Configuration(new File(new File(aEvent.getModConfigurationDirectory(), "GregTech"), "Client.cfg"))); - GregTech_API.mIC2Classic = Loader.isModLoaded("IC2-Classic-Spmod"); - GregTech_API.mGTPlusPlus = Loader.isModLoaded("miscutils"); - GregTech_API.mTranslocator = Loader.isModLoaded("Translocator"); - GregTech_API.mTConstruct = Loader.isModLoaded("TConstruct"); - GregTech_API.mGalacticraft = Loader.isModLoaded("GalacticraftCore"); - GregTech_API.mAE2 = Loader.isModLoaded(MOD_ID_AE); - GT_Log.out.println("GT_Mod: Are you there Translocator? " + GregTech_API.mTranslocator); - GT_Log.out.println("GT_Mod: Are you there TConstruct? " + GregTech_API.mTConstruct); - GT_Log.out.println("GT_Mod: Are you there GalacticraftCore? " + GregTech_API.mGalacticraft); - - GT_Log.mLogFile = new File(aEvent.getModConfigurationDirectory().getParentFile(), "logs/GregTech.log"); - if (!GT_Log.mLogFile.exists()) { - try { - GT_Log.mLogFile.createNewFile(); - } catch (Throwable ignored) { - } - } - try { - GT_Log.out = GT_Log.err = new PrintStream(GT_Log.mLogFile); - } catch (FileNotFoundException ignored) { - } - GT_Log.mOreDictLogFile = new File(aEvent.getModConfigurationDirectory().getParentFile(), "logs/OreDict.log"); - if (!GT_Log.mOreDictLogFile.exists()) { - try { - GT_Log.mOreDictLogFile.createNewFile(); - } catch (Throwable ignored) { - } - } - if (tMainConfig.get(aTextGeneral, "LoggingExplosions", true).getBoolean(true)) { - GT_Log.mExplosionLog = new File(aEvent.getModConfigurationDirectory().getParentFile(), "logs/Explosion.log"); - if (!GT_Log.mExplosionLog.exists()) { - try { - GT_Log.mExplosionLog.createNewFile(); - } catch (Throwable ignored) { - } - } - try { - GT_Log.exp = new PrintStream(GT_Log.mExplosionLog); - } catch (Throwable ignored) { - } - } + Configuration tMainConfig = GT_PreLoad.getConfiguration(aEvent.getModConfigurationDirectory()); + GT_PreLoad.initCompat(); + GT_PreLoad.createLogFiles(aEvent.getModConfigurationDirectory().getParentFile(), tMainConfig); - if (tMainConfig.get(aTextGeneral, "LoggingPlayerActivity", true).getBoolean(true)) { - GT_Log.mPlayerActivityLogFile = new File(aEvent.getModConfigurationDirectory().getParentFile(), "logs/PlayerActivity.log"); - if (!GT_Log.mPlayerActivityLogFile.exists()) { - try { - GT_Log.mPlayerActivityLogFile.createNewFile(); - } catch (Throwable ignored) { - } - } - try { - GT_Log.pal = new PrintStream(GT_Log.mPlayerActivityLogFile); - } catch (Throwable ignored) { - } - } - try { - List<String> tList = ((GT_Log.LogBuffer) GT_Log.ore).mBufferedOreDictLog; - GT_Log.ore.println("******************************************************************************"); - GT_Log.ore.println("* This is the complete log of the GT5-Unofficial OreDictionary Handler. It *"); - GT_Log.ore.println("* processes all OreDictionary entries and can sometimes cause errors. All *"); - GT_Log.ore.println("* entries and errors are being logged. If you see an error please raise an *"); - GT_Log.ore.println("* issue at https://github.com/Blood-Asp/GT5-Unofficial. *"); - GT_Log.ore.println("******************************************************************************"); - tList.forEach(GT_Log.ore::println); - } catch (Throwable ignored) { - } gregtechproxy.onPreLoad(); GT_Log.out.println("GT_Mod: Setting Configs"); - GT_Values.D1 = tMainConfig.get(aTextGeneral, "Debug", false).getBoolean(false); - GT_Values.D2 = tMainConfig.get(aTextGeneral, "Debug2", false).getBoolean(false); - GT_Values.hideAssLineRecipes = tMainConfig.get(aTextGeneral, "hide assline recipes", false).getBoolean(false); - GT_Values.updateFluidDisplayItems = tMainConfig.get(aTextGeneral, "update fluid display items", true).getBoolean(true); - GT_Values.allow_broken_recipemap = tMainConfig.get(aTextGeneral, "debug allow broken recipemap", false).getBoolean(false); - GT_Values.debugCleanroom = tMainConfig.get(aTextGeneral, "debugCleanroom", false).getBoolean(false); - GT_Values.debugDriller = tMainConfig.get(aTextGeneral, "debugDriller", false).getBoolean(false); - GT_Values.debugWorldGen = tMainConfig.get(aTextGeneral, "debugWorldGen", false).getBoolean(false); - GT_Values.debugOrevein = tMainConfig.get(aTextGeneral, "debugOrevein", false).getBoolean(false); - GT_Values.debugSmallOres = tMainConfig.get(aTextGeneral, "debugSmallOres", false).getBoolean(false); - GT_Values.debugStones = tMainConfig.get(aTextGeneral, "debugStones", false).getBoolean(false); - GT_Values.debugBlockMiner = tMainConfig.get(aTextGeneral, "debugBlockMiner", false).getBoolean(false); - GT_Values.debugBlockPump = tMainConfig.get(aTextGeneral, "debugBlockPump", false).getBoolean(false); - GT_Values.debugEntityCramming = tMainConfig.get(aTextGeneral, "debugEntityCramming", false).getBoolean(false); - GT_Values.debugWorldData = tMainConfig.get(aTextGeneral, "debugWorldData", false).getBoolean(false); - GT_Values.oreveinPercentage = tMainConfig.get(aTextGeneral, "oreveinPercentage_100", 100).getInt(100); - GT_Values.oreveinAttempts = tMainConfig.get(aTextGeneral, "oreveinAttempts_64", 64).getInt(64); - GT_Values.oreveinMaxPlacementAttempts = tMainConfig.get(aTextGeneral, "oreveinMaxPlacementAttempts_8", 8).getInt(8); - GT_Values.oreveinPlacerOres = tMainConfig.get(aTextGeneral, "oreveinPlacerOres", true).getBoolean(true); - GT_Values.oreveinPlacerOresMultiplier = tMainConfig.get(aTextGeneral, "oreveinPlacerOresMultiplier", 2).getInt(2); - //GT_Values.oreveinMaxSize = tMainConfig.get(aTextGeneral, "oreveinMaxSize_64",64).getInt(64); - GT_Values.ticksBetweenSounds = tMainConfig.get("machines", "TicksBetweenSounds", 30).getInt(30); - GT_Values.cleanroomGlass = (float) tMainConfig.get("machines", "ReinforcedGlassPercentageForCleanroom", 5D).getDouble(5D); - GT_Values.enableChunkloaders = tMainConfig.get("machines", "enableChunkloaders", true).getBoolean(true); - GT_Values.alwaysReloadChunkloaders = tMainConfig.get("machines", "alwaysReloadChunkloaders", false).getBoolean(false); - GT_Values.debugChunkloaders = tMainConfig.get("machines", "debugChunkloaders", false).getBoolean(false); - GT_Values.disableDigitalChestsExternalAccess = tMainConfig.get("machines", "disableDigitalChestsExternalAccess", false).getBoolean(false); - GregTech_API.TICKS_FOR_LAG_AVERAGING = tMainConfig.get(aTextGeneral, "TicksForLagAveragingWithScanner", 25).getInt(25); - GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING = tMainConfig.get(aTextGeneral, "MillisecondsPassedInGTTileEntityUntilLagWarning", 100).getInt(100); - if (tMainConfig.get(aTextGeneral, "disable_STDOUT", false).getBoolean(false)) { - GT_FML_LOGGER.info("Disableing Console Messages."); - GT_FML_LOGGER.exit(); - System.out.close(); - System.err.close(); - } - /*if (tMainConfig.get(aTextGeneral, "disable_STDERR", false).getBoolean(false)) { - System.err.close(); - }*/ - GregTech_API.sMachineExplosions = tMainConfig.get("machines", "machines_explosion_damage", true).getBoolean(false); - GregTech_API.sMachineFlammable = tMainConfig.get("machines", "machines_flammable", true).getBoolean(false); - GregTech_API.sMachineNonWrenchExplosions = tMainConfig.get("machines", "explosions_on_nonwrenching", true).getBoolean(false); - GregTech_API.sMachineWireFire = tMainConfig.get("machines", "wirefire_on_explosion", true).getBoolean(false); - GregTech_API.sMachineFireExplosions = tMainConfig.get("machines", "fire_causes_explosions", true).getBoolean(false); - GregTech_API.sMachineRainExplosions = tMainConfig.get("machines", "rain_causes_explosions", true).getBoolean(false); - GregTech_API.sMachineThunderExplosions = tMainConfig.get("machines", "lightning_causes_explosions", true).getBoolean(false); - GregTech_API.sConstantEnergy = tMainConfig.get("machines", "constant_need_of_energy", true).getBoolean(false); - GregTech_API.sColoredGUI = tMainConfig.get("machines", "colored_guis_when_painted", true).getBoolean(false); - GregTech_API.sMachineMetalGUI = tMainConfig.get("machines", "guis_in_consistent_machine_metal_color", false).getBoolean(false); - - // Implementation for this is actually handled in NewHorizonsCoreMod in MainRegistry.java! - GregTech_API.sUseMachineMetal = tMainConfig.get("machines", "use_machine_metal_tint", true).getBoolean(true); - - GregTech_API.sTimber = tMainConfig.get(aTextGeneral, "timber_axe", true).getBoolean(true); - GregTech_API.sDrinksAlwaysDrinkable = tMainConfig.get(aTextGeneral, "drinks_always_drinkable", false).getBoolean(false); - GregTech_API.sDoShowAllItemsInCreative = tMainConfig.get(aTextGeneral, "show_all_metaitems_in_creative_and_NEI", false).getBoolean(false); - GregTech_API.sMultiThreadedSounds = tMainConfig.get(aTextGeneral, "sound_multi_threading", false).getBoolean(false); - String SBdye0 = "ColorModulation."; - Arrays.stream(Dyes.values()).filter(tDye -> (tDye != Dyes._NULL) && (tDye.mIndex < 0)).forEach(tDye -> { - String SBdye1 = SBdye0 + tDye; - tDye.mRGBa[0] = ((short) Math.min(255, Math.max(0, GregTech_API.sClientDataFile.get(SBdye1, "R", tDye.mRGBa[0])))); - tDye.mRGBa[1] = ((short) Math.min(255, Math.max(0, GregTech_API.sClientDataFile.get(SBdye1, "G", tDye.mRGBa[1])))); - tDye.mRGBa[2] = ((short) Math.min(255, Math.max(0, GregTech_API.sClientDataFile.get(SBdye1, "B", tDye.mRGBa[2])))); - } - ); - gregtechproxy.mRenderTileAmbientOcclusion = GregTech_API.sClientDataFile.get("render", "TileAmbientOcclusion", true); - gregtechproxy.mRenderGlowTextures = GregTech_API.sClientDataFile.get("render", "GlowTextures", true); - gregtechproxy.mRenderFlippedMachinesFlipped = GregTech_API.sClientDataFile.get("render", "RenderFlippedMachinesFlipped", true); - gregtechproxy.mRenderIndicatorsOnHatch = GregTech_API.sClientDataFile.get("render", "RenderIndicatorsOnHatch", true); - gregtechproxy.mRenderDirtParticles = GregTech_API.sClientDataFile.get("render", "RenderDirtParticles", true); - gregtechproxy.mRenderPollutionFog = GregTech_API.sClientDataFile.get("render", "RenderPollutionFog", true); - - gregtechproxy.mMaxEqualEntitiesAtOneSpot = tMainConfig.get(aTextGeneral, "MaxEqualEntitiesAtOneSpot", 3).getInt(3); - gregtechproxy.mSkeletonsShootGTArrows = tMainConfig.get(aTextGeneral, "SkeletonsShootGTArrows", 16).getInt(16); - gregtechproxy.mFlintChance = tMainConfig.get(aTextGeneral, "FlintAndSteelChance", 30).getInt(30); - gregtechproxy.mItemDespawnTime = tMainConfig.get(aTextGeneral, "ItemDespawnTime", 6000).getInt(6000); - gregtechproxy.mAllowSmallBoilerAutomation = tMainConfig.get(aTextGeneral, "AllowSmallBoilerAutomation", false).getBoolean(false); - gregtechproxy.mHardMachineCasings = tMainConfig.get(aTextGeneral, "HardMachineCasings", true).getBoolean(true); - gregtechproxy.mDisableVanillaOres = tMainConfig.get(aTextGeneral, "DisableVanillaOres", true).getBoolean(true); - gregtechproxy.mNerfDustCrafting = tMainConfig.get(aTextGeneral, "NerfDustCrafting", true).getBoolean(true); - gregtechproxy.mIncreaseDungeonLoot = tMainConfig.get(aTextGeneral, "IncreaseDungeonLoot", true).getBoolean(true); - gregtechproxy.mAxeWhenAdventure = tMainConfig.get(aTextGeneral, "AdventureModeStartingAxe", true).getBoolean(true); - gregtechproxy.mHardcoreCables = tMainConfig.get(aTextGeneral, "HardCoreCableLoss", false).getBoolean(false); - gregtechproxy.mSurvivalIntoAdventure = tMainConfig.get(aTextGeneral, "forceAdventureMode", false).getBoolean(false); - gregtechproxy.mHungerEffect = tMainConfig.get(aTextGeneral, "AFK_Hunger", false).getBoolean(false); - gregtechproxy.mHardRock = tMainConfig.get(aTextGeneral, "harderstone", false).getBoolean(false); - gregtechproxy.mInventoryUnification = tMainConfig.get(aTextGeneral, "InventoryUnification", true).getBoolean(true); - gregtechproxy.mGTBees = tMainConfig.get(aTextGeneral, "GTBees", true).getBoolean(true); - gregtechproxy.mCraftingUnification = tMainConfig.get(aTextGeneral, "CraftingUnification", true).getBoolean(true); - gregtechproxy.mNerfedWoodPlank = tMainConfig.get(aTextGeneral, "WoodNeedsSawForCrafting", true).getBoolean(true); - gregtechproxy.mNerfedVanillaTools = tMainConfig.get(aTextGeneral, "smallerVanillaToolDurability", true).getBoolean(true); - gregtechproxy.mSortToTheEnd = tMainConfig.get(aTextGeneral, "EnsureToBeLoadedLast", true).getBoolean(true); - gregtechproxy.mDisableIC2Cables = tMainConfig.get(aTextGeneral, "DisableIC2Cables", true).getBoolean(true); - gregtechproxy.mAchievements = tMainConfig.get(aTextGeneral, "EnableAchievements", true).getBoolean(true); - gregtechproxy.mAE2Integration = GregTech_API.sSpecialFile.get(ConfigCategories.general, "EnableAE2Integration", GregTech_API.mAE2); - gregtechproxy.mNerfedCombs = tMainConfig.get(aTextGeneral, "NerfCombs", true).getBoolean(true); - gregtechproxy.mNerfedCrops = tMainConfig.get(aTextGeneral, "NerfCrops", true).getBoolean(true); - gregtechproxy.mHideUnusedOres = tMainConfig.get(aTextGeneral, "HideUnusedOres", true).getBoolean(true); - gregtechproxy.mHideRecyclingRecipes = tMainConfig.get(aTextGeneral, "HideRecyclingRecipes", true).getBoolean(true); - gregtechproxy.mArcSmeltIntoAnnealed = tMainConfig.get(aTextGeneral, "ArcSmeltIntoAnnealedWrought", true).getBoolean(true); - gregtechproxy.mEnableAllMaterials = tMainConfig.get("general", "EnableAllMaterials", false).getBoolean(false); - gregtechproxy.mEnableAllComponents = tMainConfig.get("general", "EnableAllComponents", false).getBoolean(false); - - //Pollution: edit GT_Proxy.java to change default values - gregtechproxy.mPollution = tMainConfig.get("Pollution", "EnablePollution", gregtechproxy.mPollution).getBoolean(gregtechproxy.mPollution); - gregtechproxy.mPollutionSmogLimit = tMainConfig.get("Pollution", "SmogLimit", gregtechproxy.mPollutionSmogLimit).getInt(gregtechproxy.mPollutionSmogLimit); - gregtechproxy.mPollutionPoisonLimit = tMainConfig.get("Pollution", "PoisonLimit", gregtechproxy.mPollutionPoisonLimit).getInt(gregtechproxy.mPollutionPoisonLimit); - gregtechproxy.mPollutionVegetationLimit = tMainConfig.get("Pollution", "VegetationLimit", gregtechproxy.mPollutionVegetationLimit).getInt(gregtechproxy.mPollutionVegetationLimit); - gregtechproxy.mPollutionSourRainLimit = tMainConfig.get("Pollution", "SourRainLimit", gregtechproxy.mPollutionSourRainLimit).getInt(gregtechproxy.mPollutionSourRainLimit); - gregtechproxy.mPollutionOnExplosion = tMainConfig.get("Pollution", "SourRainLimit", gregtechproxy.mPollutionOnExplosion).getInt(gregtechproxy.mPollutionOnExplosion); - gregtechproxy.mExplosionItemDrop = tMainConfig.get("general", "ExplosionItemDrops", gregtechproxy.mExplosionItemDrop).getBoolean(gregtechproxy.mExplosionItemDrop); - gregtechproxy.mPollutionPrimitveBlastFurnacePerSecond = tMainConfig.get("Pollution", "PollutionPrimitiveBlastFurnace", gregtechproxy.mPollutionPrimitveBlastFurnacePerSecond).getInt(gregtechproxy.mPollutionPrimitveBlastFurnacePerSecond); - gregtechproxy.mPollutionCharcoalPitPerSecond = tMainConfig.get("Pollution", "PollutionCharcoalPit", gregtechproxy.mPollutionCharcoalPitPerSecond).getInt(gregtechproxy.mPollutionCharcoalPitPerSecond); - gregtechproxy.mPollutionEBFPerSecond = tMainConfig.get("Pollution", "PollutionEBF", gregtechproxy.mPollutionEBFPerSecond).getInt(gregtechproxy.mPollutionEBFPerSecond); - gregtechproxy.mPollutionLargeCombustionEnginePerSecond = tMainConfig.get("Pollution", "PollutionLargeCombustionEngine",gregtechproxy.mPollutionLargeCombustionEnginePerSecond).getInt(gregtechproxy.mPollutionLargeCombustionEnginePerSecond); - gregtechproxy.mPollutionExtremeCombustionEnginePerSecond = tMainConfig.get("Pollution", "PollutionExtremeCombustionEngine",gregtechproxy.mPollutionExtremeCombustionEnginePerSecond).getInt(gregtechproxy.mPollutionExtremeCombustionEnginePerSecond); - gregtechproxy.mPollutionImplosionCompressorPerSecond = tMainConfig.get("Pollution", "PollutionImplosionCompressor", gregtechproxy.mPollutionImplosionCompressorPerSecond).getInt(gregtechproxy.mPollutionImplosionCompressorPerSecond); - gregtechproxy.mPollutionLargeBronzeBoilerPerSecond = tMainConfig.get("Pollution", "PollutionLargeBronzeBoiler", gregtechproxy.mPollutionLargeBronzeBoilerPerSecond).getInt(gregtechproxy.mPollutionLargeBronzeBoilerPerSecond); - gregtechproxy.mPollutionLargeSteelBoilerPerSecond = tMainConfig.get("Pollution", "PollutionLargeSteelBoiler", gregtechproxy.mPollutionLargeSteelBoilerPerSecond).getInt(gregtechproxy.mPollutionLargeSteelBoilerPerSecond); - gregtechproxy.mPollutionLargeTitaniumBoilerPerSecond = tMainConfig.get("Pollution", "PollutionLargeTitaniumBoiler", gregtechproxy.mPollutionLargeTitaniumBoilerPerSecond ).getInt(gregtechproxy.mPollutionLargeTitaniumBoilerPerSecond ); - gregtechproxy.mPollutionLargeTungstenSteelBoilerPerSecond = tMainConfig.get("Pollution", "PollutionLargeTungstenSteelBoiler", gregtechproxy.mPollutionLargeTungstenSteelBoilerPerSecond).getInt(gregtechproxy.mPollutionLargeTungstenSteelBoilerPerSecond); - gregtechproxy.mPollutionReleasedByThrottle = tMainConfig.get("Pollution", "PollutionReleasedByThrottle", gregtechproxy.mPollutionReleasedByThrottle).getDouble(gregtechproxy.mPollutionReleasedByThrottle); - gregtechproxy.mPollutionLargeGasTurbinePerSecond = tMainConfig.get("Pollution", "PollutionLargeGasTurbine", gregtechproxy.mPollutionLargeGasTurbinePerSecond).getInt( gregtechproxy.mPollutionLargeGasTurbinePerSecond); - gregtechproxy.mPollutionMultiSmelterPerSecond = tMainConfig.get("Pollution", "PollutionMultiSmelter", gregtechproxy.mPollutionMultiSmelterPerSecond).getInt(gregtechproxy.mPollutionMultiSmelterPerSecond); - gregtechproxy.mPollutionPyrolyseOvenPerSecond = tMainConfig.get("Pollution", "PollutionPyrolyseOven", gregtechproxy.mPollutionPyrolyseOvenPerSecond).getInt(gregtechproxy.mPollutionPyrolyseOvenPerSecond); - gregtechproxy.mPollutionSmallCoalBoilerPerSecond = tMainConfig.get("Pollution", "PollutionSmallCoalBoiler", gregtechproxy.mPollutionSmallCoalBoilerPerSecond).getInt(gregtechproxy.mPollutionSmallCoalBoilerPerSecond); - gregtechproxy.mPollutionHighPressureLavaBoilerPerSecond = tMainConfig.get("Pollution", "PollutionHighPressureLavaBoiler", gregtechproxy.mPollutionHighPressureLavaBoilerPerSecond).getInt(gregtechproxy.mPollutionHighPressureLavaBoilerPerSecond); - gregtechproxy.mPollutionHighPressureCoalBoilerPerSecond = tMainConfig.get("Pollution", "PollutionHighPressureCoalBoiler", gregtechproxy.mPollutionHighPressureCoalBoilerPerSecond).getInt(gregtechproxy.mPollutionHighPressureCoalBoilerPerSecond); - gregtechproxy.mPollutionBaseDieselGeneratorPerSecond = tMainConfig.get("Pollution", "PollutionBaseDieselGenerator",gregtechproxy.mPollutionBaseDieselGeneratorPerSecond).getInt(gregtechproxy.mPollutionBaseDieselGeneratorPerSecond); - gregtechproxy.mPollutionDieselGeneratorReleasedByTier = tMainConfig.get("Pollution", "PollutionReleasedByTierDieselGenerator", gregtechproxy.mPollutionDieselGeneratorReleasedByTier).getDoubleList(); - gregtechproxy.mPollutionBaseGasTurbinePerSecond = tMainConfig.get("Pollution", "PollutionBaseGasTurbineGenerator", gregtechproxy.mPollutionBaseGasTurbinePerSecond).getInt(gregtechproxy.mPollutionBaseGasTurbinePerSecond); - gregtechproxy.mPollutionGasTurbineReleasedByTier = tMainConfig.get("Pollution", "PollutionReleasedByTierGasTurbineGenerator", gregtechproxy.mPollutionGasTurbineReleasedByTier).getDoubleList(); - - gregtechproxy.mUndergroundOil.getConfig(tMainConfig, "undergroundfluid"); - gregtechproxy.mEnableCleanroom = tMainConfig.get("general", "EnableCleanroom", true).getBoolean(true); - if (gregtechproxy.mEnableCleanroom) - GT_MetaTileEntity_Cleanroom.loadConfig(tMainConfig); - gregtechproxy.mLowGravProcessing = Loader.isModLoaded(GT_Values.MOD_ID_GC_CORE) && tMainConfig.get("general", "LowGravProcessing", true).getBoolean(true); - gregtechproxy.mUseGreatlyShrukenReplacementList = tMainConfig.get("general", "GTNH Optimised Material Loading", true).getBoolean(true); - Calendar now = Calendar.getInstance(); - gregtechproxy.mAprilFool = GregTech_API.sSpecialFile.get(ConfigCategories.general, "AprilFool", now.get(Calendar.MONTH) == Calendar.APRIL && now.get(Calendar.DAY_OF_MONTH) == 1); - gregtechproxy.mCropNeedBlock = tMainConfig.get("general", "CropNeedBlockBelow", true).getBoolean(true); - gregtechproxy.mDisableOldChemicalRecipes = tMainConfig.get("general", "DisableOldChemicalRecipes", false).getBoolean(false); - gregtechproxy.mAMHInteraction = tMainConfig.get("general", "AllowAutoMaintenanceHatchInteraction", false).getBoolean(false); - GregTech_API.mOutputRF = GregTech_API.sOPStuff.get(ConfigCategories.general, "OutputRF", true); - GregTech_API.mInputRF = GregTech_API.sOPStuff.get(ConfigCategories.general, "InputRF", false); - GregTech_API.mEUtoRF = GregTech_API.sOPStuff.get(ConfigCategories.general, "100EUtoRF", 360); - GregTech_API.mRFtoEU = GregTech_API.sOPStuff.get(ConfigCategories.general, "100RFtoEU", 20); - GregTech_API.mRFExplosions = GregTech_API.sOPStuff.get(ConfigCategories.general, "RFExplosions", false); - GregTech_API.meIOLoaded = Loader.isModLoaded("EnderIO"); - gregtechproxy.mForceFreeFace = GregTech_API.sMachineFile.get(ConfigCategories.machineconfig, "forceFreeFace", true); - gregtechproxy.mBrickedBlastFurnace = tMainConfig.get("general", "BrickedBlastFurnace", true).getBoolean(true); - gregtechproxy.mEasierIVPlusCables = tMainConfig.get("general", "EasierEVPlusCables", false).getBoolean(false); - gregtechproxy.mMixedOreOnlyYieldsTwoThirdsOfPureOre = tMainConfig.get("general", "MixedOreOnlyYieldsTwoThirdsOfPureOre", false).getBoolean(false); - gregtechproxy.enableBlackGraniteOres = GregTech_API.sWorldgenFile.get("general", "enableBlackGraniteOres", gregtechproxy.enableBlackGraniteOres); - gregtechproxy.enableRedGraniteOres = GregTech_API.sWorldgenFile.get("general", "enableRedGraniteOres", gregtechproxy.enableRedGraniteOres); - gregtechproxy.enableMarbleOres = GregTech_API.sWorldgenFile.get("general", "enableMarbleOres", gregtechproxy.enableMarbleOres); - gregtechproxy.enableBasaltOres = GregTech_API.sWorldgenFile.get("general", "enableBasaltOres", gregtechproxy.enableBasaltOres); - gregtechproxy.gt6Pipe = tMainConfig.get("general", "GT6StyledPipesConnection", true).getBoolean(true); - gregtechproxy.gt6Cable = tMainConfig.get("general", "GT6StyledWiresConnection", true).getBoolean(true); - gregtechproxy.ic2EnergySourceCompat = tMainConfig.get("general", "Ic2EnergySourceCompat", true).getBoolean(true); - gregtechproxy.costlyCableConnection = tMainConfig.get("general", "CableConnectionRequiresSolderingMaterial", false).getBoolean(false); - GT_LanguageManager.i18nPlaceholder = tMainConfig.get("general", "EnablePlaceholderForMaterialNamesInLangFile", true).getBoolean(true); - GT_MetaTileEntity_LongDistancePipelineBase.minimalDistancePoints = tMainConfig.get("general", "LongDistancePipelineMinimalDistancePoints", 64).getInt(64); - - GregTech_API.mUseOnlyGoodSolderingMaterials = GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.harderrecipes, "useonlygoodsolderingmaterials", GregTech_API.mUseOnlyGoodSolderingMaterials); - gregtechproxy.mChangeHarvestLevels = GregTech_API.sMaterialProperties.get("havestLevel", "activateHarvestLevelChange", false);//TODO CHECK - if (gregtechproxy.mChangeHarvestLevels) { - gregtechproxy.mGraniteHavestLevel = GregTech_API.sMaterialProperties.get("havestLevel", "graniteHarvestLevel", 3); - gregtechproxy.mMaxHarvestLevel = Math.min(15, GregTech_API.sMaterialProperties.get("havestLevel", "maxLevel", 7)); - Materials.getMaterialsMap().values().parallelStream().filter(tMaterial -> tMaterial != null && tMaterial.mToolQuality > 0 && tMaterial.mMetaItemSubID < gregtechproxy.mHarvestLevel.length && tMaterial.mMetaItemSubID >= 0).forEach( - tMaterial -> gregtechproxy.mHarvestLevel[tMaterial.mMetaItemSubID] = GregTech_API.sMaterialProperties.get("materialHavestLevel", tMaterial.mDefaultLocalName, tMaterial.mToolQuality) - ); - } - - if (tMainConfig.get("general", "hardermobspawners", true).getBoolean(true)) { - Blocks.mob_spawner.setHardness(500.0F).setResistance(6000000.0F); - } - gregtechproxy.mOnline = tMainConfig.get(aTextGeneral, "online", true).getBoolean(false); - - gregtechproxy.mUpgradeCount = Math.min(64, Math.max(1, tMainConfig.get("features", "UpgradeStacksize", 4).getInt())); - for (OrePrefixes tPrefix : OrePrefixes.values()) { - if (tPrefix.mIsUsedForOreProcessing) { - tPrefix.mDefaultStackSize = ((byte) Math.min(64, Math.max(1, tMainConfig.get("features", "MaxOreStackSize", 64).getInt()))); - } else if (tPrefix == OrePrefixes.plank) { - tPrefix.mDefaultStackSize = ((byte) Math.min(64, Math.max(16, tMainConfig.get("features", "MaxPlankStackSize", 64).getInt()))); - } else if ((tPrefix == OrePrefixes.wood) || (tPrefix == OrePrefixes.treeLeaves) || (tPrefix == OrePrefixes.treeSapling) || (tPrefix == OrePrefixes.log)) { - tPrefix.mDefaultStackSize = ((byte) Math.min(64, Math.max(16, tMainConfig.get("features", "MaxLogStackSize", 64).getInt()))); - } else if (tPrefix.mIsUsedForBlocks) { - tPrefix.mDefaultStackSize = ((byte) Math.min(64, Math.max(16, tMainConfig.get("features", "MaxOtherBlockStackSize", 64).getInt()))); - } - } + GT_PreLoad.loadConfig(tMainConfig); new Enchantment_EnderDamage(); new Enchantment_Radioactivity(); - //GT_Config.troll = (Calendar.getInstance().get(2) + 1 == 4) && (Calendar.getInstance().get(5) >= 1) && (Calendar.getInstance().get(5) <= 2); Materials.init(); GT_Log.out.println("GT_Mod: Saving Main Config"); tMainConfig.save(); - GT_Log.out.println("GT_Mod: Generating Lang-File"); - GT_LanguageManager.sEnglishFile = new Configuration(new File(aEvent.getModConfigurationDirectory().getParentFile(), "GregTech.lang")); - GT_LanguageManager.sEnglishFile.load(); - if (GT_LanguageManager.sEnglishFile.get("EnableLangFile", "UseThisFileAsLanguageFile", false).getBoolean(false)) { - GT_LanguageManager.sLanguage = GT_LanguageManager.sEnglishFile.get("EnableLangFile", "Language", "en_US").getString(); - } - - Materials.getMaterialsMap().values().parallelStream().filter(Objects::nonNull).forEach(aMaterial -> aMaterial.mLocalizedName = GT_LanguageManager.addStringLocalization("Material." + aMaterial.mName.toLowerCase(), aMaterial.mDefaultLocalName)); - - GT_Log.out.println("GT_Mod: Removing all original Scrapbox Drops."); - try { - GT_Utility.getField("ic2.core.item.ItemScrapbox$Drop", "topChance", true, true).set(null, 0); - ((List) GT_Utility.getFieldContent(GT_Utility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true), "drops", true, true)).clear(); - } catch (Throwable e) { - if (GT_Values.D1) { - e.printStackTrace(GT_Log.err); - } - } - GT_Log.out.println("GT_Mod: Adding Scrap with a Weight of 200.0F to the Scrapbox Drops."); - GT_ModHandler.addScrapboxDrop(200.0F, GT_ModHandler.getIC2Item("scrap", 1L)); + GT_PreLoad.initLocalization(aEvent.getModConfigurationDirectory().getParentFile()); + GT_PreLoad.adjustScrap(); EntityRegistry.registerModEntity(GT_Entity_Arrow.class, "GT_Entity_Arrow", 1, GT_Values.GT, 160, 1, true); EntityRegistry.registerModEntity(GT_Entity_Arrow_Potion.class, "GT_Entity_Arrow_Potion", 2, GT_Values.GT, 160, 1, true); - GT_FML_LOGGER.info("preReader"); - List<String> oreTags = new ArrayList<>(); - if (Loader.isModLoaded("MineTweaker3")) { - File globalDir = new File("scripts"); - if (globalDir.exists()) { - List<String> scripts = new ArrayList<>(); - for (File file : globalDir.listFiles()) { - if (file.getName().endsWith(".zs")) { - try (BufferedReader br = new BufferedReader(new FileReader(file))) { - String line; - while ((line = br.readLine()) != null) { - scripts.add(line); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - String pattern1 = "<"; - String pattern2 = ">"; - - Pattern p = Pattern.compile(Pattern.quote(pattern1) + "(.*?)" + Pattern.quote(pattern2)); - for (String text : scripts) { - Matcher m = p.matcher(text); - while (m.find()) { - String hit = m.group(1); - if (hit.startsWith("ore:")) { - hit = hit.substring(4); - if (!oreTags.contains(hit)) oreTags.add(hit); - } else if (hit.startsWith("gregtech:gt.metaitem.0")) { - hit = hit.substring(22); - int mIt = Integer.parseInt(hit.substring(0, 1)); - if (mIt > 0) { - int meta = 0; - try { - hit = hit.substring(2); - meta = Integer.parseInt(hit); - } catch (Exception e) { - GT_FML_LOGGER.info("parseError: " + hit); - } - if (meta > 0 && meta < 32000) { - int prefix = meta / 1000; - int material = meta % 1000; - String tag = ""; - String[] tags = new String[]{}; - if (mIt == 1) - tags = new String[]{"dustTiny", "dustSmall", "dust", "dustImpure", "dustPure", "crushed", "crushedPurified", "crushedCentrifuged", "gem", "nugget", null, "ingot", "ingotHot", "ingotDouble", "ingotTriple", "ingotQuadruple", "ingotQuintuple", "plate", "plateDouble", "plateTriple", "plateQuadruple", "plateQuintuple", "plateDense", "stick", "lens", "round", "bolt", "screw", "ring", "foil", "cell", "cellPlasma", "cellMolten"}; - if (mIt == 2) - tags = new String[]{"toolHeadSword", "toolHeadPickaxe", "toolHeadShovel", "toolHeadAxe", "toolHeadHoe", "toolHeadHammer", "toolHeadFile", "toolHeadSaw", "toolHeadDrill", "toolHeadChainsaw", "toolHeadWrench", "toolHeadUniversalSpade", "toolHeadSense", "toolHeadPlow", "toolHeadArrow", "toolHeadBuzzSaw", "turbineBlade", null, null, "wireFine", "gearGtSmall", "rotor", "stickLong", "springSmall", "spring", "arrowGtWood", "arrowGtPlastic", "gemChipped", "gemFlawed", "gemFlawless", "gemExquisite", "gearGt"}; - if (mIt == 3) - tags = new String[]{"crateGtDust", "crateGtIngot", "crateGtGem", "crateGtPlate", "itemCasing"}; - if (tags.length > prefix) tag = tags[prefix]; - if (GregTech_API.sGeneratedMaterials[material] != null) { - tag += GregTech_API.sGeneratedMaterials[material].mName; - if (!oreTags.contains(tag)) oreTags.add(tag); - } else if (material > 0) { - GT_FML_LOGGER.info("MaterialDisabled: " + material + " " + m.group(1)); - } - } - } - } - } - } - } - } - String[] preS = new String[]{"dustTiny", "dustSmall", "dust", "dustImpure", "dustPure", "crushed", "crushedPurified", "crushedCentrifuged", "gem", "nugget", "ingot", "ingotHot", "ingotDouble", "ingotTriple", "ingotQuadruple", "ingotQuintuple", "plate", "plateDouble", "plateTriple", "plateQuadruple", "plateQuintuple", "plateDense", "stick", "lens", "round", "bolt", "screw", "ring", "foil", "cell", "cellPlasma", "toolHeadSword", "toolHeadPickaxe", "toolHeadShovel", "toolHeadAxe", "toolHeadHoe", "toolHeadHammer", "toolHeadFile", "toolHeadSaw", "toolHeadDrill", "toolHeadChainsaw", "toolHeadWrench", "toolHeadUniversalSpade", "toolHeadSense", "toolHeadPlow", "toolHeadArrow", "toolHeadBuzzSaw", "turbineBlade", "wireFine", "gearGtSmall", "rotor", "stickLong", "springSmall", "spring", "arrowGtWood", "arrowGtPlastic", "gemChipped", "gemFlawed", "gemFlawless", "gemExquisite", "gearGt", "crateGtDust", "crateGtIngot", "crateGtGem", "crateGtPlate", "cellMolten"}; - - List<String> mMTTags = new ArrayList<>(); - oreTags.stream() - .filter(test -> StringUtils.startsWithAny(test, preS)) - .forEach(test -> { - mMTTags.add(test); - if (GT_Values.D1) - GT_FML_LOGGER.info("oretag: " + test); - }); - - GT_FML_LOGGER.info("reenableMetaItems"); - - for (String reEnable : mMTTags) { - OrePrefixes tPrefix = OrePrefixes.getOrePrefix(reEnable); - if (tPrefix != null) { - Materials tName = Materials.get(reEnable.replaceFirst(tPrefix.toString(), "")); - if (tName != null) { - tPrefix.mDisabledItems.remove(tName); - tPrefix.mGeneratedItems.add(tName); - if (tPrefix == OrePrefixes.screw) { - OrePrefixes.bolt.mDisabledItems.remove(tName); - OrePrefixes.bolt.mGeneratedItems.add(tName); - OrePrefixes.stick.mDisabledItems.remove(tName); - OrePrefixes.stick.mGeneratedItems.add(tName); - } - if (tPrefix == OrePrefixes.round) { - OrePrefixes.nugget.mDisabledItems.remove(tName); - OrePrefixes.nugget.mGeneratedItems.add(tName); - } - if (tPrefix == OrePrefixes.spring) { - OrePrefixes.stickLong.mDisabledItems.remove(tName); - OrePrefixes.stickLong.mGeneratedItems.add(tName); - OrePrefixes.stick.mDisabledItems.remove(tName); - OrePrefixes.stick.mGeneratedItems.add(tName); - } - if (tPrefix == OrePrefixes.springSmall) { - OrePrefixes.stick.mDisabledItems.remove(tName); - OrePrefixes.stick.mGeneratedItems.add(tName); - } - if (tPrefix == OrePrefixes.stickLong) { - OrePrefixes.stick.mDisabledItems.remove(tName); - OrePrefixes.stick.mGeneratedItems.add(tName); - } - if (tPrefix == OrePrefixes.rotor) { - OrePrefixes.ring.mDisabledItems.remove(tName); - OrePrefixes.ring.mGeneratedItems.add(tName); - } - } else { - GT_FML_LOGGER.info("noMaterial " + reEnable); - } - } else { - GT_FML_LOGGER.info("noPrefix " + reEnable); - } - } + GT_PreLoad.runMineTweakerCompat(); new GT_Loader_OreProcessing().run(); new GT_Loader_OreDictionary().run(); @@ -631,33 +200,8 @@ public class GT_Mod implements IGT_Mod { new GT_CoverBehaviorLoader().run(); new GT_SonictronLoader().run(); new GT_SpawnEventHandler(); - - if (gregtechproxy.mSortToTheEnd) { - try { - GT_Log.out.println("GT_Mod: Sorting GregTech to the end of the Mod List for further processing."); - LoadController tLoadController = (LoadController) GT_Utility.getFieldContent(Loader.instance(), "modController", true, true); - List<ModContainer> tModList = tLoadController.getActiveModList(); - List<ModContainer> tNewModsList = new ArrayList<>(); - ModContainer tGregTech = null; - short tModList_sS = (short) tModList.size(); - for (short i = 0; i < tModList_sS; i = (short) (i + 1)) { - ModContainer tMod = tModList.get(i); - if (tMod.getModId().equalsIgnoreCase("gregtech")) { - tGregTech = tMod; - } else { - tNewModsList.add(tMod); - } - } - if (tGregTech != null) { - tNewModsList.add(tGregTech); - } - GT_Utility.getField(tLoadController, "activeModList", true, true).set(tLoadController, tNewModsList); - } catch (Throwable e) { - if (GT_Values.D1) { - e.printStackTrace(GT_Log.err); - } - } - } + + GT_PreLoad.sortToTheEnd(); GregTech_API.sPreloadFinished = true; GT_Log.out.println("GT_Mod: Preload-Phase finished!"); GT_Log.ore.println("GT_Mod: Preload-Phase finished!"); @@ -691,7 +235,7 @@ public class GT_Mod implements IGT_Mod { if (Loader.isModLoaded(MOD_ID_FR)) new GT_Bees(); - //Disable Low Grav regardless of config if Cleanroom is disabled. + // Disable Low Grav regardless of config if Cleanroom is disabled. if (!gregtechproxy.mEnableCleanroom) { gregtechproxy.mLowGravProcessing = false; } @@ -778,55 +322,10 @@ public class GT_Mod implements IGT_Mod { GT_Log.out.println("GT_Mod: Activating OreDictionary Handler, this can take some time, as it scans the whole OreDictionary"); GT_FML_LOGGER.info("If your Log stops here, you were too impatient. Wait a bit more next time, before killing Minecraft with the Task Manager."); - Stopwatch stopwatch = Stopwatch.createStarted(); - gregtechproxy.activateOreDictHandler(); - GT_FML_LOGGER.info("Congratulations, you have been waiting long enough (" + stopwatch.stop() + "). Have a Cake."); - GT_Log.out.println("GT_Mod: List of Lists of Tool Recipes: " + GT_ModHandler.sSingleNonBlockDamagableRecipeList_list.toString()); - GT_Log.out.println("GT_Mod: Vanilla Recipe List -> Outputs null or stackSize <=0: " + GT_ModHandler.sVanillaRecipeList_warntOutput.toString()); - GT_Log.out.println("GT_Mod: Single Non Block Damagable Recipe List -> Outputs null or stackSize <=0: " + GT_ModHandler.sSingleNonBlockDamagableRecipeList_warntOutput.toString()); - - Set<Materials> replaceVanillaItemsSet = gregtechproxy.mUseGreatlyShrukenReplacementList ? Arrays.stream(Materials.values()).filter(GT_RecipeRegistrator::hasVanillaRecipes).collect(Collectors.toSet()) : new HashSet<>(Arrays.asList(Materials.values())); - - stopwatch.reset(); - stopwatch.start(); - GT_FML_LOGGER.info("Replacing Vanilla Materials in recipes, please wait."); + GT_PostLoad.activateOreDictHandler(); + GT_PostLoad.replaceVanillaMaterials(); + GT_PostLoad.removeIc2Recipes(aMaceratorRecipeList, aCompressorRecipeList, aExtractorRecipeList, aOreWashingRecipeList, aThermalCentrifugeRecipeList); - ProgressManager.ProgressBar progressBar = ProgressManager.push("Register materials", replaceVanillaItemsSet.size()); - if (GT_Values.cls_enabled){ - try { - GT_CLS_Compat.doActualRegistrationCLS(progressBar,replaceVanillaItemsSet); - GT_CLS_Compat.pushToDisplayProgress(); - } catch (InvocationTargetException | IllegalAccessException e) { - GT_Mod.GT_FML_LOGGER.catching(e); - } - } - else { - replaceVanillaItemsSet.forEach(m -> { - progressBar.step(m.mDefaultLocalName); - doActualRegistration(m); - }); - } - ProgressManager.pop(progressBar); - GT_FML_LOGGER.info("Replaced Vanilla Materials (" + stopwatch.stop() + "). Have a Cake."); - - - stopwatch.reset(); - stopwatch.start(); - // remove gemIridium exploit - ItemStack iridiumOre = GT_ModHandler.getIC2Item("iridiumOre", 1); - aCompressorRecipeList.entrySet().parallelStream() - .filter(e -> e.getKey().getInputs().size() == 1 && e.getKey().getInputs().get(0).isItemEqual(iridiumOre)) - .findAny() - .ifPresent(e -> aCompressorRecipeList.remove(e.getKey())); - //Add default IC2 recipe to GT - GT_ModHandler.addIC2RecipesToGT(aMaceratorRecipeList, GT_Recipe.GT_Recipe_Map.sMaceratorRecipes, true, true, true); - GT_ModHandler.addIC2RecipesToGT(aCompressorRecipeList, GT_Recipe.GT_Recipe_Map.sCompressorRecipes, true, true, true); - GT_ModHandler.addIC2RecipesToGT(aExtractorRecipeList, GT_Recipe.GT_Recipe_Map.sExtractorRecipes, true, true, true); - GT_ModHandler.addIC2RecipesToGT(aOreWashingRecipeList, GT_Recipe.GT_Recipe_Map.sOreWasherRecipes, false, true, true); - GT_ModHandler.addIC2RecipesToGT(aThermalCentrifugeRecipeList, GT_Recipe.GT_Recipe_Map.sThermalCentrifugeRecipes, true, true, true); - GT_FML_LOGGER.info("IC2 Removal (" + stopwatch.stop() + "). Have a Cake."); - - if (GT_Values.D1) { GT_ModHandler.sSingleNonBlockDamagableRecipeList.forEach(iRecipe -> GT_Log.out.println("=> " + iRecipe.getRecipeOutput().getDisplayName())); } @@ -836,17 +335,8 @@ public class GT_Mod implements IGT_Mod { } GT_ModHandler.removeRecipeByOutput(GT_ModHandler.getIC2Item("machine", 1L)); GT_ModHandler.addCraftingRecipe(GT_ModHandler.getIC2Item("machine", 1L), GT_ModHandler.RecipeBits.BUFFERED | GT_ModHandler.RecipeBits.NOT_REMOVABLE | GT_ModHandler.RecipeBits.REVERSIBLE, new Object[]{"RRR", "RwR", "RRR", 'R', OrePrefixes.plate.get(Materials.Iron)}); - ItemStack ISdata0 = new ItemStack(Items.potionitem, 1, 0); - ItemStack ILdata0 = ItemList.Bottle_Empty.get(1L); - for (FluidContainerRegistry.FluidContainerData tData : FluidContainerRegistry.getRegisteredFluidContainerData()) { - if ((tData.filledContainer.getItem() == Items.potionitem) && (tData.filledContainer.getItemDamage() == 0)) { - GT_Recipe.GT_Recipe_Map.sFluidCannerRecipes.addRecipe(true, new ItemStack[]{ILdata0}, new ItemStack[]{ISdata0}, null, new FluidStack[]{Materials.Water.getFluid(250L)}, null, 4, 1, 0); - GT_Recipe.GT_Recipe_Map.sFluidCannerRecipes.addRecipe(true, new ItemStack[]{ISdata0}, new ItemStack[]{ILdata0}, null, null, null, 4, 1, 0); - } else { - GT_Recipe.GT_Recipe_Map.sFluidCannerRecipes.addRecipe(true, new ItemStack[]{tData.emptyContainer}, new ItemStack[]{tData.filledContainer}, null, new FluidStack[]{tData.fluid}, null, tData.fluid.amount / 62, 1, 0); - GT_Recipe.GT_Recipe_Map.sFluidCannerRecipes.addRecipe(true, new ItemStack[]{tData.filledContainer}, new ItemStack[]{GT_Utility.getContainerItem(tData.filledContainer, true)}, null, null, new FluidStack[]{tData.fluid}, tData.fluid.amount / 62, 1, 0); - } - } + + GT_PostLoad.registerFluidCannerRecipes(); if (Loader.isModLoaded(MOD_ID_FR)) { GT_Forestry_Compat.transferCentrifugeRecipes(); @@ -862,40 +352,9 @@ public class GT_Mod implements IGT_Mod { }) .filter(tName -> GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.disabledrecipes, aTextIC2 + tName, true)) .map(tName -> GT_ModHandler.getIC2Item(tName, 1L)).forEach(GT_ModHandler::removeRecipeByOutputDelayed); - - if (gregtechproxy.mNerfedVanillaTools) { - GT_Log.out.println("GT_Mod: Nerfing Vanilla Tool Durability"); - Items.wooden_sword.setMaxDamage(12); - Items.wooden_pickaxe.setMaxDamage(12); - Items.wooden_shovel.setMaxDamage(12); - Items.wooden_axe.setMaxDamage(12); - Items.wooden_hoe.setMaxDamage(12); - - Items.stone_sword.setMaxDamage(48); - Items.stone_pickaxe.setMaxDamage(48); - Items.stone_shovel.setMaxDamage(48); - Items.stone_axe.setMaxDamage(48); - Items.stone_hoe.setMaxDamage(48); - - Items.iron_sword.setMaxDamage(256); - Items.iron_pickaxe.setMaxDamage(256); - Items.iron_shovel.setMaxDamage(256); - Items.iron_axe.setMaxDamage(256); - Items.iron_hoe.setMaxDamage(256); - - Items.golden_sword.setMaxDamage(24); - Items.golden_pickaxe.setMaxDamage(24); - Items.golden_shovel.setMaxDamage(24); - Items.golden_axe.setMaxDamage(24); - Items.golden_hoe.setMaxDamage(24); - - Items.diamond_sword.setMaxDamage(768); - Items.diamond_pickaxe.setMaxDamage(768); - Items.diamond_shovel.setMaxDamage(768); - Items.diamond_axe.setMaxDamage(768); - Items.diamond_hoe.setMaxDamage(768); - } + + GT_PostLoad.nerfVanillaTools(); new GT_ExtremeDieselFuelLoader().run(); @@ -905,8 +364,7 @@ public class GT_Mod implements IGT_Mod { * modifications. */ - stopwatch.reset(); - stopwatch.start(); + Stopwatch stopwatch = Stopwatch.createStarted(); GT_Log.out.println("GT_Mod: Adding buffered Recipes."); GT_ModHandler.stopBufferingCraftingRecipes(); GT_FML_LOGGER.info("Executed delayed Crafting Recipes (" + stopwatch.stop() + "). Have a Cake."); @@ -923,57 +381,7 @@ public class GT_Mod implements IGT_Mod { e.printStackTrace(GT_Log.err); } } - GT_Log.out.println("GT_Mod: Adding Fake Recipes for NEI"); - - if (Loader.isModLoaded(MOD_ID_FR)) - GT_Forestry_Compat.populateFakeNeiRecipes(); - - if (ItemList.IC2_Crop_Seeds.get(1L) != null) { - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{ItemList.IC2_Crop_Seeds.getWildcard(1L)}, new ItemStack[]{ItemList.IC2_Crop_Seeds.getWithName(1L, "Scanned Seeds")}, null, null, null, 160, 8, 0); - } - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{new ItemStack(Items.written_book, 1, 32767)}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Scanned Book Data")}, ItemList.Tool_DataStick.getWithName(1L, "Stick to save it to"), null, null, 128, 30, 0); - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{new ItemStack(Items.filled_map, 1, 32767)}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Scanned Map Data")}, ItemList.Tool_DataStick.getWithName(1L, "Stick to save it to"), null, null, 128, 30, 0); - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{ItemList.Tool_DataOrb.getWithName(1L, "Orb to overwrite")}, new ItemStack[]{ItemList.Tool_DataOrb.getWithName(1L, "Copy of the Orb")}, ItemList.Tool_DataOrb.getWithName(0L, "Orb to copy"), null, null, 512, 30, 0); - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Stick to overwrite")}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Copy of the Stick")}, ItemList.Tool_DataStick.getWithName(0L, "Stick to copy"), null, null, 128, 30, 0); - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Raw Prospection Data")}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Analyzed Prospection Data")}, null, null, null, 1000, 30, 0); - if (Loader.isModLoaded("GalacticraftCore")) { - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{GT_ModHandler.getModItem("GalacticraftCore", "item.schematic", 1, Short.MAX_VALUE).setStackDisplayName("Any Schematic")}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Scanned Schematic")}, ItemList.Tool_DataStick.getWithName(1L, "Stick to save it to"), null, null, 36000, 480, 0); - if (Loader.isModLoaded("GalacticraftMars")) - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{GT_ModHandler.getModItem("GalacticraftMars", "item.schematic", 1, Short.MAX_VALUE).setStackDisplayName("Any Schematic")}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Scanned Schematic")}, ItemList.Tool_DataStick.getWithName(1L, "Stick to save it to"), null, null, 36000, 480, 0); - if (Loader.isModLoaded("GalaxySpace")) { - for (int i = 4; i < 9; i++) { - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{GT_ModHandler.getModItem("GalaxySpace", "item.SchematicTier" + i, 1).setStackDisplayName("Any Schematic")}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Scanned Schematic")}, ItemList.Tool_DataStick.getWithName(1L, "Stick to save it to"), null, null, 36000, 480, 0); - } - } - } - Materials.getMaterialsMap().values().stream().forEach(tMaterial -> { - if ((tMaterial.mElement != null) && (!tMaterial.mElement.mIsIsotope) && (tMaterial != Materials.Magic) && (tMaterial.getMass() > 0L)) { - ItemStack tOutput = ItemList.Tool_DataOrb.get(1L); - Behaviour_DataOrb.setDataTitle(tOutput, "Elemental-Scan"); - Behaviour_DataOrb.setDataName(tOutput, tMaterial.mElement.name()); - ItemStack tInput = GT_OreDictUnificator.get(OrePrefixes.dust, tMaterial, 1L); - ItemStack[] ISmat0 = new ItemStack[]{tInput}; - ItemStack[] ISmat1 = new ItemStack[]{tOutput}; - if (tInput != null) { - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, ISmat0, ISmat1, ItemList.Tool_DataOrb.get(1L), null, null, (int) (tMaterial.getMass() * 8192L), 30, 0); - GT_Recipe.GT_Recipe_Map.sReplicatorFakeRecipes.addFakeRecipe(false, null, ISmat0, ISmat1, new FluidStack[]{Materials.UUMatter.getFluid(tMaterial.getMass())}, null, (int) (tMaterial.getMass() * 512L), 30, 0); - - } - tInput = GT_OreDictUnificator.get(OrePrefixes.cell, tMaterial, 1L); - ISmat0 = new ItemStack[]{tInput}; - if (tInput != null) { - GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, ISmat0, ISmat1, ItemList.Tool_DataOrb.get(1L), null, null, (int) (tMaterial.getMass() * 8192L), 30, 0); - GT_Recipe.GT_Recipe_Map.sReplicatorFakeRecipes.addFakeRecipe(false, null, ISmat0, ISmat1, new FluidStack[]{Materials.UUMatter.getFluid(tMaterial.getMass())}, null, (int) (tMaterial.getMass() * 512L), 30, 0); - } - } - }); - - if (!GT_MetaTileEntity_Massfabricator.sRequiresUUA) - GT_Recipe.GT_Recipe_Map.sMassFabFakeRecipes.addFakeRecipe(false, null, null, null, null, new FluidStack[]{Materials.UUMatter.getFluid(1L)}, GT_MetaTileEntity_Massfabricator.sDurationMultiplier, 256, 0); - GT_Recipe.GT_Recipe_Map.sMassFabFakeRecipes.addFakeRecipe(false, null, null, null, new FluidStack[]{Materials.UUAmplifier.getFluid(GT_MetaTileEntity_Massfabricator.sUUAperUUM)}, new FluidStack[]{Materials.UUMatter.getFluid(1L)}, GT_MetaTileEntity_Massfabricator.sDurationMultiplier / GT_MetaTileEntity_Massfabricator.sUUASpeedBonus, 256, 0); - GT_Recipe.GT_Recipe_Map.sRockBreakerFakeRecipes.addFakeRecipe(false, new ItemStack[]{ItemList.Display_ITS_FREE.getWithName(0L, "Place Lava on Side")}, new ItemStack[]{new ItemStack(Blocks.cobblestone, 1)}, null, null, null, 16, 30, 0); - GT_Recipe.GT_Recipe_Map.sRockBreakerFakeRecipes.addFakeRecipe(false, new ItemStack[]{ItemList.Display_ITS_FREE.getWithName(0L, "Place Lava on Top")}, new ItemStack[]{new ItemStack(Blocks.stone, 1)}, null, null, null, 16, 30, 0); - GT_Recipe.GT_Recipe_Map.sRockBreakerFakeRecipes.addFakeRecipe(false, new ItemStack[]{GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Redstone, 1L)}, new ItemStack[]{new ItemStack(Blocks.obsidian, 1)}, null, null, null, 128, 30, 0); + GT_PostLoad.addFakeRecipes(); if (GregTech_API.mOutputRF || GregTech_API.mInputRF) { GT_Utility.checkAvailabilities(); @@ -983,8 +391,8 @@ public class GT_Mod implements IGT_Mod { } } - addSolidFakeLargeBoilerFuels(); - identifyAnySteam(); + GT_PostLoad.addSolidFakeLargeBoilerFuels(); + GT_PostLoad.identifyAnySteam(); achievements = new GT_Achievements(); @@ -992,56 +400,15 @@ public class GT_Mod implements IGT_Mod { ReverseShapelessRecipe.runReverseRecipes(); GT_Recipe.GTppRecipeHelper = true; - GT_Log.out.println("GT_Mod: Loading finished, deallocating temporary Init Variables."); + GT_Log.out.println("GT_Mod: Loading finished, de-allocating temporary Init Variables."); GregTech_API.sBeforeGTPreload = null; GregTech_API.sAfterGTPreload = null; GregTech_API.sBeforeGTLoad = null; GregTech_API.sAfterGTLoad = null; GregTech_API.sBeforeGTPostload = null; GregTech_API.sAfterGTPostload = null; - - - CreativeTabs mainTab = new CreativeTabs("GTtools") { - @SideOnly(Side.CLIENT) - @Override - public ItemStack getIconItemStack() { - return ItemList.Tool_Cheat.get(1, new ItemStack(Blocks.iron_block, 1)); - } - - @SideOnly(Side.CLIENT) - @Override - public Item getTabIconItem() { - return ItemList.Circuit_Integrated.getItem(); - } - - @Override - public void displayAllReleventItems(List aList) { - for (int i = 0; i < 32766; i += 2) { - if (GT_MetaGenerated_Tool_01.INSTANCE.getToolStats(new ItemStack(GT_MetaGenerated_Tool_01.INSTANCE, 1, i)) != null) { - ItemStack tStack = new ItemStack(GT_MetaGenerated_Tool_01.INSTANCE, 1, i); - GT_MetaGenerated_Tool_01.INSTANCE.isItemStackUsable(tStack); - aList.add(GT_MetaGenerated_Tool_01.INSTANCE.getToolWithStats(i, 1, Materials.Lead, Materials.Lead, null)); - aList.add(GT_MetaGenerated_Tool_01.INSTANCE.getToolWithStats(i, 1, Materials.Nickel, Materials.Nickel, null)); - aList.add(GT_MetaGenerated_Tool_01.INSTANCE.getToolWithStats(i, 1, Materials.Cobalt, Materials.Cobalt, null)); - aList.add(GT_MetaGenerated_Tool_01.INSTANCE.getToolWithStats(i, 1, Materials.Osmium, Materials.Osmium, null)); - aList.add(GT_MetaGenerated_Tool_01.INSTANCE.getToolWithStats(i, 1, Materials.Adamantium, Materials.Adamantium, null)); - aList.add(GT_MetaGenerated_Tool_01.INSTANCE.getToolWithStats(i, 1, Materials.Neutronium, Materials.Neutronium, null)); - } - } - super.displayAllReleventItems(aList); - } - }; - } - - public static void doActualRegistration(Materials m){ - String platename = OrePrefixes.plate.get(m).toString(); - boolean noSmash = !m.contains(SubTag.NO_SMASHING); - if ((m.mTypes & 2) != 0) - GT_RecipeRegistrator.registerUsagesForMaterials(platename, noSmash, m.getIngots(1)); - if ((m.mTypes & 4) != 0) - GT_RecipeRegistrator.registerUsagesForMaterials(platename, noSmash, m.getGems(1)); - if (m.getBlocks(1) != null) - GT_RecipeRegistrator.registerUsagesForMaterials(null, noSmash, m.getBlocks(1)); + + GT_PostLoad.createGTtoolsCreativeTab(); } @Mod.EventHandler @@ -1165,7 +532,7 @@ public class GT_Mod implements IGT_Mod { } aEvent.registerServerCommand(new GT_Command()); - //Sets a new Machine Block Update Thread everytime a world is loaded + // Sets a new Machine Block Update Thread everytime a world is loaded GT_Runnable_MachineBlockUpdate.initExecutorService(); } @@ -1218,72 +585,7 @@ public class GT_Mod implements IGT_Mod { } gregtechproxy.onServerStopping(); - try { - if ((GT_Values.D1) || (GT_Log.out != System.out)) { - GT_Log.out.println("*"); - GT_Log.out.println("Printing List of all registered Objects inside the OreDictionary, now with free extra Sorting:"); - GT_Log.out.println("*"); - GT_Log.out.println("*"); - GT_Log.out.println("*"); - - String[] tList = OreDictionary.getOreNames(); - Arrays.sort(tList); - for (String tOreName : tList) { - int tAmount = OreDictionary.getOres(tOreName).size(); - if (tAmount > 0) { - GT_Log.out.println((tAmount < 10 ? " " : "") + tAmount + "x " + tOreName); - } - } - GT_Log.out.println("*"); - GT_Log.out.println("Printing List of all registered Objects inside the Fluid Registry, now with free extra Sorting:"); - GT_Log.out.println("*"); - GT_Log.out.println("*"); - GT_Log.out.println("*"); - - tList = FluidRegistry.getRegisteredFluids().keySet().toArray(new String[0]); - Arrays.sort(tList); - for (String tFluidName : tList) { - GT_Log.out.println(tFluidName); - } - GT_Log.out.println("*"); - GT_Log.out.println("*"); - GT_Log.out.println("*"); - GT_Log.out.println("Outputting all the Names inside the Biomeslist"); - GT_Log.out.println("*"); - GT_Log.out.println("*"); - GT_Log.out.println("*"); - for (int i = 0; i < BiomeGenBase.getBiomeGenArray().length; i++) { - if (BiomeGenBase.getBiomeGenArray()[i] != null) { - GT_Log.out.println(BiomeGenBase.getBiomeGenArray()[i].biomeID + " = " + BiomeGenBase.getBiomeGenArray()[i].biomeName); - } - } - GT_Log.out.println("*"); - GT_Log.out.println("*"); - GT_Log.out.println("*"); - GT_Log.out.println("Printing List of generatable Materials"); - GT_Log.out.println("*"); - GT_Log.out.println("*"); - GT_Log.out.println("*"); - for (int i = 0; i < GregTech_API.sGeneratedMaterials.length; i++) { - if (GregTech_API.sGeneratedMaterials[i] == null) { - GT_Log.out.println("Index " + i + ":" + null); - } else { - GT_Log.out.println("Index " + i + ":" + GregTech_API.sGeneratedMaterials[i]); - } - } - GT_Log.out.println("*"); - GT_Log.out.println("*"); - GT_Log.out.println("*"); - GT_Log.out.println("END GregTech-Debug"); - GT_Log.out.println("*"); - GT_Log.out.println("*"); - GT_Log.out.println("*"); - } - } catch (Throwable e) { - if (GT_Values.D1) { - e.printStackTrace(GT_Log.err); - } - } + for (Runnable tRunnable : GregTech_API.sAfterGTServerstop) { try { tRunnable.run(); @@ -1295,43 +597,9 @@ public class GT_Mod implements IGT_Mod { GT_Runnable_MachineBlockUpdate.shutdownExecutorService(); } - private void addSolidFakeLargeBoilerFuels() { - GT_Recipe.GT_Recipe_Map.sLargeBoilerFakeFuels.addSolidRecipes( - GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Charcoal, 1), - GT_OreDictUnificator.get(OrePrefixes.gem, Materials.Charcoal, 1), - GT_OreDictUnificator.get(OrePrefixes.block, Materials.Charcoal, 1), - GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Coal, 1), - GT_OreDictUnificator.get(OrePrefixes.gem, Materials.Coal, 1), - GT_OreDictUnificator.get(OrePrefixes.block, Materials.Coal, 1), - GT_OreDictUnificator.get(OrePrefixes.crushed, Materials.Coal, 1), - GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Lignite, 1), - GT_OreDictUnificator.get(OrePrefixes.gem, Materials.Lignite, 1), - GT_OreDictUnificator.get(OrePrefixes.block, Materials.Lignite, 1), - GT_OreDictUnificator.get(OrePrefixes.crushed, Materials.Lignite, 1), - GT_OreDictUnificator.get(OrePrefixes.log, Materials.Wood, 1), - GT_OreDictUnificator.get(OrePrefixes.plank, Materials.Wood, 1), - GT_OreDictUnificator.get(OrePrefixes.stick, Materials.Wood, 1), - GT_OreDictUnificator.get(OrePrefixes.slab, Materials.Wood, 1), - GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 1), - GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Sodium, 1), - GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Lithium, 1), - GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Caesium, 1), - GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Sulfur, 1), - GT_OreDictUnificator.get(ItemList.Block_SSFUEL.get(1)), - GT_OreDictUnificator.get(ItemList.Block_MSSFUEL.get(1)), - GT_OreDictUnificator.get(OrePrefixes.rod, Materials.Blaze, 1)); - if (Loader.isModLoaded("Thaumcraft")) { - GT_Recipe.GT_Recipe_Map.sLargeBoilerFakeFuels.addSolidRecipe(GT_ModHandler.getModItem("Thaumcraft", "ItemResource", 1)); - } - } - - private void identifyAnySteam() { - final String[] steamCandidates = {"steam", "ic2steam"}; - final String[] superHeatedSteamCandidates = {"ic2superheatedsteam"}; - - GT_ModHandler.sAnySteamFluidIDs = Arrays.stream(steamCandidates).map(FluidRegistry::getFluid).filter(Objects::nonNull) - .map(FluidRegistry::getFluidID).collect(Collectors.toList()); - GT_ModHandler.sSuperHeatedSteamFluidIDs = Arrays.stream(superHeatedSteamCandidates).map(FluidRegistry::getFluid).filter(Objects::nonNull) - .map(FluidRegistry::getFluidID).collect(Collectors.toList()); + public static void logStackTrace(Throwable t) { + final StringWriter sw = new StringWriter(); + t.printStackTrace(new PrintWriter(sw)); + GT_FML_LOGGER.error(sw); } } diff --git a/src/main/java/gregtech/api/GregTech_API.java b/src/main/java/gregtech/api/GregTech_API.java index 87b0457f4f..23c4bdade0 100644 --- a/src/main/java/gregtech/api/GregTech_API.java +++ b/src/main/java/gregtech/api/GregTech_API.java @@ -54,9 +54,8 @@ import java.util.Map; import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiFunction; -import java.util.function.UnaryOperator; -import java.util.stream.Collectors; import java.util.function.Predicate; +import java.util.stream.Collectors; import static gregtech.api.enums.GT_Values.B; import static gregtech.api.enums.GT_Values.L; @@ -333,7 +332,7 @@ public class GregTech_API { mOutputRF = false, mInputRF = false, meIOLoaded = false, - mRFExplosions = true, + mRFExplosions = false, mServerStarted = false, mIC2Classic = false, mMagneticraft = false, diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java index 30a5230168..2b67e680a4 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java @@ -1,19 +1,12 @@ package gregtech.api.interfaces.tileentity; import cofh.api.energy.IEnergyReceiver; -import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.util.GT_Utility; -import gregtech.api.util.WorldSpawnedEventBuilder; -import gregtech.common.GT_Pollution; import ic2.api.energy.tile.IEnergySink; -import net.minecraft.init.Blocks; import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import static gregtech.api.enums.GT_Values.V; - /** * Interface for getting Connected to the GregTech Energy Network. * <p/> @@ -84,45 +77,6 @@ public interface IEnergyConnected extends IColoredTileEntity, IHasWorldObjectAnd ((IEnergyReceiver) tTileEntity).receiveEnergy(tDirection, rfOut, false); rUsedAmperes++; } - if (GregTech_API.mRFExplosions && GregTech_API.sMachineExplosions && ((IEnergyReceiver) tTileEntity).getMaxEnergyStored(tDirection) < rfOut * 600L) { - if (rfOut > 32L * GregTech_API.mEUtoRF / 100L) { - int aExplosionPower = rfOut; - float tStrength = - aExplosionPower < V[0] ? 1.0F : - aExplosionPower < V[1] ? 2.0F : - aExplosionPower < V[2] ? 3.0F : - aExplosionPower < V[3] ? 4.0F : - aExplosionPower < V[4] ? 5.0F : - aExplosionPower < V[4] * 2 ? 6.0F : - aExplosionPower < V[5] ? 7.0F : - aExplosionPower < V[6] ? 8.0F : - aExplosionPower < V[7] ? 9.0F : - aExplosionPower < V[8] ? 10.0F : - aExplosionPower < V[8] * 2 ? 11.0F : - aExplosionPower < V[9] ? 12.0F : - aExplosionPower < V[10] ? 13.0F : - aExplosionPower < V[11] ? 14.0F : - aExplosionPower < V[12] ? 15.0F : - aExplosionPower < V[12] * 2 ? 16.0F : - aExplosionPower < V[13] ? 17.0F : - aExplosionPower < V[14] ? 18.0F : - aExplosionPower < V[15] ? 19.0F : 20.0F; - int tX = tTileEntity.xCoord, tY = tTileEntity.yCoord, tZ = tTileEntity.zCoord; - World tWorld = tTileEntity.getWorldObj(); - GT_Utility.sendSoundToPlayers(tWorld, GregTech_API.sSoundList.get(209), 1.0F, -1, tX, tY, tZ); - tWorld.setBlock(tX, tY, tZ, Blocks.air); - if (GregTech_API.sMachineExplosions) - if (GT_Mod.gregtechproxy.mPollution) - GT_Pollution.addPollution(tWorld.getChunkFromBlockCoords(tX, tZ), GT_Mod.gregtechproxy.mPollutionOnExplosion); - - new WorldSpawnedEventBuilder.ExplosionEffectEventBuilder() - .setStrength(tStrength) - .setSmoking(true) - .setPosition(tX + 0.5, tY + 0.5, tZ + 0.5) - .setWorld(tWorld) - .run(); - } - } } } } diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java index e9e229e6a0..bd060d9ae8 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java @@ -2,7 +2,6 @@ package gregtech.api.metatileentity; import static gregtech.GT_Mod.GT_FML_LOGGER; import static gregtech.api.enums.GT_Values.NW; -import static gregtech.api.metatileentity.BaseMetaTileEntity.COVER_DATA_NBT_KEYS; import java.util.ArrayList; import java.util.Arrays; @@ -22,24 +21,19 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.interfaces.tileentity.IPipeRenderedTileEntity; import gregtech.api.net.GT_Packet_TileEntity; import gregtech.api.objects.GT_ItemStack; -import gregtech.api.util.GT_CoverBehavior; -import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; import gregtech.common.GT_Client; -import gregtech.common.covers.GT_Cover_Fluidfilter; import net.minecraft.block.Block; import net.minecraft.entity.Entity; -import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; import net.minecraft.network.Packet; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.EnumChatFormatting; @@ -52,19 +46,15 @@ import net.minecraftforge.fluids.*; * <p/> * This is the main TileEntity for EVERYTHING. */ -public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileEntity, IPipeRenderedTileEntity { - private final GT_CoverBehaviorBase<?>[] mCoverBehaviors = new GT_CoverBehaviorBase<?>[]{GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior}; +public class BaseMetaPipeEntity extends CoverableGregTechTileEntity implements IGregTechTileEntity, IPipeRenderedTileEntity { public byte mConnections = IConnectable.NO_CONNECTION; protected MetaPipeEntity mMetaTileEntity; private byte[] mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; - private int[] mCoverSides = new int[]{0, 0, 0, 0, 0, 0}, mTimeStatistics = new int[GregTech_API.TICKS_FOR_LAG_AVERAGING]; - private ISerializableObject[] mCoverData = new ISerializableObject[6]; + private int[] mTimeStatistics = new int[GregTech_API.TICKS_FOR_LAG_AVERAGING]; private boolean mInventoryChanged = false, mWorkUpdate = false, mWorks = true, mNeedsUpdate = true, mNeedsBlockUpdate = true, mSendClientData = false; private final boolean mCheckConnections = false; private byte mColor = 0, oColor = 0, mStrongRedstone = 0, oStrongRedstone = 0, oRedstoneData = 63, oTextureData = 0, oUpdateData = 0, mLagWarningCount = 0; private int oX = 0, oY = 0, oZ = 0, mTimeStatisticsIndex = 0; - private short mID = 0; - private long mTickTimer = 0; protected Node node; protected NodePath nodePath; @@ -98,11 +88,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE } try { aNBT.setInteger("mID", mID); - for (int i = 0; i < mCoverData.length; i++) { - if (mCoverSides[i] != 0 && mCoverData[i] != null) - aNBT.setTag(COVER_DATA_NBT_KEYS[i], mCoverData[i].saveDataToNBT()); - } - aNBT.setIntArray("mCoverSides", mCoverSides); + saveCoverNBT(aNBT); aNBT.setByteArray("mRedstoneSided", mSidedRedstone); aNBT.setByte("mConnections", mConnections); aNBT.setByte("mColor", mColor); @@ -112,31 +98,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk would've been corrupted by now, but I prevented that. Please report immediately to GregTech Intergalactical!!!"); e.printStackTrace(GT_Log.err); } - try { - if (hasValidMetaTileEntity()) { - NBTTagList tItemList = new NBTTagList(); - for (int i = 0; i < mMetaTileEntity.getRealInventory().length; i++) { - ItemStack tStack = mMetaTileEntity.getRealInventory()[i]; - if (tStack != null) { - NBTTagCompound tTag = new NBTTagCompound(); - tTag.setInteger("IntSlot", i); - tStack.writeToNBT(tTag); - tItemList.appendTag(tTag); - } - } - aNBT.setTag("Inventory", tItemList); - - try { - mMetaTileEntity.saveNBTData(aNBT); - } catch (Throwable e) { - GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk whould've been corrupted by now, but I prevented that. Please report immediately to GregTech Intergalactical!!!"); - e.printStackTrace(GT_Log.err); - } - } - } catch (Throwable e) { - GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk whould've been corrupted by now, but I prevented that. Please report immediately to GregTech Intergalactical!!!"); - e.printStackTrace(GT_Log.err); - } + saveMetaTileNBT(aNBT); } @Override @@ -154,74 +116,17 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE } else { if (aID <= 0) mID = (short) aNBT.getInteger("mID"); else mID = aID; - mCoverSides = aNBT.getIntArray("mCoverSides"); mSidedRedstone = aNBT.getByteArray("mRedstoneSided"); mConnections = aNBT.getByte("mConnections"); mColor = aNBT.getByte("mColor"); mStrongRedstone = aNBT.getByte("mStrongRedstone"); mWorks = !aNBT.getBoolean("mWorks"); - if (mCoverSides.length != 6) mCoverSides = new int[]{0, 0, 0, 0, 0, 0}; if (mSidedRedstone.length != 6) mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; - for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); - - // check old form of data - mCoverData = new ISerializableObject[6]; - if (aNBT.hasKey("mCoverData", 11) && aNBT.getIntArray("mCoverData").length == 6) { - int[] tOldData = aNBT.getIntArray("mCoverData"); - for (int i = 0; i < tOldData.length; i++) { - if(mCoverBehaviors[i] instanceof GT_Cover_Fluidfilter) { - final String filterKey = String.format("fluidFilter%d", i); - if (aNBT.hasKey(filterKey)) { - mCoverData[i] = mCoverBehaviors[i].createDataObject((tOldData[i] & 7) | (FluidRegistry.getFluidID(aNBT.getString(filterKey)) << 3)); - } - } else if (mCoverBehaviors[i] != null && mCoverBehaviors[i] != GregTech_API.sNoBehavior) { - mCoverData[i] = mCoverBehaviors[i].createDataObject(tOldData[i]); - } - } - } else { - // no old data - for (byte i = 0; i<6; i++) { - if (mCoverBehaviors[i] == null) - continue; - if (aNBT.hasKey(COVER_DATA_NBT_KEYS[i])) - mCoverData[i] = mCoverBehaviors[i].createDataObject(aNBT.getTag(COVER_DATA_NBT_KEYS[i])); - else - mCoverData[i] = mCoverBehaviors[i].createDataObject(); - } - } - if (mID != 0 && createNewMetatileEntity(mID)) { - NBTTagList tItemList = aNBT.getTagList("Inventory", 10); - for (int i = 0; i < tItemList.tagCount(); i++) { - NBTTagCompound tTag = tItemList.getCompoundTagAt(i); - int tSlot = tTag.getInteger("IntSlot"); - if (tSlot >= 0 && tSlot < mMetaTileEntity.getRealInventory().length) { - mMetaTileEntity.getRealInventory()[tSlot] = GT_Utility.loadItem(tTag); - } - } - - try { - mMetaTileEntity.loadNBTData(aNBT); - } catch (Throwable e) { - GT_Log.err.println("Encountered Exception while loading MetaTileEntity, the Server should've crashed now, but I prevented that. Please report immediately to GregTech Intergalactical!!!"); - e.printStackTrace(GT_Log.err); - } - } - } - } - - private boolean createNewMetatileEntity(short aID) { - if (aID <= 0 || aID >= GregTech_API.METATILEENTITIES.length || GregTech_API.METATILEENTITIES[aID] == null) { - GT_Log.err.println("MetaID " + aID + " not loadable => locking TileEntity!"); - } else { - if (hasValidMetaTileEntity()) mMetaTileEntity.setBaseMetaTileEntity(null); - GregTech_API.METATILEENTITIES[aID].newMetaEntity(this).setBaseMetaTileEntity(this); - mTickTimer = 0; - mID = aID; - return true; + loadCoverNBT(aNBT); + loadMetaTileNBT(aNBT); } - return false; } @Override @@ -234,124 +139,87 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE } long tTime = System.nanoTime(); - int tCode = 0; + try { + if (hasValidMetaTileEntity()) { + if (mTickTimer++ == 0) { + oX = xCoord; + oY = yCoord; + oZ = zCoord; + if (isServerSide()) + checkDropCover(); + worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this); + mMetaTileEntity.onFirstTick(this); + if (!hasValidMetaTileEntity()) return; + } + + if (isClientSide()) { + if (mColor != oColor) { + mMetaTileEntity.onColorChangeClient(oColor = mColor); + issueTextureUpdate(); + } + + if (mNeedsUpdate) { + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + mNeedsUpdate = false; + } + } + if (isServerSide() && mTickTimer > 10) { + if (!doCoverThings()) + return; + + byte oldConnections = mConnections; + // Mask-out connection direction bits to keep only Foam related connections + mConnections = (byte) (mMetaTileEntity.mConnections | (mConnections & ~IConnectable.CONNECTED_ALL)); + // If foam not hardened, tries roll chance to harden + if ((mConnections & IConnectable.HAS_FOAM) == IConnectable.HAS_FRESHFOAM && getRandomNumber(1000) == 0) { + mConnections = (byte) ((mConnections & ~IConnectable.HAS_FRESHFOAM) | IConnectable.HAS_HARDENEDFOAM); + } + if (mTickTimer > 12 && oldConnections != mConnections) + GregTech_API.causeCableUpdate(worldObj, xCoord, yCoord, zCoord); + } + mMetaTileEntity.onPreTick(this, mTickTimer); + if (!hasValidMetaTileEntity()) return; + if (isServerSide()) { + if (mTickTimer == 10) { + updateCoverBehavior(); + issueBlockUpdate(); + joinEnet(); + } - try { for (tCode = 0; hasValidMetaTileEntity() && tCode >= 0; ) { - switch (tCode) { - case 0: - tCode++; - if (mTickTimer++ == 0) { + if (xCoord != oX || yCoord != oY || zCoord != oZ) { oX = xCoord; oY = yCoord; oZ = zCoord; - if (isServerSide()) for (byte i = 0; i < 6; i++) - if (getCoverIDAtSide(i) != 0) - if (!mMetaTileEntity.allowCoverOnSide(i, new GT_ItemStack(getCoverIDAtSide(i)))) - dropCover(i, i, true); - worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this); - mMetaTileEntity.onFirstTick(this); - if (!hasValidMetaTileEntity()) return; + issueClientUpdate(); + clearTileEntityBuffer(); } - case 1: - tCode++; - if (isClientSide()) { - if (mColor != oColor) { - mMetaTileEntity.onColorChangeClient(oColor = mColor); - issueTextureUpdate(); - } + } - if (mNeedsUpdate) { - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - //worldObj.func_147479_m(xCoord, yCoord, zCoord); - mNeedsUpdate = false; - } - } - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - if (isServerSide() && mTickTimer > 10) { - for (byte i = (byte) (tCode - 2); i < 6; i++) - if (getCoverIDAtSide(i) != 0) { - tCode++; - GT_CoverBehaviorBase<?> tCover = getCoverBehaviorAtSideNew(i); - int tCoverTickRate = tCover.getTickRate(i, getCoverIDAtSide(i), mCoverData[i], this); - if (tCoverTickRate > 0 && mTickTimer % tCoverTickRate == 0) { - byte tRedstone = tCover.isRedstoneSensitive(i, getCoverIDAtSide(i), mCoverData[i], this, mTickTimer) ? getInputRedstoneSignal(i) : 0; - mCoverData[i] = tCover.doCoverThings(i, tRedstone, getCoverIDAtSide(i), mCoverData[i], this, mTickTimer); - if (!hasValidMetaTileEntity()) return; - } - } - byte oldConnections = mConnections; - // Mask-out connection direction bits to keep only Foam related connections - mConnections = (byte) (mMetaTileEntity.mConnections | (mConnections & ~IConnectable.CONNECTED_ALL)); - // If foam not hardened, tries roll chance to harden - if ((mConnections & IConnectable.HAS_FOAM) == IConnectable.HAS_FRESHFOAM && getRandomNumber(1000) == 0) { - mConnections = (byte) ((mConnections & ~IConnectable.HAS_FRESHFOAM) | IConnectable.HAS_HARDENEDFOAM); - } - if (mTickTimer > 12 && oldConnections != mConnections) - GregTech_API.causeCableUpdate(worldObj,xCoord,yCoord,zCoord); - } - case 8: - tCode = 9; - mMetaTileEntity.onPreTick(this, mTickTimer); - if (!hasValidMetaTileEntity()) return; - case 9: - tCode++; - if (isServerSide()) { - if (mTickTimer == 10) { - for (byte i = 0; i < 6; i++) - mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); - issueBlockUpdate(); - joinEnet(); - } - - if (xCoord != oX || yCoord != oY || zCoord != oZ) { - oX = xCoord; - oY = yCoord; - oZ = zCoord; - issueClientUpdate(); - clearTileEntityBuffer(); - } - } - case 10: - tCode++; - mMetaTileEntity.onPostTick(this, mTickTimer); - if (!hasValidMetaTileEntity()) return; - case 11: - tCode++; - if (isServerSide()) { - if (mTickTimer % 10 == 0) { - if (mSendClientData) { - NW.sendPacketToAllPlayersInRange(worldObj, new GT_Packet_TileEntity(xCoord, (short) yCoord, zCoord, mID, mCoverSides[0], mCoverSides[1], mCoverSides[2], mCoverSides[3], mCoverSides[4], mCoverSides[5], oTextureData = mConnections, oUpdateData = hasValidMetaTileEntity() ? mMetaTileEntity.getUpdateData() : 0, oRedstoneData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | ((mSidedRedstone[4] > 0) ? 16 : 0) | ((mSidedRedstone[5] > 0) ? 32 : 0)), oColor = mColor), xCoord, zCoord); - mSendClientData = false; - } - } - - if (mTickTimer > 10) { - if (mConnections != oTextureData) sendBlockEvent((byte) 0, oTextureData = mConnections); - byte tData = mMetaTileEntity.getUpdateData(); - if (tData != oUpdateData) sendBlockEvent((byte) 1, oUpdateData = tData); - if (mColor != oColor) sendBlockEvent((byte) 2, oColor = mColor); - tData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | ((mSidedRedstone[4] > 0) ? 16 : 0) | ((mSidedRedstone[5] > 0) ? 32 : 0)); - if (tData != oRedstoneData) sendBlockEvent((byte) 3, oRedstoneData = tData); - } - - if (mNeedsBlockUpdate) { - updateNeighbours(mStrongRedstone, oStrongRedstone); - oStrongRedstone = mStrongRedstone; - mNeedsBlockUpdate = false; - } - } - default: - tCode = -1; - break; + mMetaTileEntity.onPostTick(this, mTickTimer); + if (!hasValidMetaTileEntity()) return; + + if (isServerSide()) { + if (mTickTimer % 10 == 0) { + sendClientData(); + } + + if (mTickTimer > 10) { + if (mConnections != oTextureData) sendBlockEvent((byte) 0, oTextureData = mConnections); + byte tData = mMetaTileEntity.getUpdateData(); + if (tData != oUpdateData) sendBlockEvent((byte) 1, oUpdateData = tData); + if (mColor != oColor) sendBlockEvent((byte) 2, oColor = mColor); + tData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | ((mSidedRedstone[4] > 0) ? 16 : 0) | ((mSidedRedstone[5] > 0) ? 32 : 0)); + if (tData != oRedstoneData) sendBlockEvent((byte) 3, oRedstoneData = tData); + } + + if (mNeedsBlockUpdate) { + updateNeighbours(mStrongRedstone, oStrongRedstone); + oStrongRedstone = mStrongRedstone; + mNeedsBlockUpdate = false; + } + } } - } } catch (Throwable e) { - //GT_Log.err.println("Encountered Exception while ticking MetaTileEntity in Step " + (tCode - 1) + ". The Game should've crashed now, but I prevented that. Please report immidietly to GregTech Intergalactical!!!"); e.printStackTrace(GT_Log.err); } @@ -366,6 +234,21 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE mWorkUpdate = mInventoryChanged = false; } + private void sendClientData() { + if (mSendClientData) { + NW.sendPacketToAllPlayersInRange( + worldObj, + new GT_Packet_TileEntity( + xCoord, (short) yCoord, zCoord, mID, mCoverSides[0], mCoverSides[1], mCoverSides[2], mCoverSides[3], mCoverSides[4], mCoverSides[5], oTextureData = mConnections, + oUpdateData = hasValidMetaTileEntity() ? mMetaTileEntity.getUpdateData() : 0, + oRedstoneData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | ((mSidedRedstone[4] > 0) ? 16 : 0) | ((mSidedRedstone[5] > 0) ? 32 : 0)), + oColor = mColor + ), xCoord, zCoord + ); + mSendClientData = false; + } + } + @Override public Packet getDescriptionPacket() { issueClientUpdate(); @@ -386,10 +269,10 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE setCoverIDAtSide((byte) 4, aCover4); setCoverIDAtSide((byte) 5, aCover5); - receiveClientEvent(0, aTextureData); - receiveClientEvent(1, aUpdateData); - receiveClientEvent(2, aColorData); - receiveClientEvent(3, aRedstoneData); + receiveClientEvent(MetaTileClientEvents.CHANGE_COMMON_DATA, aTextureData); + receiveClientEvent(MetaTileClientEvents.CHANGE_CUSTOM_DATA, aUpdateData); + receiveClientEvent(MetaTileClientEvents.CHANGE_COLOR, aColorData); + receiveClientEvent(MetaTileClientEvents.CHANGE_REDSTONE_OUTPUT, aRedstoneData); } @Override @@ -408,17 +291,17 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE if (isClientSide()) { issueTextureUpdate(); switch (aEventID) { - case 0: + case MetaTileClientEvents.CHANGE_COMMON_DATA: mConnections = (byte) aValue; break; - case 1: + case MetaTileClientEvents.CHANGE_CUSTOM_DATA: if (hasValidMetaTileEntity()) mMetaTileEntity.onValueUpdate((byte) aValue); break; - case 2: + case MetaTileClientEvents.CHANGE_COLOR: if (aValue > 16 || aValue < 0) aValue = 0; mColor = (byte) aValue; break; - case 3: + case MetaTileClientEvents.CHANGE_REDSTONE_OUTPUT: mSidedRedstone[0] = (byte) ((aValue & 1) == 1 ? 15 : 0); mSidedRedstone[1] = (byte) ((aValue & 2) == 2 ? 15 : 0); mSidedRedstone[2] = (byte) ((aValue & 4) == 4 ? 15 : 0); @@ -426,15 +309,15 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE mSidedRedstone[4] = (byte) ((aValue & 16) == 16 ? 15 : 0); mSidedRedstone[5] = (byte) ((aValue & 32) == 32 ? 15 : 0); break; - case 4: + case MetaTileClientEvents.DO_SOUND: if (hasValidMetaTileEntity() && mTickTimer > 20) mMetaTileEntity.doSound((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); break; - case 5: + case MetaTileClientEvents.START_SOUND_LOOP: if (hasValidMetaTileEntity() && mTickTimer > 20) mMetaTileEntity.startSoundLoop((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); break; - case 6: + case MetaTileClientEvents.STOP_SOUND_LOOP: if (hasValidMetaTileEntity() && mTickTimer > 20) mMetaTileEntity.stopSoundLoop((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); break; @@ -852,6 +735,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE return Textures.BlockIcons.ERROR_RENDERING; } + @Override protected boolean hasValidMetaTileEntity() { return mMetaTileEntity != null && mMetaTileEntity.getBaseMetaTileEntity() == this; } @@ -1168,86 +1052,6 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE } @Override - @Deprecated - public GT_CoverBehavior getCoverBehaviorAtSide(byte aSide) { - if (aSide >= 0 && aSide < mCoverBehaviors.length && mCoverBehaviors[aSide] instanceof GT_CoverBehavior) - return (GT_CoverBehavior) mCoverBehaviors[aSide]; - return GregTech_API.sNoBehavior; - } - - @Override - public void setCoverIDAtSide(byte aSide, int aID) { - if (aSide >= 0 && aSide < 6) { - mCoverSides[aSide] = aID; - mCoverBehaviors[aSide] = GregTech_API.getCoverBehaviorNew(aID); - mCoverData[aSide] = mCoverBehaviors[aSide].createDataObject(); - issueCoverUpdate(aSide); - issueBlockUpdate(); - } - } - - @Override - public void setCoverItemAtSide(byte aSide, ItemStack aCover) { - GregTech_API.getCoverBehaviorNew(aCover).placeCover(aSide, aCover, this); - } - - @Override - public int getCoverIDAtSide(byte aSide) { - if (aSide >= 0 && aSide < 6) return mCoverSides[aSide]; - return 0; - } - - @Override - public ItemStack getCoverItemAtSide(byte aSide) { - return GT_Utility.intToStack(getCoverIDAtSide(aSide)); - } - - @Override - public boolean canPlaceCoverIDAtSide(byte aSide, int aID) { - return getCoverIDAtSide(aSide) == 0; - } - - @Override - public boolean canPlaceCoverItemAtSide(byte aSide, ItemStack aCover) { - return getCoverIDAtSide(aSide) == 0; - } - - @Override - @Deprecated - public void setCoverDataAtSide(byte aSide, int aData) { - if (aSide >= 0 && aSide < 6 && mCoverData[aSide] instanceof ISerializableObject.LegacyCoverData) - mCoverData[aSide] = new ISerializableObject.LegacyCoverData(aData); - } - - @Override - @Deprecated - public int getCoverDataAtSide(byte aSide) { - if (aSide >= 0 && aSide < 6 && mCoverData[aSide] instanceof ISerializableObject.LegacyCoverData) - return ((ISerializableObject.LegacyCoverData) mCoverData[aSide]).get(); - return 0; - } - - @Override - public void setCoverDataAtSide(byte aSide, ISerializableObject aData) { - if (aSide >= 0 && aSide < 6 && getCoverBehaviorAtSideNew(aSide) != null && getCoverBehaviorAtSideNew(aSide).cast(aData) != null) - mCoverData[aSide] = aData; - } - - @Override - public ISerializableObject getComplexCoverDataAtSide(byte aSide) { - if (aSide >= 0 && aSide < 6 && getCoverBehaviorAtSideNew(aSide) != null) - return mCoverData[aSide]; - return GregTech_API.sNoBehavior.createDataObject(); - } - - @Override - public GT_CoverBehaviorBase<?> getCoverBehaviorAtSideNew(byte aSide) { - if (aSide >= 0 && aSide < 6) - return mCoverBehaviors[aSide]; - return GregTech_API.sNoBehavior; - } - - @Override public void setLightValue(byte aLightValue) { // } @@ -1263,26 +1067,6 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE } @Override - public boolean dropCover(byte aSide, byte aDroppedSide, boolean aForced) { - if (getCoverBehaviorAtSideNew(aSide).onCoverRemoval(aSide, getCoverIDAtSide(aSide), mCoverData[aSide], this, aForced) || aForced) { - ItemStack tStack = getCoverBehaviorAtSideNew(aSide).getDrop(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this); - if (tStack != null) { - tStack.setTagCompound(null); - EntityItem tEntity = new EntityItem(worldObj, getOffsetX(aDroppedSide, 1) + 0.5, getOffsetY(aDroppedSide, 1) + 0.5, getOffsetZ(aDroppedSide, 1) + 0.5, tStack); - tEntity.motionX = 0; - tEntity.motionY = 0; - tEntity.motionZ = 0; - worldObj.spawnEntityInWorld(tEntity); - } - - setCoverIDAtSide(aSide, 0); - setOutputRedstoneSignal(aSide, (byte) 0); - return true; - } - return false; - } - - @Override public String getOwnerName() { return "Player"; } diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 5de34ccc7c..ddcb9b99cd 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -44,7 +44,6 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; import net.minecraft.network.Packet; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; @@ -77,23 +76,22 @@ import static gregtech.api.objects.XSTR.XSTR_INSTANCE; @Optional.InterfaceList(value = { @Optional.Interface(iface = "appeng.api.networking.security.IActionHost", modid = "appliedenergistics2", striprefs = true), @Optional.Interface(iface = "appeng.me.helpers.IGridProxyable", modid = "appliedenergistics2", striprefs = true)}) -public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileEntity, IActionHost, IGridProxyable, IAlignmentProvider, IConstructableProvider { - static final String[] COVER_DATA_NBT_KEYS = Arrays.stream(ForgeDirection.VALID_DIRECTIONS).mapToInt(Enum::ordinal).mapToObj(i -> "mCoverData" + i).toArray(String[]::new); - private final GT_CoverBehaviorBase<?>[] mCoverBehaviors = new GT_CoverBehaviorBase<?>[]{GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior}; +public class BaseMetaTileEntity extends CoverableGregTechTileEntity implements IGregTechTileEntity, IActionHost, IGridProxyable, IAlignmentProvider, IConstructableProvider { protected MetaTileEntity mMetaTileEntity; protected long mStoredEnergy = 0, mStoredSteam = 0; protected int mAverageEUInputIndex = 0, mAverageEUOutputIndex = 0; protected boolean mReleaseEnergy = false; protected long[] mAverageEUInput = new long[]{0, 0, 0, 0, 0}, mAverageEUOutput = new long[]{0, 0, 0, 0, 0}; - private boolean[] mActiveEUInputs = new boolean[]{false, false, false, false, false, false}, mActiveEUOutputs = new boolean[]{false, false, false, false, false, false}; + private final boolean[] mActiveEUInputs = new boolean[]{false, false, false, false, false, false}; + private final boolean[] mActiveEUOutputs = new boolean[]{false, false, false, false, false, false}; private byte[] mSidedRedstone = new byte[]{15, 15, 15, 15, 15, 15}; - private int[] mCoverSides = new int[]{0, 0, 0, 0, 0, 0}, mTimeStatistics = new int[GregTech_API.TICKS_FOR_LAG_AVERAGING]; - private ISerializableObject[] mCoverData = new ISerializableObject[6]; - private boolean mHasEnoughEnergy = true, mRunningThroughTick = false, mInputDisabled = false, mOutputDisabled = false, mMuffler = false, mLockUpgrade = false, mActive = false, mRedstone = false, mWorkUpdate = false, mSteamConverter = false, mInventoryChanged = false, mWorks = true, mNeedsUpdate = true, mNeedsBlockUpdate = true, mSendClientData = false, oRedstone = false; - private byte mColor = 0, oColor = 0, oStrongRedstone = 0, mStrongRedstone = 0, oRedstoneData = 63, oTextureData = 0, oUpdateData = 0, oTexturePage=0, oLightValueClient = -1, oLightValue = -1, mLightValue = 0, mOtherUpgrades = 0, mFacing = 0, oFacing = 0, mWorkData = 0; + private final int[] mTimeStatistics = new int[GregTech_API.TICKS_FOR_LAG_AVERAGING]; + private boolean mHasEnoughEnergy = true, mRunningThroughTick = false, mInputDisabled = false, mOutputDisabled = false, mMuffler = false, mLockUpgrade = false; + private boolean mActive = false, mRedstone = false, mWorkUpdate = false, mSteamConverter = false, mInventoryChanged = false, mWorks = true, mNeedsUpdate = true; + private boolean mNeedsBlockUpdate = true, mSendClientData = false, oRedstone = false; + private byte mColor = 0, oColor = 0, oStrongRedstone = 0, mStrongRedstone = 0, oRedstoneData = 63, oTextureData = 0, oUpdateData = 0, oTexturePage=0; + private byte oLightValueClient = -1, oLightValue = -1, mLightValue = 0, mOtherUpgrades = 0, mFacing = 0, oFacing = 0, mWorkData = 0; private int mDisplayErrorCode = 0, oX = 0, oY = 0, oZ = 0, mTimeStatisticsIndex = 0, mLagWarningCount = 0; - private short mID = 0; - public long mTickTimer = 0; private long oOutput = 0, mAcceptedAmperes = Long.MAX_VALUE; public long mLastSoundTick = 0; private long mLastCheckTick = 0; @@ -132,18 +130,14 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE try { super.writeToNBT(aNBT); } catch (Throwable e) { - GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk whould've been corrupted by now, but I prevented that. Please report immediately to GregTech Intergalactical!!!"); + GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity."); e.printStackTrace(GT_Log.err); } try { aNBT.setInteger("mID", mID); aNBT.setLong("mStoredSteam", mStoredSteam); aNBT.setLong("mStoredEnergy", mStoredEnergy); - for (int i = 0; i < mCoverData.length; i++) { - if (mCoverSides[i] != 0 && mCoverData[i] != null) - aNBT.setTag(COVER_DATA_NBT_KEYS[i], mCoverData[i].saveDataToNBT()); - } - aNBT.setIntArray("mCoverSides", mCoverSides); + saveCoverNBT(aNBT); aNBT.setByteArray("mRedstoneSided", mSidedRedstone); aNBT.setByte("mColor", mColor); aNBT.setByte("mLightValue", mLightValue); @@ -164,34 +158,10 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE aNBT.setTag("GT.CraftingComponents", mRecipeStuff); aNBT.setInteger("nbtVersion", GT_Mod.TOTAL_VERSION); } catch (Throwable e) { - GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk whould've been corrupted by now, but I prevented that. Please report immediately to GregTech Intergalactical!!!"); - e.printStackTrace(GT_Log.err); - } - try { - if (hasValidMetaTileEntity()) { - NBTTagList tItemList = new NBTTagList(); - for (int i = 0; i < mMetaTileEntity.getRealInventory().length; i++) { - ItemStack tStack = mMetaTileEntity.getRealInventory()[i]; - if (tStack != null) { - NBTTagCompound tTag = new NBTTagCompound(); - tTag.setInteger("IntSlot", i); - tStack.writeToNBT(tTag); - tItemList.appendTag(tTag); - } - } - aNBT.setTag("Inventory", tItemList); - - try { - mMetaTileEntity.saveNBTData(aNBT); - } catch (Throwable e) { - GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk whould've been corrupted by now, but I prevented that. Please report immediately to GregTech Intergalactical!!!"); - e.printStackTrace(GT_Log.err); - } - } - } catch (Throwable e) { - GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity, the Chunk whould've been corrupted by now, but I prevented that. Please report immediately to GregTech Intergalactical!!!"); + GT_Log.err.println("Encountered CRITICAL ERROR while saving MetaTileEntity."); e.printStackTrace(GT_Log.err); } + saveMetaTileNBT(aNBT); } @Override @@ -232,57 +202,19 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE mInputDisabled = aNBT.getBoolean("mInputDisabled"); mOutputDisabled = aNBT.getBoolean("mOutputDisabled"); mOtherUpgrades = (byte) (aNBT.getByte("mOtherUpgrades") + aNBT.getByte("mBatteries") + aNBT.getByte("mLiBatteries")); - mCoverSides = aNBT.getIntArray("mCoverSides"); mSidedRedstone = aNBT.getByteArray("mRedstoneSided"); mRecipeStuff = aNBT.getCompoundTag("GT.CraftingComponents"); int nbtVersion = aNBT.getInteger("nbtVersion"); - if (mCoverSides.length != 6) mCoverSides = new int[]{0, 0, 0, 0, 0, 0}; - if (mSidedRedstone.length != 6) - if (hasValidMetaTileEntity() && mMetaTileEntity.hasSidedRedstoneOutputBehavior()) + if (mSidedRedstone.length != 6) { + if (hasValidMetaTileEntity() && mMetaTileEntity.hasSidedRedstoneOutputBehavior()) { mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; - else mSidedRedstone = new byte[]{15, 15, 15, 15, 15, 15}; - - for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); - - // check legacy data - mCoverData = new ISerializableObject[6]; - if (aNBT.hasKey("mCoverData", 11) && aNBT.getIntArray("mCoverData").length == 6) { - int[] tOldData = aNBT.getIntArray("mCoverData"); - for (int i = 0; i < tOldData.length; i++) { - if (mCoverBehaviors[i] != null) - mCoverData[i] = mCoverBehaviors[i].createDataObject(tOldData[i]); - } - } else { - // no old data - for (byte i = 0; i<6; i++) { - if (mCoverBehaviors[i] == null) - continue; - if (aNBT.hasKey(COVER_DATA_NBT_KEYS[i])) - mCoverData[i] = mCoverBehaviors[i].createDataObject(aNBT.getTag(COVER_DATA_NBT_KEYS[i])); - else - mCoverData[i] = mCoverBehaviors[i].createDataObject(); } + else mSidedRedstone = new byte[]{15, 15, 15, 15, 15, 15}; } - if (mID != 0 && createNewMetatileEntity(mID)) { - NBTTagList tItemList = aNBT.getTagList("Inventory", 10); - for (int i = 0; i < tItemList.tagCount(); i++) { - NBTTagCompound tTag = tItemList.getCompoundTagAt(i); - int tSlot = tTag.getInteger("IntSlot"); - tSlot = migrateInventoryIndex(tSlot, nbtVersion); - if (tSlot >= 0 && tSlot < mMetaTileEntity.getRealInventory().length) { - mMetaTileEntity.getRealInventory()[tSlot] = GT_Utility.loadItem(tTag); - } - } - - try { - mMetaTileEntity.loadNBTData(aNBT); - } catch (Throwable e) { - GT_Log.err.println("Encountered Exception while loading MetaTileEntity, the Server should've crashed now, but I prevented that. Please report immediately to GregTech Intergalactical!!!"); - e.printStackTrace(GT_Log.err); - } - } + loadCoverNBT(aNBT); + loadMetaTileNBT(aNBT); } if (mCoverData == null || mCoverData.length != 6) mCoverData = new ISerializableObject[6]; @@ -292,20 +224,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE mSidedRedstone = new byte[]{0, 0, 0, 0, 0, 0}; else mSidedRedstone = new byte[]{15, 15, 15, 15, 15, 15}; - for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); - } - - private boolean createNewMetatileEntity(short aID) { - if (aID <= 0 || aID >= GregTech_API.METATILEENTITIES.length || GregTech_API.METATILEENTITIES[aID] == null) { - GT_Log.err.println("MetaID " + aID + " not loadable => locking TileEntity!"); - } else { - if (hasValidMetaTileEntity()) mMetaTileEntity.setBaseMetaTileEntity(null); - GregTech_API.METATILEENTITIES[aID].newMetaEntity(this).setBaseMetaTileEntity(this); - mTickTimer = 0; - mID = aID; - return true; - } - return false; + updateCoverBehavior(); } /** @@ -341,331 +260,269 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE mRunningThroughTick = true; long tTime = System.nanoTime(); - int tCode = 0; boolean aSideServer = isServerSide(); boolean aSideClient = isClientSide(); - try { for (tCode = 0; hasValidMetaTileEntity() && tCode >= 0; ) { - switch (tCode) { - case 0: - tCode++; - if (mTickTimer++ == 0) { - oX = xCoord; - oY = yCoord; - oZ = zCoord; - if (aSideServer) for (byte i = 0; i < 6; i++) - if (getCoverIDAtSide(i) != 0) - if (!mMetaTileEntity.allowCoverOnSide(i, new GT_ItemStack(getCoverIDAtSide(i)))) - dropCover(i, i, true); - worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this); - mMetaTileEntity.onFirstTick(this); - if (!hasValidMetaTileEntity()) { - mRunningThroughTick = false; - return; - } + try { + if (hasValidMetaTileEntity()) { + if (mTickTimer++ == 0) { + oX = xCoord; + oY = yCoord; + oZ = zCoord; + if (aSideServer) { + checkDropCover(); } - case 1: - tCode++; - if (aSideClient) { - if (mColor != oColor) { - mMetaTileEntity.onColorChangeClient(oColor = mColor); - issueTextureUpdate(); - } - - if (mLightValue != oLightValueClient) { - worldObj.setLightValue(EnumSkyBlock.Block, xCoord, yCoord, zCoord, mLightValue); - worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord); - worldObj.updateLightByType(EnumSkyBlock.Block, xCoord + 1, yCoord, zCoord); - worldObj.updateLightByType(EnumSkyBlock.Block, xCoord - 1, yCoord, zCoord); - worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord + 1, zCoord); - worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord - 1, zCoord); - worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord + 1); - worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord - 1); - oLightValueClient = mLightValue; - issueTextureUpdate(); - } - - if (mNeedsUpdate) { - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - //worldObj.func_147479_m(xCoord, yCoord, zCoord); - mNeedsUpdate = false; - } + worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this); + mMetaTileEntity.onFirstTick(this); + if (!hasValidMetaTileEntity()) { + mRunningThroughTick = false; + return; + } + } + if (aSideClient) { + if (mColor != oColor) { + mMetaTileEntity.onColorChangeClient(oColor = mColor); + issueTextureUpdate(); } - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - if (aSideServer && mTickTimer > 10) { - for (byte i = (byte) (tCode - 2); i < 6; i++) - if (getCoverIDAtSide(i) != 0) { - tCode++; - GT_CoverBehaviorBase<?> tCover = getCoverBehaviorAtSideNew(i); - int tCoverTickRate = tCover.getTickRate(i, getCoverIDAtSide(i), mCoverData[i], this); - if (tCoverTickRate > 0 && mTickTimer % tCoverTickRate == 0) { - byte tRedstone = tCover.isRedstoneSensitive(i, getCoverIDAtSide(i), mCoverData[i], this, mTickTimer) ? getInputRedstoneSignal(i) : 0; - mCoverData[i] = tCover.doCoverThings(i, tRedstone, getCoverIDAtSide(i), mCoverData[i], this, mTickTimer); - if (!hasValidMetaTileEntity()) { - mRunningThroughTick = false; - return; - } - } - } + if (mLightValue != oLightValueClient) { + worldObj.setLightValue(EnumSkyBlock.Block, xCoord, yCoord, zCoord, mLightValue); + worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord); + worldObj.updateLightByType(EnumSkyBlock.Block, xCoord + 1, yCoord, zCoord); + worldObj.updateLightByType(EnumSkyBlock.Block, xCoord - 1, yCoord, zCoord); + worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord + 1, zCoord); + worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord - 1, zCoord); + worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord + 1); + worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord - 1); + oLightValueClient = mLightValue; + issueTextureUpdate(); } - case 8: - tCode = 9; - if (aSideServer) { - if (++mAverageEUInputIndex >= mAverageEUInput.length) mAverageEUInputIndex = 0; - if (++mAverageEUOutputIndex >= mAverageEUOutput.length) mAverageEUOutputIndex = 0; - mAverageEUInput[mAverageEUInputIndex] = 0; - mAverageEUOutput[mAverageEUOutputIndex] = 0; + if (mNeedsUpdate) { + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + //worldObj.func_147479_m(xCoord, yCoord, zCoord); + mNeedsUpdate = false; } - case 9: - tCode++; - mMetaTileEntity.onPreTick(this, mTickTimer); - if (!hasValidMetaTileEntity()) { + } + if (aSideServer && mTickTimer > 10) { + if(!doCoverThings()) { mRunningThroughTick = false; return; } - case 10: - tCode++; - if (aSideServer) { - if (mRedstone != oRedstone || mTickTimer == 10) { - for (byte i = 0; i < 6; i++) - mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); - oRedstone = mRedstone; - issueBlockUpdate(); - } - if(mTickTimer == 10) joinEnet(); - - if (xCoord != oX || yCoord != oY || zCoord != oZ) { - oX = xCoord; - oY = yCoord; - oZ = zCoord; - issueClientUpdate(); - clearTileEntityBuffer(); - } + } + if (aSideServer) { + if (++mAverageEUInputIndex >= mAverageEUInput.length) mAverageEUInputIndex = 0; + if (++mAverageEUOutputIndex >= mAverageEUOutput.length) mAverageEUOutputIndex = 0; - if (mFacing != oFacing) { - oFacing = mFacing; - for (byte i = 0; i < 6; i++) - if (getCoverIDAtSide(i) != 0) - if (!mMetaTileEntity.allowCoverOnSide(i, new GT_ItemStack(getCoverIDAtSide(i)))) - dropCover(i, i, true); - issueBlockUpdate(); - } + mAverageEUInput[mAverageEUInputIndex] = 0; + mAverageEUOutput[mAverageEUOutputIndex] = 0; + } + + mMetaTileEntity.onPreTick(this, mTickTimer); + + if (!hasValidMetaTileEntity()) { + mRunningThroughTick = false; + return; + } + if (aSideServer) { + if (mRedstone != oRedstone || mTickTimer == 10) { + updateCoverBehavior(); + oRedstone = mRedstone; + issueBlockUpdate(); + } + if (mTickTimer == 10) joinEnet(); + + if (xCoord != oX || yCoord != oY || zCoord != oZ) { + oX = xCoord; + oY = yCoord; + oZ = zCoord; + issueClientUpdate(); + clearTileEntityBuffer(); + } - if (mTickTimer > 20 && mMetaTileEntity.isElectric()) { - mAcceptedAmperes = 0; + if (mFacing != oFacing) { + oFacing = mFacing; + checkDropCover(); + issueBlockUpdate(); + } - if (getOutputVoltage() != oOutput) { - oOutput = getOutputVoltage(); - } + if (mTickTimer > 20 && mMetaTileEntity.isElectric()) { + mAcceptedAmperes = 0; - if (mMetaTileEntity.isEnetOutput() || mMetaTileEntity.isEnetInput()) { - for (byte i = 0; i < 6; i++) { - boolean - temp = isEnergyInputSide(i); - if (temp != mActiveEUInputs[i]) { - mActiveEUInputs[i] = temp; - } - temp = isEnergyOutputSide(i); - if (temp != mActiveEUOutputs[i]) { - mActiveEUOutputs[i] = temp; - } + if (getOutputVoltage() != oOutput) { + oOutput = getOutputVoltage(); + } + + if (mMetaTileEntity.isEnetOutput() || mMetaTileEntity.isEnetInput()) { + for (byte i = 0; i < 6; i++) { + boolean temp = isEnergyInputSide(i); + if (temp != mActiveEUInputs[i]) { + mActiveEUInputs[i] = temp; + } + temp = isEnergyOutputSide(i); + if (temp != mActiveEUOutputs[i]) { + mActiveEUOutputs[i] = temp; } } + } - if (mMetaTileEntity.isEnetOutput() && oOutput > 0) { - long tOutputVoltage = Math.max(oOutput, oOutput + (1L << Math.max(0, GT_Utility.getTier(oOutput) - 1))), - tUsableAmperage = Math.min(getOutputAmperage(), (getStoredEU() - mMetaTileEntity.getMinimumStoredEU()) / tOutputVoltage); - if (tUsableAmperage > 0) { - long tEU = tOutputVoltage * IEnergyConnected.Util.emitEnergyToNetwork(oOutput, tUsableAmperage, this); - mAverageEUOutput[mAverageEUOutputIndex] += tEU; - decreaseStoredEU(tEU, true); - } + if (mMetaTileEntity.isEnetOutput() && oOutput > 0) { + long tOutputVoltage = Math.max(oOutput, oOutput + (1L << Math.max(0, GT_Utility.getTier(oOutput) - 1))), + tUsableAmperage = Math.min(getOutputAmperage(), (getStoredEU() - mMetaTileEntity.getMinimumStoredEU()) / tOutputVoltage); + if (tUsableAmperage > 0) { + long tEU = tOutputVoltage * Util.emitEnergyToNetwork(oOutput, tUsableAmperage, this); + mAverageEUOutput[mAverageEUOutputIndex] += tEU; + decreaseStoredEU(tEU, true); + } + } + if (getEUCapacity() > 0) { + if (GregTech_API.sMachineFireExplosions && getRandomNumber(1000) == 0) { + Block tBlock = getBlockAtSide((byte) getRandomNumber(6)); + if (tBlock instanceof BlockFire) doEnergyExplosion(); } - if (getEUCapacity() > 0) { - if (GregTech_API.sMachineFireExplosions && getRandomNumber(1000) == 0) { - Block tBlock = getBlockAtSide((byte) getRandomNumber(6)); - if (tBlock instanceof BlockFire) doEnergyExplosion(); - } - - if (!hasValidMetaTileEntity()) { - mRunningThroughTick = false; - return; - } - if (getRandomNumber(1000) == 0) { - int precipitationHeightAtSide2 = worldObj.getPrecipitationHeight(xCoord, zCoord - 1); - int precipitationHeightAtSide3 = worldObj.getPrecipitationHeight(xCoord, zCoord + 1); - int precipitationHeightAtSide4 = worldObj.getPrecipitationHeight(xCoord - 1, zCoord); - int precipitationHeightAtSide5 = worldObj.getPrecipitationHeight(xCoord + 1, zCoord); - - if ((getCoverIDAtSide((byte) 1) == 0 && worldObj.getPrecipitationHeight(xCoord, zCoord) - 2 < yCoord) - || (getCoverIDAtSide((byte) 2) == 0 && precipitationHeightAtSide2 - 1 < yCoord && precipitationHeightAtSide2 > -1) - || (getCoverIDAtSide((byte) 3) == 0 && precipitationHeightAtSide3 - 1 < yCoord && precipitationHeightAtSide3 > -1) - || (getCoverIDAtSide((byte) 4) == 0 && precipitationHeightAtSide4 - 1 < yCoord && precipitationHeightAtSide4 > -1) - || (getCoverIDAtSide((byte) 5) == 0 && precipitationHeightAtSide5 - 1 < yCoord && precipitationHeightAtSide5 > -1)) { - if (GregTech_API.sMachineRainExplosions && worldObj.isRaining() && getBiome().rainfall > 0) { - if (getRandomNumber(10) == 0) { - try{ - GT_Mod.instance.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(mOwnerName), "badweather"); - }catch(Exception e){ - - } - GT_Log.exp.println("Machine at: "+ this.getXCoord()+" | "+ this.getYCoord()+" | "+ this.getZCoord()+" DIMID: " +this.worldObj.provider.dimensionId +" explosion due to rain!"); - doEnergyExplosion(); - } else { - GT_Log.exp.println("Machine at: "+ this.getXCoord()+" | "+ this.getYCoord()+" | "+ this.getZCoord()+" DIMID: " +this.worldObj.provider.dimensionId +" set to Fire due to rain!"); - setOnFire(); - } - } - if (!hasValidMetaTileEntity()) { - mRunningThroughTick = false; - return; - } - if (GregTech_API.sMachineThunderExplosions && worldObj.isThundering() && getBiome().rainfall > 0 && getRandomNumber(3) == 0) { - try{ - GT_Mod.instance.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(mOwnerName), "badweather"); - }catch(Exception e){ + if (!hasValidMetaTileEntity()) { + mRunningThroughTick = false; + return; + } - } - GT_Log.exp.println("Machine at: "+ this.getXCoord()+" | "+ this.getYCoord()+" | "+ this.getZCoord()+" DIMID: " +this.worldObj.provider.dimensionId + " explosion due to Thunderstorm!"); + if (getRandomNumber(1000) == 0) { + int precipitationHeightAtSide2 = worldObj.getPrecipitationHeight(xCoord, zCoord - 1); + int precipitationHeightAtSide3 = worldObj.getPrecipitationHeight(xCoord, zCoord + 1); + int precipitationHeightAtSide4 = worldObj.getPrecipitationHeight(xCoord - 1, zCoord); + int precipitationHeightAtSide5 = worldObj.getPrecipitationHeight(xCoord + 1, zCoord); + + if ((getCoverIDAtSide((byte) 1) == 0 && worldObj.getPrecipitationHeight(xCoord, zCoord) - 2 < yCoord) + || (getCoverIDAtSide((byte) 2) == 0 && precipitationHeightAtSide2 - 1 < yCoord && precipitationHeightAtSide2 > -1) + || (getCoverIDAtSide((byte) 3) == 0 && precipitationHeightAtSide3 - 1 < yCoord && precipitationHeightAtSide3 > -1) + || (getCoverIDAtSide((byte) 4) == 0 && precipitationHeightAtSide4 - 1 < yCoord && precipitationHeightAtSide4 > -1) + || (getCoverIDAtSide((byte) 5) == 0 && precipitationHeightAtSide5 - 1 < yCoord && precipitationHeightAtSide5 > -1)) { + if (GregTech_API.sMachineRainExplosions && worldObj.isRaining() && getBiome().rainfall > 0) { + if (getRandomNumber(10) == 0) { + try { + GT_Mod.instance.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(mOwnerName), "badweather"); + } catch (Exception ignored) {} + GT_Log.exp.println("Machine at: " + this.getXCoord() + " | " + this.getYCoord() + " | " + this.getZCoord() + " DIMID: " + this.worldObj.provider.dimensionId + " explosion due to rain!"); doEnergyExplosion(); + } else { + GT_Log.exp.println("Machine at: " + this.getXCoord() + " | " + this.getYCoord() + " | " + this.getZCoord() + " DIMID: " + this.worldObj.provider.dimensionId + " set to Fire due to rain!"); + setOnFire(); } } + if (!hasValidMetaTileEntity()) { + mRunningThroughTick = false; + return; + } + if (GregTech_API.sMachineThunderExplosions && worldObj.isThundering() && getBiome().rainfall > 0 && getRandomNumber( + 3) == 0) { + try { + GT_Mod.instance.achievements.issueAchievement(this.getWorldObj().getPlayerEntityByName(mOwnerName), "badweather"); + } catch (Exception ignored) {} + GT_Log.exp.println("Machine at: " + this.getXCoord() + " | " + this.getYCoord() + " | " + this.getZCoord() + " DIMID: " + this.worldObj.provider.dimensionId + " explosion due to Thunderstorm!"); + doEnergyExplosion(); + } } } } + } - if (!hasValidMetaTileEntity()) { - mRunningThroughTick = false; - return; - } + if (!hasValidMetaTileEntity()) { + mRunningThroughTick = false; + return; } - case 11: - tCode++; - if (aSideServer) { - if (mMetaTileEntity.dechargerSlotCount() > 0 && getStoredEU() < getEUCapacity()) { - for (int i = mMetaTileEntity.dechargerSlotStartIndex(), k = mMetaTileEntity.dechargerSlotCount() + i; i < k; i++) { - if (mMetaTileEntity.mInventory[i] != null && getStoredEU() < getEUCapacity()) { - dischargeItem(mMetaTileEntity.mInventory[i]); - if(ic2.api.info.Info.itemEnergy.getEnergyValue(mMetaTileEntity.mInventory[i])>0){ - if((getStoredEU() + ic2.api.info.Info.itemEnergy.getEnergyValue(mMetaTileEntity.mInventory[i]))<getEUCapacity()){ - increaseStoredEnergyUnits((long)ic2.api.info.Info.itemEnergy.getEnergyValue(mMetaTileEntity.mInventory[i]),false); - mMetaTileEntity.mInventory[i].stackSize--; - mInventoryChanged = true; - } - } - if (mMetaTileEntity.mInventory[i].stackSize <= 0) { - mMetaTileEntity.mInventory[i] = null; + } + if (aSideServer) { + if (mMetaTileEntity.dechargerSlotCount() > 0 && getStoredEU() < getEUCapacity()) { + for (int i = mMetaTileEntity.dechargerSlotStartIndex(), k = mMetaTileEntity.dechargerSlotCount() + i; i < k; i++) { + if (mMetaTileEntity.mInventory[i] != null && getStoredEU() < getEUCapacity()) { + dischargeItem(mMetaTileEntity.mInventory[i]); + if (ic2.api.info.Info.itemEnergy.getEnergyValue(mMetaTileEntity.mInventory[i]) > 0) { + if ((getStoredEU() + ic2.api.info.Info.itemEnergy.getEnergyValue(mMetaTileEntity.mInventory[i])) < getEUCapacity()) { + increaseStoredEnergyUnits((long) ic2.api.info.Info.itemEnergy.getEnergyValue(mMetaTileEntity.mInventory[i]), false); + mMetaTileEntity.mInventory[i].stackSize--; mInventoryChanged = true; } } + if (mMetaTileEntity.mInventory[i].stackSize <= 0) { + mMetaTileEntity.mInventory[i] = null; + mInventoryChanged = true; + } } } } - case 12: - tCode++; - if (aSideServer) { - if (mMetaTileEntity.rechargerSlotCount() > 0 && getStoredEU() > 0) { - for (int i = mMetaTileEntity.rechargerSlotStartIndex(), k = mMetaTileEntity.rechargerSlotCount() + i; i < k; i++) { - if (getStoredEU() > 0 && mMetaTileEntity.mInventory[i] != null) { - chargeItem(mMetaTileEntity.mInventory[i]); - if (mMetaTileEntity.mInventory[i].stackSize <= 0) { - mMetaTileEntity.mInventory[i] = null; - mInventoryChanged = true; - } + } + if (aSideServer) { + if (mMetaTileEntity.rechargerSlotCount() > 0 && getStoredEU() > 0) { + for (int i = mMetaTileEntity.rechargerSlotStartIndex(), k = mMetaTileEntity.rechargerSlotCount() + i; i < k; i++) { + if (getStoredEU() > 0 && mMetaTileEntity.mInventory[i] != null) { + chargeItem(mMetaTileEntity.mInventory[i]); + if (mMetaTileEntity.mInventory[i].stackSize <= 0) { + mMetaTileEntity.mInventory[i] = null; + mInventoryChanged = true; } } } } - case 13: - tCode++; - updateStatus(); - if (!hasValidMetaTileEntity()) { - mRunningThroughTick = false; - return; + } + updateStatus(); + if (!hasValidMetaTileEntity()) { + mRunningThroughTick = false; + return; + } + mMetaTileEntity.onPostTick(this, mTickTimer); + if (!hasValidMetaTileEntity()) { + mRunningThroughTick = false; + return; + } + if (aSideServer) { + if (mTickTimer > 20 && cableUpdateDelay == 0) { + generatePowerNodes(); } - case 14: - tCode++; - mMetaTileEntity.onPostTick(this, mTickTimer); - if (!hasValidMetaTileEntity()) { - mRunningThroughTick = false; - return; + cableUpdateDelay--; + if (mTickTimer % 10 == 0) { + sendClientData(); } - case 15: - tCode++; - if (aSideServer) { - if (mTickTimer > 20 && cableUpdateDelay == 0) { - generatePowerNodes(); - cableUpdateDelay--; - } else { - cableUpdateDelay--; - } - if (mTickTimer % 10 == 0) { - if (mSendClientData) { - NW.sendPacketToAllPlayersInRange(worldObj, - new GT_Packet_TileEntity(xCoord, (short) yCoord, zCoord, mID, - mCoverSides[0], mCoverSides[1], mCoverSides[2], mCoverSides[3], mCoverSides[4], mCoverSides[5], - oTextureData = (byte) ((mFacing & 7) | (mActive ? 8 : 0) | (mRedstone ? 16 : 0) | (mLockUpgrade ? 32 : 0) | (mWorks ? 64 : 0) ), - oTexturePage = (hasValidMetaTileEntity() && mMetaTileEntity instanceof GT_MetaTileEntity_Hatch) ? ((GT_MetaTileEntity_Hatch) mMetaTileEntity).getTexturePage() : 0, - oUpdateData = hasValidMetaTileEntity() ? mMetaTileEntity.getUpdateData() : 0, - oRedstoneData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | ((mSidedRedstone[4] > 0) ? 16 : 0) | ((mSidedRedstone[5] > 0) ? 32 : 0)), - oColor = mColor), - xCoord, zCoord); - mSendClientData = false; - } - } - if (mTickTimer > 10) { - byte tData = (byte) ((mFacing & 7) | (mActive ? 8 : 0) | (mRedstone ? 16 : 0) | (mLockUpgrade ? 32 : 0)| (mWorks ? 64 : 0)); - if (tData != oTextureData) - sendBlockEvent(ClientEvents.CHANGE_COMMON_DATA, oTextureData = tData); - - tData = mMetaTileEntity.getUpdateData(); - if (tData != oUpdateData) - sendBlockEvent(ClientEvents.CHANGE_CUSTOM_DATA, oUpdateData = tData); - if (mMetaTileEntity instanceof GT_MetaTileEntity_Hatch) { - tData = ((GT_MetaTileEntity_Hatch) mMetaTileEntity).getTexturePage(); - if (tData != oTexturePage) - sendBlockEvent(ClientEvents.CHANGE_CUSTOM_DATA, (byte) ((oTexturePage = tData) | 0x80));//set last bit as a flag for page - } - if (mColor != oColor) sendBlockEvent(ClientEvents.CHANGE_COLOR, oColor = mColor); - tData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | ((mSidedRedstone[4] > 0) ? 16 : 0) | ((mSidedRedstone[5] > 0) ? 32 : 0)); - if (tData != oRedstoneData) - sendBlockEvent(ClientEvents.CHANGE_REDSTONE_OUTPUT, oRedstoneData = tData); - if (mLightValue != oLightValue) { - worldObj.setLightValue(EnumSkyBlock.Block, xCoord, yCoord, zCoord, mLightValue); - worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord); - worldObj.updateLightByType(EnumSkyBlock.Block, xCoord + 1, yCoord, zCoord); - worldObj.updateLightByType(EnumSkyBlock.Block, xCoord - 1, yCoord, zCoord); - worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord + 1, zCoord); - worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord - 1, zCoord); - worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord + 1); - worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord - 1); - issueTextureUpdate(); - sendBlockEvent(ClientEvents.CHANGE_LIGHT, oLightValue = mLightValue); - } + if (mTickTimer > 10) { + byte tData = (byte) ((mFacing & 7) | (mActive ? 8 : 0) | (mRedstone ? 16 : 0) | (mLockUpgrade ? 32 : 0) | (mWorks ? 64 : 0)); + if (tData != oTextureData) + sendBlockEvent(MetaTileClientEvents.CHANGE_COMMON_DATA, oTextureData = tData); + + tData = mMetaTileEntity.getUpdateData(); + if (tData != oUpdateData) + sendBlockEvent(MetaTileClientEvents.CHANGE_CUSTOM_DATA, oUpdateData = tData); + if (mMetaTileEntity instanceof GT_MetaTileEntity_Hatch) { + tData = ((GT_MetaTileEntity_Hatch) mMetaTileEntity).getTexturePage(); + if (tData != oTexturePage) + sendBlockEvent(MetaTileClientEvents.CHANGE_CUSTOM_DATA, (byte) ((oTexturePage = tData) | 0x80));//set last bit as a flag for page } - - if (mNeedsBlockUpdate) { - updateNeighbours(mStrongRedstone, oStrongRedstone); - oStrongRedstone = mStrongRedstone; - mNeedsBlockUpdate = false; + if (mColor != oColor) sendBlockEvent(MetaTileClientEvents.CHANGE_COLOR, oColor = mColor); + tData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | ((mSidedRedstone[4] > 0) ? 16 : 0) | ((mSidedRedstone[5] > 0) ? 32 : 0)); + if (tData != oRedstoneData) + sendBlockEvent(MetaTileClientEvents.CHANGE_REDSTONE_OUTPUT, oRedstoneData = tData); + if (mLightValue != oLightValue) { + worldObj.setLightValue(EnumSkyBlock.Block, xCoord, yCoord, zCoord, mLightValue); + worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord); + worldObj.updateLightByType(EnumSkyBlock.Block, xCoord + 1, yCoord, zCoord); + worldObj.updateLightByType(EnumSkyBlock.Block, xCoord - 1, yCoord, zCoord); + worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord + 1, zCoord); + worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord - 1, zCoord); + worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord + 1); + worldObj.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord - 1); + issueTextureUpdate(); + sendBlockEvent(MetaTileClientEvents.CHANGE_LIGHT, oLightValue = mLightValue); } } - default: - tCode = -1; + + if (mNeedsBlockUpdate) { + updateNeighbours(mStrongRedstone, oStrongRedstone); + oStrongRedstone = mStrongRedstone; + mNeedsBlockUpdate = false; + } + } } - } } catch (Throwable e) { - //gregtech.api.util.GT_Log.err.println("Encountered Exception while ticking MetaTileEntity in Step " + (tCode - 1) + ". The Game should've crashed now, but I prevented that. Please report immidietly to GregTech Intergalactical!!!"); e.printStackTrace(GT_Log.err); } @@ -680,6 +537,23 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE mWorkUpdate = mInventoryChanged = mRunningThroughTick = false; } + private void sendClientData() { + if (mSendClientData) { + NW.sendPacketToAllPlayersInRange( + worldObj, + new GT_Packet_TileEntity( + xCoord, (short) yCoord, zCoord, mID, mCoverSides[0], mCoverSides[1], mCoverSides[2], mCoverSides[3], mCoverSides[4], mCoverSides[5], + oTextureData = (byte) ((mFacing & 7) | (mActive ? 8 : 0) | (mRedstone ? 16 : 0) | (mLockUpgrade ? 32 : 0) | (mWorks ? 64 : 0)), + oTexturePage = (hasValidMetaTileEntity() && mMetaTileEntity instanceof GT_MetaTileEntity_Hatch) ? ((GT_MetaTileEntity_Hatch) mMetaTileEntity).getTexturePage() : 0, + oUpdateData = hasValidMetaTileEntity() ? mMetaTileEntity.getUpdateData() : 0, + oRedstoneData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | ((mSidedRedstone[4] > 0) ? 16 : 0) | ((mSidedRedstone[5] > 0) ? 32 : 0)), + oColor = mColor), + xCoord, zCoord + ); + mSendClientData = false; + } + } + @Override public Packet getDescriptionPacket() { issueClientUpdate(); @@ -700,47 +574,18 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE setCoverIDAtSide((byte) 4, aCover4); setCoverIDAtSide((byte) 5, aCover5); - receiveClientEvent(ClientEvents.CHANGE_COMMON_DATA, aTextureData); - receiveClientEvent(ClientEvents.CHANGE_CUSTOM_DATA, aUpdateData & 0x7F); - receiveClientEvent(ClientEvents.CHANGE_CUSTOM_DATA, aTexturePage | 0x80); - receiveClientEvent(ClientEvents.CHANGE_COLOR, aColorData); - receiveClientEvent(ClientEvents.CHANGE_REDSTONE_OUTPUT, aRedstoneData); + receiveClientEvent(MetaTileClientEvents.CHANGE_COMMON_DATA, aTextureData); + receiveClientEvent(MetaTileClientEvents.CHANGE_CUSTOM_DATA, aUpdateData & 0x7F); + receiveClientEvent(MetaTileClientEvents.CHANGE_CUSTOM_DATA, aTexturePage | 0x80); + receiveClientEvent(MetaTileClientEvents.CHANGE_COLOR, aColorData); + receiveClientEvent(MetaTileClientEvents.CHANGE_REDSTONE_OUTPUT, aRedstoneData); } @Deprecated public final void receiveMetaTileEntityData(short aID, int aCover0, int aCover1, int aCover2, int aCover3, int aCover4, int aCover5, byte aTextureData, byte aUpdateData, byte aRedstoneData, byte aColorData) { - issueTextureUpdate(); - if (mID != aID && aID > 0) { - mID = aID; - createNewMetatileEntity(mID); - } - - mCoverSides[0] = aCover0; - mCoverSides[1] = aCover1; - mCoverSides[2] = aCover2; - mCoverSides[3] = aCover3; - mCoverSides[4] = aCover4; - mCoverSides[5] = aCover5; - - for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); - - receiveClientEvent(ClientEvents.CHANGE_COMMON_DATA, aTextureData); - receiveClientEvent(ClientEvents.CHANGE_CUSTOM_DATA, aUpdateData & 0x7F); - receiveClientEvent(ClientEvents.CHANGE_CUSTOM_DATA, 0x80); - receiveClientEvent(ClientEvents.CHANGE_COLOR, aColorData); - receiveClientEvent(ClientEvents.CHANGE_REDSTONE_OUTPUT, aRedstoneData); + receiveMetaTileEntityData(aID, aCover0, aCover1, aCover2, aCover3, aCover4, aCover5, aTextureData, (byte)0, aUpdateData, aRedstoneData, aColorData); } - public static class ClientEvents { - public static final byte CHANGE_COMMON_DATA = 0; - public static final byte CHANGE_CUSTOM_DATA = 1; - public static final byte CHANGE_COLOR = 2; - public static final byte CHANGE_REDSTONE_OUTPUT = 3; - public static final byte DO_SOUND = 4; - public static final byte START_SOUND_LOOP = 5; - public static final byte STOP_SOUND_LOOP = 6; - public static final byte CHANGE_LIGHT = 7; - } @Override public boolean receiveClientEvent(int aEventID, int aValue) { @@ -758,14 +603,14 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE if (isClientSide()) { issueTextureUpdate(); switch (aEventID) { - case ClientEvents.CHANGE_COMMON_DATA: + case MetaTileClientEvents.CHANGE_COMMON_DATA: mFacing = (byte) (aValue & 7); mActive = ((aValue & 8) != 0); mRedstone = ((aValue & 16) != 0); //mLockUpgrade = ((aValue&32) != 0); mWorks = ((aValue & 64) != 0); break; - case ClientEvents.CHANGE_CUSTOM_DATA: + case MetaTileClientEvents.CHANGE_CUSTOM_DATA: if (hasValidMetaTileEntity()) { if ((aValue & 0x80) == 0) //Is texture index mMetaTileEntity.onValueUpdate((byte) (aValue & 0x7F)); @@ -773,11 +618,11 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE ((GT_MetaTileEntity_Hatch) mMetaTileEntity).onTexturePageUpdate((byte) (aValue & 0x7F)); } break; - case ClientEvents.CHANGE_COLOR: + case MetaTileClientEvents.CHANGE_COLOR: if (aValue > 16 || aValue < 0) aValue = 0; mColor = (byte) aValue; break; - case ClientEvents.CHANGE_REDSTONE_OUTPUT: + case MetaTileClientEvents.CHANGE_REDSTONE_OUTPUT: mSidedRedstone[0] = (byte) ((aValue & 1) == 1 ? 15 : 0); mSidedRedstone[1] = (byte) ((aValue & 2) == 2 ? 15 : 0); mSidedRedstone[2] = (byte) ((aValue & 4) == 4 ? 15 : 0); @@ -785,19 +630,19 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE mSidedRedstone[4] = (byte) ((aValue & 16) == 16 ? 15 : 0); mSidedRedstone[5] = (byte) ((aValue & 32) == 32 ? 15 : 0); break; - case ClientEvents.DO_SOUND: + case MetaTileClientEvents.DO_SOUND: if (hasValidMetaTileEntity() && mTickTimer > 20) mMetaTileEntity.doSound((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); break; - case ClientEvents.START_SOUND_LOOP: + case MetaTileClientEvents.START_SOUND_LOOP: if (hasValidMetaTileEntity() && mTickTimer > 20) mMetaTileEntity.startSoundLoop((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); break; - case ClientEvents.STOP_SOUND_LOOP: + case MetaTileClientEvents.STOP_SOUND_LOOP: if (hasValidMetaTileEntity() && mTickTimer > 20) mMetaTileEntity.stopSoundLoop((byte) aValue, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5); break; - case ClientEvents.CHANGE_LIGHT: + case MetaTileClientEvents.CHANGE_LIGHT: mLightValue = (byte) aValue; break; } @@ -1297,7 +1142,8 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE } return false; } - + + @Override protected boolean hasValidMetaTileEntity() { return mMetaTileEntity != null && mMetaTileEntity.getBaseMetaTileEntity() == this; } @@ -1588,14 +1434,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE if (!getCoverBehaviorAtSideNew(aSide).isGUIClickable(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this)) return false; - if (isUpgradable() && tCurrentItem != null) {/* - if (ItemList.Upgrade_SteamEngine.isStackEqual(aPlayer.inventory.getCurrentItem())) { - if (addSteamEngineUpgrade()) { - GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(3), 1.0F, -1, xCoord, yCoord, zCoord); - if (!aPlayer.capabilities.isCreativeMode) aPlayer.inventory.getCurrentItem().stackSize--; - } - return true; - }*/ + if (isUpgradable() && tCurrentItem != null) { if (ItemList.Upgrade_Muffler.isStackEqual(aPlayer.inventory.getCurrentItem())) { if (addMufflerUpgrade()) { GT_Utility.sendSoundToPlayers(worldObj, GregTech_API.sSoundList.get(3), 1.0F, -1, xCoord, yCoord, zCoord); @@ -1807,84 +1646,6 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE mMetaTileEntity = (MetaTileEntity) aMetaTileEntity; } - @Override - @Deprecated - public GT_CoverBehavior getCoverBehaviorAtSide(byte aSide) { - if (aSide >= 0 && aSide < mCoverBehaviors.length && mCoverBehaviors[aSide] instanceof GT_CoverBehavior) - return (GT_CoverBehavior) mCoverBehaviors[aSide]; - return GregTech_API.sNoBehavior; - } - - @Override - public void setCoverIDAtSide(byte aSide, int aID) { - if (aSide >= 0 && aSide < 6) { - mCoverSides[aSide] = aID; - mCoverBehaviors[aSide] = GregTech_API.getCoverBehaviorNew(aID); - mCoverData[aSide] = mCoverBehaviors[aSide].createDataObject(); - issueCoverUpdate(aSide); - issueBlockUpdate(); - } - } - - @Override - public void setCoverItemAtSide(byte aSide, ItemStack aCover) { - GregTech_API.getCoverBehaviorNew(aCover).placeCover(aSide, aCover, this); - } - - @Override - public int getCoverIDAtSide(byte aSide) { - if (aSide >= 0 && aSide < 6) return mCoverSides[aSide]; - return 0; - } - - @Override - public ItemStack getCoverItemAtSide(byte aSide) { - return GT_Utility.intToStack(getCoverIDAtSide(aSide)); - } - - @Override - public boolean canPlaceCoverIDAtSide(byte aSide, int aID) { - return getCoverIDAtSide(aSide) == 0; - } - - @Override - public boolean canPlaceCoverItemAtSide(byte aSide, ItemStack aCover) { - return getCoverIDAtSide(aSide) == 0; - } - - @Override - @Deprecated - public void setCoverDataAtSide(byte aSide, int aData) { - if (aSide >= 0 && aSide < 6) mCoverData[aSide] = new ISerializableObject.LegacyCoverData(aData); - } - - @Override - @Deprecated - public int getCoverDataAtSide(byte aSide) { - if (aSide >= 0 && aSide < 6 && mCoverData[aSide] instanceof ISerializableObject.LegacyCoverData) - return ((ISerializableObject.LegacyCoverData) mCoverData[aSide]).get(); - return 0; - } - @Override - public void setCoverDataAtSide(byte aSide, ISerializableObject aData) { - if (aSide >= 0 && aSide < 6 && getCoverBehaviorAtSideNew(aSide) != null && getCoverBehaviorAtSideNew(aSide).cast(aData) != null) - mCoverData[aSide] = aData; - } - - @Override - public ISerializableObject getComplexCoverDataAtSide(byte aSide) { - if (aSide >= 0 && aSide < 6 && getCoverBehaviorAtSideNew(aSide) != null) - return mCoverData[aSide]; - return GregTech_API.sNoBehavior.createDataObject(); - } - - @Override - public GT_CoverBehaviorBase<?> getCoverBehaviorAtSideNew(byte aSide) { - if (aSide >= 0 && aSide < 6) - return mCoverBehaviors[aSide]; - return GregTech_API.sNoBehavior; - } - public byte getLightValue() { return mLightValue; } @@ -1912,29 +1673,16 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE return rEU / (mAverageEUOutput.length - 1); } + @Override - public boolean dropCover(byte aSide, byte aDroppedSide, boolean aForced) { - if (getCoverBehaviorAtSideNew(aSide).onCoverRemoval(aSide, getCoverIDAtSide(aSide), mCoverData[aSide], this, aForced) || aForced) { - ItemStack tStack = getCoverBehaviorAtSideNew(aSide).getDrop(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this); - if (tStack != null) { - tStack.setTagCompound(null); - EntityItem tEntity = new EntityItem(worldObj, getOffsetX(aDroppedSide, 1) + 0.5, getOffsetY(aDroppedSide, 1) + 0.5, getOffsetZ(aDroppedSide, 1) + 0.5, tStack); - tEntity.motionX = 0; - tEntity.motionY = 0; - tEntity.motionZ = 0; - worldObj.spawnEntityInWorld(tEntity); - } - setCoverIDAtSide(aSide, 0); - if (mMetaTileEntity.hasSidedRedstoneOutputBehavior()) { - setOutputRedstoneSignal(aSide, (byte) 0); - } else { - setOutputRedstoneSignal(aSide, (byte) 15); - } - return true; + protected void updateOutputRedstoneSignal(byte aSide) { + if (mMetaTileEntity.hasSidedRedstoneOutputBehavior()) { + setOutputRedstoneSignal(aSide, (byte) 0); + } else { + setOutputRedstoneSignal(aSide, (byte) 15); } - return false; } - + @Override public String getOwnerName() { if (GT_Utility.isStringInvalid(mOwnerName)) return "Player"; diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntityUE.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntityUE.java deleted file mode 100644 index 1fb4f861ae..0000000000 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntityUE.java +++ /dev/null @@ -1,98 +0,0 @@ -package gregtech.api.metatileentity; - - -/** - * NEVER INCLUDE THIS FILE IN YOUR MOD!!! - * <p/> - * This file contains all the needed 'implements' of the Interfaces for the Universal Electricity Stuff. - * <p/> - * I am using the BC3 Ratio, since that is a constant in comparison to IC² Energy (1 MJ is always 2,5 EU). - */ -public class BaseMetaTileEntityUE extends BaseMetaTileEntity /*implements IUETileEntity*/ { - public BaseMetaTileEntityUE() { - super(); - } - /* - @Override - public void updateStatus() { - super.updateStatus(); - } - - @Override - public void chargeItem(ItemStack aStack) { - super.chargeItem(aStack); - float tEnergy = ElectricItemHelper.chargeItem(aStack, (float)(getOfferedEnergy() * (Compatibility.BC3_RATIO * 0.4F))); - if (tEnergy > 0) decreaseStoredEU((int)(tEnergy / (Compatibility.BC3_RATIO * 0.4F)) + 1, true); - } - - @Override - public void dischargeItem(ItemStack aStack) { - super.dischargeItem(aStack); - float tEnergy = ElectricItemHelper.dischargeItem(aStack, (float)(demandedEnergyUnits() * (Compatibility.BC3_RATIO * 0.4F))); - if (tEnergy > 0) increaseStoredEnergyUnits((int)(tEnergy / (Compatibility.BC3_RATIO * 0.4F)), true); - } - - @Override - public float receiveElectricity(ForgeDirection aSide, ElectricityPack aPacket, boolean doReceive) { - if (!getUEConsumingSides().contains(aSide)) return 0; - int aInserted = (int)(aPacket.getWatts()/(Compatibility.BC3_RATIO * 0.4F)); - if (doReceive) return injectEnergyUnits((byte)aSide.ordinal(), aInserted, 1) ? aInserted : 0; - return getEUCapacity() - getStoredEU() >= aInserted ? aInserted : 0; - } - - @Override - public ElectricityPack provideElectricity(ForgeDirection aSide, ElectricityPack aRequested, boolean doProvide) { - if (!getUEProducingSides().contains(aSide)) return null; - int aExtracted = (int)getOfferedEnergy(); - if (doProvide) return aRequested.getWatts()/(Compatibility.BC3_RATIO * 0.4F) >= getOfferedEnergy() ? decreaseStoredEU(aExtracted, false) ? new ElectricityPack(aExtracted * (Compatibility.BC3_RATIO * 0.4F), 1) : null : decreaseStoredEU((int)(aRequested.getWatts()/(Compatibility.BC3_RATIO * 0.4F)), false) ? new ElectricityPack((int)(aRequested.getWatts()/(Compatibility.BC3_RATIO * 0.4F)) * (Compatibility.BC3_RATIO * 0.4F), 1) : null; - return aRequested.getWatts()/(Compatibility.BC3_RATIO * 0.4F) >= getOfferedEnergy() ? new ElectricityPack(aExtracted * (Compatibility.BC3_RATIO * 0.4F), 1) : new ElectricityPack((int)(aRequested.getWatts()/(Compatibility.BC3_RATIO * 0.4F)) * (Compatibility.BC3_RATIO * 0.4F), 1); - } - - @Override - public float getRequest(ForgeDirection aSide) { - if (!getUEConsumingSides().contains(aSide)) return 0; - return (float)(demandedEnergyUnits() * (Compatibility.BC3_RATIO * 0.4F)); - } - - @Override - public float getProvide(ForgeDirection aSide) { - if (!getUEProducingSides().contains(aSide)) return 0; - return (float)(getOfferedEnergy() * (Compatibility.BC3_RATIO * 0.4F)); - } - - @Override - public float getVoltage() { - return (float)(getOfferedEnergy() * (Compatibility.BC3_RATIO * 0.4F)); - } - - @Override - public boolean canConnect(ForgeDirection aSide) { - return getUEProducingSides().contains(aSide) || getUEConsumingSides().contains(aSide); - } - - private EnumSet<ForgeDirection> getUEConsumingSides() { - EnumSet<ForgeDirection> rSides = EnumSet.noneOf(ForgeDirection.class); - for (byte i = 0; i < 6; i++) { - if (inputEnergyFrom(i)) { - Object tTileEntity = getTileEntityAtSide(i); - if (tTileEntity instanceof IConductor) { - rSides.add(ForgeDirection.getOrientation(i)); - } - } - } - return rSides; - } - - private EnumSet<ForgeDirection> getUEProducingSides() { - EnumSet<ForgeDirection> rSides = EnumSet.noneOf(ForgeDirection.class); - for (byte i = 0; i < 6; i++) { - if (outputsEnergyTo(i)) { - Object tTileEntity = getTileEntityAtSide(i); - if (tTileEntity instanceof IConductor) { - rSides.add(ForgeDirection.getOrientation(i)); - } - } - } - return rSides; - }*/ -} diff --git a/src/main/java/gregtech/api/metatileentity/CoverableGregTechTileEntity.java b/src/main/java/gregtech/api/metatileentity/CoverableGregTechTileEntity.java new file mode 100644 index 0000000000..0460f93f78 --- /dev/null +++ b/src/main/java/gregtech/api/metatileentity/CoverableGregTechTileEntity.java @@ -0,0 +1,267 @@ +package gregtech.api.metatileentity; + +import gregtech.GT_Mod; +import gregtech.api.GregTech_API; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.util.GT_CoverBehavior; +import gregtech.api.util.GT_CoverBehaviorBase; +import gregtech.api.util.GT_Log; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.ISerializableObject; +import gregtech.common.covers.GT_Cover_Fluidfilter; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidRegistry; + +import java.util.Arrays; + +import static gregtech.GT_Mod.GT_FML_LOGGER; + +public abstract class CoverableGregTechTileEntity extends BaseTileEntity implements IGregTechTileEntity { + static final String[] COVER_DATA_NBT_KEYS = Arrays.stream(ForgeDirection.VALID_DIRECTIONS).mapToInt(Enum::ordinal).mapToObj(i -> "mCoverData" + i).toArray(String[]::new); + protected final GT_CoverBehaviorBase<?>[] mCoverBehaviors = new GT_CoverBehaviorBase<?>[]{GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior, GregTech_API.sNoBehavior}; + + protected int[] mCoverSides = new int[]{0, 0, 0, 0, 0, 0}; + protected ISerializableObject[] mCoverData = new ISerializableObject[6]; + protected short mID = 0; + public long mTickTimer = 0; + + protected void saveCoverNBT(NBTTagCompound aNBT) { + for (int i = 0; i < mCoverData.length; i++) { + if (mCoverSides[i] != 0 && mCoverData[i] != null) + aNBT.setTag(COVER_DATA_NBT_KEYS[i], mCoverData[i].saveDataToNBT()); + } + aNBT.setIntArray("mCoverSides", mCoverSides); + + } + + protected void saveMetaTileNBT(NBTTagCompound aNBT) { + try { + if (hasValidMetaTileEntity()) { + NBTTagList tItemList = new NBTTagList(); + for (int i = 0; i < getMetaTileEntity().getRealInventory().length; i++) { + ItemStack tStack = getMetaTileEntity().getRealInventory()[i]; + if (tStack != null) { + NBTTagCompound tTag = new NBTTagCompound(); + tTag.setInteger("IntSlot", i); + tStack.writeToNBT(tTag); + tItemList.appendTag(tTag); + } + } + aNBT.setTag("Inventory", tItemList); + + try { + getMetaTileEntity().saveNBTData(aNBT); + } catch (Throwable e) { + GT_FML_LOGGER.error("Encountered CRITICAL ERROR while saving MetaTileEntity."); + GT_Mod.logStackTrace(e); + } + } + } catch (Throwable e) { + GT_FML_LOGGER.error("Encountered CRITICAL ERROR while saving MetaTileEntity."); + GT_Mod.logStackTrace(e); + } + } + + protected void loadMetaTileNBT(NBTTagCompound aNBT) { + if (mID != 0 && createNewMetatileEntity(mID)) { + NBTTagList tItemList = aNBT.getTagList("Inventory", 10); + for (int i = 0; i < tItemList.tagCount(); i++) { + NBTTagCompound tTag = tItemList.getCompoundTagAt(i); + int tSlot = tTag.getInteger("IntSlot"); + if (tSlot >= 0 && tSlot < getMetaTileEntity().getRealInventory().length) { + getMetaTileEntity().getRealInventory()[tSlot] = GT_Utility.loadItem(tTag); + } + } + + try { + getMetaTileEntity().loadNBTData(aNBT); + } catch (Throwable e) { + GT_FML_LOGGER.error("Encountered Exception while loading MetaTileEntity."); + GT_Mod.logStackTrace(e); + } + } + } + + protected void loadCoverNBT(NBTTagCompound aNBT) { + mCoverSides = aNBT.getIntArray("mCoverSides"); + if (mCoverSides.length != 6) mCoverSides = new int[]{0, 0, 0, 0, 0, 0}; + for (byte i = 0; i < 6; i++) mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); + + // check old form of data + mCoverData = new ISerializableObject[6]; + if (aNBT.hasKey("mCoverData", 11) && aNBT.getIntArray("mCoverData").length == 6) { + int[] tOldData = aNBT.getIntArray("mCoverData"); + for (int i = 0; i < tOldData.length; i++) { + if(mCoverBehaviors[i] instanceof GT_Cover_Fluidfilter) { + final String filterKey = String.format("fluidFilter%d", i); + if (aNBT.hasKey(filterKey)) { + mCoverData[i] = mCoverBehaviors[i].createDataObject((tOldData[i] & 7) | (FluidRegistry.getFluidID(aNBT.getString(filterKey)) << 3)); + } + } else if (mCoverBehaviors[i] != null && mCoverBehaviors[i] != GregTech_API.sNoBehavior) { + mCoverData[i] = mCoverBehaviors[i].createDataObject(tOldData[i]); + } + } + } else { + // no old data + for (byte i = 0; i<6; i++) { + if (mCoverBehaviors[i] == null) + continue; + if (aNBT.hasKey(COVER_DATA_NBT_KEYS[i])) + mCoverData[i] = mCoverBehaviors[i].createDataObject(aNBT.getTag(COVER_DATA_NBT_KEYS[i])); + else + mCoverData[i] = mCoverBehaviors[i].createDataObject(); + } + } + } + + protected boolean doCoverThings() { + for (byte i = 0; i < 6; i++) + if (getCoverIDAtSide(i) != 0) { + GT_CoverBehaviorBase<?> tCover = getCoverBehaviorAtSideNew(i); + int tCoverTickRate = tCover.getTickRate(i, getCoverIDAtSide(i), mCoverData[i], this); + if (tCoverTickRate > 0 && mTickTimer % tCoverTickRate == 0) { + byte tRedstone = tCover.isRedstoneSensitive(i, getCoverIDAtSide(i), mCoverData[i], this, mTickTimer) ? getInputRedstoneSignal(i) : 0; + mCoverData[i] = tCover.doCoverThings(i, tRedstone, getCoverIDAtSide(i), mCoverData[i], this, mTickTimer); + if (!hasValidMetaTileEntity()) return false; + } + } + return true; + } + + protected void checkDropCover() { + for (byte i = 0; i < 6; i++) + if (getCoverIDAtSide(i) != 0) + if (!getMetaTileEntity().allowCoverOnSide(i, new GT_ItemStack(getCoverIDAtSide(i)))) + dropCover(i, i, true); + } + + protected void updateCoverBehavior() { + for (byte i = 0; i < 6; i++) + mCoverBehaviors[i] = GregTech_API.getCoverBehaviorNew(mCoverSides[i]); + } + + protected abstract boolean hasValidMetaTileEntity(); + + protected boolean createNewMetatileEntity(short aID) { + if (aID <= 0 || aID >= GregTech_API.METATILEENTITIES.length || GregTech_API.METATILEENTITIES[aID] == null) { + GT_Log.err.println("MetaID " + aID + " not loadable => locking TileEntity!"); + } else { + if (hasValidMetaTileEntity()) getMetaTileEntity().setBaseMetaTileEntity(null); + GregTech_API.METATILEENTITIES[aID].newMetaEntity(this).setBaseMetaTileEntity(this); + mTickTimer = 0; + mID = aID; + return true; + } + return false; + } + + @Override + public void setCoverIDAtSide(byte aSide, int aID) { + if (aSide >= 0 && aSide < 6) { + mCoverSides[aSide] = aID; + mCoverBehaviors[aSide] = GregTech_API.getCoverBehaviorNew(aID); + mCoverData[aSide] = mCoverBehaviors[aSide].createDataObject(); + issueCoverUpdate(aSide); + issueBlockUpdate(); + } + } + + @Override + @Deprecated + public GT_CoverBehavior getCoverBehaviorAtSide(byte aSide) { + if (aSide >= 0 && aSide < mCoverBehaviors.length && mCoverBehaviors[aSide] instanceof GT_CoverBehavior) + return (GT_CoverBehavior) mCoverBehaviors[aSide]; + return GregTech_API.sNoBehavior; + } + + @Override + public void setCoverItemAtSide(byte aSide, ItemStack aCover) { + GregTech_API.getCoverBehaviorNew(aCover).placeCover(aSide, aCover, this); + } + + @Override + public int getCoverIDAtSide(byte aSide) { + if (aSide >= 0 && aSide < 6) return mCoverSides[aSide]; + return 0; + } + + @Override + public ItemStack getCoverItemAtSide(byte aSide) { + return GT_Utility.intToStack(getCoverIDAtSide(aSide)); + } + + @Override + public boolean canPlaceCoverIDAtSide(byte aSide, int aID) { + return getCoverIDAtSide(aSide) == 0; + } + + @Override + public boolean canPlaceCoverItemAtSide(byte aSide, ItemStack aCover) { + return getCoverIDAtSide(aSide) == 0; + } + + @Override + @Deprecated + public int getCoverDataAtSide(byte aSide) { + if (aSide >= 0 && aSide < 6 && mCoverData[aSide] instanceof ISerializableObject.LegacyCoverData) + return ((ISerializableObject.LegacyCoverData) mCoverData[aSide]).get(); + return 0; + } + + @Override + @Deprecated + public void setCoverDataAtSide(byte aSide, int aData) { + if (aSide >= 0 && aSide < 6 && mCoverData[aSide] instanceof ISerializableObject.LegacyCoverData) + mCoverData[aSide] = new ISerializableObject.LegacyCoverData(aData); + } + + @Override + public void setCoverDataAtSide(byte aSide, ISerializableObject aData) { + if (aSide >= 0 && aSide < 6 && getCoverBehaviorAtSideNew(aSide) != null && getCoverBehaviorAtSideNew(aSide).cast(aData) != null) + mCoverData[aSide] = aData; + } + + @Override + public ISerializableObject getComplexCoverDataAtSide(byte aSide) { + if (aSide >= 0 && aSide < 6 && getCoverBehaviorAtSideNew(aSide) != null) + return mCoverData[aSide]; + return GregTech_API.sNoBehavior.createDataObject(); + } + + @Override + public GT_CoverBehaviorBase<?> getCoverBehaviorAtSideNew(byte aSide) { + if (aSide >= 0 && aSide < 6) + return mCoverBehaviors[aSide]; + return GregTech_API.sNoBehavior; + } + + @Override + public boolean dropCover(byte aSide, byte aDroppedSide, boolean aForced) { + if (getCoverBehaviorAtSideNew(aSide).onCoverRemoval(aSide, getCoverIDAtSide(aSide), mCoverData[aSide], this, aForced) || aForced) { + ItemStack tStack = getCoverBehaviorAtSideNew(aSide).getDrop(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), this); + if (tStack != null) { + tStack.setTagCompound(null); + EntityItem tEntity = new EntityItem(worldObj, getOffsetX(aDroppedSide, 1) + 0.5, getOffsetY(aDroppedSide, 1) + 0.5, getOffsetZ(aDroppedSide, 1) + 0.5, tStack); + tEntity.motionX = 0; + tEntity.motionY = 0; + tEntity.motionZ = 0; + worldObj.spawnEntityInWorld(tEntity); + } + setCoverIDAtSide(aSide, 0); + updateOutputRedstoneSignal(aSide); + + return true; + } + return false; + } + + protected void updateOutputRedstoneSignal(byte aSide) { + setOutputRedstoneSignal(aSide, (byte) 0); + } + +} diff --git a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java index 73a33fb9eb..217feb105d 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java @@ -8,7 +8,6 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IColoredTileEntity; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.BaseMetaTileEntity.ClientEvents; import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.*; import gregtech.common.GT_Client; @@ -303,19 +302,19 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable { @Override public final void sendSound(byte aIndex) { if (!getBaseMetaTileEntity().hasMufflerUpgrade()) - getBaseMetaTileEntity().sendBlockEvent(ClientEvents.DO_SOUND, aIndex); + getBaseMetaTileEntity().sendBlockEvent(MetaTileClientEvents.DO_SOUND, aIndex); } @Override public final void sendLoopStart(byte aIndex) { if (!getBaseMetaTileEntity().hasMufflerUpgrade()) - getBaseMetaTileEntity().sendBlockEvent(ClientEvents.START_SOUND_LOOP, aIndex); + getBaseMetaTileEntity().sendBlockEvent(MetaTileClientEvents.START_SOUND_LOOP, aIndex); } @Override public final void sendLoopEnd(byte aIndex) { if (!getBaseMetaTileEntity().hasMufflerUpgrade()) - getBaseMetaTileEntity().sendBlockEvent(ClientEvents.STOP_SOUND_LOOP, aIndex); + getBaseMetaTileEntity().sendBlockEvent(MetaTileClientEvents.STOP_SOUND_LOOP, aIndex); } @Override diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileClientEvents.java b/src/main/java/gregtech/api/metatileentity/MetaTileClientEvents.java new file mode 100644 index 0000000000..6b70783470 --- /dev/null +++ b/src/main/java/gregtech/api/metatileentity/MetaTileClientEvents.java @@ -0,0 +1,12 @@ +package gregtech.api.metatileentity; + +public class MetaTileClientEvents { + public static final byte CHANGE_COMMON_DATA = 0; + public static final byte CHANGE_CUSTOM_DATA = 1; + public static final byte CHANGE_COLOR = 2; + public static final byte CHANGE_REDSTONE_OUTPUT = 3; + public static final byte DO_SOUND = 4; + public static final byte START_SOUND_LOOP = 5; + public static final byte STOP_SOUND_LOOP = 6; + public static final byte CHANGE_LIGHT = 7; +} diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java index 3c499aea53..e69c8291da 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java @@ -5,12 +5,9 @@ import appeng.me.helpers.AENetworkProxy; import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import gnu.trove.list.TIntList; -import gnu.trove.list.array.TIntArrayList; import gregtech.api.GregTech_API; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.BaseMetaTileEntity.ClientEvents; import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Cable; import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.*; @@ -276,20 +273,20 @@ public abstract class MetaTileEntity implements IMetaTileEntity { @Override public final void sendSound(byte aIndex) { if (!getBaseMetaTileEntity().hasMufflerUpgrade()) - getBaseMetaTileEntity().sendBlockEvent(ClientEvents.DO_SOUND, aIndex); + getBaseMetaTileEntity().sendBlockEvent(MetaTileClientEvents.DO_SOUND, aIndex); } @Override public final void sendLoopStart(byte aIndex) { if (!getBaseMetaTileEntity().hasMufflerUpgrade()) - getBaseMetaTileEntity().sendBlockEvent(ClientEvents.START_SOUND_LOOP, aIndex); + getBaseMetaTileEntity().sendBlockEvent(MetaTileClientEvents.START_SOUND_LOOP, aIndex); mSoundRequests++; } @Override public final void sendLoopEnd(byte aIndex) { if (!getBaseMetaTileEntity().hasMufflerUpgrade()) - getBaseMetaTileEntity().sendBlockEvent(ClientEvents.STOP_SOUND_LOOP, aIndex); + getBaseMetaTileEntity().sendBlockEvent(MetaTileClientEvents.STOP_SOUND_LOOP, aIndex); } /** diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java index 85eebe5070..8fa9819e6a 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java @@ -37,6 +37,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { public static boolean disableMaintenance; public boolean mMachine = false, mWrench = false, mScrewdriver = false, mSoftHammer = false, mHardHammer = false, mSolderingTool = false, mCrowbar = false, mRunningOnLoad = false; + public boolean mStructureChanged = false; public int mPollution = 0, mProgresstime = 0, mMaxProgresstime = 0, mEUt = 0, mEfficiencyIncrease = 0, mStartUpCheck = 100, mRuntime = 0, mEfficiency = 0; public volatile int mUpdate = 0; //TODO: Replace with AtomicInteger public ItemStack[] mOutputItems = null; @@ -233,98 +234,60 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { return 2; } + /** + * Set the structure as having changed, and trigger an update. + */ + public void onStructureChange() { + mStructureChanged = true; + } + @Override public void onMachineBlockUpdate() { mUpdate = 50; } + /** + * ClearHatches as a part of structure check. + * If your multiblock has any hatches that need clearing override this method, call super, and clear your own hatches + */ + public void clearHatches() { + mInputHatches.clear(); + mInputBusses.clear(); + mOutputHatches.clear(); + mOutputBusses.clear(); + mDynamoHatches.clear(); + mEnergyHatches.clear(); + mMufflerHatches.clear(); + mMaintenanceHatches.clear(); + } + + public boolean checkStructure(boolean aForceReset) { + return checkStructure(aForceReset, getBaseMetaTileEntity()); + } + + public boolean checkStructure(boolean aForceReset, IGregTechTileEntity aBaseMetaTileEntity) { + if(!aBaseMetaTileEntity.isServerSide()) return mMachine; + // Only trigger an update if forced (from onPostTick, generally), or if the structure has changed + if ((mStructureChanged || aForceReset)) { + clearHatches(); + mMachine = checkMachine(aBaseMetaTileEntity, mInventory[1]); + } + mStructureChanged = false; + return mMachine; + } + @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { if (aBaseMetaTileEntity.isServerSide()) { if (mEfficiency < 0) mEfficiency = 0; if (--mUpdate == 0 || --mStartUpCheck == 0) { - mInputHatches.clear(); - mInputBusses.clear(); - mOutputHatches.clear(); - mOutputBusses.clear(); - mDynamoHatches.clear(); - mEnergyHatches.clear(); - mMufflerHatches.clear(); - mMaintenanceHatches.clear(); - mMachine = checkMachine(aBaseMetaTileEntity, mInventory[1]); + checkStructure(true, aBaseMetaTileEntity); } if (mStartUpCheck < 0) { if (mMachine) { - for (GT_MetaTileEntity_Hatch_Maintenance tHatch : mMaintenanceHatches) { - if (isValidMetaTileEntity(tHatch)) { - if (disableMaintenance){ - mWrench = true; - mScrewdriver = true; - mSoftHammer = true; - mHardHammer = true; - mSolderingTool = true; - mCrowbar = true; - } else { - if (tHatch.mAuto && !(mWrench&&mScrewdriver&&mSoftHammer&&mHardHammer&&mSolderingTool&&mCrowbar))tHatch.autoMaintainance(); - if (tHatch.mWrench) mWrench = true; - if (tHatch.mScrewdriver) mScrewdriver = true; - if (tHatch.mSoftHammer) mSoftHammer = true; - if (tHatch.mHardHammer) mHardHammer = true; - if (tHatch.mSolderingTool) mSolderingTool = true; - if (tHatch.mCrowbar) mCrowbar = true; - - tHatch.mWrench = false; - tHatch.mScrewdriver = false; - tHatch.mSoftHammer = false; - tHatch.mHardHammer = false; - tHatch.mSolderingTool = false; - tHatch.mCrowbar = false; - } - } - } + checkMaintenance(); if (getRepairStatus() > 0) { - if (mMaxProgresstime > 0 && doRandomMaintenanceDamage()) { - if (onRunningTick(mInventory[1])) { - if (!polluteEnvironment(getPollutionPerTick(mInventory[1]))) { - stopMachine(); - } - if (mMaxProgresstime > 0 && ++mProgresstime >= mMaxProgresstime) { - if (mOutputItems != null) for (ItemStack tStack : mOutputItems) - if (tStack != null) { - try { - GT_Mod.achievements.issueAchivementHatch(aBaseMetaTileEntity.getWorld().getPlayerEntityByName(aBaseMetaTileEntity.getOwnerName()), tStack); - } catch (Exception ignored) { - } - addOutput(tStack); - } - if (mOutputFluids != null) { - addFluidOutputs(mOutputFluids); - } - mEfficiency = Math.max(0, Math.min(mEfficiency + mEfficiencyIncrease, getMaxEfficiency(mInventory[1]) - ((getIdealStatus() - getRepairStatus()) * 1000))); - mOutputItems = null; - mProgresstime = 0; - mMaxProgresstime = 0; - mEfficiencyIncrease = 0; - if (aBaseMetaTileEntity.isAllowedToWork()) checkRecipe(mInventory[1]); - if (mOutputFluids != null && mOutputFluids.length > 0) { - if (mOutputFluids.length > 1) { - try { - GT_Mod.achievements.issueAchievement(aBaseMetaTileEntity.getWorld().getPlayerEntityByName(aBaseMetaTileEntity.getOwnerName()), "oilplant"); - } catch (Exception ignored) { - } - } - } - } - } - } else { - if (aTick % 100 == 0 || aBaseMetaTileEntity.hasWorkJustBeenEnabled() || aBaseMetaTileEntity.hasInventoryBeenModified()) { - - if (aBaseMetaTileEntity.isAllowedToWork()) { - checkRecipe(mInventory[1]); - } - if (mMaxProgresstime <= 0) mEfficiency = Math.max(0, mEfficiency - 1000); - } - } + runMachine(aBaseMetaTileEntity, aTick); } else { stopMachine(); } @@ -344,6 +307,83 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { } } + private void checkMaintenance() { + if (disableMaintenance) { + mWrench = true; + mScrewdriver = true; + mSoftHammer = true; + mHardHammer = true; + mSolderingTool = true; + mCrowbar = true; + + return; + } + for (GT_MetaTileEntity_Hatch_Maintenance tHatch : mMaintenanceHatches) { + if (isValidMetaTileEntity(tHatch)) { + if (tHatch.mAuto && !( mWrench && mScrewdriver && mSoftHammer && mHardHammer && mSolderingTool && mCrowbar)) tHatch.autoMaintainance(); + if (tHatch.mWrench) mWrench = true; + if (tHatch.mScrewdriver) mScrewdriver = true; + if (tHatch.mSoftHammer) mSoftHammer = true; + if (tHatch.mHardHammer) mHardHammer = true; + if (tHatch.mSolderingTool) mSolderingTool = true; + if (tHatch.mCrowbar) mCrowbar = true; + + tHatch.mWrench = false; + tHatch.mScrewdriver = false; + tHatch.mSoftHammer = false; + tHatch.mHardHammer = false; + tHatch.mSolderingTool = false; + tHatch.mCrowbar = false; + } + } + } + + protected void runMachine(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (mMaxProgresstime > 0 && doRandomMaintenanceDamage()) { + if (onRunningTick(mInventory[1])) { + if (!polluteEnvironment(getPollutionPerTick(mInventory[1]))) { + stopMachine(); + } + if (mMaxProgresstime > 0 && ++mProgresstime >= mMaxProgresstime) { + if (mOutputItems != null) for (ItemStack tStack : mOutputItems) + if (tStack != null) { + try { + GT_Mod.achievements.issueAchivementHatch( + aBaseMetaTileEntity.getWorld().getPlayerEntityByName(aBaseMetaTileEntity.getOwnerName()), tStack); + } catch (Exception ignored) { + } + addOutput(tStack); + } + if (mOutputFluids != null) { + addFluidOutputs(mOutputFluids); + } + mEfficiency = Math.max(0, Math.min(mEfficiency + mEfficiencyIncrease, getMaxEfficiency(mInventory[1]) - ((getIdealStatus() - getRepairStatus()) * 1000))); + mOutputItems = null; + mProgresstime = 0; + mMaxProgresstime = 0; + mEfficiencyIncrease = 0; + if (aBaseMetaTileEntity.isAllowedToWork()) checkRecipe(mInventory[1]); + if (mOutputFluids != null && mOutputFluids.length > 0) { + if (mOutputFluids.length > 1) { + try { + GT_Mod.achievements.issueAchievement(aBaseMetaTileEntity.getWorld().getPlayerEntityByName(aBaseMetaTileEntity.getOwnerName()), "oilplant"); + } catch (Exception ignored) { + } + } + } + } + } + } else { + if (aTick % 100 == 0 || aBaseMetaTileEntity.hasWorkJustBeenEnabled() || aBaseMetaTileEntity.hasInventoryBeenModified()) { + + if (aBaseMetaTileEntity.isAllowedToWork()) { + checkRecipe(mInventory[1]); + } + if (mMaxProgresstime <= 0) mEfficiency = Math.max(0, mEfficiency - 1000); + } + } + } + public boolean polluteEnvironment(int aPollutionLevel) { mPollution += aPollutionLevel; for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { @@ -483,62 +523,6 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { if (mInventory[1] != null && getBaseMetaTileEntity().getRandomNumber(2) == 0 && !mInventory[1].getUnlocalizedName().startsWith("gt.blockmachines.basicmachine.")) { if (mInventory[1].getItem() instanceof GT_MetaGenerated_Tool_01) { NBTTagCompound tNBT = mInventory[1].getTagCompound(); - if (tNBT != null) { - NBTTagCompound tNBT2 = tNBT.getCompoundTag("GT.CraftingComponents");//tNBT2 dont use out if - /*if (!tNBT.getBoolean("mDis")) { - tNBT2 = new NBTTagCompound(); - Materials tMaterial = GT_MetaGenerated_Tool.getPrimaryMaterial(mInventory[1]); - ItemStack tTurbine = GT_OreDictUnificator.get(OrePrefixes.turbineBlade, tMaterial, 1); - int i = mInventory[1].getItemDamage(); - if (i == 170) { - ItemStack tStack = GT_Utility.copyAmount(1, tTurbine); - tNBT2.setTag("Ingredient.0", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.1", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.2", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.3", tStack.writeToNBT(new NBTTagCompound())); - tStack = GT_OreDictUnificator.get(OrePrefixes.stickLong, Materials.Magnalium, 1); - tNBT2.setTag("Ingredient.4", tStack.writeToNBT(new NBTTagCompound())); - } else if (i == 172) { - ItemStack tStack = GT_Utility.copyAmount(1, tTurbine); - tNBT2.setTag("Ingredient.0", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.1", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.2", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.3", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.5", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.6", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.7", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.8", tStack.writeToNBT(new NBTTagCompound())); - tStack = GT_OreDictUnificator.get(OrePrefixes.stickLong, Materials.Titanium, 1); - tNBT2.setTag("Ingredient.4", tStack.writeToNBT(new NBTTagCompound())); - } else if (i == 174) { - ItemStack tStack = GT_Utility.copyAmount(2, tTurbine); - tNBT2.setTag("Ingredient.0", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.1", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.2", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.3", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.5", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.6", tStack.writeToNBT(new NBTTagCompound())); - tStack = GT_OreDictUnificator.get(OrePrefixes.stickLong, Materials.TungstenSteel, 1); - tNBT2.setTag("Ingredient.4", tStack.writeToNBT(new NBTTagCompound())); - } else if (i == 176) { - ItemStack tStack = GT_Utility.copyAmount(2, tTurbine); - tNBT2.setTag("Ingredient.0", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.1", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.2", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.3", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.5", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.6", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.7", tStack.writeToNBT(new NBTTagCompound())); - tNBT2.setTag("Ingredient.8", tStack.writeToNBT(new NBTTagCompound())); - tStack = GT_OreDictUnificator.get(OrePrefixes.stickLong, Materials.Americium, 1); - tNBT2.setTag("Ingredient.4", tStack.writeToNBT(new NBTTagCompound())); - } - tNBT.setTag("GT.CraftingComponents", tNBT2); - tNBT.setBoolean("mDis", true); - mInventory[1].setTagCompound(tNBT); - - }*/ - } ((GT_MetaGenerated_Tool) mInventory[1].getItem()).doDamage(mInventory[1], (long)getDamageToComponent(mInventory[1]) * (long) Math.min(mEUt / this.damageFactorLow, Math.pow(mEUt, this.damageFactorHigh))); if (mInventory[1].stackSize == 0) mInventory[1] = null; } @@ -858,12 +842,6 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { public ArrayList<ItemStack> getStoredInputs() { ArrayList<ItemStack> rList = new ArrayList<>(); -// for (GT_MetaTileEntity_Hatch_Input tHatch : mInputHatches) { -// tHatch.mRecipeMap = getRecipeMap(); -// if (isValidMetaTileEntity(tHatch) && tHatch.getBaseMetaTileEntity().getStackInSlot(0) != null) { -// rList.add(tHatch.getBaseMetaTileEntity().getStackInSlot(0)); -// } -// } for (GT_MetaTileEntity_Hatch_InputBus tHatch : mInputBusses) { tHatch.mRecipeMap = getRecipeMap(); if (isValidMetaTileEntity(tHatch)) { diff --git a/src/main/java/gregtech/api/util/GT_CLS_Compat.java b/src/main/java/gregtech/api/util/GT_CLS_Compat.java index 902aa28a80..83b292d274 100644 --- a/src/main/java/gregtech/api/util/GT_CLS_Compat.java +++ b/src/main/java/gregtech/api/util/GT_CLS_Compat.java @@ -4,6 +4,7 @@ import cpw.mods.fml.common.ProgressManager; import gregtech.GT_Mod; import gregtech.api.enums.Materials; import gregtech.common.GT_Proxy; +import gregtech.loaders.postload.GT_PostLoad; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -137,7 +138,7 @@ public class GT_CLS_Compat { } registerAndReportProgression("Vanilla materials", replacedVanillaItemsSet, progressBar, m -> m.mDefaultLocalName, - m -> GT_Mod.doActualRegistration(m) + m -> GT_PostLoad.doActualRegistration(m) ); } diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java index 80b505ccfb..0d8585994f 100644 --- a/src/main/java/gregtech/api/util/GT_ModHandler.java +++ b/src/main/java/gregtech/api/util/GT_ModHandler.java @@ -535,21 +535,12 @@ public class GT_ModHandler { /** * RC-BlastFurnace Recipes - + */ + @Deprecated public static boolean addRCBlastFurnaceRecipe(ItemStack aInput, ItemStack aOutput, int aTime) { - aOutput = GT_OreDictUnificator.get(true, aOutput); - if (aInput == null || aOutput == null || aTime <= 0) return false; - if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.rcblastfurnace, aInput, true)) return false; - aInput = GT_Utility.copyOrNull(aInput); - aOutput = GT_Utility.copyOrNull(aOutput); - try { - mods.railcraft.api.crafting.RailcraftCraftingManager.blastFurnace.addRecipe(aInput, true, false, aTime, aOutput); - } catch (Throwable e) { - return false; - } return true; } -*/ + public static boolean addPulverisationRecipe(ItemStack aInput, ItemStack aOutput1) { return addPulverisationRecipe(aInput, aOutput1, null, 0, false); } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java index be605e9249..02748d08c6 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java @@ -329,15 +329,7 @@ public abstract class GT_MetaTileEntity_FusionComputer extends GT_MetaTileEntity checkRecipe(mInventory[1]); } if (--mUpdate == 0 || --mStartUpCheck == 0) { - mInputHatches.clear(); - mInputBusses.clear(); - mOutputHatches.clear(); - mOutputBusses.clear(); - mDynamoHatches.clear(); - mEnergyHatches.clear(); - mMufflerHatches.clear(); - mMaintenanceHatches.clear(); - mMachine = checkMachine(aBaseMetaTileEntity, mInventory[1]); + checkStructure(true, aBaseMetaTileEntity); } if (mStartUpCheck < 0) { if (mMachine) { diff --git a/src/main/java/gregtech/loaders/postload/GT_PostLoad.java b/src/main/java/gregtech/loaders/postload/GT_PostLoad.java new file mode 100644 index 0000000000..02edca4332 --- /dev/null +++ b/src/main/java/gregtech/loaders/postload/GT_PostLoad.java @@ -0,0 +1,291 @@ +package gregtech.loaders.postload; + +import com.google.common.base.Stopwatch; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ProgressManager; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.GT_Mod; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.SubTag; +import gregtech.api.util.GT_CLS_Compat; +import gregtech.api.util.GT_Forestry_Compat; +import gregtech.api.util.GT_Log; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_RecipeRegistrator; +import gregtech.api.util.GT_Utility; +import gregtech.common.items.GT_MetaGenerated_Tool_01; +import gregtech.common.items.behaviors.Behaviour_DataOrb; +import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Massfabricator; +import ic2.api.recipe.IRecipeInput; +import ic2.api.recipe.RecipeOutput; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +import static gregtech.api.enums.GT_Values.MOD_ID_FR; + +@SuppressWarnings("ALL") +public class GT_PostLoad { + public static void activateOreDictHandler() { + Stopwatch stopwatch = Stopwatch.createStarted(); + GT_Mod.gregtechproxy.activateOreDictHandler(); + GT_Mod.GT_FML_LOGGER.info("Congratulations, you have been waiting long enough (" + stopwatch.stop() + "). Have a Cake."); + GT_Log.out.println("GT_Mod: List of Lists of Tool Recipes: " + GT_ModHandler.sSingleNonBlockDamagableRecipeList_list.toString()); + GT_Log.out.println("GT_Mod: Vanilla Recipe List -> Outputs null or stackSize <=0: " + GT_ModHandler.sVanillaRecipeList_warntOutput.toString()); + GT_Log.out.println("GT_Mod: Single Non Block Damagable Recipe List -> Outputs null or stackSize <=0: " + GT_ModHandler.sSingleNonBlockDamagableRecipeList_warntOutput.toString()); + } + + + public static void removeIc2Recipes(Map<IRecipeInput, RecipeOutput> aMaceratorRecipeList, Map<IRecipeInput, RecipeOutput> aCompressorRecipeList, Map<IRecipeInput, RecipeOutput> aExtractorRecipeList, Map<IRecipeInput, RecipeOutput> aOreWashingRecipeList, Map<IRecipeInput, RecipeOutput> aThermalCentrifugeRecipeList) { + Stopwatch stopwatch = Stopwatch.createStarted(); + // remove gemIridium exploit + ItemStack iridiumOre = GT_ModHandler.getIC2Item("iridiumOre", 1); + aCompressorRecipeList.entrySet().parallelStream() + .filter(e -> e.getKey().getInputs().size() == 1 && e.getKey().getInputs().get(0).isItemEqual(iridiumOre)) + .findAny() + .ifPresent(e -> aCompressorRecipeList.remove(e.getKey())); + //Add default IC2 recipe to GT + GT_ModHandler.addIC2RecipesToGT(aMaceratorRecipeList, GT_Recipe.GT_Recipe_Map.sMaceratorRecipes, true, true, true); + GT_ModHandler.addIC2RecipesToGT(aCompressorRecipeList, GT_Recipe.GT_Recipe_Map.sCompressorRecipes, true, true, true); + GT_ModHandler.addIC2RecipesToGT(aExtractorRecipeList, GT_Recipe.GT_Recipe_Map.sExtractorRecipes, true, true, true); + GT_ModHandler.addIC2RecipesToGT(aOreWashingRecipeList, GT_Recipe.GT_Recipe_Map.sOreWasherRecipes, false, true, true); + GT_ModHandler.addIC2RecipesToGT(aThermalCentrifugeRecipeList, GT_Recipe.GT_Recipe_Map.sThermalCentrifugeRecipes, true, true, true); + GT_Mod.GT_FML_LOGGER.info("IC2 Removal (" + stopwatch.stop() + "). Have a Cake."); + } + + + public static void registerFluidCannerRecipes() { + ItemStack ISdata0 = new ItemStack(Items.potionitem, 1, 0); + ItemStack ILdata0 = ItemList.Bottle_Empty.get(1L); + + for (FluidContainerRegistry.FluidContainerData tData : FluidContainerRegistry.getRegisteredFluidContainerData()) { + if ((tData.filledContainer.getItem() == Items.potionitem) && (tData.filledContainer.getItemDamage() == 0)) { + GT_Recipe.GT_Recipe_Map.sFluidCannerRecipes.addRecipe(true, new ItemStack[]{ILdata0}, new ItemStack[]{ISdata0}, null, new FluidStack[]{Materials.Water.getFluid(250L)}, null, 4, 1, 0); + GT_Recipe.GT_Recipe_Map.sFluidCannerRecipes.addRecipe(true, new ItemStack[]{ISdata0}, new ItemStack[]{ILdata0}, null, null, null, 4, 1, 0); + } else { + GT_Recipe.GT_Recipe_Map.sFluidCannerRecipes.addRecipe(true, new ItemStack[]{tData.emptyContainer}, new ItemStack[]{tData.filledContainer}, null, new FluidStack[]{tData.fluid}, null, tData.fluid.amount / 62, 1, 0); + GT_Recipe.GT_Recipe_Map.sFluidCannerRecipes.addRecipe(true, new ItemStack[]{tData.filledContainer}, new ItemStack[]{GT_Utility.getContainerItem(tData.filledContainer, true)}, null, null, new FluidStack[]{tData.fluid}, tData.fluid.amount / 62, 1, 0); + } + } + } + + public static void addFakeRecipes() { + GT_Log.out.println("GT_Mod: Adding Fake Recipes for NEI"); + + if (Loader.isModLoaded(MOD_ID_FR)) + GT_Forestry_Compat.populateFakeNeiRecipes(); + + if (ItemList.IC2_Crop_Seeds.get(1L) != null) { + GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{ItemList.IC2_Crop_Seeds.getWildcard(1L)}, new ItemStack[]{ItemList.IC2_Crop_Seeds.getWithName(1L, "Scanned Seeds")}, null, null, null, 160, 8, 0); + } + GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{new ItemStack(Items.written_book, 1, 32767)}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Scanned Book Data")}, ItemList.Tool_DataStick.getWithName(1L, "Stick to save it to"), null, null, 128, 30, 0); + GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{new ItemStack(Items.filled_map, 1, 32767)}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Scanned Map Data")}, ItemList.Tool_DataStick.getWithName(1L, "Stick to save it to"), null, null, 128, 30, 0); + GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{ItemList.Tool_DataOrb.getWithName(1L, "Orb to overwrite")}, new ItemStack[]{ItemList.Tool_DataOrb.getWithName(1L, "Copy of the Orb")}, ItemList.Tool_DataOrb.getWithName(0L, "Orb to copy"), null, null, 512, 30, 0); + GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Stick to overwrite")}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Copy of the Stick")}, ItemList.Tool_DataStick.getWithName(0L, "Stick to copy"), null, null, 128, 30, 0); + GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Raw Prospection Data")}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Analyzed Prospection Data")}, null, null, null, 1000, 30, 0); + if (Loader.isModLoaded("GalacticraftCore")) { + GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{GT_ModHandler.getModItem("GalacticraftCore", "item.schematic", 1, Short.MAX_VALUE).setStackDisplayName("Any Schematic")}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Scanned Schematic")}, ItemList.Tool_DataStick.getWithName(1L, "Stick to save it to"), null, null, 36000, 480, 0); + if (Loader.isModLoaded("GalacticraftMars")) + GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{GT_ModHandler.getModItem("GalacticraftMars", "item.schematic", 1, Short.MAX_VALUE).setStackDisplayName("Any Schematic")}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Scanned Schematic")}, ItemList.Tool_DataStick.getWithName(1L, "Stick to save it to"), null, null, 36000, 480, 0); + if (Loader.isModLoaded("GalaxySpace")) { + for (int i = 4; i < 9; i++) { + GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{GT_ModHandler.getModItem("GalaxySpace", "item.SchematicTier" + i, 1).setStackDisplayName("Any Schematic")}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Scanned Schematic")}, ItemList.Tool_DataStick.getWithName(1L, "Stick to save it to"), null, null, 36000, 480, 0); + } + } + } + Materials.getMaterialsMap().values().stream().forEach(tMaterial -> { + if ((tMaterial.mElement != null) && (!tMaterial.mElement.mIsIsotope) && (tMaterial != Materials.Magic) && (tMaterial.getMass() > 0L)) { + ItemStack tOutput = ItemList.Tool_DataOrb.get(1L); + Behaviour_DataOrb.setDataTitle(tOutput, "Elemental-Scan"); + Behaviour_DataOrb.setDataName(tOutput, tMaterial.mElement.name()); + ItemStack tInput = GT_OreDictUnificator.get(OrePrefixes.dust, tMaterial, 1L); + ItemStack[] ISmat0 = new ItemStack[]{tInput}; + ItemStack[] ISmat1 = new ItemStack[]{tOutput}; + if (tInput != null) { + GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, ISmat0, ISmat1, ItemList.Tool_DataOrb.get(1L), null, null, (int) (tMaterial.getMass() * 8192L), 30, 0); + GT_Recipe.GT_Recipe_Map.sReplicatorFakeRecipes.addFakeRecipe(false, null, ISmat0, ISmat1, new FluidStack[]{Materials.UUMatter.getFluid(tMaterial.getMass())}, null, (int) (tMaterial.getMass() * 512L), 30, 0); + + } + tInput = GT_OreDictUnificator.get(OrePrefixes.cell, tMaterial, 1L); + ISmat0 = new ItemStack[]{tInput}; + if (tInput != null) { + GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, ISmat0, ISmat1, ItemList.Tool_DataOrb.get(1L), null, null, (int) (tMaterial.getMass() * 8192L), 30, 0); + GT_Recipe.GT_Recipe_Map.sReplicatorFakeRecipes.addFakeRecipe(false, null, ISmat0, ISmat1, new FluidStack[]{Materials.UUMatter.getFluid(tMaterial.getMass())}, null, (int) (tMaterial.getMass() * 512L), 30, 0); + } + } + }); + + if (!GT_MetaTileEntity_Massfabricator.sRequiresUUA) + GT_Recipe.GT_Recipe_Map.sMassFabFakeRecipes.addFakeRecipe(false, null, null, null, null, new FluidStack[]{Materials.UUMatter.getFluid(1L)}, GT_MetaTileEntity_Massfabricator.sDurationMultiplier, 256, 0); + GT_Recipe.GT_Recipe_Map.sMassFabFakeRecipes.addFakeRecipe(false, null, null, null, new FluidStack[]{Materials.UUAmplifier.getFluid(GT_MetaTileEntity_Massfabricator.sUUAperUUM)}, new FluidStack[]{Materials.UUMatter.getFluid(1L)}, GT_MetaTileEntity_Massfabricator.sDurationMultiplier / GT_MetaTileEntity_Massfabricator.sUUASpeedBonus, 256, 0); + GT_Recipe.GT_Recipe_Map.sRockBreakerFakeRecipes.addFakeRecipe(false, new ItemStack[]{ItemList.Display_ITS_FREE.getWithName(0L, "Place Lava on Side")}, new ItemStack[]{new ItemStack( + Blocks.cobblestone, 1)}, null, null, null, 16, 30, 0); + GT_Recipe.GT_Recipe_Map.sRockBreakerFakeRecipes.addFakeRecipe(false, new ItemStack[]{ItemList.Display_ITS_FREE.getWithName(0L, "Place Lava on Top")}, new ItemStack[]{new ItemStack(Blocks.stone, 1)}, null, null, null, 16, 30, 0); + GT_Recipe.GT_Recipe_Map.sRockBreakerFakeRecipes.addFakeRecipe(false, new ItemStack[]{GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Redstone, 1L)}, new ItemStack[]{new ItemStack(Blocks.obsidian, 1)}, null, null, null, 128, 30, 0); + } + + public static void nerfVanillaTools() { + if (GT_Mod.gregtechproxy.mNerfedVanillaTools) { + GT_Log.out.println("GT_Mod: Nerfing Vanilla Tool Durability"); + Items.wooden_sword.setMaxDamage(12); + Items.wooden_pickaxe.setMaxDamage(12); + Items.wooden_shovel.setMaxDamage(12); + Items.wooden_axe.setMaxDamage(12); + Items.wooden_hoe.setMaxDamage(12); + + Items.stone_sword.setMaxDamage(48); + Items.stone_pickaxe.setMaxDamage(48); + Items.stone_shovel.setMaxDamage(48); + Items.stone_axe.setMaxDamage(48); + Items.stone_hoe.setMaxDamage(48); + + Items.iron_sword.setMaxDamage(256); + Items.iron_pickaxe.setMaxDamage(256); + Items.iron_shovel.setMaxDamage(256); + Items.iron_axe.setMaxDamage(256); + Items.iron_hoe.setMaxDamage(256); + + Items.golden_sword.setMaxDamage(24); + Items.golden_pickaxe.setMaxDamage(24); + Items.golden_shovel.setMaxDamage(24); + Items.golden_axe.setMaxDamage(24); + Items.golden_hoe.setMaxDamage(24); + + Items.diamond_sword.setMaxDamage(768); + Items.diamond_pickaxe.setMaxDamage(768); + Items.diamond_shovel.setMaxDamage(768); + Items.diamond_axe.setMaxDamage(768); + Items.diamond_hoe.setMaxDamage(768); + } + } + + public static void replaceVanillaMaterials() { + Stopwatch stopwatch = Stopwatch.createStarted(); + GT_Mod.GT_FML_LOGGER.info("Replacing Vanilla Materials in recipes, please wait."); + Set<Materials> replaceVanillaItemsSet = GT_Mod.gregtechproxy.mUseGreatlyShrukenReplacementList ? Arrays.stream(Materials.values()).filter(GT_RecipeRegistrator::hasVanillaRecipes).collect( + Collectors.toSet()) : new HashSet<>(Arrays.asList(Materials.values())); + + ProgressManager.ProgressBar progressBar = ProgressManager.push("Register materials", replaceVanillaItemsSet.size()); + if (GT_Values.cls_enabled){ + try { + GT_CLS_Compat.doActualRegistrationCLS(progressBar, replaceVanillaItemsSet); + GT_CLS_Compat.pushToDisplayProgress(); + } catch (InvocationTargetException | IllegalAccessException e) { + GT_Mod.GT_FML_LOGGER.catching(e); + } + } + else { + replaceVanillaItemsSet.forEach(m -> { + progressBar.step(m.mDefaultLocalName); + doActualRegistration(m); + }); + } + ProgressManager.pop(progressBar); + GT_Mod.GT_FML_LOGGER.info("Replaced Vanilla Materials (" + stopwatch.stop() + "). Have a Cake."); + } + + public static void doActualRegistration(Materials m){ + String platename = OrePrefixes.plate.get(m).toString(); + boolean noSmash = !m.contains(SubTag.NO_SMASHING); + if ((m.mTypes & 2) != 0) + GT_RecipeRegistrator.registerUsagesForMaterials(platename, noSmash, m.getIngots(1)); + if ((m.mTypes & 4) != 0) + GT_RecipeRegistrator.registerUsagesForMaterials(platename, noSmash, m.getGems(1)); + if (m.getBlocks(1) != null) + GT_RecipeRegistrator.registerUsagesForMaterials(null, noSmash, m.getBlocks(1)); + } + + + public static void createGTtoolsCreativeTab() { + CreativeTabs mainTab = new CreativeTabs("GTtools") { + @SideOnly(Side.CLIENT) + @Override + public ItemStack getIconItemStack() { + return ItemList.Tool_Cheat.get(1, new ItemStack(Blocks.iron_block, 1)); + } + + @SideOnly(Side.CLIENT) + @Override + public Item getTabIconItem() { + return ItemList.Circuit_Integrated.getItem(); + } + + @Override + public void displayAllReleventItems(List aList) { + for (int i = 0; i < 32766; i += 2) { + if (GT_MetaGenerated_Tool_01.INSTANCE.getToolStats(new ItemStack(GT_MetaGenerated_Tool_01.INSTANCE, 1, i)) != null) { + ItemStack tStack = new ItemStack(GT_MetaGenerated_Tool_01.INSTANCE, 1, i); + GT_MetaGenerated_Tool_01.INSTANCE.isItemStackUsable(tStack); + aList.add(GT_MetaGenerated_Tool_01.INSTANCE.getToolWithStats(i, 1, Materials.Lead, Materials.Lead, null)); + aList.add(GT_MetaGenerated_Tool_01.INSTANCE.getToolWithStats(i, 1, Materials.Nickel, Materials.Nickel, null)); + aList.add(GT_MetaGenerated_Tool_01.INSTANCE.getToolWithStats(i, 1, Materials.Cobalt, Materials.Cobalt, null)); + aList.add(GT_MetaGenerated_Tool_01.INSTANCE.getToolWithStats(i, 1, Materials.Osmium, Materials.Osmium, null)); + aList.add(GT_MetaGenerated_Tool_01.INSTANCE.getToolWithStats(i, 1, Materials.Adamantium, Materials.Adamantium, null)); + aList.add(GT_MetaGenerated_Tool_01.INSTANCE.getToolWithStats(i, 1, Materials.Neutronium, Materials.Neutronium, null)); + } + } + super.displayAllReleventItems(aList); + } + }; + } + + public static void addSolidFakeLargeBoilerFuels() { + GT_Recipe.GT_Recipe_Map.sLargeBoilerFakeFuels.addSolidRecipes( + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Charcoal, 1), + GT_OreDictUnificator.get(OrePrefixes.gem, Materials.Charcoal, 1), + GT_OreDictUnificator.get(OrePrefixes.block, Materials.Charcoal, 1), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Coal, 1), + GT_OreDictUnificator.get(OrePrefixes.gem, Materials.Coal, 1), + GT_OreDictUnificator.get(OrePrefixes.block, Materials.Coal, 1), + GT_OreDictUnificator.get(OrePrefixes.crushed, Materials.Coal, 1), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Lignite, 1), + GT_OreDictUnificator.get(OrePrefixes.gem, Materials.Lignite, 1), + GT_OreDictUnificator.get(OrePrefixes.block, Materials.Lignite, 1), + GT_OreDictUnificator.get(OrePrefixes.crushed, Materials.Lignite, 1), + GT_OreDictUnificator.get(OrePrefixes.log, Materials.Wood, 1), + GT_OreDictUnificator.get(OrePrefixes.plank, Materials.Wood, 1), + GT_OreDictUnificator.get(OrePrefixes.stick, Materials.Wood, 1), + GT_OreDictUnificator.get(OrePrefixes.slab, Materials.Wood, 1), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Wood, 1), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Sodium, 1), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Lithium, 1), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Caesium, 1), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Sulfur, 1), + GT_OreDictUnificator.get(ItemList.Block_SSFUEL.get(1)), + GT_OreDictUnificator.get(ItemList.Block_MSSFUEL.get(1)), + GT_OreDictUnificator.get(OrePrefixes.rod, Materials.Blaze, 1)); + if (Loader.isModLoaded("Thaumcraft")) { + GT_Recipe.GT_Recipe_Map.sLargeBoilerFakeFuels.addSolidRecipe(GT_ModHandler.getModItem("Thaumcraft", "ItemResource", 1)); + } + } + + public static void identifyAnySteam() { + final String[] steamCandidates = {"steam", "ic2steam"}; + final String[] superHeatedSteamCandidates = {"ic2superheatedsteam"}; + + GT_ModHandler.sAnySteamFluidIDs = Arrays.stream(steamCandidates).map(FluidRegistry::getFluid).filter(Objects::nonNull) + .map(FluidRegistry::getFluidID).collect(Collectors.toList()); + GT_ModHandler.sSuperHeatedSteamFluidIDs = Arrays.stream(superHeatedSteamCandidates).map(FluidRegistry::getFluid).filter(Objects::nonNull) + .map(FluidRegistry::getFluidID).collect(Collectors.toList()); + } +} diff --git a/src/main/java/gregtech/loaders/preload/GT_PreLoad.java b/src/main/java/gregtech/loaders/preload/GT_PreLoad.java new file mode 100644 index 0000000000..15f402e062 --- /dev/null +++ b/src/main/java/gregtech/loaders/preload/GT_PreLoad.java @@ -0,0 +1,527 @@ +package gregtech.loaders.preload; + +import cpw.mods.fml.common.LoadController; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ModContainer; +import gregtech.GT_Mod; +import gregtech.api.GregTech_API; +import gregtech.api.enums.ConfigCategories; +import gregtech.api.enums.Dyes; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.util.GT_Config; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_Log; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gregtech.common.tileentities.machines.long_distance.GT_MetaTileEntity_LongDistancePipelineBase; +import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_Cleanroom; +import net.minecraft.init.Blocks; +import net.minecraftforge.common.config.Configuration; +import org.apache.commons.lang3.StringUtils; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.List; +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static gregtech.GT_Mod.GT_FML_LOGGER; +import static gregtech.api.enums.GT_Values.MOD_ID_AE; + +@SuppressWarnings("ALL") +public class GT_PreLoad { + public static void sortToTheEnd() { + if (GT_Mod.gregtechproxy.mSortToTheEnd) { + try { + GT_FML_LOGGER.info("GT_Mod: Sorting GregTech to the end of the Mod List for further processing."); + LoadController tLoadController = (LoadController) GT_Utility.getFieldContent(Loader.instance(), "modController", true, true); + List<ModContainer> tModList = tLoadController.getActiveModList(); + List<ModContainer> tNewModsList = new ArrayList<>(); + ModContainer tGregTech = null; + short tModList_sS = (short) tModList.size(); + for (short i = 0; i < tModList_sS; i = (short) (i + 1)) { + ModContainer tMod = tModList.get(i); + if (tMod.getModId().equalsIgnoreCase("gregtech")) { + tGregTech = tMod; + } else { + tNewModsList.add(tMod); + } + } + if (tGregTech != null) { + tNewModsList.add(tGregTech); + } + GT_Utility.getField(tLoadController, "activeModList", true, true).set(tLoadController, tNewModsList); + } catch (Throwable e) { + GT_Mod.logStackTrace(e); + } + } + } + + public static void initLocalization(File languageDir) { + GT_FML_LOGGER.info("GT_Mod: Generating Lang-File"); + GT_LanguageManager.sEnglishFile = new Configuration(new File(languageDir, "GregTech.lang")); + GT_LanguageManager.sEnglishFile.load(); + if (GT_LanguageManager.sEnglishFile.get("EnableLangFile", "UseThisFileAsLanguageFile", false).getBoolean(false)) { + GT_LanguageManager.sLanguage = GT_LanguageManager.sEnglishFile.get("EnableLangFile", "Language", "en_US").getString(); + } + + Materials.getMaterialsMap().values().parallelStream().filter( + Objects::nonNull).forEach(aMaterial -> aMaterial.mLocalizedName = GT_LanguageManager.addStringLocalization("Material." + aMaterial.mName.toLowerCase(), aMaterial.mDefaultLocalName)); + } + + public static Configuration getConfiguration(File configDir) { + File tFile = new File(new File(configDir, "GregTech"), "GregTech.cfg"); + Configuration tMainConfig = new Configuration(tFile); + tMainConfig.load(); + tFile = new File(new File(configDir, "GregTech"), "IDs.cfg"); + GT_Config.sConfigFileIDs = new Configuration(tFile); + GT_Config.sConfigFileIDs.load(); + GT_Config.sConfigFileIDs.save(); + GregTech_API.sRecipeFile = new GT_Config(new Configuration(new File(new File(configDir, "GregTech"), "Recipes.cfg"))); + GregTech_API.sMachineFile = new GT_Config(new Configuration(new File(new File(configDir, "GregTech"), "MachineStats.cfg"))); + GregTech_API.sWorldgenFile = new GT_Config(new Configuration(new File(new File(configDir, "GregTech"), "WorldGeneration.cfg"))); + GregTech_API.sMaterialProperties = new GT_Config(new Configuration(new File(new File(configDir, "GregTech"), "MaterialProperties.cfg"))); + GregTech_API.sMaterialComponents = new GT_Config(new Configuration(new File(new File(configDir, "GregTech"), "MaterialComponents.cfg"))); + GregTech_API.sUnification = new GT_Config(new Configuration(new File(new File(configDir, "GregTech"), "Unification.cfg"))); + GregTech_API.sSpecialFile = new GT_Config(new Configuration(new File(new File(configDir, "GregTech"), "Other.cfg"))); + GregTech_API.sOPStuff = new GT_Config(new Configuration(new File(new File(configDir, "GregTech"), "OverpoweredStuff.cfg"))); + + GregTech_API.sClientDataFile = new GT_Config(new Configuration(new File(new File(configDir, "GregTech"), "Client.cfg"))); + return tMainConfig; + } + + public static void initCompat() { + GregTech_API.mIC2Classic = Loader.isModLoaded("IC2-Classic-Spmod"); + GregTech_API.mGTPlusPlus = Loader.isModLoaded("miscutils"); + GregTech_API.mTranslocator = Loader.isModLoaded("Translocator"); + GregTech_API.mTConstruct = Loader.isModLoaded("TConstruct"); + GregTech_API.mGalacticraft = Loader.isModLoaded("GalacticraftCore"); + GregTech_API.mAE2 = Loader.isModLoaded(MOD_ID_AE); + } + + public static void createLogFiles(File parentFile, Configuration tMainConfig) { + GT_Log.mLogFile = new File(parentFile, "logs/GregTech.log"); + if (!GT_Log.mLogFile.exists()) { + try { + GT_Log.mLogFile.createNewFile(); + } catch (Throwable ignored) {} + } + try { + GT_Log.out = GT_Log.err = new PrintStream(GT_Log.mLogFile); + } catch (FileNotFoundException ignored) {} + + if (tMainConfig.get(GT_Mod.aTextGeneral, "LoggingOreDict", false).getBoolean(false)) { + GT_Log.mOreDictLogFile = new File(parentFile, "logs/OreDict.log"); + if (!GT_Log.mOreDictLogFile.exists()) { + try { + GT_Log.mOreDictLogFile.createNewFile(); + } catch (Throwable ignored) {} + } + try { + GT_Log.ore = new PrintStream(GT_Log.mOreDictLogFile); + } catch (Throwable ignored) {} + try { + List<String> tList = ((GT_Log.LogBuffer) GT_Log.ore).mBufferedOreDictLog; + GT_Log.ore.println("******************************************************************************"); + GT_Log.ore.println("* This is the complete log of the GT5-Unofficial OreDictionary Handler. It *"); + GT_Log.ore.println("* processes all OreDictionary entries and can sometimes cause errors. All *"); + GT_Log.ore.println("* entries and errors are being logged. If you see an error please raise an *"); + GT_Log.ore.println("* issue at https://github.com/Blood-Asp/GT5-Unofficial. *"); + GT_Log.ore.println("******************************************************************************"); + tList.forEach(GT_Log.ore::println); + } catch (Throwable ignored) { + } + } + if (tMainConfig.get(GT_Mod.aTextGeneral, "LoggingExplosions", true).getBoolean(true)) { + GT_Log.mExplosionLog = new File(parentFile, "logs/Explosion.log"); + if (!GT_Log.mExplosionLog.exists()) { + try { + GT_Log.mExplosionLog.createNewFile(); + } catch (Throwable ignored) {} + } + try { + GT_Log.exp = new PrintStream(GT_Log.mExplosionLog); + } catch (Throwable ignored) {} + } + + if (tMainConfig.get(GT_Mod.aTextGeneral, "LoggingPlayerActivity", true).getBoolean(true)) { + GT_Log.mPlayerActivityLogFile = new File(parentFile, "logs/PlayerActivity.log"); + if (!GT_Log.mPlayerActivityLogFile.exists()) { + try { + GT_Log.mPlayerActivityLogFile.createNewFile(); + } catch (Throwable ignored) {} + } + try { + GT_Log.pal = new PrintStream(GT_Log.mPlayerActivityLogFile); + } catch (Throwable ignored) {} + } + } + + public static void runMineTweakerCompat() { + if (Loader.isModLoaded("MineTweaker3")) + return; + + GT_FML_LOGGER.info("preReader"); + final List<String> oreTags = new ArrayList<>(); + final File globalDir = new File("scripts"); + if (globalDir.exists()) { + final List<String> scripts = new ArrayList<>(); + for (File file : globalDir.listFiles()) { + if (file.getName().endsWith(".zs")) { + try (BufferedReader br = new BufferedReader(new FileReader(file))) { + String line; + while ((line = br.readLine()) != null) { + scripts.add(line); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + String pattern1 = "<"; + String pattern2 = ">"; + + Pattern p = Pattern.compile(Pattern.quote(pattern1) + "(.*?)" + Pattern.quote(pattern2)); + for (String text : scripts) { + Matcher m = p.matcher(text); + while (m.find()) { + String hit = m.group(1); + if (hit.startsWith("ore:")) { + hit = hit.substring(4); + if (!oreTags.contains(hit)) oreTags.add(hit); + } else if (hit.startsWith("gregtech:gt.metaitem.0")) { + hit = hit.substring(22); + int mIt = Integer.parseInt(hit.substring(0, 1)); + if (mIt > 0) { + int meta = 0; + try { + hit = hit.substring(2); + meta = Integer.parseInt(hit); + } catch (Exception e) { + GT_FML_LOGGER.info("parseError: " + hit); + } + if (meta > 0 && meta < 32000) { + int prefix = meta / 1000; + int material = meta % 1000; + String tag = ""; + String[] tags = new String[]{}; + if (mIt == 1) + tags = new String[]{"dustTiny", "dustSmall", "dust", "dustImpure", "dustPure", "crushed", "crushedPurified", "crushedCentrifuged", "gem", "nugget", null, "ingot", "ingotHot", "ingotDouble", "ingotTriple", "ingotQuadruple", "ingotQuintuple", "plate", "plateDouble", "plateTriple", "plateQuadruple", "plateQuintuple", "plateDense", "stick", "lens", "round", "bolt", "screw", "ring", "foil", "cell", "cellPlasma", "cellMolten"}; + if (mIt == 2) + tags = new String[]{"toolHeadSword", "toolHeadPickaxe", "toolHeadShovel", "toolHeadAxe", "toolHeadHoe", "toolHeadHammer", "toolHeadFile", "toolHeadSaw", "toolHeadDrill", "toolHeadChainsaw", "toolHeadWrench", "toolHeadUniversalSpade", "toolHeadSense", "toolHeadPlow", "toolHeadArrow", "toolHeadBuzzSaw", "turbineBlade", null, null, "wireFine", "gearGtSmall", "rotor", "stickLong", "springSmall", "spring", "arrowGtWood", "arrowGtPlastic", "gemChipped", "gemFlawed", "gemFlawless", "gemExquisite", "gearGt"}; + if (mIt == 3) + tags = new String[]{"crateGtDust", "crateGtIngot", "crateGtGem", "crateGtPlate", "itemCasing"}; + if (tags.length > prefix) tag = tags[prefix]; + if (GregTech_API.sGeneratedMaterials[material] != null) { + tag += GregTech_API.sGeneratedMaterials[material].mName; + if (!oreTags.contains(tag)) oreTags.add(tag); + } else if (material > 0) { + GT_FML_LOGGER.info("MaterialDisabled: " + material + " " + m.group(1)); + } + } + } + } + } + } + } + + final String[] preS = new String[]{"dustTiny", "dustSmall", "dust", "dustImpure", "dustPure", "crushed", "crushedPurified", "crushedCentrifuged", "gem", "nugget", "ingot", "ingotHot", "ingotDouble", "ingotTriple", "ingotQuadruple", "ingotQuintuple", "plate", "plateDouble", "plateTriple", "plateQuadruple", "plateQuintuple", "plateDense", "stick", "lens", "round", "bolt", "screw", "ring", "foil", "cell", "cellPlasma", "toolHeadSword", "toolHeadPickaxe", "toolHeadShovel", "toolHeadAxe", "toolHeadHoe", "toolHeadHammer", "toolHeadFile", "toolHeadSaw", "toolHeadDrill", "toolHeadChainsaw", "toolHeadWrench", "toolHeadUniversalSpade", "toolHeadSense", "toolHeadPlow", "toolHeadArrow", "toolHeadBuzzSaw", "turbineBlade", "wireFine", "gearGtSmall", "rotor", "stickLong", "springSmall", "spring", "arrowGtWood", "arrowGtPlastic", "gemChipped", "gemFlawed", "gemFlawless", "gemExquisite", "gearGt", "crateGtDust", "crateGtIngot", "crateGtGem", "crateGtPlate", "cellMolten"}; + + List<String> mMTTags = new ArrayList<>(); + oreTags.stream() + .filter(test -> StringUtils.startsWithAny(test, preS)) + .forEach(test -> { + mMTTags.add(test); + if (GT_Values.D1) + GT_FML_LOGGER.info("oretag: " + test); + }); + + GT_FML_LOGGER.info("reenableMetaItems"); + + for (String reEnable : mMTTags) { + OrePrefixes tPrefix = OrePrefixes.getOrePrefix(reEnable); + if (tPrefix != null) { + Materials tName = Materials.get(reEnable.replaceFirst(tPrefix.toString(), "")); + if (tName != null) { + tPrefix.mDisabledItems.remove(tName); + tPrefix.mGeneratedItems.add(tName); + if (tPrefix == OrePrefixes.screw) { + OrePrefixes.bolt.mDisabledItems.remove(tName); + OrePrefixes.bolt.mGeneratedItems.add(tName); + OrePrefixes.stick.mDisabledItems.remove(tName); + OrePrefixes.stick.mGeneratedItems.add(tName); + } + if (tPrefix == OrePrefixes.round) { + OrePrefixes.nugget.mDisabledItems.remove(tName); + OrePrefixes.nugget.mGeneratedItems.add(tName); + } + if (tPrefix == OrePrefixes.spring) { + OrePrefixes.stickLong.mDisabledItems.remove(tName); + OrePrefixes.stickLong.mGeneratedItems.add(tName); + OrePrefixes.stick.mDisabledItems.remove(tName); + OrePrefixes.stick.mGeneratedItems.add(tName); + } + if (tPrefix == OrePrefixes.springSmall) { + OrePrefixes.stick.mDisabledItems.remove(tName); + OrePrefixes.stick.mGeneratedItems.add(tName); + } + if (tPrefix == OrePrefixes.stickLong) { + OrePrefixes.stick.mDisabledItems.remove(tName); + OrePrefixes.stick.mGeneratedItems.add(tName); + } + if (tPrefix == OrePrefixes.rotor) { + OrePrefixes.ring.mDisabledItems.remove(tName); + OrePrefixes.ring.mGeneratedItems.add(tName); + } + } else { + GT_FML_LOGGER.info("noMaterial " + reEnable); + } + } else { + GT_FML_LOGGER.info("noPrefix " + reEnable); + } + } + } + + public static void adjustScrap() { + GT_FML_LOGGER.info("GT_Mod: Removing all original Scrapbox Drops."); + try { + GT_Utility.getField("ic2.core.item.ItemScrapbox$Drop", "topChance", true, true).set(null, 0); + ((List) GT_Utility.getFieldContent(GT_Utility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true), "drops", true, true)).clear(); + } catch (Throwable e) { + if (GT_Values.D1) { + e.printStackTrace(GT_Log.err); + } + } + GT_Log.out.println("GT_Mod: Adding Scrap with a Weight of 200.0F to the Scrapbox Drops."); + GT_ModHandler.addScrapboxDrop(200.0F, GT_ModHandler.getIC2Item("scrap", 1L)); + } + + public static void loadConfig(Configuration tMainConfig) { + GT_Values.D1 = tMainConfig.get(GT_Mod.aTextGeneral, "Debug", false).getBoolean(false); + GT_Values.D2 = tMainConfig.get(GT_Mod.aTextGeneral, "Debug2", false).getBoolean(false); + GT_Values.hideAssLineRecipes = tMainConfig.get(GT_Mod.aTextGeneral, "hide assline recipes", false).getBoolean(false); + GT_Values.updateFluidDisplayItems = tMainConfig.get(GT_Mod.aTextGeneral, "update fluid display items", true).getBoolean(true); + GT_Values.allow_broken_recipemap = tMainConfig.get(GT_Mod.aTextGeneral, "debug allow broken recipemap", false).getBoolean(false); + GT_Values.debugCleanroom = tMainConfig.get(GT_Mod.aTextGeneral, "debugCleanroom", false).getBoolean(false); + GT_Values.debugDriller = tMainConfig.get(GT_Mod.aTextGeneral, "debugDriller", false).getBoolean(false); + GT_Values.debugWorldGen = tMainConfig.get(GT_Mod.aTextGeneral, "debugWorldGen", false).getBoolean(false); + GT_Values.debugOrevein = tMainConfig.get(GT_Mod.aTextGeneral, "debugOrevein", false).getBoolean(false); + GT_Values.debugSmallOres = tMainConfig.get(GT_Mod.aTextGeneral, "debugSmallOres", false).getBoolean(false); + GT_Values.debugStones = tMainConfig.get(GT_Mod.aTextGeneral, "debugStones", false).getBoolean(false); + GT_Values.debugBlockMiner = tMainConfig.get(GT_Mod.aTextGeneral, "debugBlockMiner", false).getBoolean(false); + GT_Values.debugBlockPump = tMainConfig.get(GT_Mod.aTextGeneral, "debugBlockPump", false).getBoolean(false); + GT_Values.debugEntityCramming = tMainConfig.get(GT_Mod.aTextGeneral, "debugEntityCramming", false).getBoolean(false); + GT_Values.debugWorldData = tMainConfig.get(GT_Mod.aTextGeneral, "debugWorldData", false).getBoolean(false); + GT_Values.oreveinPercentage = tMainConfig.get(GT_Mod.aTextGeneral, "oreveinPercentage_100", 100).getInt(100); + GT_Values.oreveinAttempts = tMainConfig.get(GT_Mod.aTextGeneral, "oreveinAttempts_64", 64).getInt(64); + GT_Values.oreveinMaxPlacementAttempts = tMainConfig.get(GT_Mod.aTextGeneral, "oreveinMaxPlacementAttempts_8", 8).getInt(8); + GT_Values.oreveinPlacerOres = tMainConfig.get(GT_Mod.aTextGeneral, "oreveinPlacerOres", true).getBoolean(true); + GT_Values.oreveinPlacerOresMultiplier = tMainConfig.get(GT_Mod.aTextGeneral, "oreveinPlacerOresMultiplier", 2).getInt(2); + //GT_Values.oreveinMaxSize = tMainConfig.get(aTextGeneral, "oreveinMaxSize_64",64).getInt(64); + GT_Values.ticksBetweenSounds = tMainConfig.get("machines", "TicksBetweenSounds", 30).getInt(30); + GT_Values.cleanroomGlass = (float) tMainConfig.get("machines", "ReinforcedGlassPercentageForCleanroom", 5D).getDouble(5D); + GT_Values.enableChunkloaders = tMainConfig.get("machines", "enableChunkloaders", true).getBoolean(true); + GT_Values.alwaysReloadChunkloaders = tMainConfig.get("machines", "alwaysReloadChunkloaders", false).getBoolean(false); + GT_Values.debugChunkloaders = tMainConfig.get("machines", "debugChunkloaders", false).getBoolean(false); + GT_Values.disableDigitalChestsExternalAccess = tMainConfig.get("machines", "disableDigitalChestsExternalAccess", false).getBoolean(false); + GregTech_API.TICKS_FOR_LAG_AVERAGING = tMainConfig.get(GT_Mod.aTextGeneral, "TicksForLagAveragingWithScanner", 25).getInt(25); + GregTech_API.MILLISECOND_THRESHOLD_UNTIL_LAG_WARNING = tMainConfig.get(GT_Mod.aTextGeneral, "MillisecondsPassedInGTTileEntityUntilLagWarning", 100).getInt(100); + if (tMainConfig.get(GT_Mod.aTextGeneral, "disable_STDOUT", false).getBoolean(false)) { + GT_FML_LOGGER.info("Disableing Console Messages."); + GT_FML_LOGGER.exit(); + System.out.close(); + System.err.close(); + } + /*if (tMainConfig.get(aTextGeneral, "disable_STDERR", false).getBoolean(false)) { + System.err.close(); + }*/ + GregTech_API.sMachineExplosions = tMainConfig.get("machines", "machines_explosion_damage", true).getBoolean(false); + GregTech_API.sMachineFlammable = tMainConfig.get("machines", "machines_flammable", true).getBoolean(false); + GregTech_API.sMachineNonWrenchExplosions = tMainConfig.get("machines", "explosions_on_nonwrenching", true).getBoolean(false); + GregTech_API.sMachineWireFire = tMainConfig.get("machines", "wirefire_on_explosion", true).getBoolean(false); + GregTech_API.sMachineFireExplosions = tMainConfig.get("machines", "fire_causes_explosions", true).getBoolean(false); + GregTech_API.sMachineRainExplosions = tMainConfig.get("machines", "rain_causes_explosions", true).getBoolean(false); + GregTech_API.sMachineThunderExplosions = tMainConfig.get("machines", "lightning_causes_explosions", true).getBoolean(false); + GregTech_API.sConstantEnergy = tMainConfig.get("machines", "constant_need_of_energy", true).getBoolean(false); + GregTech_API.sColoredGUI = tMainConfig.get("machines", "colored_guis_when_painted", true).getBoolean(false); + GregTech_API.sMachineMetalGUI = tMainConfig.get("machines", "guis_in_consistent_machine_metal_color", false).getBoolean(false); + + // Implementation for this is actually handled in NewHorizonsCoreMod in MainRegistry.java! + GregTech_API.sUseMachineMetal = tMainConfig.get("machines", "use_machine_metal_tint", true).getBoolean(true); + + GregTech_API.sTimber = tMainConfig.get(GT_Mod.aTextGeneral, "timber_axe", true).getBoolean(true); + GregTech_API.sDrinksAlwaysDrinkable = tMainConfig.get(GT_Mod.aTextGeneral, "drinks_always_drinkable", false).getBoolean(false); + GregTech_API.sDoShowAllItemsInCreative = tMainConfig.get(GT_Mod.aTextGeneral, "show_all_metaitems_in_creative_and_NEI", false).getBoolean(false); + GregTech_API.sMultiThreadedSounds = tMainConfig.get(GT_Mod.aTextGeneral, "sound_multi_threading", false).getBoolean(false); + String SBdye0 = "ColorModulation."; + Arrays.stream(Dyes.values()).filter(tDye -> (tDye != Dyes._NULL) && (tDye.mIndex < 0)).forEach(tDye -> { + String SBdye1 = SBdye0 + tDye; + tDye.mRGBa[0] = ((short) Math.min(255, Math.max(0, GregTech_API.sClientDataFile.get(SBdye1, "R", tDye.mRGBa[0])))); + tDye.mRGBa[1] = ((short) Math.min(255, Math.max(0, GregTech_API.sClientDataFile.get(SBdye1, "G", tDye.mRGBa[1])))); + tDye.mRGBa[2] = ((short) Math.min(255, Math.max(0, GregTech_API.sClientDataFile.get(SBdye1, "B", tDye.mRGBa[2])))); + } + ); + GT_Mod.gregtechproxy.mRenderTileAmbientOcclusion = GregTech_API.sClientDataFile.get("render", "TileAmbientOcclusion", true); + GT_Mod.gregtechproxy.mRenderGlowTextures = GregTech_API.sClientDataFile.get("render", "GlowTextures", true); + GT_Mod.gregtechproxy.mRenderFlippedMachinesFlipped = GregTech_API.sClientDataFile.get("render", "RenderFlippedMachinesFlipped", true); + GT_Mod.gregtechproxy.mRenderIndicatorsOnHatch = GregTech_API.sClientDataFile.get("render", "RenderIndicatorsOnHatch", true); + GT_Mod.gregtechproxy.mRenderDirtParticles = GregTech_API.sClientDataFile.get("render", "RenderDirtParticles", true); + GT_Mod.gregtechproxy.mRenderPollutionFog = GregTech_API.sClientDataFile.get("render", "RenderPollutionFog", true); + + GT_Mod.gregtechproxy.mMaxEqualEntitiesAtOneSpot = tMainConfig.get(GT_Mod.aTextGeneral, "MaxEqualEntitiesAtOneSpot", 3).getInt(3); + GT_Mod.gregtechproxy.mSkeletonsShootGTArrows = tMainConfig.get(GT_Mod.aTextGeneral, "SkeletonsShootGTArrows", 16).getInt(16); + GT_Mod.gregtechproxy.mFlintChance = tMainConfig.get(GT_Mod.aTextGeneral, "FlintAndSteelChance", 30).getInt(30); + GT_Mod.gregtechproxy.mItemDespawnTime = tMainConfig.get(GT_Mod.aTextGeneral, "ItemDespawnTime", 6000).getInt(6000); + GT_Mod.gregtechproxy.mAllowSmallBoilerAutomation = tMainConfig.get(GT_Mod.aTextGeneral, "AllowSmallBoilerAutomation", false).getBoolean(false); + GT_Mod.gregtechproxy.mHardMachineCasings = tMainConfig.get(GT_Mod.aTextGeneral, "HardMachineCasings", true).getBoolean(true); + GT_Mod.gregtechproxy.mDisableVanillaOres = tMainConfig.get(GT_Mod.aTextGeneral, "DisableVanillaOres", true).getBoolean(true); + GT_Mod.gregtechproxy.mNerfDustCrafting = tMainConfig.get(GT_Mod.aTextGeneral, "NerfDustCrafting", true).getBoolean(true); + GT_Mod.gregtechproxy.mIncreaseDungeonLoot = tMainConfig.get(GT_Mod.aTextGeneral, "IncreaseDungeonLoot", true).getBoolean(true); + GT_Mod.gregtechproxy.mAxeWhenAdventure = tMainConfig.get(GT_Mod.aTextGeneral, "AdventureModeStartingAxe", true).getBoolean(true); + GT_Mod.gregtechproxy.mHardcoreCables = tMainConfig.get(GT_Mod.aTextGeneral, "HardCoreCableLoss", false).getBoolean(false); + GT_Mod.gregtechproxy.mSurvivalIntoAdventure = tMainConfig.get(GT_Mod.aTextGeneral, "forceAdventureMode", false).getBoolean(false); + GT_Mod.gregtechproxy.mHungerEffect = tMainConfig.get(GT_Mod.aTextGeneral, "AFK_Hunger", false).getBoolean(false); + GT_Mod.gregtechproxy.mHardRock = tMainConfig.get(GT_Mod.aTextGeneral, "harderstone", false).getBoolean(false); + GT_Mod.gregtechproxy.mInventoryUnification = tMainConfig.get(GT_Mod.aTextGeneral, "InventoryUnification", true).getBoolean(true); + GT_Mod.gregtechproxy.mGTBees = tMainConfig.get(GT_Mod.aTextGeneral, "GTBees", true).getBoolean(true); + GT_Mod.gregtechproxy.mCraftingUnification = tMainConfig.get(GT_Mod.aTextGeneral, "CraftingUnification", true).getBoolean(true); + GT_Mod.gregtechproxy.mNerfedWoodPlank = tMainConfig.get(GT_Mod.aTextGeneral, "WoodNeedsSawForCrafting", true).getBoolean(true); + GT_Mod.gregtechproxy.mNerfedVanillaTools = tMainConfig.get(GT_Mod.aTextGeneral, "smallerVanillaToolDurability", true).getBoolean(true); + GT_Mod.gregtechproxy.mSortToTheEnd = tMainConfig.get(GT_Mod.aTextGeneral, "EnsureToBeLoadedLast", true).getBoolean(true); + GT_Mod.gregtechproxy.mDisableIC2Cables = tMainConfig.get(GT_Mod.aTextGeneral, "DisableIC2Cables", true).getBoolean(true); + GT_Mod.gregtechproxy.mAchievements = tMainConfig.get(GT_Mod.aTextGeneral, "EnableAchievements", true).getBoolean(true); + GT_Mod.gregtechproxy.mAE2Integration = GregTech_API.sSpecialFile.get(ConfigCategories.general, "EnableAE2Integration", GregTech_API.mAE2); + GT_Mod.gregtechproxy.mNerfedCombs = tMainConfig.get(GT_Mod.aTextGeneral, "NerfCombs", true).getBoolean(true); + GT_Mod.gregtechproxy.mNerfedCrops = tMainConfig.get(GT_Mod.aTextGeneral, "NerfCrops", true).getBoolean(true); + GT_Mod.gregtechproxy.mHideUnusedOres = tMainConfig.get(GT_Mod.aTextGeneral, "HideUnusedOres", true).getBoolean(true); + GT_Mod.gregtechproxy.mHideRecyclingRecipes = tMainConfig.get(GT_Mod.aTextGeneral, "HideRecyclingRecipes", true).getBoolean(true); + GT_Mod.gregtechproxy.mArcSmeltIntoAnnealed = tMainConfig.get(GT_Mod.aTextGeneral, "ArcSmeltIntoAnnealedWrought", true).getBoolean(true); + GT_Mod.gregtechproxy.mEnableAllMaterials = tMainConfig.get("general", "EnableAllMaterials", false).getBoolean(false); + GT_Mod.gregtechproxy.mEnableAllComponents = tMainConfig.get("general", "EnableAllComponents", false).getBoolean(false); + + //Pollution: edit GT_Proxy.java to change default values + GT_Mod.gregtechproxy.mPollution = tMainConfig.get("Pollution", "EnablePollution", GT_Mod.gregtechproxy.mPollution).getBoolean( + GT_Mod.gregtechproxy.mPollution); + GT_Mod.gregtechproxy.mPollutionSmogLimit = tMainConfig.get("Pollution", "SmogLimit", GT_Mod.gregtechproxy.mPollutionSmogLimit).getInt( + GT_Mod.gregtechproxy.mPollutionSmogLimit); + GT_Mod.gregtechproxy.mPollutionPoisonLimit = tMainConfig.get("Pollution", "PoisonLimit", GT_Mod.gregtechproxy.mPollutionPoisonLimit).getInt( + GT_Mod.gregtechproxy.mPollutionPoisonLimit); + GT_Mod.gregtechproxy.mPollutionVegetationLimit = tMainConfig.get("Pollution", "VegetationLimit", GT_Mod.gregtechproxy.mPollutionVegetationLimit).getInt( + GT_Mod.gregtechproxy.mPollutionVegetationLimit); + GT_Mod.gregtechproxy.mPollutionSourRainLimit = tMainConfig.get("Pollution", "SourRainLimit", GT_Mod.gregtechproxy.mPollutionSourRainLimit).getInt( + GT_Mod.gregtechproxy.mPollutionSourRainLimit); + GT_Mod.gregtechproxy.mPollutionOnExplosion = tMainConfig.get("Pollution", "SourRainLimit", GT_Mod.gregtechproxy.mPollutionOnExplosion).getInt( + GT_Mod.gregtechproxy.mPollutionOnExplosion); + GT_Mod.gregtechproxy.mExplosionItemDrop = tMainConfig.get("general", "ExplosionItemDrops", GT_Mod.gregtechproxy.mExplosionItemDrop).getBoolean( + GT_Mod.gregtechproxy.mExplosionItemDrop); + GT_Mod.gregtechproxy.mPollutionPrimitveBlastFurnacePerSecond = tMainConfig.get("Pollution", "PollutionPrimitiveBlastFurnace", GT_Mod.gregtechproxy.mPollutionPrimitveBlastFurnacePerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionPrimitveBlastFurnacePerSecond); + GT_Mod.gregtechproxy.mPollutionCharcoalPitPerSecond = tMainConfig.get("Pollution", "PollutionCharcoalPit", GT_Mod.gregtechproxy.mPollutionCharcoalPitPerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionCharcoalPitPerSecond); + GT_Mod.gregtechproxy.mPollutionEBFPerSecond = tMainConfig.get("Pollution", "PollutionEBF", GT_Mod.gregtechproxy.mPollutionEBFPerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionEBFPerSecond); + GT_Mod.gregtechproxy.mPollutionLargeCombustionEnginePerSecond = tMainConfig.get("Pollution", "PollutionLargeCombustionEngine", GT_Mod.gregtechproxy.mPollutionLargeCombustionEnginePerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionLargeCombustionEnginePerSecond); + GT_Mod.gregtechproxy.mPollutionExtremeCombustionEnginePerSecond = tMainConfig.get("Pollution", "PollutionExtremeCombustionEngine", GT_Mod.gregtechproxy.mPollutionExtremeCombustionEnginePerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionExtremeCombustionEnginePerSecond); + GT_Mod.gregtechproxy.mPollutionImplosionCompressorPerSecond = tMainConfig.get("Pollution", "PollutionImplosionCompressor", GT_Mod.gregtechproxy.mPollutionImplosionCompressorPerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionImplosionCompressorPerSecond); + GT_Mod.gregtechproxy.mPollutionLargeBronzeBoilerPerSecond = tMainConfig.get("Pollution", "PollutionLargeBronzeBoiler", GT_Mod.gregtechproxy.mPollutionLargeBronzeBoilerPerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionLargeBronzeBoilerPerSecond); + GT_Mod.gregtechproxy.mPollutionLargeSteelBoilerPerSecond = tMainConfig.get("Pollution", "PollutionLargeSteelBoiler", GT_Mod.gregtechproxy.mPollutionLargeSteelBoilerPerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionLargeSteelBoilerPerSecond); + GT_Mod.gregtechproxy.mPollutionLargeTitaniumBoilerPerSecond = tMainConfig.get("Pollution", "PollutionLargeTitaniumBoiler", GT_Mod.gregtechproxy.mPollutionLargeTitaniumBoilerPerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionLargeTitaniumBoilerPerSecond); + GT_Mod.gregtechproxy.mPollutionLargeTungstenSteelBoilerPerSecond = tMainConfig.get("Pollution", "PollutionLargeTungstenSteelBoiler", GT_Mod.gregtechproxy.mPollutionLargeTungstenSteelBoilerPerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionLargeTungstenSteelBoilerPerSecond); + GT_Mod.gregtechproxy.mPollutionReleasedByThrottle = tMainConfig.get("Pollution", "PollutionReleasedByThrottle", GT_Mod.gregtechproxy.mPollutionReleasedByThrottle).getDouble( + GT_Mod.gregtechproxy.mPollutionReleasedByThrottle); + GT_Mod.gregtechproxy.mPollutionLargeGasTurbinePerSecond = tMainConfig.get("Pollution", "PollutionLargeGasTurbine", GT_Mod.gregtechproxy.mPollutionLargeGasTurbinePerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionLargeGasTurbinePerSecond); + GT_Mod.gregtechproxy.mPollutionMultiSmelterPerSecond = tMainConfig.get("Pollution", "PollutionMultiSmelter", GT_Mod.gregtechproxy.mPollutionMultiSmelterPerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionMultiSmelterPerSecond); + GT_Mod.gregtechproxy.mPollutionPyrolyseOvenPerSecond = tMainConfig.get("Pollution", "PollutionPyrolyseOven", GT_Mod.gregtechproxy.mPollutionPyrolyseOvenPerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionPyrolyseOvenPerSecond); + GT_Mod.gregtechproxy.mPollutionSmallCoalBoilerPerSecond = tMainConfig.get("Pollution", "PollutionSmallCoalBoiler", GT_Mod.gregtechproxy.mPollutionSmallCoalBoilerPerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionSmallCoalBoilerPerSecond); + GT_Mod.gregtechproxy.mPollutionHighPressureLavaBoilerPerSecond = tMainConfig.get("Pollution", "PollutionHighPressureLavaBoiler", GT_Mod.gregtechproxy.mPollutionHighPressureLavaBoilerPerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionHighPressureLavaBoilerPerSecond); + GT_Mod.gregtechproxy.mPollutionHighPressureCoalBoilerPerSecond = tMainConfig.get("Pollution", "PollutionHighPressureCoalBoiler", GT_Mod.gregtechproxy.mPollutionHighPressureCoalBoilerPerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionHighPressureCoalBoilerPerSecond); + GT_Mod.gregtechproxy.mPollutionBaseDieselGeneratorPerSecond = tMainConfig.get("Pollution", "PollutionBaseDieselGenerator", GT_Mod.gregtechproxy.mPollutionBaseDieselGeneratorPerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionBaseDieselGeneratorPerSecond); + GT_Mod.gregtechproxy.mPollutionDieselGeneratorReleasedByTier = tMainConfig.get("Pollution", "PollutionReleasedByTierDieselGenerator", GT_Mod.gregtechproxy.mPollutionDieselGeneratorReleasedByTier).getDoubleList(); + GT_Mod.gregtechproxy.mPollutionBaseGasTurbinePerSecond = tMainConfig.get("Pollution", "PollutionBaseGasTurbineGenerator", GT_Mod.gregtechproxy.mPollutionBaseGasTurbinePerSecond).getInt( + GT_Mod.gregtechproxy.mPollutionBaseGasTurbinePerSecond); + GT_Mod.gregtechproxy.mPollutionGasTurbineReleasedByTier = tMainConfig.get("Pollution", "PollutionReleasedByTierGasTurbineGenerator", GT_Mod.gregtechproxy.mPollutionGasTurbineReleasedByTier).getDoubleList(); + + GT_Mod.gregtechproxy.mUndergroundOil.getConfig(tMainConfig, "undergroundfluid"); + GT_Mod.gregtechproxy.mEnableCleanroom = tMainConfig.get("general", "EnableCleanroom", true).getBoolean(true); + if (GT_Mod.gregtechproxy.mEnableCleanroom) + GT_MetaTileEntity_Cleanroom.loadConfig(tMainConfig); + GT_Mod.gregtechproxy.mLowGravProcessing = Loader.isModLoaded(GT_Values.MOD_ID_GC_CORE) && tMainConfig.get("general", "LowGravProcessing", true).getBoolean(true); + GT_Mod.gregtechproxy.mUseGreatlyShrukenReplacementList = tMainConfig.get("general", "GTNH Optimised Material Loading", true).getBoolean(true); + Calendar now = Calendar.getInstance(); + GT_Mod.gregtechproxy.mAprilFool = GregTech_API.sSpecialFile.get(ConfigCategories.general, "AprilFool", now.get(Calendar.MONTH) == Calendar.APRIL && now.get(Calendar.DAY_OF_MONTH) == 1); + GT_Mod.gregtechproxy.mCropNeedBlock = tMainConfig.get("general", "CropNeedBlockBelow", true).getBoolean(true); + GT_Mod.gregtechproxy.mDisableOldChemicalRecipes = tMainConfig.get("general", "DisableOldChemicalRecipes", false).getBoolean(false); + GT_Mod.gregtechproxy.mAMHInteraction = tMainConfig.get("general", "AllowAutoMaintenanceHatchInteraction", false).getBoolean(false); + GregTech_API.mOutputRF = GregTech_API.sOPStuff.get(ConfigCategories.general, "OutputRF", true); + GregTech_API.mInputRF = GregTech_API.sOPStuff.get(ConfigCategories.general, "InputRF", false); + GregTech_API.mEUtoRF = GregTech_API.sOPStuff.get(ConfigCategories.general, "100EUtoRF", 360); + GregTech_API.mRFtoEU = GregTech_API.sOPStuff.get(ConfigCategories.general, "100RFtoEU", 20); + GregTech_API.mRFExplosions = GregTech_API.sOPStuff.get(ConfigCategories.general, "RFExplosions", false); + GregTech_API.meIOLoaded = Loader.isModLoaded("EnderIO"); + GT_Mod.gregtechproxy.mForceFreeFace = GregTech_API.sMachineFile.get(ConfigCategories.machineconfig, "forceFreeFace", true); + GT_Mod.gregtechproxy.mBrickedBlastFurnace = tMainConfig.get("general", "BrickedBlastFurnace", true).getBoolean(true); + GT_Mod.gregtechproxy.mEasierIVPlusCables = tMainConfig.get("general", "EasierEVPlusCables", false).getBoolean(false); + GT_Mod.gregtechproxy.mMixedOreOnlyYieldsTwoThirdsOfPureOre = tMainConfig.get("general", "MixedOreOnlyYieldsTwoThirdsOfPureOre", false).getBoolean(false); + GT_Mod.gregtechproxy.enableBlackGraniteOres = GregTech_API.sWorldgenFile.get("general", "enableBlackGraniteOres", GT_Mod.gregtechproxy.enableBlackGraniteOres); + GT_Mod.gregtechproxy.enableRedGraniteOres = GregTech_API.sWorldgenFile.get("general", "enableRedGraniteOres", GT_Mod.gregtechproxy.enableRedGraniteOres); + GT_Mod.gregtechproxy.enableMarbleOres = GregTech_API.sWorldgenFile.get("general", "enableMarbleOres", GT_Mod.gregtechproxy.enableMarbleOres); + GT_Mod.gregtechproxy.enableBasaltOres = GregTech_API.sWorldgenFile.get("general", "enableBasaltOres", GT_Mod.gregtechproxy.enableBasaltOres); + GT_Mod.gregtechproxy.gt6Pipe = tMainConfig.get("general", "GT6StyledPipesConnection", true).getBoolean(true); + GT_Mod.gregtechproxy.gt6Cable = tMainConfig.get("general", "GT6StyledWiresConnection", true).getBoolean(true); + GT_Mod.gregtechproxy.ic2EnergySourceCompat = tMainConfig.get("general", "Ic2EnergySourceCompat", true).getBoolean(true); + GT_Mod.gregtechproxy.costlyCableConnection = tMainConfig.get("general", "CableConnectionRequiresSolderingMaterial", false).getBoolean(false); + GT_LanguageManager.i18nPlaceholder = tMainConfig.get("general", "EnablePlaceholderForMaterialNamesInLangFile", true).getBoolean(true); + GT_MetaTileEntity_LongDistancePipelineBase.minimalDistancePoints = tMainConfig.get("general", "LongDistancePipelineMinimalDistancePoints", 64).getInt(64); + + GregTech_API.mUseOnlyGoodSolderingMaterials = GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.harderrecipes, "useonlygoodsolderingmaterials", GregTech_API.mUseOnlyGoodSolderingMaterials); + GT_Mod.gregtechproxy.mChangeHarvestLevels = GregTech_API.sMaterialProperties.get("havestLevel", "activateHarvestLevelChange", false);//TODO CHECK + if (GT_Mod.gregtechproxy.mChangeHarvestLevels) { + GT_Mod.gregtechproxy.mGraniteHavestLevel = GregTech_API.sMaterialProperties.get("havestLevel", "graniteHarvestLevel", 3); + GT_Mod.gregtechproxy.mMaxHarvestLevel = Math.min(15, GregTech_API.sMaterialProperties.get("havestLevel", "maxLevel", 7)); + Materials.getMaterialsMap().values().parallelStream().filter(tMaterial -> tMaterial != null && tMaterial.mToolQuality > 0 && tMaterial.mMetaItemSubID < GT_Mod.gregtechproxy.mHarvestLevel.length && tMaterial.mMetaItemSubID >= 0).forEach( + tMaterial -> GT_Mod.gregtechproxy.mHarvestLevel[tMaterial.mMetaItemSubID] = GregTech_API.sMaterialProperties.get("materialHavestLevel", tMaterial.mDefaultLocalName, tMaterial.mToolQuality) + ); + } + + if (tMainConfig.get("general", "hardermobspawners", true).getBoolean(true)) { + Blocks.mob_spawner.setHardness(500.0F).setResistance(6000000.0F); + } + GT_Mod.gregtechproxy.mOnline = tMainConfig.get(GT_Mod.aTextGeneral, "online", true).getBoolean(false); + + GT_Mod.gregtechproxy.mUpgradeCount = Math.min(64, Math.max(1, tMainConfig.get("features", "UpgradeStacksize", 4).getInt())); + for (OrePrefixes tPrefix : OrePrefixes.values()) { + if (tPrefix.mIsUsedForOreProcessing) { + tPrefix.mDefaultStackSize = ((byte) Math.min(64, Math.max(1, tMainConfig.get("features", "MaxOreStackSize", 64).getInt()))); + } else if (tPrefix == OrePrefixes.plank) { + tPrefix.mDefaultStackSize = ((byte) Math.min(64, Math.max(16, tMainConfig.get("features", "MaxPlankStackSize", 64).getInt()))); + } else if ((tPrefix == OrePrefixes.wood) || (tPrefix == OrePrefixes.treeLeaves) || (tPrefix == OrePrefixes.treeSapling) || (tPrefix == OrePrefixes.log)) { + tPrefix.mDefaultStackSize = ((byte) Math.min(64, Math.max(16, tMainConfig.get("features", "MaxLogStackSize", 64).getInt()))); + } else if (tPrefix.mIsUsedForBlocks) { + tPrefix.mDefaultStackSize = ((byte) Math.min(64, Math.max(16, tMainConfig.get("features", "MaxOtherBlockStackSize", 64).getInt()))); + } + } + } +} |