use of crazypants.enderio.base.render.ICustomItemResourceLocation 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?");
}
}
}
}
Aggregations