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:
LexManos 2017-06-20 18:39:55 -07:00
parent a26d89c876
commit dee84dc1e4
21 changed files with 230 additions and 278 deletions

View File

@ -1,14 +0,0 @@
--- ../src-base/minecraft/net/minecraft/util/registry/RegistryNamespacedDefaultedByKey.java
+++ ../src-work/minecraft/net/minecraft/util/registry/RegistryNamespacedDefaultedByKey.java
@@ -63,4 +63,11 @@
V v = (V)super.func_186801_a(p_186801_1_);
return (V)(v == null ? this.field_148761_e : v);
}
+
+ //Bypass functions to allow querying this registry WITHOUT getting the defaulted value.
+ // MODDERS DO NOT USE THIS IS FOR FORGE INTERNAL CHECKS
+ public int getIDForObjectBypass(@Nullable V bypass) { return super.func_148757_b(bypass); }
+ @Nullable public K getNameForObjectBypass(V value) { return super.func_177774_c(value); }
+ @Nullable public V getObjectBypass(K name) { return super.func_82594_a(name); }
+ @Nullable public V getObjectByIdBypass(int id){ return super.func_148754_a(id); }
}

View File

@ -20,10 +20,11 @@
package net.minecraftforge.client.event;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.IContextSetter;
/**
* Fired when the {@link net.minecraftforge.client.model.ModelLoader} is ready to receive registrations
*/
public class ModelRegistryEvent extends Event
public class ModelRegistryEvent extends Event implements IContextSetter
{
}

View File

@ -82,12 +82,14 @@ import com.google.common.eventbus.Subscribe;
import net.minecraftforge.fml.client.FMLFileResourcePack;
import net.minecraftforge.fml.client.FMLFolderResourcePack;
import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent;
import net.minecraftforge.fml.common.AutomaticEventSubscriber;
import net.minecraftforge.fml.common.DummyModContainer;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.ICrashCallable;
import net.minecraftforge.fml.common.LoadController;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.ModMetadata;
import net.minecraftforge.fml.common.WorldAccessContainer;
import net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData;
@ -103,6 +105,7 @@ import net.minecraftforge.fml.common.network.NetworkRegistry;
import javax.annotation.Nullable;
@EventBusSubscriber(modid = "forge")
public class ForgeModContainer extends DummyModContainer implements WorldAccessContainer
{
public static final String VERSION_CHECK_CAT = "version_checking";
@ -444,6 +447,7 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
NetworkRegistry.INSTANCE.register(this, this.getClass(), "*", evt.getASMHarvestedData());
ForgeNetworkHandler.registerChannel(this, evt.getSide());
ConfigManager.sync(this.getModId(), Config.Type.INSTANCE);
MinecraftForge.EVENT_BUS.register(this);
}
@Subscribe

View File

@ -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());

View File

@ -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));
}
}

View File

@ -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);
}
}

View File

@ -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)

View File

@ -40,7 +40,7 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
private final BiMap<ResourceLocation, V> names = HashBiMap.create();
private final Class<V> superType;
private final Map<ResourceLocation, ResourceLocation> aliases = Maps.newHashMap();
private final Map<ResourceLocation, ?> slaves = Maps.newHashMap();
final Map<ResourceLocation, ?> slaves = Maps.newHashMap();
private final ResourceLocation defaultKey;
private final CreateCallback<V> create;
private final AddCallback<V> add;
@ -427,13 +427,14 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
this.ids.clear();
this.names.clear();
this.availabilityMap.clear(0, this.availabilityMap.length());
this.defaultValue = null;
this.isFrozen = false;
boolean errored = false;
for (Entry<ResourceLocation, V> entry : from.names.entrySet())
{
int id = from.ids.inverse().get(entry.getKey());
int id = from.getID(entry.getKey());
int realId = add(id, entry.getValue());
if (id != realId && id != -1)
{
@ -501,11 +502,20 @@ public class ForgeRegistry<V extends IForgeRegistryEntry<V>> implements IForgeRe
return this.isFrozen;
}
/**
* Used to control the times where people can modify this registry.
* Users should only ever register things in the Register<?> events!
*/
public void freeze()
{
this.isFrozen = true;
}
public void unfreeze()
{
this.isFrozen = false;
}
RegistryEvent.Register<V> getRegisterEvent(ResourceLocation name)
{
return new RegistryEvent.Register<V>(name, this);

View File

@ -63,6 +63,7 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@ -101,6 +102,7 @@ public class GameData
private static final ResourceLocation BLOCKSTATE_TO_ID = new ResourceLocation("minecraft:blockstatetoid");
private static boolean hasInit = false;
private static final boolean DISABLE_VANILLA_REGISTRIES = Boolean.parseBoolean(System.getProperty("forge.disableVanillaGameData", "false")); // Use for unit tests/debugging
private static final BiConsumer<ResourceLocation, ForgeRegistry<?>> LOCK_VANILLA = (name, reg) -> reg.slaves.values().stream().filter(o -> o instanceof ILockableRegistry).forEach(o -> ((ILockableRegistry)o).lock());
static {
init();
@ -192,8 +194,13 @@ public class GameData
final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(r.getKey());
loadRegistry(r.getKey(), RegistryManager.ACTIVE, RegistryManager.VANILLA, clazz, true);
}
RegistryManager.VANILLA.registries.forEach((name, reg) -> reg.validateContent(name));
RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.freeze());
RegistryManager.VANILLA.registries.forEach((name, reg) ->
{
reg.validateContent(name);
reg.freeze();
});
RegistryManager.VANILLA.registries.forEach(LOCK_VANILLA);
RegistryManager.ACTIVE.registries.forEach(LOCK_VANILLA);
FMLLog.fine("Vanilla freeze snapshot created");
}
@ -206,7 +213,11 @@ public class GameData
final Class<? extends IForgeRegistryEntry> clazz = RegistryManager.ACTIVE.getSuperType(r.getKey());
loadRegistry(r.getKey(), RegistryManager.ACTIVE, RegistryManager.FROZEN, clazz, true);
}
RegistryManager.FROZEN.registries.forEach((name, reg) -> reg.validateContent(name));
RegistryManager.FROZEN.registries.forEach((name, reg) ->
{
reg.validateContent(name);
reg.freeze();
});
RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.freeze());
FMLLog.fine("All registries frozen");
}
@ -227,7 +238,7 @@ public class GameData
loadRegistry(r.getKey(), RegistryManager.FROZEN, RegistryManager.ACTIVE, clazz, true);
}
// the id mapping has reverted, fire remap events for those that care about id changes
Loader.instance().fireRemapEvent(ImmutableMap.of(), ImmutableMap.of(), true);
Loader.instance().fireRemapEvent(ImmutableMap.of(), true);
// the id mapping has reverted, ensure we sync up the object holders
ObjectHolderRegistry.INSTANCE.applyObjectHolders();
@ -574,30 +585,25 @@ public class GameData
});
}
/*
// Validate that all the STAGING data is good
forAllRegistries(PersistentRegistry.STAGING, ValidateRegistryFunction.OPERATION);
STAGING.registries.forEach((name, reg) -> reg.validateContent(name));
// Load the STAGING registry into the ACTIVE registry
for (Map.Entry<ResourceLocation, FMLControlledNamespacedRegistry<?>> r : PersistentRegistry.ACTIVE.registries.entrySet())
for (Map.Entry<ResourceLocation, ForgeRegistry<? extends IForgeRegistryEntry<?>>> r : RegistryManager.ACTIVE.registries.entrySet())
{
final Class<? extends IForgeRegistryEntry> registrySuperType = PersistentRegistry.ACTIVE.getRegistrySuperType(r.getKey());
loadRegistry(r.getKey(), PersistentRegistry.STAGING, PersistentRegistry.ACTIVE, registrySuperType);
final Class<? extends IForgeRegistryEntry> registrySuperType = RegistryManager.ACTIVE.getSuperType(r.getKey());
loadRegistry(r.getKey(), STAGING, RegistryManager.ACTIVE, registrySuperType, true);
}
// Dump the active registry
forAllRegistries(PersistentRegistry.ACTIVE, DumpRegistryFunction.OPERATION);
RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.dump(name));
// Tell mods that the ids have changed
Loader.instance().fireRemapEvent(remaps.get(BLOCKS), remaps.get(ITEMS), false);
Loader.instance().fireRemapEvent(remaps, false);
// The id map changed, ensure we apply object holders
ObjectHolderRegistry.INSTANCE.applyObjectHolders();
// Clean out the staging registry now, we're done with it
PersistentRegistry.STAGING.clean();
*/
// Return an empty list, because we're good
return ArrayListMultimap.create();
}
@ -648,6 +654,10 @@ public class GameData
{
List<ResourceLocation> keys = Lists.newArrayList(RegistryManager.ACTIVE.registries.keySet());
Collections.sort(keys, (o1, o2) -> o1.toString().compareToIgnoreCase(o2.toString()));
RegistryManager.ACTIVE.registries.forEach((name, reg) -> {
if (filter.test(name))
((ForgeRegistry<?>)reg).unfreeze();
});
if (filter.test(BLOCKS))
{
@ -666,5 +676,11 @@ public class GameData
MinecraftForge.EVENT_BUS.post(RegistryManager.ACTIVE.getRegistry(rl).getRegisterEvent(rl));
}
ObjectHolderRegistry.INSTANCE.applyObjectHolders(); // inject everything else
RegistryManager.ACTIVE.registries.forEach((name, reg) -> {
if (filter.test(name))
((ForgeRegistry<?>)reg).freeze();
});
}
}

View File

@ -10,6 +10,8 @@ import javax.annotation.Nullable;
import org.apache.commons.lang3.Validate;
import com.google.common.collect.Maps;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.RegistryNamespacedDefaultedByKey;
import net.minecraftforge.fml.common.FMLLog;
@ -108,9 +110,6 @@ class NamespacedDefaultedWrapper<V extends IForgeRegistryEntry<V>> extends Regis
}
//internal
@Override //We override all public methods, this should be fine as null.
protected Map<ResourceLocation, V> createUnderlyingMap(){ return null; }
@Override
public void lock(){ this.locked = true; }

View File

@ -104,9 +104,6 @@ class NamespacedWrapper<V extends IForgeRegistryEntry<V>> extends RegistryNamesp
}
//internal
@Override //We override all public methods, this should be fine as null.
protected Map<ResourceLocation, V> createUnderlyingMap(){ return null; }
@Override
public void lock(){ this.locked = true; }

View File

@ -164,6 +164,7 @@ class ObjectHolderRef
private static Method fieldAccessorSet;
static Field makeWritable(Field f) throws Exception
{
f.setAccessible(true);
if (modifiersField == null)
{
Method getReflectionFactory = Class.forName("sun.reflect.ReflectionFactory").getDeclaredMethod("getReflectionFactory");

View File

@ -27,6 +27,7 @@ import java.util.Set;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.discovery.ASMDataTable;
import net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData;
import net.minecraftforge.fml.common.registry.GameRegistry;
@ -52,6 +53,11 @@ public enum ObjectHolderRegistry
Set<ASMData> allObjectHolders = table.getAll(GameRegistry.ObjectHolder.class.getName());
Map<String, String> classModIds = Maps.newHashMap();
Map<String, Class<?>> classCache = Maps.newHashMap();
for (ASMData data : table.getAll(Mod.class.getName()))
{
String modid = (String)data.getAnnotationInfo().get("modid");
classModIds.put(data.getClassName(), modid);
}
for (ASMData data : allObjectHolders)
{
String className = data.getClassName();
@ -119,7 +125,7 @@ public enum ObjectHolderRegistry
}
try
{
Field f = clazz.getField(annotationTarget);
Field f = clazz.getDeclaredField(annotationTarget);
addHolderReference(new ObjectHolderRef(f, new ResourceLocation(value), extractFromValue));
}
catch (Exception ex)

View File

@ -284,6 +284,9 @@ public net.minecraft.potion.PotionHelper func_193354_a(Lnet/minecraft/item/ItemP
public net.minecraft.potion.PotionHelper func_193357_a(Lnet/minecraft/potion/PotionType;Lnet/minecraft/item/Item;Lnet/minecraft/potion/PotionType;)V # registerPotionTypeConversion
public net.minecraft.potion.PotionHelper func_193356_a(Lnet/minecraft/potion/PotionType;Lnet/minecraft/item/crafting/Ingredient;Lnet/minecraft/potion/PotionType;)V # registerPotionTypeConversion
# TileEntity
public net.minecraft.tileentity.TileEntity func_190560_a(Ljava/lang/String;Ljava/lang/Class;)V # register
# TileEntityHopper
public net.minecraft.tileentity.TileEntityHopper func_174914_o()Z # mayTransfer
public net.minecraft.tileentity.TileEntityHopper func_145896_c(I)V # setTransferCooldown

View File

@ -31,6 +31,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.common.MinecraftForge;
@ -93,82 +94,62 @@ public class DynBucketTest
}
}
@SuppressWarnings("unused")
public DynBucketTest()
@SubscribeEvent
public void setupModels(ModelRegistryEvent event)
{
if (!ENABLE || !ModelFluidDebug.ENABLE)
MinecraftForge.EVENT_BUS.register(this);
}
ModelLoader.setBucketModelDefinition(DYN_BOTTLE);
@SidedProxy
public static CommonProxy proxy;
public static class CommonProxy { void setupModels(){} }
public static class ServerProxy extends CommonProxy{}
public static class ClientProxy extends CommonProxy
{
@SuppressWarnings("unused")
@Override
void setupModels()
final ModelResourceLocation bottle = new ModelResourceLocation(new ResourceLocation(ForgeVersion.MOD_ID, "dynbottle"), "inventory");
ModelLoader.setCustomMeshDefinition(DYN_BOTTLE, new ItemMeshDefinition()
{
if (!ENABLE || !ModelFluidDebug.ENABLE)
@Override
public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack)
{
return;
return bottle;
}
ModelLoader.setBucketModelDefinition(DYN_BOTTLE);
final ModelResourceLocation bottle = new ModelResourceLocation(new ResourceLocation(ForgeVersion.MOD_ID, "dynbottle"), "inventory");
ModelLoader.setCustomMeshDefinition(DYN_BOTTLE, new ItemMeshDefinition()
{
@Override
public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack)
{
return bottle;
}
});
ModelBakery.registerItemVariants(DYN_BOTTLE, bottle);
ModelLoader.setCustomModelResourceLocation(Item.REGISTRY.getObject(simpleTankName), 0, new ModelResourceLocation(simpleTankName, "normal"));
ModelLoader.setCustomModelResourceLocation(Item.REGISTRY.getObject(testItemName), 0, new ModelResourceLocation(new ResourceLocation("minecraft", "stick"), "inventory"));
}
});
ModelBakery.registerItemVariants(DYN_BOTTLE, bottle);
ModelLoader.setCustomModelResourceLocation(Item.REGISTRY.getObject(simpleTankName), 0, new ModelResourceLocation(simpleTankName, "normal"));
ModelLoader.setCustomModelResourceLocation(Item.REGISTRY.getObject(testItemName), 0, new ModelResourceLocation(new ResourceLocation("minecraft", "stick"), "inventory"));
}
@Mod.EventBusSubscriber(modid = MODID)
public static class Registration
@SubscribeEvent
public void registrBlocks(RegistryEvent.Register<Block> event)
{
@SubscribeEvent
public static void registrBlocks(RegistryEvent.Register<Block> event)
{
event.getRegistry().register(new BlockSimpleTank().setRegistryName(simpleTankName));
}
@SubscribeEvent
public static void registrItems(RegistryEvent.Register<Item> event)
{
FluidRegistry.addBucketForFluid(FluidRegistry.getFluid(TestFluid.name));
FluidRegistry.addBucketForFluid(FluidRegistry.getFluid(TestGas.name));
event.getRegistry().registerAll(
new TestItem().setRegistryName(testItemName),
new ItemBlock(TANK_BLOCK).setRegistryName(simpleTankName),
new DynBottle()
);
}
@SubscribeEvent
public static void registrRecipes(RegistryEvent.Register<IRecipe> event)
{
ItemStack filledBucket = FluidUtil.getFilledBucket(new FluidStack(TestFluid.instance, Fluid.BUCKET_VOLUME));
GameRegistry.addShapelessRecipe(new ResourceLocation(MODID, "diamond_to_fluid"), null, filledBucket, Ingredient.func_193368_a(Items.DIAMOND));
}
event.getRegistry().register(new BlockSimpleTank().setRegistryName(simpleTankName));
GameRegistry.registerTileEntity(TileSimpleTank.class, "simpletank");
}
@SubscribeEvent
public void registrItems(RegistryEvent.Register<Item> event)
{
FluidRegistry.addBucketForFluid(FluidRegistry.getFluid(TestFluid.name));
FluidRegistry.addBucketForFluid(FluidRegistry.getFluid(TestGas.name));
event.getRegistry().registerAll(
new TestItem().setRegistryName(testItemName),
new ItemBlock(TANK_BLOCK).setRegistryName(simpleTankName),
new DynBottle()
);
}
@SubscribeEvent
public void registrRecipes(RegistryEvent.Register<IRecipe> event)
{
ItemStack filledBucket = FluidUtil.getFilledBucket(new FluidStack(TestFluid.instance, Fluid.BUCKET_VOLUME));
GameRegistry.addShapelessRecipe(new ResourceLocation(MODID, "diamond_to_fluid"), null, filledBucket, Ingredient.func_193368_a(Items.DIAMOND));
}
@SuppressWarnings("unused")
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
logger = event.getModLog();
GameRegistry.registerTileEntity(TileSimpleTank.class, "simpletank");
proxy.setupModels();
if (!ENABLE || !ModelFluidDebug.ENABLE)
{
MinecraftForge.EVENT_BUS.register(this);
}
}
@SubscribeEvent

View File

@ -11,7 +11,9 @@ import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemMultiTexture;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
@ -25,7 +27,6 @@ import java.util.Map;
import java.util.Map.Entry;
@Mod(modid = ForgeBlockStatesLoaderDebug.MODID, name = "ForgeBlockStatesLoader", version = "1.0", acceptableRemoteVersions = "*")
@Mod.EventBusSubscriber
public class ForgeBlockStatesLoaderDebug
{
public static final String MODID = "forgeblockstatesloader";
@ -44,25 +45,25 @@ public class ForgeBlockStatesLoaderDebug
}
@SubscribeEvent
public static void registerBlocks(RegistryEvent.Register<Block> event)
public void registerBlocks(RegistryEvent.Register<Block> event)
{
event.getRegistry().registerAll(
new BlockWall(Blocks.COBBLESTONE).setUnlocalizedName(MODID + ".customWall").setRegistryName(MODID, "custom_wall")
new BlockWall(Blocks.COBBLESTONE).setUnlocalizedName(MODID + ".customWall").setRegistryName(MODID, "custom_wall")
);
}
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event)
public void registerItems(RegistryEvent.Register<Item> event)
{
event.getRegistry().registerAll(
new ItemMultiTexture(BLOCKS.custom_wall, BLOCKS.custom_wall, new ItemMultiTexture.Mapper()
new ItemMultiTexture(BLOCKS.custom_wall, BLOCKS.custom_wall, new ItemMultiTexture.Mapper()
{
@Override
public String apply(ItemStack stack)
{
@Override
public String apply(ItemStack stack)
{
return BlockWall.EnumType.byMetadata(stack.getMetadata()).getUnlocalizedName();
}
}).setRegistryName(BLOCKS.custom_wall.getRegistryName())
return BlockWall.EnumType.byMetadata(stack.getMetadata()).getUnlocalizedName();
}
}).setRegistryName(BLOCKS.custom_wall.getRegistryName())
);
}
@ -73,15 +74,11 @@ public class ForgeBlockStatesLoaderDebug
{
//blockCustom.setUnlocalizedName(MODID + ".customBlock").setRegistryName("customBlock");
//GameRegistry.registerBlock(blockCustom);
if (event.getSide() == Side.CLIENT)
{
preInitClient(event);
}
MinecraftForge.EVENT_BUS.register(this);
}
@SideOnly(Side.CLIENT)
public void preInitClient(FMLPreInitializationEvent event)
@SubscribeEvent
public void registerModels(ModelRegistryEvent event)
{
//ModelLoader.setCustomStateMapper(blockCustom, new StateMap.Builder().withName(CustomMappedBlock.VARIANT).build());

View File

@ -16,6 +16,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.debug.ObjectHolderTest.CustomRegistryEntry;
@ -42,21 +43,6 @@ public class ItemTileDebug
@ObjectHolder(TestBlock.name)
public static final Block TEST_BLOCK = null;
@SidedProxy
public static CommonProxy proxy;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
proxy.preInit(event);
}
@EventHandler
public void init(FMLInitializationEvent event)
{
proxy.init(event);
}
@Mod.EventBusSubscriber(modid = MODID)
public static class Registration
{
@ -64,6 +50,7 @@ public class ItemTileDebug
public static void registerBlocks(RegistryEvent.Register<Block> event)
{
event.getRegistry().register(new TestBlock());
GameRegistry.registerTileEntity(CustomTileEntity.class, MODID.toLowerCase() + ":custom_tile_entity");
}
@SubscribeEvent
@ -71,38 +58,17 @@ public class ItemTileDebug
{
event.getRegistry().register(new ItemBlock(TEST_BLOCK).setRegistryName(TEST_BLOCK.getRegistryName()));
}
}
public static class CommonProxy
{
public void preInit(FMLPreInitializationEvent event)
@SubscribeEvent
public static void registerModels(ModelRegistryEvent event)
{
GameRegistry.registerTileEntity(CustomTileEntity.class, MODID.toLowerCase() + ":custom_tile_entity");
}
public void init(FMLInitializationEvent event){}
}
final ModelResourceLocation itemLocation = new ModelResourceLocation(TEST_BLOCK.getRegistryName(), "normal");
public static class ServerProxy extends CommonProxy{}
public static class ClientProxy extends CommonProxy
{
private static ModelResourceLocation itemLocation = new ModelResourceLocation(TEST_BLOCK.getRegistryName(), "normal");
@SuppressWarnings("deprecation")
@Override
public void preInit(FMLPreInitializationEvent event)
{
super.preInit(event);
Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(MODID, TestBlock.name));
ForgeHooksClient.registerTESRItemStack(item, 0, CustomTileEntity.class);
ModelLoader.setCustomModelResourceLocation(item, 0, itemLocation);
MinecraftForge.EVENT_BUS.register(BakeEventHandler.instance);
}
@Override
public void init(FMLInitializationEvent event)
{
ClientRegistry.bindTileEntitySpecialRenderer(CustomTileEntity.class, TestTESR.instance);
}
}

