mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 03:59:45 +00:00
Register models and colors more efficiently
This commit is contained in:
1 parent
6b912633b9
commit
65c63dcc63
7 files changed
+74
-91
No files matched your search
@@ -13,7 +13,7 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.arboriculture.EnumWoodType;
|
||||
import forestry.core.models.ModelManager;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.core.render.ForestryResource;
|
||||
import forestry.core.utils.Translator;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class WoodHelper {
|
||||
int meta = stack.getMetadata();
|
||||
EnumWoodType woodType = wood.getWoodType(meta);
|
||||
String blockKind = wood.getBlockKind();
|
||||
return ModelManager.getInstance().getModelLocation(blockKind + "/" + woodType);
|
||||
return ForestryAPI.modelManager.getModelLocation(blockKind + "/" + woodType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -381,7 +381,7 @@ public class PluginCore extends BlankForestryPlugin {
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void onBakeModel(ModelBakeEvent event) {
|
||||
ModelManager.registerCustomModels(event);
|
||||
ModelManager.getInstance().registerCustomModels(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -10,9 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.blocks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -20,11 +17,10 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import forestry.core.models.ModelManager;
|
||||
import forestry.plugins.PluginManager;
|
||||
|
||||
public abstract class BlockRegistry {
|
||||
private final List<Block> allBlocks = new ArrayList<>();
|
||||
|
||||
protected <T extends Block> T registerBlock(T block, ItemBlock itemBlock, String name) {
|
||||
if (PluginManager.getStage() != PluginManager.Stage.REGISTER) {
|
||||
throw new RuntimeException("Tried to register Block outside of REGISTER");
|
||||
@@ -32,7 +28,7 @@ public abstract class BlockRegistry {
|
||||
block.setUnlocalizedName("for." + name);
|
||||
GameRegistry.registerBlock(block, null, name);
|
||||
GameRegistry.registerItem(itemBlock, name);
|
||||
allBlocks.add(block);
|
||||
ModelManager.getInstance().registerBlock(block);
|
||||
return block;
|
||||
}
|
||||
|
||||
@@ -46,15 +42,11 @@ public abstract class BlockRegistry {
|
||||
}
|
||||
block.setUnlocalizedName("for." + name);
|
||||
GameRegistry.registerBlock(block, itemClass, name, itemCtorArgs);
|
||||
allBlocks.add(block);
|
||||
ModelManager.getInstance().registerBlock(block);
|
||||
return block;
|
||||
}
|
||||
|
||||
protected static void registerOreDictWildcard(String oreDictName, Block block) {
|
||||
OreDictionary.registerOre(oreDictName, new ItemStack(block, 1, OreDictionary.WILDCARD_VALUE));
|
||||
}
|
||||
|
||||
public List<Block> getAllBlocks() {
|
||||
return allBlocks;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import forestry.core.models.ModelManager;
|
||||
import forestry.plugins.PluginManager;
|
||||
|
||||
public abstract class ItemRegistry {
|
||||
@@ -25,6 +26,7 @@ public abstract class ItemRegistry {
|
||||
}
|
||||
item.setUnlocalizedName("for." + name);
|
||||
GameRegistry.registerItem(item, name);
|
||||
ModelManager.getInstance().registerItem(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.core.models;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -29,7 +30,6 @@ import net.minecraft.util.registry.IRegistry;
|
||||
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.fml.common.registry.GameData;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -45,8 +45,13 @@ public class ModelManager implements IModelManager {
|
||||
|
||||
private static final ModelManager instance = new ModelManager();
|
||||
|
||||
private static final ArrayList<BlockModelIndex> customBlockModels = new ArrayList<>();
|
||||
private static final ArrayList<ModelIndex> customModels = new ArrayList<>();
|
||||
private final List<BlockModelIndex> customBlockModels = new ArrayList<>();
|
||||
private final List<ModelIndex> customModels = new ArrayList<>();
|
||||
|
||||
private final List<IItemModelRegister> itemModelRegisters = new ArrayList<>();
|
||||
private final List<IStateMapperRegister> stateMapperRegisters = new ArrayList<>();
|
||||
private final List<IBlockColor> blockColorList = new ArrayList<>();
|
||||
private final List<IItemColor> itemColorList = new ArrayList<>();
|
||||
|
||||
static {
|
||||
ForestryAPI.modelManager = instance;
|
||||
@@ -97,50 +102,67 @@ public class ModelManager implements IModelManager {
|
||||
return new ModelResourceLocation(modID + ":" + identifier, "inventory");
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: keep lists of each type of block and item to be registered.
|
||||
* Iterating over GameData.getBlockRegistry() and GameData.getItemRegistry() will be VERY slow on a big pack.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void registerModels() {
|
||||
for (Block block : GameData.getBlockRegistry()) {
|
||||
if (block instanceof IItemModelRegister) {
|
||||
((IItemModelRegister) block).registerModel(Item.getItemFromBlock(block), getInstance());
|
||||
}
|
||||
if (block instanceof IStateMapperRegister) {
|
||||
((IStateMapperRegister) block).registerStateMapper();
|
||||
}
|
||||
public void registerBlock(Block block) {
|
||||
if (block instanceof IItemModelRegister) {
|
||||
itemModelRegisters.add((IItemModelRegister) block);
|
||||
}
|
||||
for (Item item : GameData.getItemRegistry()) {
|
||||
if (item instanceof IItemModelRegister) {
|
||||
((IItemModelRegister) item).registerModel(item, getInstance());
|
||||
}
|
||||
if (block instanceof IStateMapperRegister) {
|
||||
stateMapperRegisters.add((IStateMapperRegister) block);
|
||||
}
|
||||
if (block instanceof IBlockColor) {
|
||||
blockColorList.add((IBlockColor) block);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerItem(Item item) {
|
||||
if (item instanceof IItemModelRegister) {
|
||||
itemModelRegisters.add((IItemModelRegister) item);
|
||||
}
|
||||
if (item instanceof IItemColor) {
|
||||
itemColorList.add((IItemColor) item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: keep lists of each type of block and item to be registered.
|
||||
* Iterating over GameData.getBlockRegistry() and GameData.getItemRegistry() will be VERY slow on a big pack.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void registerItemAndBlockColors() {
|
||||
public void registerModels() {
|
||||
for (IItemModelRegister itemModelRegister : itemModelRegisters) {
|
||||
Item item = null;
|
||||
if (itemModelRegister instanceof Block) {
|
||||
item = Item.getItemFromBlock((Block) itemModelRegister);
|
||||
} else if (itemModelRegister instanceof Item) {
|
||||
item = (Item) itemModelRegister;
|
||||
}
|
||||
|
||||
if (item != null) {
|
||||
itemModelRegister.registerModel(item, this);
|
||||
}
|
||||
}
|
||||
|
||||
for (IStateMapperRegister stateMapperRegister : stateMapperRegisters) {
|
||||
stateMapperRegister.registerStateMapper();
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerItemAndBlockColors() {
|
||||
Minecraft minecraft = Minecraft.getMinecraft();
|
||||
|
||||
BlockColors blockColors = minecraft.getBlockColors();
|
||||
ItemColors itemColors = minecraft.getItemColors();
|
||||
|
||||
for (Block block : GameData.getBlockRegistry()) {
|
||||
if (block instanceof IBlockColor) {
|
||||
blockColors.registerBlockColorHandler((IBlockColor) block, block);
|
||||
for (IBlockColor blockColor : blockColorList) {
|
||||
if (blockColor instanceof Block) {
|
||||
blockColors.registerBlockColorHandler(blockColor, (Block) blockColor);
|
||||
}
|
||||
}
|
||||
for (Item item : GameData.getItemRegistry()) {
|
||||
if (item instanceof IItemColor) {
|
||||
itemColors.registerItemColorHandler((IItemColor) item, item);
|
||||
|
||||
ItemColors itemColors = minecraft.getItemColors();
|
||||
for (IItemColor itemColor : itemColorList) {
|
||||
if (itemColor instanceof Item) {
|
||||
itemColors.registerItemColorHandler(itemColor, (Item) itemColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerCustomModels(ModelBakeEvent event) {
|
||||
public void registerCustomModels(ModelBakeEvent event) {
|
||||
IRegistry<ModelResourceLocation, IBakedModel> registry = event.getModelRegistry();
|
||||
for (final BlockModelIndex index : customBlockModels) {
|
||||
registry.putObject(index.blockModelLocation, index.model);
|
||||
@@ -152,11 +174,11 @@ public class ModelManager implements IModelManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerCustomBlockModel(@Nonnull BlockModelIndex index) {
|
||||
public void registerCustomBlockModel(@Nonnull BlockModelIndex index) {
|
||||
customBlockModels.add(index);
|
||||
}
|
||||
|
||||
public static void registerCustomModel(@Nonnull ModelIndex index) {
|
||||
public void registerCustomModel(@Nonnull ModelIndex index) {
|
||||
customModels.add(index);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.proxy;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
@@ -21,32 +19,24 @@ import net.minecraft.client.particle.EffectRenderer;
|
||||
import net.minecraft.client.particle.EntityFX;
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
|
||||
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.statemap.IStateMapper;
|
||||
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
|
||||
import net.minecraft.client.renderer.color.IItemColor;
|
||||
import net.minecraft.client.renderer.color.ItemColors;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.animation.Animation;
|
||||
import net.minecraftforge.common.animation.ITimeValue;
|
||||
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
|
||||
|
||||
import forestry.apiculture.entities.EntityFXBee;
|
||||
import forestry.apiculture.render.ParticleRenderer;
|
||||
import forestry.apiculture.render.TextureHabitatLocator;
|
||||
import forestry.core.PluginCore;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.entities.EntityFXHoneydust;
|
||||
@@ -55,7 +45,6 @@ import forestry.core.entities.EntityFXSmoke;
|
||||
import forestry.core.entities.EntityFXSnow;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.items.ItemCrated;
|
||||
import forestry.core.items.ItemOverlay;
|
||||
import forestry.core.models.BlockModelIndex;
|
||||
import forestry.core.models.ModelIndex;
|
||||
import forestry.core.models.ModelManager;
|
||||
@@ -133,14 +122,14 @@ public class ProxyRenderClient extends ProxyRender {
|
||||
|
||||
@Override
|
||||
public void registerBlockModel(@Nonnull final BlockModelIndex index) {
|
||||
ModelManager.registerCustomBlockModel(index);
|
||||
ModelManager.getInstance().registerCustomBlockModel(index);
|
||||
StateMapperBase ignoreState = new BlockModeStateMapper(index);
|
||||
registerStateMapper(index.block, ignoreState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModel(@Nonnull ModelIndex index) {
|
||||
ModelManager.registerCustomModel(index);
|
||||
ModelManager.getInstance().registerCustomModel(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -151,28 +140,6 @@ public class ProxyRenderClient extends ProxyRender {
|
||||
// registerModel(new ModelIndex(modelLocation, new ModelCrate()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initRendering() {
|
||||
Minecraft minecraft = Minecraft.getMinecraft();
|
||||
|
||||
ItemColors itemColors = minecraft.getItemColors();
|
||||
|
||||
// itemColors.registerItemColorHandler(new ItemOverlayColor(),
|
||||
// PluginCore.items.
|
||||
// );
|
||||
}
|
||||
|
||||
private static class ItemOverlayColor implements IItemColor {
|
||||
@Override
|
||||
public int getColorFromItemstack(ItemStack stack, int tintIndex) {
|
||||
Item item = stack.getItem();
|
||||
if (item instanceof ItemOverlay) {
|
||||
return ((ItemOverlay) item).getColorFromItemStack(stack, tintIndex);
|
||||
}
|
||||
return 0xffffff;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerFluidStateMapper(Block block, final Fluids forestryFluid) {
|
||||
final ModelResourceLocation fluidLocation = new ModelResourceLocation("forestry:blockforestryfluid",
|
||||
@@ -190,12 +157,12 @@ public class ProxyRenderClient extends ProxyRender {
|
||||
|
||||
@Override
|
||||
public void registerModels() {
|
||||
ModelManager.registerModels();
|
||||
ModelManager.getInstance().registerModels();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerItemAndBlockColors() {
|
||||
ModelManager.registerItemAndBlockColors();
|
||||
ModelManager.getInstance().registerItemAndBlockColors();
|
||||
}
|
||||
|
||||
// @Override
|
||||
|
||||
@@ -12,8 +12,8 @@ package forestry.lepidopterology.proxy;
|
||||
|
||||
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.core.models.ModelIndex;
|
||||
import forestry.core.models.ModelManager;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.lepidopterology.entities.EntityButterfly;
|
||||
import forestry.lepidopterology.render.ModelButterflyItem;
|
||||
@@ -24,6 +24,6 @@ public class ProxyLepidopterologyClient extends ProxyLepidopterology {
|
||||
@Override
|
||||
public void preInitializeRendering() {
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityButterfly.class, new RenderButterflyEntity.Factory());
|
||||
Proxies.render.registerModel(new ModelIndex(ModelManager.getInstance().getModelLocation("butterflyGE"), new ModelButterflyItem()));
|
||||
Proxies.render.registerModel(new ModelIndex(ForestryAPI.modelManager.getModelLocation("butterflyGE"), new ModelButterflyItem()));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user