ModelBakery .java

net.minecraft.client.resources.model.ModelBakery (class, 723 lines): members: LOCATIONS_BUILTIN_TEXTURES, itemModelGenerator, setupModelRegistry, JOINER.

net.minecraft.client.resources.modelclass723 linesclient36.7 KB

API Surface (3)

IRegistry<ModelResourceLocation, IBakedModel> setupModelRegistry()
int compare(ModelResourceLocation p_compare_1_, ModelResourceLocation p_compare_2_)
void registerSprites(TextureMap iconRegistry)

Fields & Constants (21)

LOCATIONS_BUILTIN_TEXTURES
LOGGER
MODEL_MISSING
BUILT_IN_MODELS
JOINER
MODEL_GENERATED
MODEL_COMPASS
MODEL_CLOCK
MODEL_ENTITY
resourceManager
sprites
models
variants
textureMap
blockModelShapes
faceBakery
itemModelGenerator
bakedRegistry
itemLocations
blockDefinitions
variantNames

String literals (267)

"blocks/water_flow"
"blocks/water_still"
"blocks/lava_flow"
"blocks/lava_still"
"blocks/destroy_stage_0"
"blocks/destroy_stage_1"
"blocks/destroy_stage_2"
"blocks/destroy_stage_3"
"blocks/destroy_stage_4"
"blocks/destroy_stage_5"
"blocks/destroy_stage_6"
"blocks/destroy_stage_7"
"blocks/destroy_stage_8"
"blocks/destroy_stage_9"
"items/empty_armor_slot_helmet"
"items/empty_armor_slot_chestplate"
"items/empty_armor_slot_leggings"
"items/empty_armor_slot_boots"
"builtin/missing"
"missing"
"item_frame"
"normal"
"Unable to load variant: "
" from "

Full Source

