Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class SpecialFlowerBakedModel implements IPerspectiveAwareModel {
- private final ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms;
- private final ImmutableMap<Optional<String>, ModelResourceLocation> blockModels;
- private final ImmutableMap<Optional<String>, ModelResourceLocation> itemModels;
- private IBakedModel baseModel;
- private ImmutableMap<String, IBakedModel> bakedBlockModels;
- private ImmutableMap<String, IBakedModel> bakedItemModels;
- public SpecialFlowerBakedModel(ImmutableMap<Optional<String>, ModelResourceLocation> blockModels,
- ImmutableMap<Optional<String>, ModelResourceLocation> itemModels, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> cameraTransforms) {
- this.blockModels = blockModels;
- this.itemModels = itemModels;
- this.transforms = cameraTransforms;
- }
- private void refreshBakedModels() {
- if(baseModel == null) {
- // If not done already, bake and cache all models
- baseModel = getBlockModel(Optional.absent());
- ImmutableMap.Builder<String, IBakedModel> builder = ImmutableMap.builder();
- for(Map.Entry<Optional<String>, ModelResourceLocation> e : blockModels.entrySet()) {
- if(e.getKey().isPresent()) {
- builder.put(e.getKey().get(), getBlockModel(e.getKey()));
- }
- }
- bakedBlockModels = builder.build();
- ImmutableMap.Builder<String, IBakedModel> builder2 = ImmutableMap.builder();
- for(Map.Entry<Optional<String>, ModelResourceLocation> e : itemModels.entrySet()) {
- if(e.getKey().isPresent()) {
- builder2.put(e.getKey().get(), getItemModel(e.getKey()));
- }
- }
- bakedItemModels = builder2.build();
- }
- }
- private IBakedModel getBlockModel(Optional<String> opt) {
- ModelResourceLocation loc = blockModels.get(opt);
- if(loc == null) {
- loc = new ModelResourceLocation("builtin/missing", "missing");
- }
- IModel model = ModelLoaderRegistry.getModelOrMissing(loc);
- return model.bake(new SimpleModelState(transforms), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
- }
- private IBakedModel getItemModel(Optional<String> opt) {
- ModelResourceLocation loc = itemModels.get(opt);
- if(loc == null) {
- loc = new ModelResourceLocation("builtin/missing", "missing");
- }
- IModel model = ModelLoaderRegistry.getModelOrMissing(loc);
- return model.bake(new SimpleModelState(transforms), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
- }
- @Nonnull
- @Override
- public List<BakedQuad> getQuads(IBlockState state, EnumFacing face, long rand) {
- if(state.getBlock() != ModBlocks.specialFlower)
- return Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager().getMissingModel().getQuads(state, face, rand);
- refreshBakedModels();
- IExtendedBlockState extendedState = ((IExtendedBlockState) state);
- IBakedModel ret = bakedBlockModels.get(extendedState.getValue(BotaniaStateProps.SUBTILE_ID));
- if(ret == null)
- ret = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager().getMissingModel();
- return ret.getQuads(state, face, rand);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement