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 committed 2017-06-23 16:59:57 -05:00
1 parent a26d89c876
commit dee84dc1e4
21 files changed
+230 -278

No files matched your search

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