private void loadVariantModels() { for (ModelResourceLocation modelresourcelocation : this.variants.keySet()) { for (ModelBlockDefinition.Variant modelblockdefinition$variant : ((ModelBlockDefinition.Variants)this.variants.get(modelresourcelocation)).getVariants()) { ResourceLocation resourcelocation = modelblockdefinition$variant.getModelLocation(); if (this.models.get(resourcelocation) == null) { try { ModelBlock modelblock = this.loadModel(resourcelocation); this.models.put(resourcelocation, modelblock); } catch (Exception exception) { LOGGER.warn((String)("Unable to load block model: \'" + resourcelocation + "\' for variant: \'" + modelresourcelocation + "\'"), (Throwable)exception); } } } } }
private void loadItemModels() { this.registerVariantNames(); for (Item item : Item.itemRegistry) { for (String s : this.getVariantNames(item)) { ResourceLocation resourcelocation = this.getItemLocation(s); this.itemLocations.put(s, resourcelocation); if (this.models.get(resourcelocation) == null) { try { ModelBlock modelblock = this.loadModel(resourcelocation); this.models.put(resourcelocation, modelblock); } catch (Exception exception) { LOGGER.warn((String)("Unable to load item model: \'" + resourcelocation + "\' for item: \'" + Item.itemRegistry.getNameForObject(item) + "\'"), (Throwable)exception); } } } } }
private IBakedModel bakeModel(ModelBlock modelBlockIn, ModelRotation modelRotationIn, boolean uvLocked) { TextureAtlasSprite textureatlassprite = (TextureAtlasSprite)this.sprites.get(new ResourceLocation(modelBlockIn.resolveTextureName("particle"))); SimpleBakedModel.Builder simplebakedmodel$builder = (new SimpleBakedModel.Builder(modelBlockIn)).setTexture(textureatlassprite); for (BlockPart blockpart : modelBlockIn.getElements()) { for (EnumFacing enumfacing : blockpart.mapFaces.keySet()) { BlockPartFace blockpartface = (BlockPartFace)blockpart.mapFaces.get(enumfacing); TextureAtlasSprite textureatlassprite1 = (TextureAtlasSprite)this.sprites.get(new ResourceLocation(modelBlockIn.resolveTextureName(blockpartface.texture))); if (blockpartface.cullFace == null) { simplebakedmodel$builder.addGeneralQuad(this.makeBakedQuad(blockpart, blockpartface, textureatlassprite1, enumfacing, modelRotationIn, uvLocked)); } else { simplebakedmodel$builder.addFaceQuad(modelRotationIn.rotateFace(blockpartface.cullFace), this.makeBakedQuad(blockpart, blockpartface, textureatlassprite1, enumfacing, modelRotationIn, uvLocked)); } } } return simplebakedmodel$builder.makeBakedModel(); }
private Set<ResourceLocation> getTextureLocations(ModelBlock p_177585_1_) { Set<ResourceLocation> set = Sets.<ResourceLocation>newHashSet(); for (BlockPart blockpart : p_177585_1_.getElements()) { for (BlockPartFace blockpartface : blockpart.mapFaces.values()) { ResourceLocation resourcelocation = new ResourceLocation(p_177585_1_.resolveTextureName(blockpartface.texture)); set.add(resourcelocation); } } set.add(new ResourceLocation(p_177585_1_.resolveTextureName("particle"))); return set; }
private static ModelBlock makeModelBlock(String[] p_makeModelBlock_0_) { StringBuffer stringbuffer = new StringBuffer(); stringbuffer.append("{\"parent\": \"builtin/generated\",\"textures\": {"); for (int i = 0; i < p_makeModelBlock_0_.length; ++i) { String s = p_makeModelBlock_0_[i]; if (i > 0) { stringbuffer.append(", "); } stringbuffer.append("\"layer" + i + "\": \"" + s + "\""); } stringbuffer.append("}}"); String s1 = stringbuffer.toString(); ModelBlock modelblock = ModelBlock.deserialize(s1); return modelblock; }
public IModel loadModel(ResourceLocation modelLocation) throws Exception { if(modelLocation.equals(MODEL_MISSING) && loader.missingModel != null) { return loader.getMissingModel(); } String modelPath = modelLocation.getResourcePath(); if(modelLocation.getResourcePath().startsWith("models/")) { modelPath = modelPath.substring("models/".length()); } ResourceLocation armatureLocation = new ResourceLocation(modelLocation.getResourceDomain(), "armatures/" + modelPath + ".json"); ModelBlockAnimation animation = ModelBlockAnimation.loadVanillaAnimation(loader.resourceManager, armatureLocation); ModelBlock model = loader.loadModel(modelLocation); IModel iModel = loader.new VanillaModelWrapper(modelLocation, model, false, animation); if(loader.missingModel == null && modelLocation.equals(MODEL_MISSING)) { loader.missingModel = iModel; } return iModel; }
@SideOnly(Side.CLIENT) public static String getTexture(IBlockState state, String defaultTexture) { try { ModelLoader loader = ModelLoader.VanillaLoader.INSTANCE.getLoader(); BlockStateMapper mapper = loader.blockModelShapes.getBlockStateMapper(); Map<IBlockState, ModelResourceLocation> map = mapper.getVariants(state.getBlock()); ModelResourceLocation stateLocation = map.get(state); ModelBlockDefinition definition = loader.getModelBlockDefinition(stateLocation); ResourceLocation modelLocation = definition.getVariant(stateLocation.getVariant()).getVariantList().get(0).getModelLocation(); ModelBlock modelBlock = loader.loadModel( new ResourceLocation(modelLocation.getResourceDomain(), "models/" + modelLocation.getResourcePath())); String texture = getTexture(modelBlock); return ObjectUtils.firstNonNull(texture, defaultTexture); } catch (Exception e) { e.printStackTrace(); return defaultTexture; } }
@Nullable @SideOnly(Side.CLIENT) public static String getTexture(ModelBlock modelBlock) { if (modelBlock == null) return null; if (modelBlock.textures == null) return getTexture(modelBlock.parent); String texture = modelBlock.textures.get("all"); if (texture != null) return texture; texture = modelBlock.textures.get("side"); if (texture != null) return texture; texture = modelBlock.textures.get("particle"); if (texture != null) return texture; for (Entry<String, String> entry : modelBlock.textures.entrySet()) if (!entry.getKey().equals("end") && !entry.getValue().contains("_top") && !entry.getValue().contains("top_")) return entry.getValue(); return getTexture(modelBlock.parent); }
private Set<ResourceLocation> getVariantsTextureLocations() { Set<ResourceLocation> set = Sets.<ResourceLocation>newHashSet(); List<ModelResourceLocation> list = Lists.newArrayList(this.variants.keySet()); Collections.sort(list, new Comparator<ModelResourceLocation>() { public int compare(ModelResourceLocation p_compare_1_, ModelResourceLocation p_compare_2_) { return p_compare_1_.toString().compareTo(p_compare_2_.toString()); } }); for (ModelResourceLocation modelresourcelocation : list) { ModelBlockDefinition.Variants modelblockdefinition$variants = (ModelBlockDefinition.Variants)this.variants.get(modelresourcelocation); for (ModelBlockDefinition.Variant modelblockdefinition$variant : modelblockdefinition$variants.getVariants()) { ModelBlock modelblock = (ModelBlock)this.models.get(modelblockdefinition$variant.getModelLocation()); if (modelblock == null) { LOGGER.warn("Missing model for: " + modelresourcelocation); } else { set.addAll(this.getTextureLocations(modelblock)); } } } set.addAll(LOCATIONS_BUILTIN_TEXTURES); return set; }
private void loadModelsCheck() { this.loadModels(); for (ModelBlock modelblock : this.models.values()) { modelblock.getParentFromMap(this.models); } ModelBlock.checkModelHierarchy(this.models); }
private ResourceLocation getParentLocation(ResourceLocation p_177576_1_) { for (Entry<ResourceLocation, ModelBlock> entry : this.models.entrySet()) { ModelBlock modelblock = (ModelBlock)entry.getValue(); if (modelblock != null && p_177576_1_.equals(modelblock.getParentLocation())) { return (ResourceLocation)entry.getKey(); } } return null; }
private boolean hasItemModel(ModelBlock p_177581_1_) { if (p_177581_1_ == null) { return false; } else { ModelBlock modelblock = p_177581_1_.getRootModel(); return modelblock == MODEL_GENERATED || modelblock == MODEL_COMPASS || modelblock == MODEL_CLOCK; } }
private boolean isCustomRenderer(ModelBlock p_177587_1_) { if (p_177587_1_ == null) { return false; } else { ModelBlock modelblock = p_177587_1_.getRootModel(); return modelblock == MODEL_ENTITY; } }
private void bakeItemModels() { for (ResourceLocation resourcelocation : this.itemLocations.values()) { ModelBlock modelblock = (ModelBlock)this.models.get(resourcelocation); if (this.hasItemModel(modelblock)) { ModelBlock modelblock1 = this.makeItemModel(modelblock); if (modelblock1 != null) { modelblock1.name = resourcelocation.toString(); } this.models.put(resourcelocation, modelblock1); } else if (this.isCustomRenderer(modelblock)) { this.models.put(resourcelocation, modelblock); } } for (TextureAtlasSprite textureatlassprite : this.sprites.values()) { if (!textureatlassprite.hasAnimationMetadata()) { textureatlassprite.clearFramesTextureData(); } } }
private static IBakedModel makeBakedModel(TextureMap p_makeBakedModel_0_, ItemModelGenerator p_makeBakedModel_1_, String[] p_makeBakedModel_2_, boolean p_makeBakedModel_3_) { ModelBlock modelblock = makeModelBlock(p_makeBakedModel_2_); ModelBlock modelblock1 = p_makeBakedModel_1_.makeItemModel(p_makeBakedModel_0_, modelblock); IBakedModel ibakedmodel = bakeModel(p_makeBakedModel_0_, modelblock1, p_makeBakedModel_3_); return ibakedmodel; }
private static IBakedModel makeBakedModel(TextureMap p_makeBakedModel_0_, ItemModelGenerator p_makeBakedModel_1_, String[] p_makeBakedModel_2_, boolean p_makeBakedModel_3_) { String[] astring = new String[p_makeBakedModel_2_.length]; for (int i = 0; i < astring.length; ++i) { String s = p_makeBakedModel_2_[i]; astring[i] = StrUtils.removePrefix(s, "textures/"); } ModelBlock modelblock = makeModelBlock(astring); ModelBlock modelblock1 = p_makeBakedModel_1_.makeItemModel(p_makeBakedModel_0_, modelblock); IBakedModel ibakedmodel = bakeModel(p_makeBakedModel_0_, modelblock1, p_makeBakedModel_3_); return ibakedmodel; }
public VanillaModelWrapper(ResourceLocation location, ModelBlock model, boolean uvlock, ModelBlockAnimation animation) { this.location = location; this.model = model; this.uvlock = uvlock; this.animation = animation; }
public IBakedModel bake(IModelState state, final VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { if(!Attributes.moreSpecific(format, Attributes.DEFAULT_BAKED_FORMAT)) { throw new IllegalArgumentException("can't bake vanilla models to the format that doesn't fit into the default one: " + format); } ModelBlock model = this.model; if(model == null) return getMissingModel().bake(getMissingModel().getDefaultState(), format, bakedTextureGetter); List<TRSRTransformation> newTransforms = Lists.newArrayList(); for(int i = 0; i < model.getElements().size(); i++) { BlockPart part = model.getElements().get(i); newTransforms.add(animation.getPartTransform(state, part, i)); } ItemCameraTransforms transforms = model.getAllTransforms(); Map<TransformType, TRSRTransformation> tMap = Maps.newHashMap(); tMap.putAll(IPerspectiveAwareModel.MapWrapper.getTransforms(transforms)); tMap.putAll(IPerspectiveAwareModel.MapWrapper.getTransforms(state)); IModelState perState = new SimpleModelState(ImmutableMap.copyOf(tMap)); if(hasItemModel(model)) { return new ItemLayerModel(model).bake(perState, format, bakedTextureGetter); } if(isCustomRenderer(model)) return new BuiltInModel(transforms, model.createOverrides()); return bakeNormal(model, perState, state, newTransforms, format, bakedTextureGetter, uvlock); }
@Override public VanillaModelWrapper smoothLighting(boolean value) { if(model.ambientOcclusion == value) { return this; } ModelBlock newModel = new ModelBlock(model.getParentLocation(), model.getElements(), model.textures, value, model.isGui3d(), model.getAllTransforms(), Lists.newArrayList(model.getOverrides())); newModel.parent = model.parent; newModel.name = model.name; return new VanillaModelWrapper(location, newModel, uvlock, animation); }