Warn when the objectholder finds nothing in the registry. Helps debug mismatched names.

Also, actually make the scoping thing work with objectholder

Also handle Blocks.air as a special case. It should never be a valid block in the block registry.

Nothing can ever replace the default block registry block. It is disabled for replacement.

Air is properly skipped
This commit is contained in:
Christian 2014-05-26 10:58:13 -04:00
parent bcec606b12
commit d932a23751
3 changed files with 60 additions and 6 deletions

View file

@ -330,7 +330,7 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
if (name.isEmpty()) throw new IllegalArgumentException(String.format("Can't use an empty name for the registry, object %s.", thing));
if (name.indexOf(':') == -1) throw new IllegalArgumentException(String.format("Can't add the name (%s) without a prefix, object %s", name, thing));
if (thing == null) throw new NullPointerException(String.format("Can't add null-object to the registry, name %s.", name));
if (name.equals(optionalDefaultName))
if (name.equals(optionalDefaultName) && this.optionalDefaultObject == null)
{
this.optionalDefaultObject = thing;
}
@ -420,4 +420,9 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
underlyingIntegerMap.func_148746_a(thing, id); // obj <-> id
super.putObject(name, thing); // name <-> obj
}
public I getDefaultValue()
{
return optionalDefaultObject;
}
}

View file

@ -8,6 +8,7 @@ import com.google.common.base.Throwables;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.registry.GameRegistry.ObjectHolder;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
@ -34,8 +35,20 @@ class ObjectHolderRef {
try
{
Object existing = field.get(null);
this.injectedObject = isBlock ? GameData.getBlockRegistry().getNameForObject(existing) :
isItem ? GameData.getItemRegistry().getNameForObject(existing) : null;
// nothing is ever allowed to replace AIR
if (existing == null || existing == GameData.getBlockRegistry().getDefaultValue())
{
this.injectedObject = null;
this.field = null;
this.isBlock = false;
this.isItem = false;
return;
}
else
{
this.injectedObject = isBlock ? GameData.getBlockRegistry().getNameForObject(existing) :
isItem ? GameData.getItemRegistry().getNameForObject(existing) : null;
}
} catch (Exception e)
{
throw Throwables.propagate(e);
@ -85,9 +98,27 @@ class ObjectHolderRef {
{
Object thing;
if (isBlock)
{
thing = GameData.getBlockRegistry().getObject(injectedObject);
else
if (thing == Blocks.air)
{
thing = null;
}
}
else if (isItem)
{
thing = GameData.getItemRegistry().getObject(injectedObject);
}
else
{
thing = null;
}
if (thing == null)
{
FMLLog.warning("Unable to lookup %s for %s. Is there something wrong with the registry?", injectedObject, field);
return;
}
try
{
Object fieldAccessor = newFieldAccessor.invoke(reflectionFactory, field, false);

View file

@ -34,7 +34,22 @@ public enum ObjectHolderRegistry {
String annotationTarget = data.getObjectName();
String value = (String) data.getAnnotationInfo().get("value");
boolean isClass = className.equals(annotationTarget);
scanTarget(classModIds, classCache, className, annotationTarget, value, isClass, false);
if (isClass)
{
scanTarget(classModIds, classCache, className, annotationTarget, value, isClass, false);
}
}
// double pass - get all the class level annotations first, then the field level annotations
for (ASMData data : allObjectHolders)
{
String className = data.getClassName();
String annotationTarget = data.getObjectName();
String value = (String) data.getAnnotationInfo().get("value");
boolean isClass = className.equals(annotationTarget);
if (!isClass)
{
scanTarget(classModIds, classCache, className, annotationTarget, value, isClass, false);
}
}
scanTarget(classModIds, classCache, "net.minecraft.init.Blocks", null, "minecraft", true, true);
scanTarget(classModIds, classCache, "net.minecraft.init.Items", null, "minecraft", true, true);
@ -107,7 +122,10 @@ public enum ObjectHolderRegistry {
private void addHolderReference(ObjectHolderRef ref)
{
objectHolders.add(ref);
if (ref.isValid())
{
objectHolders.add(ref);
}
}
public void applyObjectHolders()