ForgePatch/src/main/java/net/minecraftforge/fml/language/ModContainer.java

123 lines
3.2 KiB
Java
Raw Normal View History

2012-03-30 14:11:13 +00:00
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* 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
2012-03-30 14:11:13 +00:00
*/
package net.minecraftforge.fml.language;
2018-06-11 01:12:46 +00:00
import net.minecraftforge.fml.LifecycleEventProvider;
import net.minecraftforge.fml.loading.ModLoadingStage;
2018-06-11 01:12:46 +00:00
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
/**
* The container that wraps around mods in the system.
* <p>
* The philosophy is that individual mod implementation technologies should not
* impact the actual loading and management of mod code. This interface provides
* a mechanism by which we can wrap actual mod code so that the loader and other
* facilities can treat mods at arms length.
* </p>
*
* @author cpw
*
*/
2012-03-30 14:11:13 +00:00
2018-06-11 01:12:46 +00:00
public abstract class ModContainer
{
2018-06-11 01:12:46 +00:00
protected final String modId;
protected final IModInfo modInfo;
protected ModLoadingStage modLoadingStage;
protected final Map<ModLoadingStage, Consumer<LifecycleEventProvider.LifecycleEvent>> triggerMap;
public ModContainer(IModInfo info)
{
this.modId = info.getModId();
this.modInfo = info;
this.triggerMap = new HashMap<>();
this.modLoadingStage = ModLoadingStage.BEGIN;
}
/**
2018-06-11 01:12:46 +00:00
* @return the modid for this mod
*/
2018-06-11 01:12:46 +00:00
public final String getModId()
{
return modId;
}
/**
2018-06-11 01:12:46 +00:00
* @return the resource prefix for the mod
*/
2018-06-11 01:12:46 +00:00
public final String getPrefix()
{
return modId;
}
/**
2018-06-11 01:12:46 +00:00
* @return The current loading stage for this mod
*/
2018-06-11 01:12:46 +00:00
public ModLoadingStage getCurrentState()
{
return modLoadingStage;
}
/**
2018-06-11 01:12:46 +00:00
* Transition the mod to this event if possible.
* @param event to transition to
*/
2018-06-11 01:12:46 +00:00
public final void transitionState(LifecycleEventProvider.LifecycleEvent event)
{
if (modLoadingStage != event.fromStage())
{
try
{
triggerMap.getOrDefault(modLoadingStage, e->{}).accept(event);
modLoadingStage = event.toStage();
}
catch (RuntimeException e)
{
modLoadingStage = ModLoadingStage.ERROR;
}
}
}
/**
2018-06-11 01:12:46 +00:00
* @return the modinfo used to create this mod instance
*/
2018-06-11 01:12:46 +00:00
public IModInfo getModInfo()
{
return modInfo;
}
/**
2018-06-11 01:12:46 +00:00
* Does this mod match the supplied mod?
*
2018-06-11 01:12:46 +00:00
* @param mod to compare
* @return if the mod matches
*/
2018-06-11 01:12:46 +00:00
public abstract boolean matches(Object mod);
/**
2018-06-11 01:12:46 +00:00
* @return the mod object instance
*/
2018-06-11 01:12:46 +00:00
public abstract Object getMod();
public abstract <T> T getCustomExtension(final String name);
2012-03-30 14:11:13 +00:00
}