ModelBakery.java723 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.resources.model;
2
3
import com.google.common.base.Charsets;
4
import com.google.common.base.Joiner;
5
import com.google.common.collect.Lists;
6
import com.google.common.collect.Maps;
7
import com.google.common.collect.Queues;
8
import com.google.common.collect.Sets;
9
import java.io.FileNotFoundException;
10
import java.io.IOException;
11
import java.io.InputStream;
12
import java.io.InputStreamReader;
13
import java.io.Reader;
14
import java.io.StringReader;
15
import java.util.Collection;
16
import java.util.Collections;
17
import java.util.Comparator;
18
import java.util.Deque;
19
import java.util.List;
20
import java.util.Map;
21
import java.util.Set;
22
import java.util.Map.Entry;
23
import net.minecraft.client.renderer.BlockModelShapes;
24
import net.minecraft.client.renderer.block.model.BakedQuad;
25
import net.minecraft.client.renderer.block.model.BlockPart;
26
import net.minecraft.client.renderer.block.model.BlockPartFace;
27
import net.minecraft.client.renderer.block.model.FaceBakery;
28
import net.minecraft.client.renderer.block.model.ItemModelGenerator;
29
import net.minecraft.client.renderer.block.model.ModelBlock;
30
import net.minecraft.client.renderer.block.model.ModelBlockDefinition;
31
import net.minecraft.client.renderer.texture.IIconCreator;
32
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
33
import net.minecraft.client.renderer.texture.TextureMap;
34
import net.minecraft.client.resources.IResource;
35
import net.minecraft.client.resources.IResourceManager;
36
import net.minecraft.init.Blocks;
37
import net.minecraft.init.Items;
38
import net.minecraft.item.Item;
39
import net.minecraft.util.EnumFacing;
40
import net.minecraft.util.IRegistry;
41
import net.minecraft.util.RegistrySimple;
42
import net.minecraft.util.ResourceLocation;
43
import org.apache.commons.io.IOUtils;
44
import org.apache.logging.log4j.LogManager;
45
import org.apache.logging.log4j.Logger;
46
47
public class ModelBakery
48
{
49
    private static final Set<ResourceLocation> LOCATIONS_BUILTIN_TEXTURES = Sets.newHashSet(new ResourceLocation[] {new ResourceLocation("blocks/water_flow"), new ResourceLocation("blocks/water_still"), new ResourceLocation("blocks/lava_flow"), new ResourceLocation("blocks/lava_still"), new ResourceLocation("blocks/destroy_stage_0"), new ResourceLocation("blocks/destroy_stage_1"), new ResourceLocation("blocks/destroy_stage_2"), new ResourceLocation("blocks/destroy_stage_3"), new ResourceLocation("blocks/destroy_stage_4"), new ResourceLocation("blocks/destroy_stage_5"), new ResourceLocation("blocks/destroy_stage_6"), new ResourceLocation("blocks/destroy_stage_7"), new ResourceLocation("blocks/destroy_stage_8"), new ResourceLocation("blocks/destroy_stage_9"), new ResourceLocation("items/empty_armor_slot_helmet"), new ResourceLocation("items/empty_armor_slot_chestplate"), new ResourceLocation("items/empty_armor_slot_leggings"), new ResourceLocation("items/empty_armor_slot_boots")});
50
    private static final Logger LOGGER = LogManager.getLogger();
51
    protected static final ModelResourceLocation MODEL_MISSING = new ModelResourceLocation("builtin/missing", "missing");
52
    private static final Map<String, String> BUILT_IN_MODELS = Maps.<String, String>newHashMap();
53
    private static final Joiner JOINER = Joiner.on(" -> ");
54
    private final IResourceManager resourceManager;
55
    private final Map<ResourceLocation, TextureAtlasSprite> sprites = Maps.<ResourceLocation, TextureAtlasSprite>newHashMap();
56
    private final Map<ResourceLocation, ModelBlock> models = Maps.<ResourceLocation, ModelBlock>newLinkedHashMap();
57
    private final Map<ModelResourceLocation, ModelBlockDefinition.Variants> variants = Maps.<ModelResourceLocation, ModelBlockDefinition.Variants>newLinkedHashMap();
58
    private final TextureMap textureMap;
59
    private final BlockModelShapes blockModelShapes;
60
    private final FaceBakery faceBakery = new FaceBakery();
61
    private final ItemModelGenerator itemModelGenerator = new ItemModelGenerator();
62
    private RegistrySimple<ModelResourceLocation, IBakedModel> bakedRegistry = new RegistrySimple();
63
    private static final ModelBlock MODEL_GENERATED = ModelBlock.deserialize("{\"elements\":[{  \"from\": [0, 0, 0],   \"to\": [16, 16, 16],   \"faces\": {       \"down\": {\"uv\": [0, 0, 16, 16], \"texture\":\"\"}   }}]}");
64
    private static final ModelBlock MODEL_COMPASS = ModelBlock.deserialize("{\"elements\":[{  \"from\": [0, 0, 0],   \"to\": [16, 16, 16],   \"faces\": {       \"down\": {\"uv\": [0, 0, 16, 16], \"texture\":\"\"}   }}]}");
65
    private static final ModelBlock MODEL_CLOCK = ModelBlock.deserialize("{\"elements\":[{  \"from\": [0, 0, 0],   \"to\": [16, 16, 16],   \"faces\": {       \"down\": {\"uv\": [0, 0, 16, 16], \"texture\":\"\"}   }}]}");
66
    private static final ModelBlock MODEL_ENTITY = ModelBlock.deserialize("{\"elements\":[{  \"from\": [0, 0, 0],   \"to\": [16, 16, 16],   \"faces\": {       \"down\": {\"uv\": [0, 0, 16, 16], \"texture\":\"\"}   }}]}");
67
    private Map<String, ResourceLocation> itemLocations = Maps.<String, ResourceLocation>newLinkedHashMap();
68
    private final Map<ResourceLocation, ModelBlockDefinition> blockDefinitions = Maps.<ResourceLocation, ModelBlockDefinition>newHashMap();
69
    private Map<Item, List<String>> variantNames = Maps.<Item, List<String>>newIdentityHashMap();
70
71
    public ModelBakery(IResourceManager p_i46085_1_, TextureMap p_i46085_2_, BlockModelShapes p_i46085_3_)
72
    {
73
        this.resourceManager = p_i46085_1_;
74
        this.textureMap = p_i46085_2_;
75
        this.blockModelShapes = p_i46085_3_;
76
    }
77
78
    public IRegistry<ModelResourceLocation, IBakedModel> setupModelRegistry()
79
    {
80
        this.loadVariantItemModels();
81
        this.loadModelsCheck();
82
        this.loadSprites();
83
        this.bakeItemModels();
84
        this.bakeBlockModels();
85
        return this.bakedRegistry;
86
    }
87
88
    private void loadVariantItemModels()
89
    {
90
        this.loadVariants(this.blockModelShapes.getBlockStateMapper().putAllStateModelLocations().values());
91
        this.variants.put(MODEL_MISSING, new ModelBlockDefinition.Variants(MODEL_MISSING.getVariant(), Lists.newArrayList(new ModelBlockDefinition.Variant[] {new ModelBlockDefinition.Variant(new ResourceLocation(MODEL_MISSING.getResourcePath()), ModelRotation.X0_Y0, false, 1)})));
92
        ResourceLocation resourcelocation = new ResourceLocation("item_frame");
93
        ModelBlockDefinition modelblockdefinition = this.getModelBlockDefinition(resourcelocation);
94
        this.registerVariant(modelblockdefinition, new ModelResourceLocation(resourcelocation, "normal"));
95
        this.registerVariant(modelblockdefinition, new ModelResourceLocation(resourcelocation, "map"));
96
        this.loadVariantModels();
97
        this.loadItemModels();
98
    }
99
100
    private void loadVariants(Collection<ModelResourceLocation> p_177591_1_)
101
    {
102
        for (ModelResourceLocation modelresourcelocation : p_177591_1_)
103
        {
104
            try
105
            {
106
                ModelBlockDefinition modelblockdefinition = this.getModelBlockDefinition(modelresourcelocation);
107
108
                try
109
                {
110
                    this.registerVariant(modelblockdefinition, modelresourcelocation);
111
                }
112
                catch (Exception var6)
113
                {
114
                    LOGGER.warn("Unable to load variant: " + modelresourcelocation.getVariant() + " from " + modelresourcelocation);
115
                }
116
            }
117
            catch (Exception exception)
118
            {
119
                LOGGER.warn((String)("Unable to load definition " + modelresourcelocation), (Throwable)exception);
120
            }
121
        }
122
    }
123
124
    private void registerVariant(ModelBlockDefinition p_177569_1_, ModelResourceLocation p_177569_2_)
125
    {
126
        this.variants.put(p_177569_2_, p_177569_1_.getVariants(p_177569_2_.getVariant()));
127
    }
128
129
    private ModelBlockDefinition getModelBlockDefinition(ResourceLocation p_177586_1_)
130
    {
131
        ResourceLocation resourcelocation = this.getBlockStateLocation(p_177586_1_);
132
        ModelBlockDefinition modelblockdefinition = (ModelBlockDefinition)this.blockDefinitions.get(resourcelocation);
133
134
        if (modelblockdefinition == null)
135
        {
136
            List<ModelBlockDefinition> list = Lists.<ModelBlockDefinition>newArrayList();
137
138
            try
139
            {
140
                for (IResource iresource : this.resourceManager.getAllResources(resourcelocation))
141
                {
142
                    InputStream inputstream = null;
143
144
                    try
145
                    {
146
                        inputstream = iresource.getInputStream();
147
                        ModelBlockDefinition modelblockdefinition1 = ModelBlockDefinition.parseFromReader(new InputStreamReader(inputstream, Charsets.UTF_8));
148
                        list.add(modelblockdefinition1);
149
                    }
150
                    catch (Exception exception)
151
                    {
152
                        throw new RuntimeException("Encountered an exception when loading model definition of \'" + p_177586_1_ + "\' from: \'" + iresource.getResourceLocation() + "\' in resourcepack: \'" + iresource.getResourcePackName() + "\'", exception);
153
                    }
154
                    finally
155
                    {
156
                        IOUtils.closeQuietly(inputstream);
157
                    }
158
                }
159
            }
160
            catch (IOException ioexception)
161
            {
162
                throw new RuntimeException("Encountered an exception when loading model definition of model " + resourcelocation.toString(), ioexception);
163
            }
164
165
            modelblockdefinition = new ModelBlockDefinition(list);
166
            this.blockDefinitions.put(resourcelocation, modelblockdefinition);
167
        }
168
169
        return modelblockdefinition;
170
    }
171
172
    private ResourceLocation getBlockStateLocation(ResourceLocation p_177584_1_)
173
    {
174
        return new ResourceLocation(p_177584_1_.getResourceDomain(), "blockstates/" + p_177584_1_.getResourcePath() + ".json");
175
    }
176
177
    private void loadVariantModels()
178
    {
179
        for (ModelResourceLocation modelresourcelocation : this.variants.keySet())
180
        {
181
            for (ModelBlockDefinition.Variant modelblockdefinition$variant : ((ModelBlockDefinition.Variants)this.variants.get(modelresourcelocation)).getVariants())
182
            {
183
                ResourceLocation resourcelocation = modelblockdefinition$variant.getModelLocation();
184
185
                if (this.models.get(resourcelocation) == null)
186
                {
187
                    try
188
                    {
189
                        ModelBlock modelblock = this.loadModel(resourcelocation);
190
                        this.models.put(resourcelocation, modelblock);
191
                    }
192
                    catch (Exception exception)
193
                    {
194
                        LOGGER.warn((String)("Unable to load block model: \'" + resourcelocation + "\' for variant: \'" + modelresourcelocation + "\'"), (Throwable)exception);
195
                    }
196
                }
197
            }
198
        }
199
    }
200
201
    private ModelBlock loadModel(ResourceLocation p_177594_1_) throws IOException
202
    {
203
        String s = p_177594_1_.getResourcePath();
204
205
        if ("builtin/generated".equals(s))
206
        {
207
            return MODEL_GENERATED;
208
        }
209
        else if ("builtin/compass".equals(s))
210
        {
211
            return MODEL_COMPASS;
212
        }
213
        else if ("builtin/clock".equals(s))
214
        {
215
            return MODEL_CLOCK;
216
        }
217
        else if ("builtin/entity".equals(s))
218
        {
219
            return MODEL_ENTITY;
220
        }
221
        else
222
        {
223
            Reader reader;
224
225
            if (s.startsWith("builtin/"))
226
            {
227
                String s1 = s.substring("builtin/".length());
228
                String s2 = (String)BUILT_IN_MODELS.get(s1);
229
230
                if (s2 == null)
231
                {
232
                    throw new FileNotFoundException(p_177594_1_.toString());
233
                }
234
235
                reader = new StringReader(s2);
236
            }
237
            else
238
            {
239
                IResource iresource = this.resourceManager.getResource(this.getModelLocation(p_177594_1_));
240
                reader = new InputStreamReader(iresource.getInputStream(), Charsets.UTF_8);
241
            }
242
243
            ModelBlock modelblock1;
244
245
            try
246
            {
247
                ModelBlock modelblock = ModelBlock.deserialize(reader);
248
                modelblock.name = p_177594_1_.toString();
249
                modelblock1 = modelblock;
250
            }
251
            finally
252
            {
253
                reader.close();
254
            }
255
256
            return modelblock1;
257
        }
258
    }
259
260
    private ResourceLocation getModelLocation(ResourceLocation p_177580_1_)
261
    {
262
        return new ResourceLocation(p_177580_1_.getResourceDomain(), "models/" + p_177580_1_.getResourcePath() + ".json");
263
    }
264
265
    private void loadItemModels()
266
    {
267
        this.registerVariantNames();
268
269
        for (Item item : Item.itemRegistry)
270
        {
271
            for (String s : this.getVariantNames(item))
272
            {
273
                ResourceLocation resourcelocation = this.getItemLocation(s);
274
                this.itemLocations.put(s, resourcelocation);
275
276
                if (this.models.get(resourcelocation) == null)
277
                {
278
                    try
279
                    {
280
                        ModelBlock modelblock = this.loadModel(resourcelocation);
281
                        this.models.put(resourcelocation, modelblock);
282
                    }
283
                    catch (Exception exception)
284
                    {
285
                        LOGGER.warn((String)("Unable to load item model: \'" + resourcelocation + "\' for item: \'" + Item.itemRegistry.getNameForObject(item) + "\'"), (Throwable)exception);
286
                    }
287
                }
288
            }
289
        }
290
    }
291
292
    private void registerVariantNames()
293
    {
294
        this.variantNames.put(Item.getItemFromBlock(Blocks.stone), Lists.newArrayList(new String[] {"stone", "granite", "granite_smooth", "diorite", "diorite_smooth", "andesite", "andesite_smooth"}));
295
        this.variantNames.put(Item.getItemFromBlock(Blocks.dirt), Lists.newArrayList(new String[] {"dirt", "coarse_dirt", "podzol"}));
296
        this.variantNames.put(Item.getItemFromBlock(Blocks.planks), Lists.newArrayList(new String[] {"oak_planks", "spruce_planks", "birch_planks", "jungle_planks", "acacia_planks", "dark_oak_planks"}));
297
        this.variantNames.put(Item.getItemFromBlock(Blocks.sapling), Lists.newArrayList(new String[] {"oak_sapling", "spruce_sapling", "birch_sapling", "jungle_sapling", "acacia_sapling", "dark_oak_sapling"}));
298
        this.variantNames.put(Item.getItemFromBlock(Blocks.sand), Lists.newArrayList(new String[] {"sand", "red_sand"}));
299
        this.variantNames.put(Item.getItemFromBlock(Blocks.log), Lists.newArrayList(new String[] {"oak_log", "spruce_log", "birch_log", "jungle_log"}));
300
        this.variantNames.put(Item.getItemFromBlock(Blocks.leaves), Lists.newArrayList(new String[] {"oak_leaves", "spruce_leaves", "birch_leaves", "jungle_leaves"}));
301
        this.variantNames.put(Item.getItemFromBlock(Blocks.sponge), Lists.newArrayList(new String[] {"sponge", "sponge_wet"}));
302
        this.variantNames.put(Item.getItemFromBlock(Blocks.sandstone), Lists.newArrayList(new String[] {"sandstone", "chiseled_sandstone", "smooth_sandstone"}));
303
        this.variantNames.put(Item.getItemFromBlock(Blocks.red_sandstone), Lists.newArrayList(new String[] {"red_sandstone", "chiseled_red_sandstone", "smooth_red_sandstone"}));
304
        this.variantNames.put(Item.getItemFromBlock(Blocks.tallgrass), Lists.newArrayList(new String[] {"dead_bush", "tall_grass", "fern"}));
305
        this.variantNames.put(Item.getItemFromBlock(Blocks.deadbush), Lists.newArrayList(new String[] {"dead_bush"}));
306
        this.variantNames.put(Item.getItemFromBlock(Blocks.wool), Lists.newArrayList(new String[] {"black_wool", "red_wool", "green_wool", "brown_wool", "blue_wool", "purple_wool", "cyan_wool", "silver_wool", "gray_wool", "pink_wool", "lime_wool", "yellow_wool", "light_blue_wool", "magenta_wool", "orange_wool", "white_wool"}));
307
        this.variantNames.put(Item.getItemFromBlock(Blocks.yellow_flower), Lists.newArrayList(new String[] {"dandelion"}));
308
        this.variantNames.put(Item.getItemFromBlock(Blocks.red_flower), Lists.newArrayList(new String[] {"poppy", "blue_orchid", "allium", "houstonia", "red_tulip", "orange_tulip", "white_tulip", "pink_tulip", "oxeye_daisy"}));
309
        this.variantNames.put(Item.getItemFromBlock(Blocks.stone_slab), Lists.newArrayList(new String[] {"stone_slab", "sandstone_slab", "cobblestone_slab", "brick_slab", "stone_brick_slab", "nether_brick_slab", "quartz_slab"}));
310
        this.variantNames.put(Item.getItemFromBlock(Blocks.stone_slab2), Lists.newArrayList(new String[] {"red_sandstone_slab"}));
311
        this.variantNames.put(Item.getItemFromBlock(Blocks.stained_glass), Lists.newArrayList(new String[] {"black_stained_glass", "red_stained_glass", "green_stained_glass", "brown_stained_glass", "blue_stained_glass", "purple_stained_glass", "cyan_stained_glass", "silver_stained_glass", "gray_stained_glass", "pink_stained_glass", "lime_stained_glass", "yellow_stained_glass", "light_blue_stained_glass", "magenta_stained_glass", "orange_stained_glass", "white_stained_glass"}));
312
        this.variantNames.put(Item.getItemFromBlock(Blocks.monster_egg), Lists.newArrayList(new String[] {"stone_monster_egg", "cobblestone_monster_egg", "stone_brick_monster_egg", "mossy_brick_monster_egg", "cracked_brick_monster_egg", "chiseled_brick_monster_egg"}));
313
        this.variantNames.put(Item.getItemFromBlock(Blocks.stonebrick), Lists.newArrayList(new String[] {"stonebrick", "mossy_stonebrick", "cracked_stonebrick", "chiseled_stonebrick"}));
314
        this.variantNames.put(Item.getItemFromBlock(Blocks.wooden_slab), Lists.newArrayList(new String[] {"oak_slab", "spruce_slab", "birch_slab", "jungle_slab", "acacia_slab", "dark_oak_slab"}));
315
        this.variantNames.put(Item.getItemFromBlock(Blocks.cobblestone_wall), Lists.newArrayList(new String[] {"cobblestone_wall", "mossy_cobblestone_wall"}));
316
        this.variantNames.put(Item.getItemFromBlock(Blocks.anvil), Lists.newArrayList(new String[] {"anvil_intact", "anvil_slightly_damaged", "anvil_very_damaged"}));
317
        this.variantNames.put(Item.getItemFromBlock(Blocks.quartz_block), Lists.newArrayList(new String[] {"quartz_block", "chiseled_quartz_block", "quartz_column"}));
318
        this.variantNames.put(Item.getItemFromBlock(Blocks.stained_hardened_clay), Lists.newArrayList(new String[] {"black_stained_hardened_clay", "red_stained_hardened_clay", "green_stained_hardened_clay", "brown_stained_hardened_clay", "blue_stained_hardened_clay", "purple_stained_hardened_clay", "cyan_stained_hardened_clay", "silver_stained_hardened_clay", "gray_stained_hardened_clay", "pink_stained_hardened_clay", "lime_stained_hardened_clay", "yellow_stained_hardened_clay", "light_blue_stained_hardened_clay", "magenta_stained_hardened_clay", "orange_stained_hardened_clay", "white_stained_hardened_clay"}));
319
        this.variantNames.put(Item.getItemFromBlock(Blocks.stained_glass_pane), Lists.newArrayList(new String[] {"black_stained_glass_pane", "red_stained_glass_pane", "green_stained_glass_pane", "brown_stained_glass_pane", "blue_stained_glass_pane", "purple_stained_glass_pane", "cyan_stained_glass_pane", "silver_stained_glass_pane", "gray_stained_glass_pane", "pink_stained_glass_pane", "lime_stained_glass_pane", "yellow_stained_glass_pane", "light_blue_stained_glass_pane", "magenta_stained_glass_pane", "orange_stained_glass_pane", "white_stained_glass_pane"}));
320
        this.variantNames.put(Item.getItemFromBlock(Blocks.leaves2), Lists.newArrayList(new String[] {"acacia_leaves", "dark_oak_leaves"}));
321
        this.variantNames.put(Item.getItemFromBlock(Blocks.log2), Lists.newArrayList(new String[] {"acacia_log", "dark_oak_log"}));
322
        this.variantNames.put(Item.getItemFromBlock(Blocks.prismarine), Lists.newArrayList(new String[] {"prismarine", "prismarine_bricks", "dark_prismarine"}));
323
        this.variantNames.put(Item.getItemFromBlock(Blocks.carpet), Lists.newArrayList(new String[] {"black_carpet", "red_carpet", "green_carpet", "brown_carpet", "blue_carpet", "purple_carpet", "cyan_carpet", "silver_carpet", "gray_carpet", "pink_carpet", "lime_carpet", "yellow_carpet", "light_blue_carpet", "magenta_carpet", "orange_carpet", "white_carpet"}));
324
        this.variantNames.put(Item.getItemFromBlock(Blocks.double_plant), Lists.newArrayList(new String[] {"sunflower", "syringa", "double_grass", "double_fern", "double_rose", "paeonia"}));
325
        this.variantNames.put(Items.bow, Lists.newArrayList(new String[] {"bow", "bow_pulling_0", "bow_pulling_1", "bow_pulling_2"}));
326
        this.variantNames.put(Items.coal, Lists.newArrayList(new String[] {"coal", "charcoal"}));
327
        this.variantNames.put(Items.fishing_rod, Lists.newArrayList(new String[] {"fishing_rod", "fishing_rod_cast"}));
328
        this.variantNames.put(Items.fish, Lists.newArrayList(new String[] {"cod", "salmon", "clownfish", "pufferfish"}));
329
        this.variantNames.put(Items.cooked_fish, Lists.newArrayList(new String[] {"cooked_cod", "cooked_salmon"}));
330
        this.variantNames.put(Items.dye, Lists.newArrayList(new String[] {"dye_black", "dye_red", "dye_green", "dye_brown", "dye_blue", "dye_purple", "dye_cyan", "dye_silver", "dye_gray", "dye_pink", "dye_lime", "dye_yellow", "dye_light_blue", "dye_magenta", "dye_orange", "dye_white"}));
331
        this.variantNames.put(Items.potionitem, Lists.newArrayList(new String[] {"bottle_drinkable", "bottle_splash"}));
332
        this.variantNames.put(Items.skull, Lists.newArrayList(new String[] {"skull_skeleton", "skull_wither", "skull_zombie", "skull_char", "skull_creeper"}));
333
        this.variantNames.put(Item.getItemFromBlock(Blocks.oak_fence_gate), Lists.newArrayList(new String[] {"oak_fence_gate"}));
334
        this.variantNames.put(Item.getItemFromBlock(Blocks.oak_fence), Lists.newArrayList(new String[] {"oak_fence"}));
335
        this.variantNames.put(Items.oak_door, Lists.newArrayList(new String[] {"oak_door"}));
336
    }
337
338
    private List<String> getVariantNames(Item p_177596_1_)
339
    {
340
        List<String> list = (List)this.variantNames.get(p_177596_1_);
341
342
        if (list == null)
343
        {
344
            list = Collections.<String>singletonList(((ResourceLocation)Item.itemRegistry.getNameForObject(p_177596_1_)).toString());
345
        }
346
347
        return list;
348
    }
349
350
    private ResourceLocation getItemLocation(String p_177583_1_)
351
    {
352
        ResourceLocation resourcelocation = new ResourceLocation(p_177583_1_);
353
        return new ResourceLocation(resourcelocation.getResourceDomain(), "item/" + resourcelocation.getResourcePath());
354
    }
355
356
    private void bakeBlockModels()
357
    {
358
        for (ModelResourceLocation modelresourcelocation : this.variants.keySet())
359
        {
360
            WeightedBakedModel.Builder weightedbakedmodel$builder = new WeightedBakedModel.Builder();
361
            int i = 0;
362
363
            for (ModelBlockDefinition.Variant modelblockdefinition$variant : ((ModelBlockDefinition.Variants)this.variants.get(modelresourcelocation)).getVariants())
364
            {
365
                ModelBlock modelblock = (ModelBlock)this.models.get(modelblockdefinition$variant.getModelLocation());
366
367
                if (modelblock != null && modelblock.isResolved())
368
                {
369
                    ++i;
370
                    weightedbakedmodel$builder.add(this.bakeModel(modelblock, modelblockdefinition$variant.getRotation(), modelblockdefinition$variant.isUvLocked()), modelblockdefinition$variant.getWeight());
371
                }
372
                else
373
                {
374
                    LOGGER.warn("Missing model for: " + modelresourcelocation);
375
                }
376
            }
377
378
            if (i == 0)
379
            {
380
                LOGGER.warn("No weighted models for: " + modelresourcelocation);
381
            }
382
            else if (i == 1)
383
            {
384
                this.bakedRegistry.putObject(modelresourcelocation, weightedbakedmodel$builder.first());
385
            }
386
            else
387
            {
388
                this.bakedRegistry.putObject(modelresourcelocation, weightedbakedmodel$builder.build());
389
            }
390
        }
391
392
        for (Entry<String, ResourceLocation> entry : this.itemLocations.entrySet())
393
        {
394
            ResourceLocation resourcelocation = (ResourceLocation)entry.getValue();
395
            ModelResourceLocation modelresourcelocation1 = new ModelResourceLocation((String)entry.getKey(), "inventory");
396
            ModelBlock modelblock1 = (ModelBlock)this.models.get(resourcelocation);
397
398
            if (modelblock1 != null && modelblock1.isResolved())
399
            {
400
                if (this.isCustomRenderer(modelblock1))
401
                {
402
                    this.bakedRegistry.putObject(modelresourcelocation1, new BuiltInModel(modelblock1.getAllTransforms()));
403
                }
404
                else
405
                {
406
                    this.bakedRegistry.putObject(modelresourcelocation1, this.bakeModel(modelblock1, ModelRotation.X0_Y0, false));
407
                }
408
            }
409
            else
410
            {
411
                LOGGER.warn("Missing model for: " + resourcelocation);
412
            }
413
        }
414
    }
415
416
    private Set<ResourceLocation> getVariantsTextureLocations()
417
    {
418
        Set<ResourceLocation> set = Sets.<ResourceLocation>newHashSet();
419
        List<ModelResourceLocation> list = Lists.newArrayList(this.variants.keySet());
420
        Collections.sort(list, new Comparator<ModelResourceLocation>()
421
        {
422
            public int compare(ModelResourceLocation p_compare_1_, ModelResourceLocation p_compare_2_)
423
            {
424
                return p_compare_1_.toString().compareTo(p_compare_2_.toString());
425
            }
426
        });
427
428
        for (ModelResourceLocation modelresourcelocation : list)
429
        {
430
            ModelBlockDefinition.Variants modelblockdefinition$variants = (ModelBlockDefinition.Variants)this.variants.get(modelresourcelocation);
431
432
            for (ModelBlockDefinition.Variant modelblockdefinition$variant : modelblockdefinition$variants.getVariants())
433
            {
434
                ModelBlock modelblock = (ModelBlock)this.models.get(modelblockdefinition$variant.getModelLocation());
435
436
                if (modelblock == null)
437
                {
438
                    LOGGER.warn("Missing model for: " + modelresourcelocation);
439
                }
440
                else
441
                {
442
                    set.addAll(this.getTextureLocations(modelblock));
443
                }
444
            }
445
        }
446
447
        set.addAll(LOCATIONS_BUILTIN_TEXTURES);
448
        return set;
449
    }
450
451
    private IBakedModel bakeModel(ModelBlock modelBlockIn, ModelRotation modelRotationIn, boolean uvLocked)
452
    {
453
        TextureAtlasSprite textureatlassprite = (TextureAtlasSprite)this.sprites.get(new ResourceLocation(modelBlockIn.resolveTextureName("particle")));
454
        SimpleBakedModel.Builder simplebakedmodel$builder = (new SimpleBakedModel.Builder(modelBlockIn)).setTexture(textureatlassprite);
455
456
        for (BlockPart blockpart : modelBlockIn.getElements())
457
        {
458
            for (EnumFacing enumfacing : blockpart.mapFaces.keySet())
459
            {
460
                BlockPartFace blockpartface = (BlockPartFace)blockpart.mapFaces.get(enumfacing);
461
                TextureAtlasSprite textureatlassprite1 = (TextureAtlasSprite)this.sprites.get(new ResourceLocation(modelBlockIn.resolveTextureName(blockpartface.texture)));
462
463
                if (blockpartface.cullFace == null)
464
                {
465
                    simplebakedmodel$builder.addGeneralQuad(this.makeBakedQuad(blockpart, blockpartface, textureatlassprite1, enumfacing, modelRotationIn, uvLocked));
466
                }
467
                else
468
                {
469
                    simplebakedmodel$builder.addFaceQuad(modelRotationIn.rotateFace(blockpartface.cullFace), this.makeBakedQuad(blockpart, blockpartface, textureatlassprite1, enumfacing, modelRotationIn, uvLocked));
470
                }
471
            }
472
        }
473
474
        return simplebakedmodel$builder.makeBakedModel();
475
    }
476
477
    private BakedQuad makeBakedQuad(BlockPart p_177589_1_, BlockPartFace p_177589_2_, TextureAtlasSprite p_177589_3_, EnumFacing p_177589_4_, ModelRotation p_177589_5_, boolean p_177589_6_)
478
    {
479
        return this.faceBakery.makeBakedQuad(p_177589_1_.positionFrom, p_177589_1_.positionTo, p_177589_2_, p_177589_3_, p_177589_4_, p_177589_5_, p_177589_1_.partRotation, p_177589_6_, p_177589_1_.shade);
480
    }
481
482
    private void loadModelsCheck()
483
    {
484
        this.loadModels();
485
486
        for (ModelBlock modelblock : this.models.values())
487
        {
488
            modelblock.getParentFromMap(this.models);
489
        }
490
491
        ModelBlock.checkModelHierarchy(this.models);
492
    }
493
494
    private void loadModels()
495
    {
496
        Deque<ResourceLocation> deque = Queues.<ResourceLocation>newArrayDeque();
497
        Set<ResourceLocation> set = Sets.<ResourceLocation>newHashSet();
498
499
        for (ResourceLocation resourcelocation : this.models.keySet())
500
        {
501
            set.add(resourcelocation);
502
            ResourceLocation resourcelocation1 = ((ModelBlock)this.models.get(resourcelocation)).getParentLocation();
503
504
            if (resourcelocation1 != null)
505
            {
506
                deque.add(resourcelocation1);
507
            }
508
        }
509
510
        while (!((Deque)deque).isEmpty())
511
        {
512
            ResourceLocation resourcelocation2 = (ResourceLocation)deque.pop();
513
514
            try
515
            {
516
                if (this.models.get(resourcelocation2) != null)
517
                {
518
                    continue;
519
                }
520
521
                ModelBlock modelblock = this.loadModel(resourcelocation2);
522
                this.models.put(resourcelocation2, modelblock);
523
                ResourceLocation resourcelocation3 = modelblock.getParentLocation();
524
525
                if (resourcelocation3 != null && !set.contains(resourcelocation3))
526
                {
527
                    deque.add(resourcelocation3);
528
                }
529
            }
530
            catch (Exception exception)
531
            {
532
                LOGGER.warn((String)("In parent chain: " + JOINER.join(this.getParentPath(resourcelocation2)) + "; unable to load model: \'" + resourcelocation2 + "\'"), (Throwable)exception);
533
            }
534
535
            set.add(resourcelocation2);
536
        }
537
    }
538
539
    private List<ResourceLocation> getParentPath(ResourceLocation p_177573_1_)
540
    {
541
        List<ResourceLocation> list = Lists.newArrayList(new ResourceLocation[] {p_177573_1_});
542
        ResourceLocation resourcelocation = p_177573_1_;
543
544
        while ((resourcelocation = this.getParentLocation(resourcelocation)) != null)
545
        {
546
            list.add(0, resourcelocation);
547
        }
548
549
        return list;
550
    }
551
552
    private ResourceLocation getParentLocation(ResourceLocation p_177576_1_)
553
    {
554
        for (Entry<ResourceLocation, ModelBlock> entry : this.models.entrySet())
555
        {
556
            ModelBlock modelblock = (ModelBlock)entry.getValue();
557
558
            if (modelblock != null && p_177576_1_.equals(modelblock.getParentLocation()))
559
            {
560
                return (ResourceLocation)entry.getKey();
561
            }
562
        }
563
564
        return null;
565
    }
566
567
    private Set<ResourceLocation> getTextureLocations(ModelBlock p_177585_1_)
568
    {
569
        Set<ResourceLocation> set = Sets.<ResourceLocation>newHashSet();
570
571
        for (BlockPart blockpart : p_177585_1_.getElements())
572
        {
573
            for (BlockPartFace blockpartface : blockpart.mapFaces.values())
574
            {
575
                ResourceLocation resourcelocation = new ResourceLocation(p_177585_1_.resolveTextureName(blockpartface.texture));
576
                set.add(resourcelocation);
577
            }
578
        }
579
580
        set.add(new ResourceLocation(p_177585_1_.resolveTextureName("particle")));
581
        return set;
582
    }
583
584
    private void loadSprites()
585
    {
586
        final Set<ResourceLocation> set = this.getVariantsTextureLocations();
587
        set.addAll(this.getItemsTextureLocations());
588
        set.remove(TextureMap.LOCATION_MISSING_TEXTURE);
589
        IIconCreator iiconcreator = new IIconCreator()
590
        {
591
            public void registerSprites(TextureMap iconRegistry)
592
            {
593
                for (ResourceLocation resourcelocation : set)
594
                {
595
                    TextureAtlasSprite textureatlassprite = iconRegistry.registerSprite(resourcelocation);
596
                    ModelBakery.this.sprites.put(resourcelocation, textureatlassprite);
597
                }
598
            }
599
        };
600
        this.textureMap.loadSprites(this.resourceManager, iiconcreator);
601
        this.sprites.put(new ResourceLocation("missingno"), this.textureMap.getMissingSprite());
602
    }
603
604
    private Set<ResourceLocation> getItemsTextureLocations()
605
    {
606
        Set<ResourceLocation> set = Sets.<ResourceLocation>newHashSet();
607
608
        for (ResourceLocation resourcelocation : this.itemLocations.values())
609
        {
610
            ModelBlock modelblock = (ModelBlock)this.models.get(resourcelocation);
611
612
            if (modelblock != null)
613
            {
614
                set.add(new ResourceLocation(modelblock.resolveTextureName("particle")));
615
616
                if (this.hasItemModel(modelblock))
617
                {
618
                    for (String s : ItemModelGenerator.LAYERS)
619
                    {
620
                        ResourceLocation resourcelocation2 = new ResourceLocation(modelblock.resolveTextureName(s));
621
622
                        if (modelblock.getRootModel() == MODEL_COMPASS && !TextureMap.LOCATION_MISSING_TEXTURE.equals(resourcelocation2))
623
                        {
624
                            TextureAtlasSprite.setLocationNameCompass(resourcelocation2.toString());
625
                        }
626
                        else if (modelblock.getRootModel() == MODEL_CLOCK && !TextureMap.LOCATION_MISSING_TEXTURE.equals(resourcelocation2))
627
                        {
628
                            TextureAtlasSprite.setLocationNameClock(resourcelocation2.toString());
629
                        }
630
631
                        set.add(resourcelocation2);
632
                    }
633
                }
634
                else if (!this.isCustomRenderer(modelblock))
635
                {
636
                    for (BlockPart blockpart : modelblock.getElements())
637
                    {
638
                        for (BlockPartFace blockpartface : blockpart.mapFaces.values())
639
                        {
640
                            ResourceLocation resourcelocation1 = new ResourceLocation(modelblock.resolveTextureName(blockpartface.texture));
641
                            set.add(resourcelocation1);
642
                        }
643
                    }
644
                }
645
            }
646
        }
647
648
        return set;
649
    }
650
651
    private boolean hasItemModel(ModelBlock p_177581_1_)
652
    {
653
        if (p_177581_1_ == null)
654
        {
655
            return false;
656
        }
657
        else
658
        {
659
            ModelBlock modelblock = p_177581_1_.getRootModel();
660
            return modelblock == MODEL_GENERATED || modelblock == MODEL_COMPASS || modelblock == MODEL_CLOCK;
661
        }
662
    }
663
664
    private boolean isCustomRenderer(ModelBlock p_177587_1_)
665
    {
666
        if (p_177587_1_ == null)
667
        {
668
            return false;
669
        }
670
        else
671
        {
672
            ModelBlock modelblock = p_177587_1_.getRootModel();
673
            return modelblock == MODEL_ENTITY;
674
        }
675
    }
676
677
    private void bakeItemModels()
678
    {
679
        for (ResourceLocation resourcelocation : this.itemLocations.values())
680
        {
681
            ModelBlock modelblock = (ModelBlock)this.models.get(resourcelocation);
682
683
            if (this.hasItemModel(modelblock))
684
            {
685
                ModelBlock modelblock1 = this.makeItemModel(modelblock);
686
687
                if (modelblock1 != null)
688
                {
689
                    modelblock1.name = resourcelocation.toString();
690
                }
691
692
                this.models.put(resourcelocation, modelblock1);
693
            }
694
            else if (this.isCustomRenderer(modelblock))
695
            {
696
                this.models.put(resourcelocation, modelblock);
697
            }
698
        }
699
700
        for (TextureAtlasSprite textureatlassprite : this.sprites.values())
701
        {
702
            if (!textureatlassprite.hasAnimationMetadata())
703
            {
704
                textureatlassprite.clearFramesTextureData();
705
            }
706
        }
707
    }
708
709
    private ModelBlock makeItemModel(ModelBlock p_177582_1_)
710
    {
711
        return this.itemModelGenerator.makeItemModel(this.textureMap, p_177582_1_);
712
    }
713
714
    static
715
    {
716
        BUILT_IN_MODELS.put("missing", "{ \"textures\": {   \"particle\": \"missingno\",   \"missingno\": \"missingno\"}, \"elements\": [ {     \"from\": [ 0, 0, 0 ],     \"to\": [ 16, 16, 16 ],     \"faces\": {         \"down\":  { \"uv\": [ 0, 0, 16, 16 ], \"cullface\": \"down\", \"texture\": \"#missingno\" },         \"up\":    { \"uv\": [ 0, 0, 16, 16 ], \"cullface\": \"up\", \"texture\": \"#missingno\" },         \"north\": { \"uv\": [ 0, 0, 16, 16 ], \"cullface\": \"north\", \"texture\": \"#missingno\" },         \"south\": { \"uv\": [ 0, 0, 16, 16 ], \"cullface\": \"south\", \"texture\": \"#missingno\" },         \"west\":  { \"uv\": [ 0, 0, 16, 16 ], \"cullface\": \"west\", \"texture\": \"#missingno\" },         \"east\":  { \"uv\": [ 0, 0, 16, 16 ], \"cullface\": \"east\", \"texture\": \"#missingno\" }    }}]}");
717
        MODEL_GENERATED.name = "generation marker";
718
        MODEL_COMPASS.name = "compass generation marker";
719
        MODEL_CLOCK.name = "class generation marker";
720
        MODEL_ENTITY.name = "block entity marker";
721
    }
722
}
723

Deobfuscated MCP 1.8.9 source of ModelBakery from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/resources/model/ModelBakery.java), stored verbatim.