use of crazypants.enderio.base.render.model.RelayingBakedModel in project EnderIO by SleepyTrousers.
the class SmartModelAttacher method bakeModels.
@SuppressWarnings({ "rawtypes", "unchecked" })
@SubscribeEvent
@SideOnly(Side.CLIENT)
public static void bakeModels(@Nonnull ModelBakeEvent event) {
for (RegistrationHolder holder : blocks) {
Block block = holder.block;
Map<IBlockState, ModelResourceLocation> locations = event.getModelManager().getBlockModelShapes().getBlockStateMapper().getVariants(block);
final IProperty holder_property = holder.property;
final Comparable holder_defaultsValue = holder.defaultsValue;
final IBakedModel missingModel = event.getModelManager().getMissingModel();
if (holder_property != null && block.getDefaultState().getPropertyKeys().contains(holder_property) && holder_defaultsValue != null) {
IBlockState defaultState = block.getDefaultState().withProperty(holder_property, holder_defaultsValue);
ModelResourceLocation defaultMrl = locations.get(defaultState);
if (defaultMrl == null) {
throw new RuntimeException("Model for state " + defaultState + " failed to load from " + defaultMrl + ". " + debugOutput(event.getModelRegistry(), defaultMrl, missingModel));
}
IBakedModel defaultBakedModel = event.getModelRegistry().getObject(defaultMrl);
if (defaultBakedModel == null) {
Log.warn("ModelBakeEvent: cannot register smart model over null model for " + holder.block + ". See model errors below.");
continue;
}
RelayingBakedModel model = new RelayingBakedModel(defaultBakedModel);
ModelResourceLocation itemMrl = new ModelResourceLocation(defaultMrl.getResourceDomain() + ":" + defaultMrl.getResourcePath() + "#inventory");
event.getModelRegistry().putObject(itemMrl, model);
if (defaultBakedModel == missingModel) {
// This is normal on the first pass. We register our synthetic models above anyway to avoid model loading errors.
continue;
}
for (Entry<IBlockState, ModelResourceLocation> entry : locations.entrySet()) {
final ModelResourceLocation entryMrl = NullHelper.notnullF(entry.getValue(), "BlockModelShapes contains null keys");
final IBlockState entryBlockstate = entry.getKey();
final IBakedModel existingModel = event.getModelRegistry().getObject(entryMrl);
if (existingModel == null || existingModel == missingModel) {
event.getModelRegistry().putObject(entryMrl, defaultBakedModel);
} else if (entryBlockstate.getValue(holder_property) == holder.autoValue) {
event.getModelRegistry().putObject(entryMrl, model);
}
}
} else {
IBlockState defaultState = block.getDefaultState();
ModelResourceLocation defaultMrl = locations.get(defaultState);
if (defaultMrl == null) {
throw new RuntimeException("Model for state " + defaultState + " failed to load from " + defaultMrl + ". " + debugOutput(event.getModelRegistry(), defaultMrl, missingModel));
}
IBakedModel defaultBakedModel = event.getModelRegistry().getObject(defaultMrl);
if (defaultBakedModel == null || defaultBakedModel == missingModel) {
continue;
}
if (!holder.itemOnly) {
for (ModelResourceLocation mrl0 : locations.values()) {
final ModelResourceLocation mrl = NullHelper.notnullF(mrl0, "BlockModelShapes contains null keys");
IBakedModel model = event.getModelRegistry().getObject(mrl);
if (model == null || model == missingModel) {
} else {
event.getModelRegistry().putObject(mrl, new RelayingBakedModel(NullHelper.first(model, defaultBakedModel)));
}
}
}
ModelResourceLocation itemMrl = new ModelResourceLocation(defaultMrl.getResourceDomain() + ":" + defaultMrl.getResourcePath() + "#inventory");
final IBakedModel model = event.getModelRegistry().getObject(itemMrl);
if (model == null || model == missingModel) {
event.getModelRegistry().putObject(itemMrl, new RelayingBakedModel(defaultBakedModel));
} else {
event.getModelRegistry().putObject(itemMrl, new RelayingBakedModel(model));
}
}
}
OverlayHolder.collectOverlayQuads(event);
}
Aggregations