Advertisement
Guest User

Untitled

a guest
Jun 18th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.17 KB | None | 0 0
  1. public static class SpecialFlowerBakedModel implements IPerspectiveAwareModel {
  2.  
  3.         private final ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms;
  4.         private final ImmutableMap<Optional<String>, ModelResourceLocation> blockModels;
  5.         private final ImmutableMap<Optional<String>, ModelResourceLocation> itemModels;
  6.  
  7.         private IBakedModel baseModel;
  8.         private ImmutableMap<String, IBakedModel> bakedBlockModels;
  9.         private ImmutableMap<String, IBakedModel> bakedItemModels;
  10.  
  11.         public SpecialFlowerBakedModel(ImmutableMap<Optional<String>, ModelResourceLocation> blockModels,
  12.                                        ImmutableMap<Optional<String>, ModelResourceLocation> itemModels, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> cameraTransforms) {
  13.             this.blockModels = blockModels;
  14.             this.itemModels = itemModels;
  15.             this.transforms = cameraTransforms;
  16.         }
  17.  
  18.         private void refreshBakedModels() {
  19.             if(baseModel == null) {
  20.                 // If not done already, bake and cache all models
  21.                 baseModel = getBlockModel(Optional.absent());
  22.  
  23.                 ImmutableMap.Builder<String, IBakedModel> builder = ImmutableMap.builder();
  24.                 for(Map.Entry<Optional<String>, ModelResourceLocation> e : blockModels.entrySet()) {
  25.                     if(e.getKey().isPresent()) {
  26.                         builder.put(e.getKey().get(), getBlockModel(e.getKey()));
  27.                     }
  28.                 }
  29.  
  30.                 bakedBlockModels = builder.build();
  31.  
  32.                 ImmutableMap.Builder<String, IBakedModel> builder2 = ImmutableMap.builder();
  33.                 for(Map.Entry<Optional<String>, ModelResourceLocation> e : itemModels.entrySet()) {
  34.                     if(e.getKey().isPresent()) {
  35.                         builder2.put(e.getKey().get(), getItemModel(e.getKey()));
  36.                     }
  37.                 }
  38.  
  39.                 bakedItemModels = builder2.build();
  40.             }
  41.         }
  42.  
  43.         private IBakedModel getBlockModel(Optional<String> opt) {
  44.             ModelResourceLocation loc = blockModels.get(opt);
  45.             if(loc == null) {
  46.                 loc = new ModelResourceLocation("builtin/missing", "missing");
  47.             }
  48.             IModel model = ModelLoaderRegistry.getModelOrMissing(loc);
  49.             return model.bake(new SimpleModelState(transforms), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
  50.         }
  51.  
  52.         private IBakedModel getItemModel(Optional<String> opt) {
  53.             ModelResourceLocation loc = itemModels.get(opt);
  54.             if(loc == null) {
  55.                 loc = new ModelResourceLocation("builtin/missing", "missing");
  56.             }
  57.             IModel model = ModelLoaderRegistry.getModelOrMissing(loc);
  58.             return model.bake(new SimpleModelState(transforms), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
  59.         }
  60.  
  61.         @Nonnull
  62.         @Override
  63.         public List<BakedQuad> getQuads(IBlockState state, EnumFacing face, long rand) {
  64.             if(state.getBlock() != ModBlocks.specialFlower)
  65.                 return Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager().getMissingModel().getQuads(state, face, rand);
  66.             refreshBakedModels();
  67.             IExtendedBlockState extendedState = ((IExtendedBlockState) state);
  68.             IBakedModel ret = bakedBlockModels.get(extendedState.getValue(BotaniaStateProps.SUBTILE_ID));
  69.             if(ret == null)
  70.                 ret = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager().getMissingModel();
  71.             return ret.getQuads(state, face, rand);
  72.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement