2018-06-06 11:37:56 -04:00
/*
* Minecraft Forge
2019-02-10 17:57:03 -05:00
* Copyright (c) 2016-2019.
2018-06-06 11:37:56 -04:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml ;
2019-02-13 22:13:59 -05:00
import net.minecraftforge.common.ForgeConfigSpec ;
import net.minecraftforge.fml.config.ModConfig ;
2019-02-13 21:06:39 -05:00
import java.util.function.Supplier ;
public class ModLoadingContext
2018-06-06 11:37:56 -04:00
{
2019-02-13 21:06:39 -05:00
private static ThreadLocal < ModLoadingContext > context = ThreadLocal . withInitial ( ModLoadingContext :: new );
2019-02-13 22:13:59 -05:00
private Object languageExtension ;
2018-06-06 11:37:56 -04:00
2019-02-13 21:06:39 -05:00
public static ModLoadingContext get () {
2018-06-06 11:37:56 -04:00
return context . get ();
}
2018-06-21 15:37:32 -04:00
private ModContainer activeContainer ;
2018-06-06 11:37:56 -04:00
2019-02-13 22:13:59 -05:00
public void setActiveContainer ( final ModContainer container , final Object languageExtension ) {
2018-06-21 15:37:32 -04:00
this . activeContainer = container ;
2019-02-13 22:13:59 -05:00
this . languageExtension = languageExtension ;
2018-06-21 15:37:32 -04:00
}
public ModContainer getActiveContainer () {
2019-08-04 20:16:01 -04:00
return activeContainer == null ? ModList . get (). getModContainerById ( "minecraft" ). orElseThrow (() -> new RuntimeException ( "Where is minecraft???!" )) : activeContainer ;
}
public String getActiveNamespace () {
return activeContainer == null ? "minecraft" : activeContainer . getNamespace ();
2018-06-06 11:37:56 -04:00
}
2019-02-13 21:06:39 -05:00
/**
* Register an {@link ExtensionPoint} with the mod container.
* @param point The extension point to register
* @param extension An extension operator
* @param <T> The type signature of the extension operator
*/
public < T > void registerExtensionPoint ( ExtensionPoint < T > point , Supplier < T > extension ) {
getActiveContainer (). registerExtensionPoint ( point , extension );
}
2019-02-13 22:13:59 -05:00
public void registerConfig ( ModConfig . Type type , ForgeConfigSpec spec ) {
getActiveContainer (). addConfig ( new ModConfig ( type , spec , getActiveContainer ()));
}
public void registerConfig ( ModConfig . Type type , ForgeConfigSpec spec , String fileName ) {
getActiveContainer (). addConfig ( new ModConfig ( type , spec , getActiveContainer (), fileName ));
}
@SuppressWarnings ( "unchecked" )
public < T > T extension () {
return ( T ) languageExtension ;
}
2018-06-06 11:37:56 -04:00
}