mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +00:00
Things. they work. Obviously still WAY more to do.
This commit is contained in:
1 parent
1b1ee6f0b8
commit
baa9dfe55a
95 files changed
+852
-786
No files matched your search
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.common;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModAnnotation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Automatic eventbus subscriber - reads {@link net.minecraftforge.fml.common.Mod.EventBusSubscriber}
|
||||
* annotations and passes the class instances to the {@link net.minecraftforge.common.MinecraftForge.EVENT_BUS}
|
||||
*/
|
||||
public class AutomaticEventSubscriber
|
||||
{
|
||||
private static final EnumSet<Side> DEFAULT = EnumSet.allOf(Side.class);
|
||||
public static void inject(ModContainer mod, ASMDataTable data, Side side)
|
||||
{
|
||||
FMLLog.log.debug("Attempting to inject @EventBusSubscriber classes into the eventbus for {}", mod.getModId());
|
||||
SetMultimap<String, ASMData> modData = data.getAnnotationsFor(mod);
|
||||
Set<ASMDataTable.ASMData> mods = modData.get(Mod.class.getName());
|
||||
Set<ASMDataTable.ASMData> targets = modData.get(Mod.EventBusSubscriber.class.getName());
|
||||
ClassLoader mcl = Loader.instance().getModClassLoader();
|
||||
|
||||
for (ASMDataTable.ASMData targ : targets)
|
||||
{
|
||||
try
|
||||
{
|
||||
//noinspection unchecked
|
||||
@SuppressWarnings("unchecked")
|
||||
List<ModAnnotation.EnumHolder> sidesEnum = (List<ModAnnotation.EnumHolder>)targ.getAnnotationInfo().get("value");
|
||||
EnumSet<Side> sides = DEFAULT;
|
||||
if (sidesEnum != null) {
|
||||
sides = EnumSet.noneOf(Side.class);
|
||||
for (ModAnnotation.EnumHolder h: sidesEnum) {
|
||||
sides.add(Side.valueOf(h.getValue()));
|
||||
}
|
||||
}
|
||||
if (sides == DEFAULT || sides.contains(side)) {
|
||||
//FMLLog.log.debug("Found @EventBusSubscriber class {}", targ.getClassName());
|
||||
String amodid = (String)targ.getAnnotationInfo().get("modid");
|
||||
if (Strings.isNullOrEmpty(amodid)) {
|
||||
amodid = ASMDataTable.getOwnerModID(mods, targ);
|
||||
if (Strings.isNullOrEmpty(amodid)) {
|
||||
FMLLog.bigWarning("Could not determine owning mod for @EventBusSubscriber on {} for mod {}", targ.getClassName(), mod.getModId());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!mod.getModId().equals(amodid))
|
||||
{
|
||||
FMLLog.log.debug("Skipping @EventBusSubscriber injection for {} since it is not for mod {}", targ.getClassName(), mod.getModId());
|
||||
continue; //We're not injecting this guy
|
||||
}
|
||||
FMLLog.log.debug("Registering @EventBusSubscriber for {} for mod {}", targ.getClassName(), mod.getModId());
|
||||
Class<?> subscriptionTarget = Class.forName(targ.getClassName(), false, mcl);
|
||||
MinecraftForge.EVENT_BUS.register(subscriptionTarget);
|
||||
FMLLog.log.debug("Injected @EventBusSubscriber class {}", targ.getClassName());
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
FMLLog.log.error("An error occurred trying to load an EventBusSubscriber {} for modid {}", targ.getClassName(), mod.getModId(), e);
|
||||
throw new LoaderException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -62,7 +62,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
|
||||
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.thread.SidedThreadGroup;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.server.FMLServerHandler;
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ import net.minecraftforge.fml.common.network.NetworkCheckHandler;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.network.internal.FMLNetworkHandler;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.registries.ForgeRegistry;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
@@ -119,7 +119,7 @@ public final class FMLContainer extends DummyModContainer implements WorldAccess
|
||||
mod.setString("ModVersion", mc.getVersion());
|
||||
modList.appendTag(mod);
|
||||
}
|
||||
fmlData.setTag("ModList", modList);
|
||||
fmlData.setTag("LoadingModList", modList);
|
||||
|
||||
NBTTagCompound registries = new NBTTagCompound();
|
||||
fmlData.setTag("Registries", registries);
|
||||
@@ -135,9 +135,9 @@ public final class FMLContainer extends DummyModContainer implements WorldAccess
|
||||
@Override
|
||||
public void readData(SaveHandler handler, WorldInfo info, Map<String, NBTBase> propertyMap, NBTTagCompound tag)
|
||||
{
|
||||
if (tag.hasKey("ModList"))
|
||||
if (tag.hasKey("LoadingModList"))
|
||||
{
|
||||
NBTTagList modList = tag.getTagList("ModList", (byte)10);
|
||||
NBTTagList modList = tag.getTagList("LoadingModList", (byte)10);
|
||||
for (int i = 0; i < modList.tagCount(); i++)
|
||||
{
|
||||
NBTTagCompound mod = modList.getCompoundTagAt(i);
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
package net.minecraftforge.fml.common;
|
||||
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
|
||||
public interface FMLContainerHolder
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.IThreadListener;
|
||||
import net.minecraftforge.common.util.CompoundDataFixer;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
public interface IFMLSidedHandler
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import net.minecraftforge.fml.javafmlmod.FMLModContainer;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
public interface ILanguageAdapter {
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.stream.Stream;
|
||||
import net.minecraftforge.common.util.TextTable;
|
||||
import net.minecraftforge.fml.common.LoaderState.ModState;
|
||||
import net.minecraftforge.fml.common.ProgressManager.ProgressBar;
|
||||
import net.minecraftforge.fml.common.event.FMLEvent;
|
||||
import net.minecraftforge.fml.common.event.ModLifecycleEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLLoadEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLModDisabledEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
@@ -39,7 +39,7 @@ import net.minecraftforge.fml.common.event.FMLStateEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.FMLThrowingEventBus;
|
||||
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
|
||||
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.ThreadContext;
|
||||
import org.apache.logging.log4j.message.FormattedMessage;
|
||||
@@ -175,7 +175,7 @@ public class LoadController
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void propogateStateMessage(FMLEvent stateEvent)
|
||||
public void propogateStateMessage(ModLifecycleEvent stateEvent)
|
||||
{
|
||||
if (stateEvent instanceof FMLPreInitializationEvent)
|
||||
{
|
||||
@@ -190,7 +190,7 @@ public class LoadController
|
||||
ProgressManager.pop(bar);
|
||||
}
|
||||
|
||||
private void sendEventToModContainer(FMLEvent stateEvent, ModContainer mc)
|
||||
private void sendEventToModContainer(ModLifecycleEvent stateEvent, ModContainer mc)
|
||||
{
|
||||
String modId = mc.getModId();
|
||||
Collection<String> requirements = mc.getRequirements().stream().map(ArtifactVersion::getLabel).collect(Collectors.toCollection(HashSet::new));
|
||||
|
||||
@@ -42,8 +42,8 @@ import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
import net.minecraftforge.common.config.ConfigManager;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.fml.common.LoaderState.ModState;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.language.ModContainer.Disableable;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer.Disableable;
|
||||
import net.minecraftforge.fml.common.ProgressManager.ProgressBar;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable;
|
||||
import net.minecraftforge.fml.common.discovery.ContainerType;
|
||||
|
||||
@@ -24,8 +24,8 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import net.minecraftforge.fml.client.IModGuiFactory;
|
||||
import net.minecraftforge.fml.common.event.FMLEvent;
|
||||
import net.minecraftforge.api.Side;
|
||||
import net.minecraftforge.fml.common.event.ModLifecycleEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms;
|
||||
@@ -37,15 +37,12 @@ import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStoppedEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCEvent;
|
||||
import net.minecraftforge.fml.common.network.NetworkCheckHandler;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.common.versioning.VersionRange;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
/**
|
||||
* This defines a Mod to FML.
|
||||
* Any class found with this annotation applied will be loaded as a Mod. The instance that is loaded will
|
||||
* represent the mod to other Mods in the system. It will be sent various subclasses of {@link FMLEvent}
|
||||
* represent the mod to other Mods in the system. It will be sent various subclasses of {@link ModLifecycleEvent}
|
||||
* at pre-defined times during the loading of the game, based on where you have applied the {@link EventHandler}
|
||||
* annotation.
|
||||
*/
|
||||
@@ -60,7 +57,7 @@ public @interface Mod
|
||||
* This will be used to identify your mod for third parties (other mods), it will be used to identify your mod for registries such as block and item registries.
|
||||
* By default, you will have a resource domain that matches the modid. All these uses require that constraints are imposed on the format of the modid.
|
||||
*/
|
||||
String modid();
|
||||
String value();
|
||||
/**
|
||||
* Marks the associated method as handling an FML lifecycle event.
|
||||
* The method must have a single parameter, one of the following types. This annotation
|
||||
@@ -105,20 +102,6 @@ public @interface Mod
|
||||
@Target(ElementType.METHOD)
|
||||
@interface EventHandler{}
|
||||
|
||||
/**
|
||||
* Populate the annotated field with the mod instance based on the specified ModId. This can be used
|
||||
* to retrieve instances of other mods.
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
@interface Instance {
|
||||
/**
|
||||
* The mod object to inject into this field
|
||||
*/
|
||||
String value() default "";
|
||||
}
|
||||
/**
|
||||
* A class which will be subscribed to {@link net.minecraftforge.common.MinecraftForge.EVENT_BUS} at mod construction time.
|
||||
*/
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.util.Map;
|
||||
import net.minecraftforge.fml.common.discovery.ModCandidate;
|
||||
import net.minecraftforge.fml.common.discovery.asm.ASMModParser;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLModContainer;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModAnnotation;
|
||||
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
|
||||
/**
|
||||
* @author cpw
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.Set;
|
||||
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
@@ -24,6 +24,7 @@ import net.minecraftforge.fml.client.GuiWrongMinecraft;
|
||||
import net.minecraftforge.fml.client.IDisplayableError;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
|
||||
public class WrongMinecraftVersionException extends EnhancedRuntimeException implements IDisplayableError
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
|
||||
public class ASMDataTable
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@ package net.minecraftforge.fml.common.discovery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
|
||||
public enum ContainerType
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.regex.Matcher;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.LoaderException;
|
||||
import net.minecraftforge.fml.common.MetadataCollection;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.common.ModContainerFactory;
|
||||
import net.minecraftforge.fml.common.discovery.asm.ASMModParser;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ package net.minecraftforge.fml.common.discovery;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
|
||||
public interface ITypeDiscoverer
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.jar.JarFile;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.LoaderException;
|
||||
import net.minecraftforge.fml.common.MetadataCollection;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.common.ModContainerFactory;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData;
|
||||
import net.minecraftforge.fml.common.discovery.asm.ASMModParser;
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.List;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.LoaderException;
|
||||
import net.minecraftforge.fml.common.ModClassLoader;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.relauncher.CoreModManager;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.common.event;
|
||||
|
||||
import net.minecraftforge.fml.common.ModClassLoader;
|
||||
import net.minecraftforge.fml.common.LoaderState.ModState;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable;
|
||||
|
||||
import com.google.common.collect.ListMultimap;
|
||||
|
||||
/**
|
||||
* An internal FML event used to signal the construction of mods. Should not be used by mods.
|
||||
*/
|
||||
public class FMLConstructionEvent extends FMLStateEvent
|
||||
{
|
||||
private ModClassLoader modClassLoader;
|
||||
private ASMDataTable asmData;
|
||||
private ListMultimap<String,String> reverseDependencies;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public FMLConstructionEvent(Object... eventData)
|
||||
{
|
||||
this.modClassLoader = (ModClassLoader)eventData[0];
|
||||
this.asmData = (ASMDataTable) eventData[1];
|
||||
this.reverseDependencies = (ListMultimap<String, String>) eventData[2];
|
||||
}
|
||||
|
||||
public ModClassLoader getModClassLoader()
|
||||
{
|
||||
return modClassLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModState getModState()
|
||||
{
|
||||
return ModState.CONSTRUCTED;
|
||||
}
|
||||
|
||||
public ASMDataTable getASMHarvestedData()
|
||||
{
|
||||
return asmData;
|
||||
}
|
||||
|
||||
public ListMultimap<String, String> getReverseDependencies()
|
||||
{
|
||||
return reverseDependencies;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,8 @@ import net.minecraftforge.fml.common.Mod;
|
||||
* A special event used when the {@link Mod#certificateFingerprint()} doesn't match the certificate loaded from the JAR
|
||||
* file. You could use this to log a warning that the code that is running might not be yours, for example.
|
||||
*/
|
||||
public class FMLFingerprintViolationEvent extends FMLEvent {
|
||||
public class FMLFingerprintViolationEvent extends ModLifecycleEvent
|
||||
{
|
||||
|
||||
private final boolean isDirectory;
|
||||
private final Set<String> fingerprints;
|
||||
@@ -39,7 +40,7 @@ public class FMLFingerprintViolationEvent extends FMLEvent {
|
||||
|
||||
public FMLFingerprintViolationEvent(boolean isDirectory, File source, ImmutableSet<String> fingerprints, String expectedFingerprint)
|
||||
{
|
||||
super();
|
||||
super(null);
|
||||
this.isDirectory = isDirectory;
|
||||
this.source = source;
|
||||
this.fingerprints = fingerprints;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
package net.minecraftforge.fml.common.event;
|
||||
|
||||
import net.minecraftforge.fml.common.LoaderState.ModState;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
|
||||
/**
|
||||
* Called after {@link FMLPreInitializationEvent} and before {@link FMLPostInitializationEvent} during mod
|
||||
@@ -34,18 +34,11 @@ import net.minecraftforge.fml.common.LoaderState.ModState;
|
||||
* @see net.minecraftforge.fml.common.Mod.EventHandler for how to subscribe to this event
|
||||
* @author cpw
|
||||
*/
|
||||
public class FMLInitializationEvent extends FMLStateEvent
|
||||
public class FMLInitializationEvent extends ModLifecycleEvent
|
||||
{
|
||||
|
||||
public FMLInitializationEvent(Object... data)
|
||||
public FMLInitializationEvent(final ModContainer container)
|
||||
{
|
||||
super(data);
|
||||
super(container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModState getModState()
|
||||
{
|
||||
return ModState.INITIALIZED;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,11 +24,13 @@ import java.util.Optional;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.ModThreadContext;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.LoaderState;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.common.Mod.Instance;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
@@ -54,9 +56,15 @@ public class FMLInterModComms {
|
||||
* @see net.minecraftforge.fml.common.Mod.EventHandler for how to subscribe to this event
|
||||
* @author cpw
|
||||
*/
|
||||
public static class IMCEvent extends FMLEvent {
|
||||
public static class IMCEvent extends ModLifecycleEvent
|
||||
{
|
||||
private ModContainer activeContainer;
|
||||
|
||||
public IMCEvent()
|
||||
{
|
||||
super(activeContainer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyModContainer(ModContainer activeContainer)
|
||||
{
|
||||
@@ -371,27 +379,19 @@ public class FMLInterModComms {
|
||||
|
||||
private static boolean enqueueStartupMessage(String modTarget, IMCMessage message)
|
||||
{
|
||||
if (Loader.instance().activeModContainer() == null)
|
||||
if (ModThreadContext.get().getCurrentContainer() == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
enqueueMessage(Loader.instance().activeModContainer(), modTarget, message);
|
||||
return Loader.isModLoaded(modTarget) && !Loader.instance().hasReachedState(LoaderState.POSTINITIALIZATION);
|
||||
enqueueMessage(ModThreadContext.get().getCurrentContainer(), modTarget, message);
|
||||
return ModList.get().isLoaded(modTarget);
|
||||
|
||||
}
|
||||
private static void enqueueMessage(Object sourceMod, String modTarget, IMCMessage message)
|
||||
private static void enqueueMessage(ModContainer sourceMod, String modTarget, IMCMessage message)
|
||||
{
|
||||
ModContainer mc;
|
||||
if (sourceMod instanceof ModContainer) {
|
||||
mc = (ModContainer) sourceMod;
|
||||
}
|
||||
else
|
||||
if (ModList.get().isLoaded(modTarget))
|
||||
{
|
||||
mc = FMLCommonHandler.instance().findContainerFor(sourceMod);
|
||||
}
|
||||
if (mc != null && Loader.isModLoaded(modTarget))
|
||||
{
|
||||
message.setSender(mc);
|
||||
message.setSender(sourceMod);
|
||||
modMessages.put(modTarget, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
package net.minecraftforge.fml.common.event;
|
||||
|
||||
import net.minecraftforge.fml.common.LoaderState.ModState;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
|
||||
/**
|
||||
* This is a mostly internal event fired to mod containers that indicates that loading is complete. Mods should not
|
||||
@@ -27,18 +27,10 @@ import net.minecraftforge.fml.common.LoaderState.ModState;
|
||||
*
|
||||
* @author cpw
|
||||
*/
|
||||
public class FMLLoadCompleteEvent extends FMLStateEvent
|
||||
public class FMLLoadCompleteEvent extends ModLifecycleEvent
|
||||
{
|
||||
|
||||
public FMLLoadCompleteEvent(Object... data)
|
||||
public FMLLoadCompleteEvent(final ModContainer container)
|
||||
{
|
||||
super(data);
|
||||
super(container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModState getModState()
|
||||
{
|
||||
return ModState.AVAILABLE;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.common.event;
|
||||
|
||||
/**
|
||||
* Internal only event, used to begin the lifecycle of loading mods.
|
||||
*
|
||||
* @author cpw
|
||||
*/
|
||||
public class FMLLoadEvent
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
package net.minecraftforge.fml.common.event;
|
||||
|
||||
public class FMLModDisabledEvent extends FMLEvent {
|
||||
}
|
||||
@@ -42,7 +42,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
* @see net.minecraftforge.fml.common.Mod.EventHandler for how to subscribe to this event
|
||||
* @author cpw
|
||||
*/
|
||||
public class FMLModIdMappingEvent extends FMLEvent
|
||||
public class FMLModIdMappingEvent extends ModLifecycleEvent
|
||||
{
|
||||
public class ModRemapping
|
||||
{
|
||||
@@ -66,6 +66,7 @@ public class FMLModIdMappingEvent extends FMLEvent
|
||||
public final boolean isFrozen;
|
||||
public FMLModIdMappingEvent(Map<ResourceLocation, Map<ResourceLocation, Integer[]>> remaps, boolean isFrozen)
|
||||
{
|
||||
super(null);
|
||||
this.isFrozen = isFrozen;
|
||||
this.remaps = Maps.newHashMap();
|
||||
remaps.forEach((name, rm) ->
|
||||
|
||||
@@ -19,15 +19,7 @@
|
||||
|
||||
package net.minecraftforge.fml.common.event;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.LoaderState.ModState;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
|
||||
/**
|
||||
* Called after {@link FMLInitializationEvent} has been dispatched on every mod. This is the third and last
|
||||
@@ -38,45 +30,10 @@ import java.lang.reflect.Constructor;
|
||||
* @see net.minecraftforge.fml.common.Mod.EventHandler for how to subscribe to this event
|
||||
* @author cpw
|
||||
*/
|
||||
public class FMLPostInitializationEvent extends FMLStateEvent
|
||||
public class FMLPostInitializationEvent extends ModLifecycleEvent
|
||||
{
|
||||
public FMLPostInitializationEvent(Object... data)
|
||||
public FMLPostInitializationEvent(final ModContainer container)
|
||||
{
|
||||
super(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModState getModState()
|
||||
{
|
||||
return ModState.POSTINITIALIZED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an object depending on if a specific target mod is loaded or not.
|
||||
*
|
||||
* Usually would be used to access an object from the other mod.
|
||||
*
|
||||
* @param modId The modId I conditionally want to build an object for
|
||||
* @param className The name of the class I wish to instantiate
|
||||
* @return An optional containing the object if possible, or null if not
|
||||
*/
|
||||
public Optional<?> buildSoftDependProxy(String modId, String className, Object... arguments)
|
||||
{
|
||||
if (Loader.isModLoaded(modId))
|
||||
{
|
||||
Class<?>[] args = Arrays.stream(arguments).filter(Objects::nonNull).map(Object::getClass).toArray(Class<?>[]::new);
|
||||
try
|
||||
{
|
||||
Class<?> clz = Class.forName(className,true,Loader.instance().getModClassLoader());
|
||||
Constructor<?> ct = clz.getConstructor(args);
|
||||
return Optional.of(ct.newInstance(arguments));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLLog.log.info("An error occurred trying to build a soft depend proxy", e);
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
super(container);
|
||||
}
|
||||
}
|
||||
@@ -19,21 +19,8 @@
|
||||
|
||||
package net.minecraftforge.fml.common.event;
|
||||
|
||||
import java.io.File;
|
||||
import java.security.CodeSource;
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.Properties;
|
||||
|
||||
import net.minecraftforge.fml.javafmlmod.FMLModContainer;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.common.ModMetadata;
|
||||
import net.minecraftforge.fml.common.LoaderState.ModState;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Called before {@link FMLInitializationEvent} during mod startup.
|
||||
@@ -50,131 +37,10 @@ import javax.annotation.Nullable;
|
||||
* @see net.minecraftforge.fml.common.Mod.EventHandler for how to subscribe to this event
|
||||
* @author cpw
|
||||
*/
|
||||
public class FMLPreInitializationEvent extends FMLStateEvent
|
||||
public class FMLPreInitializationEvent extends ModLifecycleEvent
|
||||
{
|
||||
private ModMetadata modMetadata;
|
||||
private File sourceFile;
|
||||
private File configurationDir;
|
||||
private File suggestedConfigFile;
|
||||
private ASMDataTable asmData;
|
||||
private ModContainer modContainer;
|
||||
|
||||
public FMLPreInitializationEvent(Object... data)
|
||||
public FMLPreInitializationEvent(final ModContainer container)
|
||||
{
|
||||
super(data);
|
||||
this.asmData = (ASMDataTable)data[0];
|
||||
this.configurationDir = (File)data[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModState getModState()
|
||||
{
|
||||
return ModState.PREINITIALIZED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyModContainer(ModContainer activeContainer)
|
||||
{
|
||||
this.modContainer = activeContainer;
|
||||
this.modMetadata = activeContainer.getMetadata();
|
||||
this.sourceFile = activeContainer.getSource();
|
||||
this.suggestedConfigFile = new File(configurationDir, activeContainer.getModId()+".cfg");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link File} the mod was loaded from
|
||||
* @return The file the mod was loaded from
|
||||
*/
|
||||
public File getSourceFile()
|
||||
{
|
||||
return sourceFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link ModMetadata} for this mod
|
||||
* @return the mod metadata for the mod
|
||||
*/
|
||||
public ModMetadata getModMetadata()
|
||||
{
|
||||
return modMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the main configuration directory for this minecraft instance
|
||||
* @return the main configuration directory
|
||||
*/
|
||||
public File getModConfigurationDirectory()
|
||||
{
|
||||
return configurationDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a suggested configuration file for this mod. It will be of the form <modid>.cfg
|
||||
* @return A suggested configuration file name for this mod
|
||||
*/
|
||||
public File getSuggestedConfigurationFile()
|
||||
{
|
||||
return suggestedConfigFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link ASMDataTable} for this instance of Minecraft. This is a special structure containing
|
||||
* parsing information from FML. It can be searched for annotations parsed out by FML.
|
||||
* @return
|
||||
*/
|
||||
public ASMDataTable getAsmData()
|
||||
{
|
||||
return asmData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a version.properties file as a {@link Properties} object from the mod file.
|
||||
* This can be used to load build-type information
|
||||
* such as a unique version number from a properties file shipped as part of the distributable.
|
||||
* @return A properties object if one exists, else null
|
||||
*/
|
||||
@Nullable
|
||||
public Properties getVersionProperties()
|
||||
{
|
||||
if (this.modContainer instanceof FMLModContainer)
|
||||
{
|
||||
return ((FMLModContainer)this.modContainer).searchForVersionProperties();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a logger instance configured to write to the FML Log as a parent, identified by modid. Handy for mod logging!
|
||||
*
|
||||
* @return A logger
|
||||
*/
|
||||
public Logger getModLog()
|
||||
{
|
||||
return LogManager.getLogger(modContainer.getModId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the FML signing certificates, if any. Validate these against the
|
||||
* published FML certificates in your mod, if you wish.
|
||||
*
|
||||
* Deprecated because mods should <b>NOT</b> trust this code. Rather
|
||||
* they should copy this, or something like this, into their own mods.
|
||||
*
|
||||
* @return Certificates used to sign FML and Forge
|
||||
*/
|
||||
@Deprecated
|
||||
public Certificate[] getFMLSigningCertificates()
|
||||
{
|
||||
CodeSource codeSource = getClass().getClassLoader().getParent().getClass().getProtectionDomain().getCodeSource();
|
||||
Certificate[] certs = codeSource.getCertificates();
|
||||
if (certs == null)
|
||||
{
|
||||
return new Certificate[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
return certs;
|
||||
}
|
||||
super(container);
|
||||
}
|
||||
}
|
||||
@@ -20,25 +20,19 @@
|
||||
package net.minecraftforge.fml.common.event;
|
||||
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.LoaderState.ModState;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
/**
|
||||
* The parent of all mod-state changing events
|
||||
*/
|
||||
public abstract class FMLStateEvent extends FMLEvent
|
||||
public abstract class FMLStateEvent extends ModLifecycleEvent
|
||||
{
|
||||
public FMLStateEvent(Object... data)
|
||||
|
||||
public FMLStateEvent()
|
||||
{
|
||||
|
||||
super(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* The current state of the mod
|
||||
* @return The current state of the mod
|
||||
*/
|
||||
public abstract ModState getModState();
|
||||
|
||||
/**
|
||||
* The side we're loading on. {@link Side#CLIENT} means we're loading in the client, {@link Side#SERVER} means
|
||||
* we're loading in the dedicated server.
|
||||
|
||||
+10
-9
@@ -19,24 +19,25 @@
|
||||
|
||||
package net.minecraftforge.fml.common.event;
|
||||
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
|
||||
/**
|
||||
* Parent type to all FML events. This is based on Guava EventBus. Event Subscription isn't using the Guava annotation
|
||||
* however, it's using a custom annotation specific to FML {@link net.minecraftforge.fml.common.Mod.EventHandler}
|
||||
* Parent type to all ModLifecycle events. This is based on Forge EventBus. They fire through the
|
||||
* ModContainer's eventbus instance.
|
||||
*/
|
||||
public class FMLEvent
|
||||
public class ModLifecycleEvent extends Event
|
||||
{
|
||||
public final String getEventType()
|
||||
private final ModContainer container;
|
||||
|
||||
public ModLifecycleEvent(ModContainer container)
|
||||
{
|
||||
return getClass().getSimpleName();
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
public final String description()
|
||||
{
|
||||
String cn = getClass().getName();
|
||||
return cn.substring(cn.lastIndexOf('.')+4,cn.length()-5);
|
||||
}
|
||||
public void applyModContainer(ModContainer activeContainer) {
|
||||
// NO OP
|
||||
}
|
||||
}
|
||||
@@ -25,12 +25,14 @@ import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraftforge.api.Side;
|
||||
import net.minecraftforge.fml.ModThreadContext;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.common.network.FMLOutboundHandler.OutboundTarget;
|
||||
import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher;
|
||||
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.javafmlmod.ModLoadingContext;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -44,7 +46,7 @@ import javax.annotation.Nullable;
|
||||
public class FMLEmbeddedChannel extends EmbeddedChannel {
|
||||
public FMLEmbeddedChannel(String channelName, Side source, ChannelHandler... handlers)
|
||||
{
|
||||
this(Loader.instance().activeModContainer(), channelName, source, handlers);
|
||||
this(ModThreadContext.get().getCurrentContainer(), channelName, source, handlers);
|
||||
}
|
||||
public FMLEmbeddedChannel(ModContainer container, String channelName, Side source, ChannelHandler... handlers)
|
||||
{
|
||||
|
||||
@@ -35,16 +35,16 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.network.INetHandler;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.Side;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable;
|
||||
import net.minecraftforge.fml.common.network.FMLOutboundHandler.OutboundTarget;
|
||||
import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher;
|
||||
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
|
||||
import net.minecraftforge.fml.common.network.internal.NetworkModHolder;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
@@ -311,7 +311,7 @@ public enum NetworkRegistry
|
||||
{
|
||||
return registry.values().stream()
|
||||
.filter(mod -> !mod.acceptsVanilla(from))
|
||||
.map(mod -> mod.getContainer().getName())
|
||||
.map(mod -> mod.getContainer().getModId())
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@@ -338,6 +338,7 @@ public enum NetworkRegistry
|
||||
*/
|
||||
public void fireNetworkHandshake(NetworkDispatcher networkDispatcher, Side origin)
|
||||
{
|
||||
/*
|
||||
NetworkHandshakeEstablished handshake = new NetworkHandshakeEstablished(networkDispatcher, networkDispatcher.getNetHandler(), origin);
|
||||
for (FMLEmbeddedChannel channel : channels.get(origin).values())
|
||||
{
|
||||
@@ -345,6 +346,7 @@ public enum NetworkRegistry
|
||||
channel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(networkDispatcher);
|
||||
channel.pipeline().fireUserEventTriggered(handshake);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public void cleanAttributes()
|
||||
|
||||
+19
@@ -17,6 +17,25 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
// This method is called every tick (20 times per second normally)
|
||||
|
||||
if (world.isRemote) {
|
||||
// We only do something on the client so we don't have to bother about client-server communication.
|
||||
// The effect that we want to have (blinking the block) is client-side as well.
|
||||
updateCounter();
|
||||
counter -= lastCount * 3;
|
||||
if (counter <= 0) {
|
||||
lit = !lit;
|
||||
counter = 400; // This is 20 seconds. Rate increases if more mods are near
|
||||
world.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCounter() {
|
||||
|
||||
package net.minecraftforge.fml.common.network.handshake;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ import java.util.Set;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.network.internal.FMLMessage.EntityMessage;
|
||||
import net.minecraftforge.fml.common.registry.EntityRegistry;
|
||||
|
||||
@@ -31,7 +31,7 @@ import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.datasync.EntityDataManager;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration;
|
||||
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
|
||||
|
||||
@@ -42,7 +42,7 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.FMLContainer;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.common.network.FMLEmbeddedChannel;
|
||||
import net.minecraftforge.fml.common.network.FMLOutboundHandler;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
|
||||
@@ -23,15 +23,15 @@ import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraftforge.api.Side;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData;
|
||||
import net.minecraftforge.fml.common.network.NetworkCheckHandler;
|
||||
import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
|
||||
import net.minecraftforge.fml.common.versioning.InvalidVersionSpecificationException;
|
||||
import net.minecraftforge.fml.common.versioning.VersionRange;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
@@ -22,7 +22,7 @@ package net.minecraftforge.fml.common.network.simpleimpl;
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
import net.minecraft.network.INetHandler;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.api.Side;
|
||||
|
||||
/**
|
||||
* Context for the {@link IMessageHandler}
|
||||
|
||||
+1
-1
@@ -19,13 +19,13 @@
|
||||
|
||||
package net.minecraftforge.fml.common.network.simpleimpl;
|
||||
|
||||
import net.minecraftforge.api.Side;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import net.minecraft.network.INetHandler;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.network.FMLOutboundHandler;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
|
||||
+1
-1
@@ -33,13 +33,13 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.INetHandler;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.api.Side;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.network.FMLEmbeddedChannel;
|
||||
import net.minecraftforge.fml.common.network.FMLOutboundHandler;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
/**
|
||||
* This class is a simplified netty wrapper for those not wishing to deal with the full power of netty.
|
||||
|
||||
@@ -30,7 +30,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
@@ -32,7 +32,7 @@ import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.Biome.SpawnListEntry;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.common.network.internal.FMLMessage.EntitySpawnMessage;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -29,7 +29,7 @@ import net.minecraftforge.fml.common.DummyModContainer;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModAPIManager;
|
||||
import net.minecraftforge.fml.language.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.common.toposort.TopologicalSort.DirectedGraph;
|
||||
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraftforge.fml.client.GuiSortingProblem;
|
||||
import net.minecraftforge.fml.client.IDisplayableError;
|
||||
import net.minecraftforge.fml.common.EnhancedRuntimeException;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
|
||||
package net.minecraftforge.fml.common.toposort;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.apache.logging.log4j.message.Message;
|
||||
import org.apache.logging.log4j.util.StringBuilderFormattable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -176,7 +180,7 @@ public class TopologicalSort
|
||||
return;
|
||||
}
|
||||
|
||||
throw new TopoSortException(node, sortedResult, visitedNodes, expandedNodes);
|
||||
throw new TopoSortException(new TopoSortException.TopoSortExceptionData<>(node, sortedResult, visitedNodes, expandedNodes));
|
||||
}
|
||||
|
||||
// Visit this node
|
||||
@@ -194,38 +198,68 @@ public class TopologicalSort
|
||||
expandedNodes.add(node);
|
||||
}
|
||||
|
||||
static class TopoSortException extends RuntimeException {
|
||||
private final Object node;
|
||||
private final List<?> sortedResult;
|
||||
private final Set<?> visitedNodes;
|
||||
private final Set<?> expandedNodes;
|
||||
public static class TopoSortException extends RuntimeException {
|
||||
private final TopoSortExceptionData<?> topoSortData;
|
||||
|
||||
public TopoSortException(Object node, List<?> sortedResult, Set<?> visitedNodes, Set<?> expandedNodes)
|
||||
public static class TopoSortExceptionData<T> implements Message, StringBuilderFormattable
|
||||
{
|
||||
this.node = node;
|
||||
this.sortedResult = sortedResult;
|
||||
this.visitedNodes = visitedNodes;
|
||||
this.expandedNodes = expandedNodes;
|
||||
private final List<T> sortedResult;
|
||||
private final Set<T> visitedNodes;
|
||||
private final Set<T> expandedNodes;
|
||||
private final T node;
|
||||
|
||||
TopoSortExceptionData(T node, List<T> sortedResult, Set<T> visitedNodes, Set<T> expandedNodes)
|
||||
{
|
||||
this.node = node;
|
||||
this.sortedResult = sortedResult;
|
||||
this.visitedNodes = visitedNodes;
|
||||
this.expandedNodes = expandedNodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormattedMessage()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormat()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getParameters()
|
||||
{
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Throwable getThrowable()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void formatTo(StringBuilder buffer)
|
||||
{
|
||||
buffer.append("Mod Sorting failed.\n");
|
||||
buffer.append("Visiting node {}\n").append(String.valueOf(node));
|
||||
buffer.append("Current sorted list : {}\n").append(String.valueOf(sortedResult));
|
||||
buffer.append("Visited set for this node : {}\n").append(String.valueOf(visitedNodes));
|
||||
buffer.append("Explored node set : {}\n").append(expandedNodes);
|
||||
buffer.append("Likely cycle is in : {}\n").append(Sets.difference(visitedNodes, expandedNodes));
|
||||
}
|
||||
}
|
||||
|
||||
public Object getNode()
|
||||
public <T> TopoSortException(TopoSortExceptionData<T> data)
|
||||
{
|
||||
return node;
|
||||
this.topoSortData = data;
|
||||
}
|
||||
|
||||
public List<?> getSortedResult()
|
||||
{
|
||||
return sortedResult;
|
||||
}
|
||||
|
||||
public Set<?> getVisitedNodes()
|
||||
{
|
||||
return visitedNodes;
|
||||
}
|
||||
|
||||
public Set<?> getExpandedNodes()
|
||||
{
|
||||
return expandedNodes;
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> TopoSortExceptionData<T> getData() {
|
||||
return (TopoSortExceptionData<T>)this.topoSortData;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user