use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project Tropicraft by Tropicraft.
the class ClientProxy method onModelBake.
@SubscribeEvent
public void onModelBake(ModelBakeEvent event) {
for (Entry<String, String[]> e : blockVariants.entrySet()) {
for (String variant : e.getValue()) {
ModelResourceLocation loc = new ModelResourceLocation(Info.MODID + ":" + e.getKey(), variant);
IModel model = ModelLoaderRegistry.getModelOrLogError(loc, "Could not load arbitrary block variant " + variant + " for block " + e.getKey());
event.getModelRegistry().putObject(loc, model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()));
}
}
try {
IModel waterTop = ModelLoaderRegistry.getModel(new ResourceLocation("tropicraft:block/tropics_water_top"));
final IBakedModel waterTopBaked = waterTop.bake(waterTop.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
Block[] fences = new Block[] { BlockRegistry.bambooFence, BlockRegistry.chunkFence, BlockRegistry.mahoganyFence, BlockRegistry.palmFence, BlockRegistry.thatchFence };
for (Block block : fences) {
ModelResourceLocation loc = new ModelResourceLocation(block.getRegistryName(), "normal");
final IBakedModel fenceModel = event.getModelRegistry().getObject(loc);
event.getModelRegistry().putObject(loc, new IBakedModel() {
@Override
@Nonnull
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer();
if (layer == null || layer == BlockRenderLayer.SOLID) {
return fenceModel.getQuads(state, side, rand);
} else if (layer == BlockRenderLayer.TRANSLUCENT && state.getValue(BlockTropicraftFence.WATER) == WaterState.SURFACE) {
return waterTopBaked.getQuads(state, side, rand);
}
return Collections.emptyList();
}
@Override
public boolean isGui3d() {
return true;
}
@Override
public boolean isBuiltInRenderer() {
return false;
}
@Override
public boolean isAmbientOcclusion() {
return true;
}
@Override
@Nonnull
public TextureAtlasSprite getParticleTexture() {
return fenceModel.getParticleTexture();
}
@Override
@Nonnull
public ItemOverrideList getOverrides() {
return fenceModel.getOverrides();
}
});
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project EnderIO by SleepyTrousers.
the class ItemModelRegistry method bakeModels.
@SubscribeEvent()
public void bakeModels(@Nonnull ModelBakeEvent event) {
for (Entry<ModelResourceLocation, Registry> entry : registries.entrySet()) {
final ModelResourceLocation resource = entry.getKey();
if (resource != null) {
IBakedModel model = event.getModelRegistry().getObject(resource);
final Registry registry = entry.getValue();
if (registry != null && model != null) {
event.getModelRegistry().putObject(resource, registry.wrap(model));
}
}
}
}
use of net.minecraft.client.renderer.block.model.ModelResourceLocation 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?");
}
}
}
}
use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project EnderIO by SleepyTrousers.
the class ItemEnderface method registerVariant.
private void registerVariant(@Nonnull IModObject mo, int meta, String name) {
ModelLoader.setCustomModelResourceLocation(this, meta, new ModelResourceLocation(mo.getRegistryName(), "variant=" + name));
// Non-glint version
ModelLoader.setCustomModelResourceLocation(this, meta | (1 << 4), new ModelResourceLocation(mo.getRegistryName(), "variant=" + name));
}
use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project EnderIO by SleepyTrousers.
the class BlockDecoration method registerRenderers.
@Override
@SideOnly(Side.CLIENT)
public void registerRenderers(@Nonnull IModObject modObject) {
Item item = Item.getItemFromBlock(this);
Map<IBlockState, ModelResourceLocation> locations = new DefaultStateMapper().putStateModelLocations(this);
NNIterator<EnumDecoBlock> iterator = NNList.of(EnumDecoBlock.class).iterator();
while (iterator.hasNext()) {
EnumDecoBlock type = iterator.next();
IBlockState state = getDefaultState().withProperty(EnumDecoBlock.TYPE, type);
ModelResourceLocation mrl = locations.get(state);
if (mrl != null) {
ModelLoader.setCustomModelResourceLocation(item, EnumDecoBlock.getMetaFromType(type), mrl);
}
}
}
Aggregations