mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 11:29:15 +00:00
More work, game loads and runs now.
Moved Registry events to directly AFTER PreInit instead of before. This allows modders to register handlers for it without @EventBusSubscriber. It also allows you to register custom things needed before the construction of blocks or items such as Fluids. TODO: Move Fluids to a real registry. @ObjectHolder can now be used on private fields. Reworked FMLModIdMappingEvent to include data for all registries. Tile Entities are now registrable.
This commit is contained in:
1 parent
a26d89c876
commit
dee84dc1e4
21 files changed
+230
-278
No files matched your search
@@ -29,9 +29,6 @@ import net.minecraftforge.fml.common.discovery.asm.ModAnnotation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -56,6 +53,7 @@ public class AutomaticEventSubscriber
|
||||
try
|
||||
{
|
||||
//noinspection unchecked
|
||||
@SuppressWarnings("unchecked")
|
||||
List<ModAnnotation.EnumHolder> sidesEnum = (List<ModAnnotation.EnumHolder>)targ.getAnnotationInfo().get("value");
|
||||
EnumSet<Side> sides = DEFAULT;
|
||||
if (sidesEnum != null) {
|
||||
@@ -65,7 +63,7 @@ public class AutomaticEventSubscriber
|
||||
}
|
||||
}
|
||||
if (sides == DEFAULT || sides.contains(side)) {
|
||||
FMLLog.log.debug("Found @EventBusSubscriber class {}", targ.getClassName());
|
||||
//FMLLog.log.debug("Found @EventBusSubscriber class {}", targ.getClassName());
|
||||
String amodid = (String)targ.getAnnotationInfo().get("modid");
|
||||
if (Strings.isNullOrEmpty(amodid)) {
|
||||
amodid = ASMDataTable.getOwnerModID(mods, targ);
|
||||
@@ -79,6 +77,7 @@ public class AutomaticEventSubscriber
|
||||
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(), true, mcl);
|
||||
MinecraftForge.EVENT_BUS.register(subscriptionTarget);
|
||||
FMLLog.log.debug("Injected @EventBusSubscriber class {}", targ.getClassName());
|
||||
|
||||
@@ -642,9 +642,9 @@ public class Loader
|
||||
ObjectHolderRegistry.INSTANCE.findObjectHolders(discoverer.getASMTable());
|
||||
ItemStackHolderInjector.INSTANCE.findHolders(discoverer.getASMTable());
|
||||
CapabilityManager.INSTANCE.injectCapabilities(discoverer.getASMTable());
|
||||
modController.distributeStateMessage(LoaderState.PREINITIALIZATION, discoverer.getASMTable(), canonicalConfigDir);
|
||||
GameData.fireRegistryEvents();
|
||||
FMLCommonHandler.instance().fireSidedRegistryEvents();
|
||||
modController.distributeStateMessage(LoaderState.PREINITIALIZATION, discoverer.getASMTable(), canonicalConfigDir);
|
||||
ObjectHolderRegistry.INSTANCE.applyObjectHolders();
|
||||
ItemStackHolderInjector.INSTANCE.inject();
|
||||
modController.transition(LoaderState.INITIALIZATION, false);
|
||||
@@ -1003,11 +1003,11 @@ public class Loader
|
||||
return true;
|
||||
}
|
||||
|
||||
public void fireRemapEvent(Map<ResourceLocation, Integer[]> remapBlocks, Map<ResourceLocation, Integer[]> remapItems, boolean isFreezing)
|
||||
public void fireRemapEvent(Map<ResourceLocation, Map<ResourceLocation, Integer[]>> remaps, boolean isFreezing)
|
||||
{
|
||||
if (modController!=null)
|
||||
{
|
||||
modController.propogateStateMessage(new FMLModIdMappingEvent(remapBlocks, remapItems, isFreezing));
|
||||
modController.propogateStateMessage(new FMLModIdMappingEvent(remaps, isFreezing));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,13 +20,13 @@
|
||||
package net.minecraftforge.fml.common.event;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/**
|
||||
@@ -42,48 +42,49 @@ 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 enum RemapTarget { BLOCK, ITEM }
|
||||
public class FMLModIdMappingEvent extends FMLEvent
|
||||
{
|
||||
public class ModRemapping
|
||||
{
|
||||
public final ResourceLocation registry;
|
||||
public final ResourceLocation key;
|
||||
public final int oldId;
|
||||
public final int newId;
|
||||
public final String tag;
|
||||
public final RemapTarget remapTarget;
|
||||
public final ResourceLocation resourceLocation;
|
||||
|
||||
public ModRemapping(int oldId, int newId, ResourceLocation tag, RemapTarget type)
|
||||
private ModRemapping(ResourceLocation registry, ResourceLocation key, int oldId, int newId)
|
||||
{
|
||||
this.registry = registry;
|
||||
this.key = key;
|
||||
this.oldId = oldId;
|
||||
this.newId = newId;
|
||||
this.tag = tag.toString();
|
||||
this.remapTarget = type;
|
||||
this.resourceLocation = tag;
|
||||
}
|
||||
|
||||
}
|
||||
public final ImmutableList<ModRemapping> remappedIds;
|
||||
|
||||
private final Map<ResourceLocation, ImmutableList<ModRemapping>> remaps;
|
||||
private final ImmutableSet<ResourceLocation> keys;
|
||||
|
||||
public final boolean isFrozen;
|
||||
public FMLModIdMappingEvent(Map<ResourceLocation, Integer[]> blocks, Map<ResourceLocation, Integer[]> items, boolean isFrozen)
|
||||
public FMLModIdMappingEvent(Map<ResourceLocation, Map<ResourceLocation, Integer[]>> remaps, boolean isFrozen)
|
||||
{
|
||||
this.isFrozen = isFrozen;
|
||||
List<ModRemapping> remappings = Lists.newArrayList();
|
||||
for (Entry<ResourceLocation, Integer[]> mapping : blocks.entrySet())
|
||||
this.remaps = Maps.newHashMap();
|
||||
remaps.forEach((name, rm) ->
|
||||
{
|
||||
remappings.add(new ModRemapping(mapping.getValue()[0], mapping.getValue()[1], mapping.getKey(), RemapTarget.BLOCK));
|
||||
}
|
||||
for (Entry<ResourceLocation, Integer[]> mapping : items.entrySet())
|
||||
{
|
||||
remappings.add(new ModRemapping(mapping.getValue()[0], mapping.getValue()[1], mapping.getKey(), RemapTarget.ITEM));
|
||||
}
|
||||
|
||||
Collections.sort(remappings, new Comparator<ModRemapping>() {
|
||||
@Override
|
||||
public int compare(ModRemapping o1, ModRemapping o2)
|
||||
{
|
||||
return (o1.newId < o2.newId) ? -1 : ((o1.newId == o2.newId) ? 0 : 1);
|
||||
}
|
||||
List<ModRemapping> tmp = Lists.newArrayList();
|
||||
rm.entrySet().forEach(e -> tmp.add(new ModRemapping(name, e.getKey(), e.getValue()[0], e.getValue()[1])));
|
||||
Collections.sort(tmp, (o1, o2) -> (o1.newId < o2.newId) ? -1 : ((o1.newId == o2.newId) ? 0 : 1));
|
||||
this.remaps.put(name, ImmutableList.copyOf(tmp));
|
||||
});
|
||||
remappedIds = ImmutableList.copyOf(remappings);
|
||||
this.keys = ImmutableSet.copyOf(this.remaps.keySet());
|
||||
}
|
||||
|
||||
public ImmutableSet<ResourceLocation> getRegistries()
|
||||
{
|
||||
return this.keys;
|
||||
}
|
||||
|
||||
public ImmutableList<ModRemapping> getRemaps(ResourceLocation registry)
|
||||
{
|
||||
return this.remaps.get(registry);
|
||||
}
|
||||
}
|
||||
@@ -241,8 +241,7 @@ public class GameRegistry
|
||||
|
||||
public static void registerTileEntity(Class<? extends TileEntity> tileEntityClass, String key)
|
||||
{
|
||||
throw new RuntimeException("TODO: TileEntity registration");
|
||||
//TileEntity.register(key, tileEntityClass);
|
||||
TileEntity.register(key, tileEntityClass);
|
||||
}
|
||||
|
||||
public static void registerFuelHandler(IFuelHandler handler)
|
||||
|
||||
Reference in new issue
Block a user