2016-06-23 03:49:47 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
2018-07-01 21:17:28 +00:00
|
|
|
* Copyright (c) 2016-2018.
|
2016-06-23 03:49:47 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2017-06-19 22:02:18 +00:00
|
|
|
package net.minecraftforge.registries;
|
2016-04-01 21:13:06 +00:00
|
|
|
|
|
|
|
import com.google.common.reflect.TypeToken;
|
|
|
|
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
|
2017-01-11 23:17:56 +00:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2016-04-01 21:13:06 +00:00
|
|
|
public interface IForgeRegistryEntry<V>
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Sets a unique name for this Item. This should be used for uniquely identify the instance of the Item.
|
|
|
|
* This is the valid replacement for the atrocious 'getUnlocalizedName().substring(6)' stuff that everyone does.
|
|
|
|
* Unlocalized names have NOTHING to do with unique identifiers. As demonstrated by vanilla blocks and items.
|
|
|
|
*
|
|
|
|
* The supplied name will be prefixed with the currently active mod's modId.
|
|
|
|
* If the supplied name already has a prefix that is different, it will be used and a warning will be logged.
|
|
|
|
*
|
|
|
|
* If a name already exists, or this Item is already registered in a registry, then an IllegalStateException is thrown.
|
|
|
|
*
|
|
|
|
* Returns 'this' to allow for chaining.
|
|
|
|
*
|
|
|
|
* @param name Unique registry name
|
|
|
|
* @return This instance
|
2018-08-30 01:30:15 +00:00
|
|
|
* /
|
2016-04-01 21:13:06 +00:00
|
|
|
V setRegistryName(ResourceLocation name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A unique identifier for this entry, if this entry is registered already it will return it's official registry name.
|
|
|
|
* Otherwise it will return the name set in setRegistryName().
|
|
|
|
* If neither are valid null is returned.
|
|
|
|
*
|
|
|
|
* @return Unique identifier or null.
|
2018-08-30 01:30:15 +00:00
|
|
|
* /
|
2017-01-11 23:17:56 +00:00
|
|
|
@Nullable
|
2016-04-01 21:13:06 +00:00
|
|
|
ResourceLocation getRegistryName();
|
|
|
|
|
2017-05-18 20:47:13 +00:00
|
|
|
Class<V> getRegistryType();
|
2016-04-01 21:13:06 +00:00
|
|
|
|
|
|
|
// Default implementation, modders who make extra items SHOULD extend this instead of Object.
|
2017-06-14 17:14:56 +00:00
|
|
|
// So, all fields in interfaces are forced static, so even with Java8 people must still extend this.
|
2016-04-01 21:13:06 +00:00
|
|
|
@SuppressWarnings({ "serial", "unchecked" })
|
|
|
|
public static class Impl<T extends IForgeRegistryEntry<T>> implements IForgeRegistryEntry<T>
|
|
|
|
{
|
|
|
|
private TypeToken<T> token = new TypeToken<T>(getClass()){};
|
2017-06-19 22:02:18 +00:00
|
|
|
public final IRegistryDelegate<T> delegate = new RegistryDelegate<T>((T)this, (Class<T>)token.getRawType());
|
2016-04-01 21:13:06 +00:00
|
|
|
private ResourceLocation registryName = null;
|
|
|
|
|
|
|
|
public final T setRegistryName(String name)
|
|
|
|
{
|
|
|
|
if (getRegistryName() != null)
|
|
|
|
throw new IllegalStateException("Attempted to set registry name with existing registry name! New: " + name + " Old: " + getRegistryName());
|
|
|
|
|
2018-05-17 05:52:32 +00:00
|
|
|
this.registryName = GameData.checkPrefix(name);
|
2016-04-01 21:13:06 +00:00
|
|
|
return (T)this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Helper functions
|
2017-06-18 01:24:17 +00:00
|
|
|
@Override
|
2016-04-01 21:13:06 +00:00
|
|
|
public final T setRegistryName(ResourceLocation name){ return setRegistryName(name.toString()); }
|
|
|
|
public final T setRegistryName(String modID, String name){ return setRegistryName(modID + ":" + name); }
|
2017-06-18 01:24:17 +00:00
|
|
|
@Override
|
2017-01-11 23:17:56 +00:00
|
|
|
@Nullable
|
2016-04-01 21:13:06 +00:00
|
|
|
public final ResourceLocation getRegistryName()
|
|
|
|
{
|
|
|
|
if (delegate.name() != null) return delegate.name();
|
|
|
|
return registryName != null ? registryName : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-18 20:47:13 +00:00
|
|
|
public final Class<T> getRegistryType() { return (Class<T>) token.getRawType(); };
|
2016-04-01 21:13:06 +00:00
|
|
|
}
|
2018-08-30 01:30:15 +00:00
|
|
|
*/
|
2016-04-01 21:13:06 +00:00
|
|
|
}
|