View File

@ -28,6 +28,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.client.model.animation.Animation;
@ -91,6 +92,7 @@ public class ModelAnimationDebug
@SubscribeEvent
public static void registerBlocks(RegistryEvent.Register<Block> event)
{
GameRegistry.registerTileEntity(Chest.class, MODID + ":" + "tile_" + blockName);
event.getRegistry().register(
new Block(Material.WOOD)
{
@ -196,77 +198,66 @@ public class ModelAnimationDebug
}
}
@SubscribeEvent
public void registerModels(ModelRegistryEvent event)
{
B3DLoader.INSTANCE.addDomain(MODID);
ModelLoader.setCustomModelResourceLocation(TEST_ITEM, 0, new ModelResourceLocation(TEST_ITEM.getRegistryName(), "inventory"));
ClientRegistry.bindTileEntitySpecialRenderer(Chest.class, new AnimationTESR<Chest>()
{
@Override
public void handleEvents(Chest chest, float time, Iterable<Event> pastEvents)
{
chest.handleEvents(time, pastEvents);
}
});
String entityName = MODID + ":entity_chest";
//EntityRegistry.registerGlobalEntityID(EntityChest.class, entityName, EntityRegistry.findGlobalUniqueEntityId());
EntityRegistry.registerModEntity(new ResourceLocation(entityName), EntityChest.class, entityName, 0, ModelAnimationDebug.instance, 64, 20, true, 0xFFAAAA00, 0xFFDDDD00);
RenderingRegistry.registerEntityRenderingHandler(EntityChest.class, new IRenderFactory<EntityChest>()
{
@SuppressWarnings("deprecation")
public Render<EntityChest> createRenderFor(RenderManager manager)
{
/*model = ModelLoaderRegistry.getModel(new ResourceLocation(ModelLoaderRegistryDebug.MODID, "block/chest.b3d"));
if(model instanceof IRetexturableModel)
{
model = ((IRetexturableModel)model).retexture(ImmutableMap.of("#chest", "entity/chest/normal"));
}
if(model instanceof IModelCustomData)
{
model = ((IModelCustomData)model).process(ImmutableMap.of("mesh", "[\"Base\", \"Lid\"]"));
}*/
ResourceLocation location = new ModelResourceLocation(new ResourceLocation(MODID, blockName), "entity");
return new RenderLiving<EntityChest>(manager, new net.minecraftforge.client.model.animation.AnimationModelBase<EntityChest>(location, new VertexLighterSmoothAo(Minecraft.getMinecraft().getBlockColors()))
{
@Override
public void handleEvents(EntityChest chest, float time, Iterable<Event> pastEvents)
{
chest.handleEvents(time, pastEvents);
}
}, 0.5f)
{
protected ResourceLocation getEntityTexture(EntityChest entity)
{
return TextureMap.LOCATION_BLOCKS_TEXTURE;
}
};
}
});
}
public static abstract class CommonProxy
{
public void preInit(FMLPreInitializationEvent event)
{
GameRegistry.registerTileEntity(Chest.class, MODID + ":" + "tile_" + blockName);
}
@Nullable
public abstract IAnimationStateMachine load(ResourceLocation location, ImmutableMap<String, ITimeValue> parameters);
public IAnimationStateMachine load(ResourceLocation location, ImmutableMap<String, ITimeValue> parameters){ return null; };
}
public static class ServerProxy extends CommonProxy
{
@Nullable
public IAnimationStateMachine load(ResourceLocation location, ImmutableMap<String, ITimeValue> parameters)
{
return null;
}
}
public static class ServerProxy extends CommonProxy {}
public static class ClientProxy extends CommonProxy
{
@Override
public void preInit(FMLPreInitializationEvent event)
{
super.preInit(event);
B3DLoader.INSTANCE.addDomain(MODID);
ModelLoader.setCustomModelResourceLocation(TEST_ITEM, 0, new ModelResourceLocation(TEST_ITEM.getRegistryName(), "inventory"));
ClientRegistry.bindTileEntitySpecialRenderer(Chest.class, new AnimationTESR<Chest>()
{
@Override
public void handleEvents(Chest chest, float time, Iterable<Event> pastEvents)
{
chest.handleEvents(time, pastEvents);
}
});
String entityName = MODID + ":entity_chest";
//EntityRegistry.registerGlobalEntityID(EntityChest.class, entityName, EntityRegistry.findGlobalUniqueEntityId());
EntityRegistry.registerModEntity(new ResourceLocation(entityName), EntityChest.class, entityName, 0, ModelAnimationDebug.instance, 64, 20, true, 0xFFAAAA00, 0xFFDDDD00);
RenderingRegistry.registerEntityRenderingHandler(EntityChest.class, new IRenderFactory<EntityChest>()
{
@SuppressWarnings("deprecation")
public Render<EntityChest> createRenderFor(RenderManager manager)
{
/*model = ModelLoaderRegistry.getModel(new ResourceLocation(ModelLoaderRegistryDebug.MODID, "block/chest.b3d"));
if(model instanceof IRetexturableModel)
{
model = ((IRetexturableModel)model).retexture(ImmutableMap.of("#chest", "entity/chest/normal"));
}
if(model instanceof IModelCustomData)
{
model = ((IModelCustomData)model).process(ImmutableMap.of("mesh", "[\"Base\", \"Lid\"]"));
}*/
ResourceLocation location = new ModelResourceLocation(new ResourceLocation(MODID, blockName), "entity");
return new RenderLiving<EntityChest>(manager, new net.minecraftforge.client.model.animation.AnimationModelBase<EntityChest>(location, new VertexLighterSmoothAo(Minecraft.getMinecraft().getBlockColors()))
{
@Override
public void handleEvents(EntityChest chest, float time, Iterable<Event> pastEvents)
{
chest.handleEvents(time, pastEvents);
}
}, 0.5f)
{
protected ResourceLocation getEntityTexture(EntityChest entity)
{
return TextureMap.LOCATION_BLOCKS_TEXTURE;
}
};
}
});
}
public IAnimationStateMachine load(ResourceLocation location, ImmutableMap<String, ITimeValue> parameters)
{
@ -305,7 +296,6 @@ public class ModelAnimationDebug
public void preInit(FMLPreInitializationEvent event)
{
logger = event.getModLog();
proxy.preInit(event);
}
public static class Chest extends TileEntity

View File

@ -52,17 +52,6 @@ public class ModelFluidDebug
public static final Fluid GAS = new TestGas();
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
if (ENABLE)
{
FluidRegistry.registerFluid(FLUID);
FluidRegistry.registerFluid(GAS);
FluidRegistry.registerFluid(MILK);
}
}
@Mod.EventBusSubscriber(modid = MODID)
public static class Registration
{
@ -71,6 +60,13 @@ public class ModelFluidDebug
{
if (!ENABLE)
return;
//TODO: Make FluidRegistry a full registry?
//Make a delegate system for FluidBlocks/Fluid Stacks?
//Fluids must be registered before a FluidStack can be made. Which is done in the block constructor
FluidRegistry.registerFluid(FLUID);
FluidRegistry.registerFluid(GAS);
FluidRegistry.registerFluid(MILK);
event.getRegistry().registerAll(
new TestFluidBlock(),
new TestGasBlock(),

View File

@ -28,10 +28,10 @@ public class PotionRegistryDebug
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event)
{
Potion forge = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forge"), false, 0xff00ff).setRegistryName(new ResourceLocation(ForgeVersion.MOD_ID, "forge")); // test automatic id distribution
Potion forgy = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forgy"), true, 0x00ff00).setRegistryName(new ResourceLocation(ForgeVersion.MOD_ID, "forgy")); // test that ids above 127 work
Potion forge = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forge"), false, 0xff00ff).setRegistryName(new ResourceLocation(MODID, "forge")); // test automatic id distribution
Potion forgy = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forgy"), true, 0x00ff00).setRegistryName(new ResourceLocation(MODID, "forgy")); // test that ids above 127 work
ForgeRegistries.POTIONS.register(forge);
Potion.REGISTRY.register(200, forgy.getRegistryName(), forgy);
//((ForgeRegistry)ForgeRegistries.POTIONS).register(200, forgy.getRegistryName(), forgy);
Random rand = new Random();
TIntSet taken = new TIntHashSet(100);

View File

@ -72,7 +72,7 @@ public class SubstitutionInjectionTest
// TEST 0a: Validate that the ItemBlock for Dirt points at vanilla dirt
ItemBlock dirtitem = (ItemBlock) itemRegistry.getValue(MC_DIRT);
assertEquals("ItemBlock points at my block", currDirt, dirtitem.block);
assertEquals("ItemBlock points at my block", currDirt, dirtitem.getBlock());
blockRegistry.register(toSub); //Register a new object, with the same vanilla name, Should cause the item to be replaced
GameData.freezeData();