mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 11:05:40 +00:00
Tests do not run yet. Things of note: Removed the idea of substitutions, just register multiple items with the same name they will override each other like a normal map. Decoupled Forge registries from vanilla classes. They now use bouncer classes. MODDERS SHOULD NEVER USE THESE Introduced more stringent registry locking. As it sits things are only allowed to be registered during the RegistryEvent.Registry phases! This is to force modders to split up their registrations, and pave the way for calling these functions multiple times during a single MC lifecycle. ObjectHolder, Missing Mappings, etc... *should* now work for all registry types, nothing should be special cased to Blocks/Items anymore. Added optional generic dummy factory to registries, to allow registry creators the ability to dummy more then just Blocks. Re-worked the ItemStack transformer and applied it to ItemBlock and ItemBlockSpecial. Allowing us to cleanup reflective hacks in Block callbacks. Registry onAdd callback is now only fired on the ACTIVE registry, fixing any issues of temp registries overriding active objects.
135 lines
4.7 KiB
Java
135 lines
4.7 KiB
Java
package net.minecraftforge.debug;
|
|
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.potion.Potion;
|
|
import net.minecraft.util.ResourceLocation;
|
|
import net.minecraft.util.SoundEvent;
|
|
import net.minecraftforge.event.RegistryEvent;
|
|
import net.minecraftforge.fml.common.Mod;
|
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
|
import net.minecraftforge.registries.IForgeRegistryEntry;
|
|
import net.minecraftforge.registries.RegistryBuilder;
|
|
|
|
@Mod(modid = ObjectHolderTest.MODID, name = "ObjectHolderTests", version = "1.0", acceptableRemoteVersions = "*")
|
|
public class ObjectHolderTest
|
|
{
|
|
public static final String MODID = "objectholdertest";
|
|
|
|
@Mod.EventHandler
|
|
public void init(FMLInitializationEvent event)
|
|
{
|
|
//verifies @ObjectHolder with custom id
|
|
assert VanillaObjectHolder.uiButtonClick != null;
|
|
//verifies modded items work
|
|
assert ForgeObjectHolder.forge_potion != null;
|
|
//verifies minecraft:air is now resolvable
|
|
assert VanillaObjectHolder.air != null;
|
|
//verifies unexpected name should not have defaulted to AIR.
|
|
assert VanillaObjectHolder.nonExistentBlock == null;
|
|
//verifies custom registries
|
|
assert CustomRegistryObjectHolder.custom_entry != null;
|
|
//verifies interfaces are supported
|
|
assert CustomRegistryObjectHolder.custom_entry_by_interface != null;
|
|
|
|
}
|
|
|
|
protected static class PotionForge extends Potion
|
|
{
|
|
protected PotionForge(ResourceLocation location, boolean badEffect, int potionColor)
|
|
{
|
|
super(badEffect, potionColor);
|
|
setPotionName("potion." + location.getResourcePath());
|
|
setRegistryName(location);
|
|
}
|
|
}
|
|
|
|
@Mod.EventBusSubscriber(modid = MODID)
|
|
public static class Registration
|
|
{
|
|
@SubscribeEvent
|
|
public static void newRegistry(RegistryEvent.NewRegistry event)
|
|
{
|
|
new RegistryBuilder<ICustomRegistryEntry>()
|
|
.setType(ICustomRegistryEntry.class)
|
|
.setName(new ResourceLocation("object_holder_test_custom_registry"))
|
|
.setIDRange(0, 255)
|
|
.create();
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void registerPotions(RegistryEvent.Register<Potion> event)
|
|
{
|
|
event.getRegistry().register(
|
|
new ObjectHolderTest.PotionForge(new ResourceLocation(ObjectHolderTest.MODID, "forge_potion"), false, 0xff00ff) // test automatic id distribution
|
|
);
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void registerInterfaceRegistryForge(RegistryEvent.Register<ICustomRegistryEntry> event)
|
|
{
|
|
event.getRegistry().register(
|
|
new CustomRegistryEntry().setRegistryName(new ResourceLocation(MODID, "custom_entry_by_interface"))
|
|
);
|
|
|
|
event.getRegistry().register(
|
|
new CustomRegistryEntry().setRegistryName(new ResourceLocation(MODID, "custom_entry"))
|
|
);
|
|
}
|
|
}
|
|
interface ICustomRegistryEntry extends IForgeRegistryEntry<ICustomRegistryEntry>{}
|
|
|
|
|
|
static class CustomRegistryEntry implements ICustomRegistryEntry
|
|
{
|
|
private ResourceLocation name;
|
|
|
|
@Override
|
|
public ICustomRegistryEntry setRegistryName(ResourceLocation name)
|
|
{
|
|
this.name = name;
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public ResourceLocation getRegistryName()
|
|
{
|
|
return name;
|
|
}
|
|
|
|
@Override
|
|
public Class<ICustomRegistryEntry> getRegistryType()
|
|
{
|
|
return ICustomRegistryEntry.class;
|
|
}
|
|
}
|
|
|
|
@GameRegistry.ObjectHolder("minecraft")
|
|
static class VanillaObjectHolder
|
|
{
|
|
//Tests importing vanilla objects that need the @ObjectHolder annotation to get a valid ResourceLocation
|
|
@GameRegistry.ObjectHolder("ui.button.click")
|
|
public static final SoundEvent uiButtonClick = null;
|
|
public static final Block air = null;
|
|
public static final Block nonExistentBlock = null;
|
|
}
|
|
|
|
@GameRegistry.ObjectHolder(ObjectHolderTest.MODID)
|
|
static class ForgeObjectHolder
|
|
{
|
|
//Tests using subclasses for injections
|
|
public static final ObjectHolderTest.PotionForge forge_potion = null;
|
|
}
|
|
|
|
@GameRegistry.ObjectHolder(ObjectHolderTest.MODID)
|
|
static class CustomRegistryObjectHolder
|
|
{
|
|
//Tests whether custom registries can be used
|
|
public static final ICustomRegistryEntry custom_entry = null;
|
|
|
|
//Tests whether interfaces can be used
|
|
public static final ICustomRegistryEntry custom_entry_by_interface = null;
|
|
}
|
|
}
|