Search in sources :

Example 1 with ICustomSubItems

use of crazypants.enderio.base.render.ICustomSubItems in project EnderIO by SleepyTrousers.

the class SmartModelAttacher method registerBlockItemModels.

/**
 * Registers the default ModelResourceLocation for the items of all blocks that have registered for MachineSmartModel-based rendering.
 * <p>
 * For items that have subtypes, all subtypes are registered. All subtypes are registered to the same model, as the smart model can be damage-aware.
 */
@SideOnly(Side.CLIENT)
public static void registerBlockItemModels() {
    for (RegistrationHolder<?, ?> holder : blocks) {
        Block block = holder.block;
        Registerable modObject = ModObjectRegistry.getModObject(holder.block);
        if (modObject == null) {
            Log.debug("Block " + block + " has no modObject. What?");
        } else {
            Item item = modObject.getItem();
            if (item instanceof IHaveRenderers || block instanceof IHaveRenderers) {
                // Nothing to do for us, the item/block handles it for itself
                Log.debug(block.getClass() + " handles its item registrations itself");
                if (item instanceof ICustomSubItems || block instanceof ICustomSubItems) {
                    throw new RuntimeException(block.getClass() + " implements both IHaveRenderers and ICustomSubItems");
                }
            } else if (block instanceof IDefaultRenderers) {
                // Nothing to do for us, the block wants ClientProxy to handle it
                Log.debug(block.getClass() + " has default item registrations");
                if (item instanceof ICustomSubItems || block instanceof ICustomSubItems) {
                    throw new RuntimeException(block.getClass() + " implements both IDefaultRenderers and ICustomSubItems");
                }
            } else if (item != null && item != Items.AIR) {
                @Nonnull final ResourceLocation registryName = item instanceof ICustomItemResourceLocation ? ((ICustomItemResourceLocation) item).getRegistryNameForCustomModelResourceLocation() : NullHelper.notnullF(item.getRegistryName(), "Item.getItemFromBlock() returned an unregistered item");
                ModelResourceLocation location = new ModelResourceLocation(registryName, "inventory");
                if (item.getHasSubtypes()) {
                    NNList<ItemStack> subItems;
                    if (item instanceof ICustomSubItems) {
                        subItems = ((ICustomSubItems) item).getSubItems();
                    } else if (block instanceof ICustomSubItems) {
                        subItems = ((ICustomSubItems) block).getSubItems();
                    } else {
                        throw new RuntimeException(block.getClass() + " has subitems but it does not implement ICustomSubItems");
                    }
                    for (ItemStack itemStack : subItems) {
                        Log.debug("Registering RL " + location + " for " + itemStack);
                        ModelLoader.setCustomModelResourceLocation(item, itemStack.getItemDamage(), location);
                    }
                } else {
                    Log.debug("Registering RL " + location + " for " + item);
                    ModelLoader.setCustomModelResourceLocation(item, 0, location);
                }
            } else {
                Log.debug("Block " + block + " has no item, is it intended?");
            }
        }
    }
}
Also used : ICustomSubItems(crazypants.enderio.base.render.ICustomSubItems) Nonnull(javax.annotation.Nonnull) IDefaultRenderers(crazypants.enderio.base.render.IDefaultRenderers) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) Item(net.minecraft.item.Item) ITintedItem(crazypants.enderio.base.render.ITintedItem) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ICustomItemResourceLocation(crazypants.enderio.base.render.ICustomItemResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ITintedBlock(crazypants.enderio.base.render.ITintedBlock) Block(net.minecraft.block.Block) Registerable(crazypants.enderio.base.init.IModObject.Registerable) IHaveRenderers(crazypants.enderio.base.render.IHaveRenderers) ICustomItemResourceLocation(crazypants.enderio.base.render.ICustomItemResourceLocation) ItemStack(net.minecraft.item.ItemStack) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with ICustomSubItems

use of crazypants.enderio.base.render.ICustomSubItems in project EnderIO by SleepyTrousers.

the class ClientProxy method onModelRegistryEvent.

@SubscribeEvent
public static void onModelRegistryEvent(@Nonnull ModelRegistryEvent event) {
    // Custom state mappers
    EnderIOGlassesStateMapper.create();
    ColdFireStateMapper.create();
    LeverStateMapper.create();
    final StateMap doorMapper = (new StateMap.Builder()).ignore(new IProperty[] { BlockDoor.POWERED }).build();
    ModelLoader.setCustomStateMapper(ModObject.blockDarkSteelDoor.getBlockNN(), doorMapper);
    ModelLoader.setCustomStateMapper(ModObject.blockPaintedDarkSteelDoor.getBlockNN(), doorMapper);
    ModelLoader.setCustomStateMapper(ModObject.blockPaintedIronDoor.getBlockNN(), doorMapper);
    ModelLoader.setCustomStateMapper(ModObject.blockPaintedWoodenDoor.getBlockNN(), doorMapper);
    // Items of blocks that use smart rendering
    SmartModelAttacher.registerBlockItemModels();
    /*
     * Most blocks register themselves with the SmartModelAttacher which will also handle their items. Those that don't need to implement IHaveRenderers and
     * have their items handled here.
     * 
     * Items that do _not_ belong to a block are handled here by either having the item implement IHaveRenderers or by registering the default renderer.
     */
    for (IModObject mo : ModObjectRegistry.getObjects()) {
        final Block block = mo.getBlock();
        if (block instanceof ICustomSubItems) {
        // NOP, handled by SmartModelAttacher
        } else if (block instanceof IHaveRenderers) {
            ((IHaveRenderers) block).registerRenderers(mo);
        } else if (block instanceof IDefaultRenderers) {
            ClientUtil.registerDefaultItemRenderer(mo);
        } else if (block == null || block == Blocks.AIR) {
            final Item item = mo.getItem();
            if (item instanceof ICustomSubItems) {
            // NOP, handled by SmartModelAttacher
            } else if (item instanceof IHaveRenderers) {
                ((IHaveRenderers) item).registerRenderers(mo);
            } else if (item != null && item != Items.AIR) {
                ClientUtil.registerDefaultItemRenderer(mo);
            }
        }
        if (block instanceof IHaveTESR) {
            ((IHaveTESR) block).bindTileEntitySpecialRenderer();
        }
    }
}
Also used : Item(net.minecraft.item.Item) ICustomSubItems(crazypants.enderio.base.render.ICustomSubItems) IProperty(net.minecraft.block.properties.IProperty) IHaveTESR(crazypants.enderio.base.render.IHaveTESR) StateMap(net.minecraft.client.renderer.block.statemap.StateMap) IDefaultRenderers(crazypants.enderio.base.render.IDefaultRenderers) Block(net.minecraft.block.Block) IHaveRenderers(crazypants.enderio.base.render.IHaveRenderers) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ICustomSubItems (crazypants.enderio.base.render.ICustomSubItems)2 IDefaultRenderers (crazypants.enderio.base.render.IDefaultRenderers)2 IHaveRenderers (crazypants.enderio.base.render.IHaveRenderers)2 Block (net.minecraft.block.Block)2 Item (net.minecraft.item.Item)2 Registerable (crazypants.enderio.base.init.IModObject.Registerable)1 ICustomItemResourceLocation (crazypants.enderio.base.render.ICustomItemResourceLocation)1 IHaveTESR (crazypants.enderio.base.render.IHaveTESR)1 ITintedBlock (crazypants.enderio.base.render.ITintedBlock)1 ITintedItem (crazypants.enderio.base.render.ITintedItem)1 Nonnull (javax.annotation.Nonnull)1 IProperty (net.minecraft.block.properties.IProperty)1 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)1 StateMap (net.minecraft.client.renderer.block.statemap.StateMap)1 ItemStack (net.minecraft.item.ItemStack)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1