@Override public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { try { IModel sub = ModelLoaderRegistry.getModel(handle); IBakedModel baked = sub.bake(state, format, bakedTextureGetter); return new BakedModelCH(baked, ModelRegistry.getInstance().bake(state, format, bakedTextureGetter)); } catch (Exception e) { e.printStackTrace(); } return ModelLoaderRegistry.getMissingModel().bake(state, format, bakedTextureGetter); }
/** * Retrieves the clip from the model. */ @SideOnly(Side.CLIENT) public static IClip getModelClipNode(ResourceLocation modelLocation, String clipName) { IModel model = ModelLoaderRegistry.getModelOrMissing(modelLocation); if(model instanceof IAnimatedModel) { Optional<? extends IClip> clip = ((IAnimatedModel)model).getClip(clipName); if(clip.isPresent()) { return new ModelClip(clip.get(), modelLocation, clipName); } FMLLog.getLogger().error("Unable to find clip " + clipName + " in the model " + modelLocation); } // FIXME: missing clip? return new ModelClip(IdentityClip.INSTANCE, modelLocation, clipName); }
public static IBakedModel getBakedCluster(){ if(bakedCluster == null){ IModel model; try { model = OBJLoader.INSTANCE.loadModel(CrystalMod.resourceL("models/block/obj/cluster.obj")); Function<ResourceLocation, TextureAtlasSprite> textureGetter; textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() { @Override public TextureAtlasSprite apply(ResourceLocation location) { return RenderUtil.getSprite(location); } }; bakedCluster = model.bake(new SimpleModelState(DynamicBaseModel.DEFAULT_PERSPECTIVE_TRANSFORMS), DefaultVertexFormats.BLOCK, textureGetter); } catch (Exception e) { e.printStackTrace(); } } return bakedCluster; }
protected IBakedModel getActualModel(String texture) { IBakedModel bakedModel = standard; if (texture!=null) { if (cache.containsKey(texture)) { bakedModel = cache.get(texture); } else if (retexturableModel != null) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.put("bottom", texture); builder.put("top", texture); builder.put("side", texture); IModel retexturedModel = retexturableModel.retexture(builder.build()); bakedModel = retexturedModel.bake(TRSRTransformation.identity(), Attributes.DEFAULT_BAKED_FORMAT, ModelLoader.defaultTextureGetter()); cache.put(texture, bakedModel); } } return bakedModel; }
@SubscribeEvent public void onModelBake(ModelBakeEvent event) { try { IModel model = ModelLoaderRegistry.getModel(MODEL_grave); if (model instanceof IRetexturableModel) { IRetexturableModel graveModel = (IRetexturableModel) model; IBakedModel standard = event.getModelRegistry().getObject(locGrave); IBakedModel finalModel = new GoodGraveModel(standard, graveModel); event.getModelRegistry().putObject(locGrave, finalModel); } } catch (Exception e) { e.printStackTrace(); } }
@Override public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { try { IModel model = ModelLoaderRegistry.getModel(sourceModel); if (model instanceof QBarOBJModel) { model = ((QBarOBJModel) model).retexture(replacedTextures); return model.bake(state, format, bakedTextureGetter); } } catch (Exception e) { throw new RuntimeException(e); } return null; }
protected IModel getModel(ResourceLocation modelLoc, ResourceLocation fallback) { try { return ModelLoaderRegistry.getModel(modelLoc); } catch (Exception e) { if (fallback != null) { try { return ModelLoaderRegistry.getModel(fallback); } catch (Exception e2) { logger.warn("Could not find model {} or fallback {}", modelLoc, fallback); return ModelLoaderRegistry.getMissingModel(); } } logger.warn("Could not find model {}", modelLoc); return ModelLoaderRegistry.getMissingModel(); } }
@Override public IModel process(IModel base) { boolean hasBase = base != ModelLoaderRegistry.getMissingModel(); if (hasBase) { base = baseVariant.process(base); } List<IModel> subModels = new LinkedList<>(); for (Variant variant : finalVariants) { if (!variant.getModelLocation().equals(new ResourceLocation("builtin/missing"))) { IModel subModel = ModelLoaderRegistry.getModelOrLogError(variant.getModelLocation(), "Unable to load subModel's Model: " + variant.getModelLocation()); subModels.add(variant.process(new StateOverrideIModel(subModel, variant.getState()))); } } return new CCMultiModel(hasBase ? base : null, baseProperties, subModels); }
@SuppressWarnings("unchecked") @Override public Collection<ResourceLocation> getTextures() { normalModels.clear(); Set<ResourceLocation> textures = Sets.newHashSet(); for (Entry<ResourceLocation, Integer> e : item.LOCATION_TO_META.entrySet()) { ResourceLocation loc = e.getKey(); if (item.OVERRIDES.containsKey(e.getKey())) { ResourceLocation[][] o = item.OVERRIDES.get(e.getKey()); textures.addAll(Arrays.asList(o[1])); loc = o[0][0]; } if (!normalModels.containsKey(loc)) { normalModels.put(loc, getModel(loc)); } IModel model = normalModels.get(loc); textures.addAll(model.getTextures().stream().filter(l -> !l.getResourcePath().startsWith("texture")).collect(Collectors.toSet())); } return textures; }
@Override public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { CustomModelLoader.log.info("Baking " + nameN + " Model..."); IBlockState s = block.getDefaultState(); TerminalBakedModel.Builder builder = new Builder(bakedTextureGetter.apply(new ResourceLocation(hasFront ? imgLoc + "Front" : "tomsmodstorage:blocks/terminalFront")), block); ResourceLocation base = new ResourceLocation("tomsmodstorage:block/" + block.getUnlocalizedName().substring(8, block.getUnlocalizedName().length() - 6) + "_base"); ResourceLocation front = new ResourceLocation("tomsmodstorage:block/terminalFront"); ResourceLocation terminalItemTransformsL = new ResourceLocation("tomsmodstorage:block/terminalitemtransforms"); IModel modelFront = getModel(front); IModel terminalItemTransforms = getModel(terminalItemTransformsL); TextureInjector injectorFront = new TextureInjector(bakedTextureGetter, hasFront ? imgLoc + "Front" : "tomsmodstorage:blocks/terminalFront"); TextureInjector injectorFrontP = new TextureInjector(bakedTextureGetter, hasFront ? imgLoc + "FrontP" : "tomsmodstorage:blocks/terminalFrontP"); TextureInjector injectorFrontOn = new TextureInjector(bakedTextureGetter, hasFront ? imgLoc + "FrontOn" : "tomsmodstorage:blocks/terminalFrontOn"); builder.setItemCameraTransformsModel(terminalItemTransforms.bake(state, format, bakedTextureGetter)); // load(null, builder, modelBase, modelFront, bakedTextureGetter, // injectorFront, injectorFrontOn, format, s); for (int ss = 0;ss < block.getStates();ss++) { for (int i = 0;i < TileEntityBasicTerminal.TerminalState.VALUES.length;i++) { TileEntityBasicTerminal.TerminalState termState = TileEntityBasicTerminal.TerminalState.VALUES[i]; load(termState, builder, base, modelFront, bakedTextureGetter, injectorFront, injectorFrontP, injectorFrontOn, format, s, ss); } } TerminalBakedModel model = builder.makeModel(); CustomModelLoader.log.info(nameN + " Model Baking Complete."); return model; }
@Override public IModel getConnectedSide(boolean isTop, boolean isBottom, boolean isDouble) { if (!isDouble) { return isBottom ? isTop ? this.singleSideLone : this.singleSideBottom : isTop ? this.singleSideTop : this.singleSideMiddle; } else { return isBottom ? isTop ? this.doubleSideLone : this.doubleSideBottom : isTop ? this.doubleSideTop : this.doubleSideMiddle; } }
/** @return Model for this wall's post with given properties. */ protected IModel getPostModel(boolean isTop, boolean isBottom, boolean isDouble) { if (!isDouble) { return isBottom ? isTop ? this.singlePostLone : this.singlePostBottom : isTop ? this.singlePostTop : this.singlePostMiddle; } else { return isBottom ? isTop ? this.doublePostLone : this.doublePostBottom : isTop ? this.doublePostTop : this.doublePostMiddle; } }
@Override public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { ARKCraft.logger.info("Baking Cable Model"); ResourceLocation noc = new ResourceLocation("arkcraft:block/cable_noc"); ResourceLocation center = new ResourceLocation("arkcraft:block/cable_base"); ResourceLocation connection = new ResourceLocation("arkcraft:block/cable_c"); ResourceLocation vertical = new ResourceLocation("arkcraft:block/cable_v"); ResourceLocation centerP = new ResourceLocation("arkcraft:block/cable_base_powered"); ResourceLocation connectionP = new ResourceLocation("arkcraft:block/cable_c_powered"); ResourceLocation verticalP = new ResourceLocation("arkcraft:block/cable_v_powered"); IBakedModel[] connections = new IBakedModel[4]; IBakedModel[] connectionsP = new IBakedModel[4]; IModel modelConnection = getModel(connection); IModel modelConnectionP = getModel(connectionP); for(EnumFacing f : EnumFacing.HORIZONTALS){ connections[f.ordinal() - 2] = modelConnection.bake(new TRSRTransformation(getMatrix(f)), format, bakedTextureGetter); connectionsP[f.ordinal() - 2] = modelConnectionP.bake(new TRSRTransformation(getMatrix(f)), format, bakedTextureGetter); } return new BakedCableModel(getModel(noc).bake(state, format, bakedTextureGetter), new IBakedModel[]{getModel(center).bake(state, format, bakedTextureGetter), getModel(centerP).bake(state, format, bakedTextureGetter)}, new IBakedModel[][]{connections, connectionsP}, new IBakedModel[]{getModel(vertical).bake(state, format, bakedTextureGetter), getModel(verticalP).bake(state, format, bakedTextureGetter)}); }
@SubscribeEvent public void bakeModels(TextureStitchEvent.Post event) { final TextureMap map = event.map; Function<ResourceLocation,TextureAtlasSprite> lookup = new Function<ResourceLocation, TextureAtlasSprite>() { @Nullable @Override public TextureAtlasSprite apply(@Nullable ResourceLocation input) { if (input == null) return map.getAtlasSprite(null); return map.getAtlasSprite(input.toString()); } }; for (FzModel fzm : instances) { IModel rawModel = raws.get(fzm); if (rawModel == null) { fzm.model = null; continue; } fzm.model = rawModel.bake(fzm.trsrt, fzm.getFormat(), lookup); } raws.clear(); }
private static IBakedModel loadModel(ModelHandle handle) { IBakedModel model = loadedModels.get(handle.getKey()); if (model != null) return model; try { IModel mod = ModelLoaderRegistry.getModel(handle.getModel()); if (handle.getTextureReplacements().size() > 0) { mod = mod.retexture(ImmutableMap.copyOf(handle.getTextureReplacements())); } if (handle.uvLocked()) { mod = mod.uvlock(true); } IModelState state = handle.getState(); if (state == null) state = mod.getDefaultState(); model = mod.bake(state, handle.getVertexFormat(), ModelLoader.defaultTextureGetter()); loadedModels.put(handle.getKey(), model); return model; } catch (Exception e) { throw new ReportedException(new CrashReport("Error loading custom model " + handle.getModel(), e)); } }
public static IBakedModel getModel(ResourceLocation resourceLocation) { IBakedModel bakedModel; IModel model; try { model = ModelLoaderRegistry.getModel(resourceLocation); } catch (Exception e) { throw new RuntimeException(e); } bakedModel = model.bake(TRSRTransformation.identity(), DefaultVertexFormats.BLOCK, location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString())); return bakedModel; }
public static IBakedModel getBakedModel(String modelLocation){ IModel model; try { model = ModelLoaderRegistry.getModel(new ResourceLocation(RunicArcana.MOD_ID, modelLocation)); } catch (Exception e) { throw new RuntimeException(e); } IBakedModel bakedModel = model.bake(TRSRTransformation.identity(), DefaultVertexFormats.BLOCK, DustModelHandler::textureGetter); return bakedModel; }
@Override public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { IBakedModel[] connections = new IBakedModel[6]; IBakedModel[] endings = new IBakedModel[6]; IBakedModel[] nodeSides = new IBakedModel[6]; //IBakedModel node = null; // d u n s w e ModelRotation[] rotations = new ModelRotation[] { ModelRotation.X90_Y0, ModelRotation.X270_Y0, ModelRotation.X0_Y0, ModelRotation.X0_Y180, ModelRotation.X0_Y270, ModelRotation.X0_Y90 }; try { IModel nodeSideModel = ModelLoaderRegistry.getModel(new ResourceLocation(Etheric.MODID, "block/pipe_node_side")); IModel connectionModel = ModelLoaderRegistry .getModel(new ResourceLocation(Etheric.MODID, "block/pipe_connection")); IModel endingModel = ModelLoaderRegistry.getModel(new ResourceLocation(Etheric.MODID, "block/pipe_end")); //node = nodeModel.bake(new TRSRTransformation(ModelRotation.X0_Y0), DefaultVertexFormats.BLOCK, // ModelLoader.defaultTextureGetter()); for (int i = 0; i < connections.length; i++) { connections[i] = connectionModel.bake(new TRSRTransformation(rotations[i]), DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()); endings[i] = endingModel.bake(new TRSRTransformation(rotations[i]), DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()); nodeSides[i] = nodeSideModel.bake(new TRSRTransformation(rotations[i]), DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter()); } } catch (Exception e) { Etheric.logger.warn(e.getMessage()); } if (connections[0] == null) { return ModelLoaderRegistry.getMissingModel().bake(state, format, bakedTextureGetter); } return new BakedPipeModel(nodeSides, connections, endings); }
@Override public IModel loadModel(ResourceLocation modelLocation) throws Exception { if (model == null) { model = new PipeModel(); } return model; }
public Map<ResourceLocation, IBakedModel> bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) throws Exception { Map<ResourceLocation, IBakedModel> ret = Maps.newHashMap(); for (TransportableChest chest : ChestRegistry.getChests()) { for (ResourceLocation location : chest.getChestModels()) { IModel model = ModelLoaderRegistry.getModel(location); ret.put(location, model.bake(state, format, bakedTextureGetter)); } } return ret; }
public BakedToolModel(IModel parent, ImmutableList<BakedQuad> quads, VertexFormat format, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms, Map<String, IBakedModel> cache) { this.quads = quads; this.format = format; this.parent = parent; this.transforms = itemTransforms(); this.cache = cache; }
@Override @Nonnull public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity) { if (stack.getItem() != ModItems.mace) { return originalModel; } BakedMaceModel model = (BakedMaceModel) originalModel; String key = IHeadTool.getHeadMat(stack).getName() + "|" + IHaftTool.getHaftMat(stack).getName() + "|" + IHandleTool.getHandleMat(stack).getName() + "|" + IAdornedTool.getAdornmentMat(stack).getName(); if (!model.cache.containsKey(key)) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.put("head", IHeadTool.getHeadMat(stack).getName()); builder.put("haft", IHaftTool.getHaftMat(stack).getName()); builder.put("handle", IHandleTool.getHandleMat(stack).getName()); if (IAdornedTool.getAdornmentMat(stack) != ModMaterials.ADORNMENT_NULL) { builder.put("adornment", IAdornedTool.getAdornmentMat(stack).getName()); } IModel parent = model.parent.retexture(builder.build()); Function<ResourceLocation, TextureAtlasSprite> textureGetter; textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() { public TextureAtlasSprite apply(ResourceLocation location) { return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()); } }; IBakedModel bakedModel = parent.bake(new SimpleModelState(model.transforms), model.format, textureGetter); model.cache.put(key, bakedModel); return bakedModel; } return model.cache.get(key); }
@Override @Nonnull public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity) { if (stack.getItem() != ModItems.dagger) { return originalModel; } BakedDaggerModel model = (BakedDaggerModel) originalModel; String key = IBladeTool.getBladeMat(stack).getName() + "|" + IHandleTool.getHandleMat(stack).getName() + "|" + IAdornedTool.getAdornmentMat(stack).getName(); if (!model.cache.containsKey(key)) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.put("blade", IBladeTool.getBladeMat(stack).getName()); builder.put("handle", IHandleTool.getHandleMat(stack).getName()); if (IAdornedTool.getAdornmentMat(stack) != ModMaterials.ADORNMENT_NULL) { builder.put("adornment", IAdornedTool.getAdornmentMat(stack).getName()); } IModel parent = model.parent.retexture(builder.build()); Function<ResourceLocation, TextureAtlasSprite> textureGetter; textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() { public TextureAtlasSprite apply(ResourceLocation location) { return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()); } }; IBakedModel bakedModel = parent.bake(new SimpleModelState(model.transforms), model.format, textureGetter); model.cache.put(key, bakedModel); return bakedModel; } return model.cache.get(key); }
@Override @Nonnull public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity) { if (stack.getItem() != ModItems.hoe) { return originalModel; } BakedHoeModel model = (BakedHoeModel) originalModel; String key = IHeadTool.getHeadMat(stack).getName() + "|" + IHaftTool.getHaftMat(stack).getName() + "|" + IHandleTool.getHandleMat(stack).getName() + "|" + IAdornedTool.getAdornmentMat(stack).getName(); if (!model.cache.containsKey(key)) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.put("head", IHeadTool.getHeadMat(stack).getName()); builder.put("haft", IHaftTool.getHaftMat(stack).getName()); builder.put("handle", IHandleTool.getHandleMat(stack).getName()); if (IAdornedTool.getAdornmentMat(stack) != ModMaterials.ADORNMENT_NULL) { builder.put("adornment", IAdornedTool.getAdornmentMat(stack).getName()); } IModel parent = model.parent.retexture(builder.build()); Function<ResourceLocation, TextureAtlasSprite> textureGetter; textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() { public TextureAtlasSprite apply(ResourceLocation location) { return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()); } }; IBakedModel bakedModel = parent.bake(new SimpleModelState(model.transforms), model.format, textureGetter); model.cache.put(key, bakedModel); return bakedModel; } return model.cache.get(key); }
@Override @Nonnull public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity) { if (stack.getItem() != ModItems.pickaxe) { return originalModel; } BakedPickaxeModel model = (BakedPickaxeModel) originalModel; String key = IHeadTool.getHeadMat(stack).getName() + "|" + IHaftTool.getHaftMat(stack).getName() + "|" + IHandleTool.getHandleMat(stack).getName() + "|" + IAdornedTool.getAdornmentMat(stack).getName(); if (!model.cache.containsKey(key)) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.put("head", IHeadTool.getHeadMat(stack).getName()); builder.put("haft", IHaftTool.getHaftMat(stack).getName()); builder.put("handle", IHandleTool.getHandleMat(stack).getName()); if (IAdornedTool.getAdornmentMat(stack) != ModMaterials.ADORNMENT_NULL) { builder.put("adornment", IAdornedTool.getAdornmentMat(stack).getName()); } IModel parent = model.parent.retexture(builder.build()); Function<ResourceLocation, TextureAtlasSprite> textureGetter; textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() { public TextureAtlasSprite apply(ResourceLocation location) { return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()); } }; IBakedModel bakedModel = parent.bake(new SimpleModelState(model.transforms), model.format, textureGetter); model.cache.put(key, bakedModel); return bakedModel; } return model.cache.get(key); }
@Override @Nonnull public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity) { if (stack.getItem() != ModItems.axe) { return originalModel; } BakedAxeModel model = (BakedAxeModel) originalModel; String key = IHeadTool.getHeadMat(stack).getName() + "|" + IHaftTool.getHaftMat(stack).getName() + "|" + IHandleTool.getHandleMat(stack).getName() + "|" + IAdornedTool.getAdornmentMat(stack).getName(); if (!model.cache.containsKey(key)) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.put("head", IHeadTool.getHeadMat(stack).getName()); builder.put("haft", IHaftTool.getHaftMat(stack).getName()); builder.put("handle", IHandleTool.getHandleMat(stack).getName()); if (IAdornedTool.getAdornmentMat(stack) != ModMaterials.ADORNMENT_NULL) { builder.put("adornment", IAdornedTool.getAdornmentMat(stack).getName()); } IModel parent = model.parent.retexture(builder.build()); Function<ResourceLocation, TextureAtlasSprite> textureGetter; textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() { public TextureAtlasSprite apply(ResourceLocation location) { return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()); } }; IBakedModel bakedModel = parent.bake(new SimpleModelState(model.transforms), model.format, textureGetter); model.cache.put(key, bakedModel); return bakedModel; } return model.cache.get(key); }
@Override @Nonnull public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity) { if (stack.getItem() != ModItems.hammer) { return originalModel; } BakedHammerModel model = (BakedHammerModel) originalModel; String key = IHeadTool.getHeadMat(stack).getName() + "|" + IHaftTool.getHaftMat(stack).getName() + "|" + IHandleTool.getHandleMat(stack).getName() + "|" + IAdornedTool.getAdornmentMat(stack).getName(); if (!model.cache.containsKey(key)) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.put("head", IHeadTool.getHeadMat(stack).getName()); builder.put("haft", IHaftTool.getHaftMat(stack).getName()); builder.put("handle", IHandleTool.getHandleMat(stack).getName()); if (IAdornedTool.getAdornmentMat(stack) != ModMaterials.ADORNMENT_NULL) { builder.put("adornment", IAdornedTool.getAdornmentMat(stack).getName()); } IModel parent = model.parent.retexture(builder.build()); Function<ResourceLocation, TextureAtlasSprite> textureGetter; textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() { public TextureAtlasSprite apply(ResourceLocation location) { return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()); } }; IBakedModel bakedModel = parent.bake(new SimpleModelState(model.transforms), model.format, textureGetter); model.cache.put(key, bakedModel); return bakedModel; } return model.cache.get(key); }
@Override @Nonnull public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity) { if (stack.getItem() != ModItems.shovel) { return originalModel; } BakedShovelModel model = (BakedShovelModel) originalModel; String key = IHeadTool.getHeadMat(stack).getName() + "|" + IHaftTool.getHaftMat(stack).getName() + "|" + IHandleTool.getHandleMat(stack).getName() + "|" + IAdornedTool.getAdornmentMat(stack).getName(); if (!model.cache.containsKey(key)) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.put("head", IHeadTool.getHeadMat(stack).getName()); builder.put("haft", IHaftTool.getHaftMat(stack).getName()); builder.put("handle", IHandleTool.getHandleMat(stack).getName()); if (IAdornedTool.getAdornmentMat(stack) != ModMaterials.ADORNMENT_NULL) { builder.put("adornment", IAdornedTool.getAdornmentMat(stack).getName()); } IModel parent = model.parent.retexture(builder.build()); Function<ResourceLocation, TextureAtlasSprite> textureGetter; textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() { public TextureAtlasSprite apply(ResourceLocation location) { return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()); } }; IBakedModel bakedModel = parent.bake(new SimpleModelState(model.transforms), model.format, textureGetter); model.cache.put(key, bakedModel); return bakedModel; } return model.cache.get(key); }
@Override public IModel loadModel(ResourceLocation modelLocation) { String path = modelLocation.getResourcePath().substring(3); int index = path.indexOf('_'); if(path.charAt(0) == 'c') index = path.indexOf('_', index + 1); String toolName = path.substring(0, index); path = path.substring(index + 1); index = path.indexOf('_'); String partName = path.substring(0, index); path = path.substring(index + 1); String matName = path; return new ToolHeadModel(modelLocation.getResourceDomain(), toolName, partName, matName); }
@Override @Nonnull public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity) { if (stack.getItem() != ModItems.sword) { return originalModel; } BakedSwordModel model = (BakedSwordModel) originalModel; String key = IBladeTool.getBladeMat(stack).getName() + "|" + ICrossguardTool.getCrossguardMat(stack).getName() + "|" + IHandleTool.getHandleMat(stack).getName() + "|" + IAdornedTool.getAdornmentMat(stack).getName(); if (!model.cache.containsKey(key)) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.put("blade", IBladeTool.getBladeMat(stack).getName()); builder.put("crossguard", ICrossguardTool.getCrossguardMat(stack).getName()); builder.put("handle", IHandleTool.getHandleMat(stack).getName()); if (IAdornedTool.getAdornmentMat(stack) != ModMaterials.ADORNMENT_NULL) { builder.put("adornment", IAdornedTool.getAdornmentMat(stack).getName()); } IModel parent = model.parent.retexture(builder.build()); Function<ResourceLocation, TextureAtlasSprite> textureGetter; textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() { public TextureAtlasSprite apply(ResourceLocation location) { return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()); } }; IBakedModel bakedModel = parent.bake(new SimpleModelState(model.transforms), model.format, textureGetter); model.cache.put(key, bakedModel); return bakedModel; } return model.cache.get(key); }
@Override @Nonnull public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity) { if (stack.getItem() != ModItems.handpick) { return originalModel; } BakedHandpickModel model = (BakedHandpickModel) originalModel; String key = IHeadTool.getHeadMat(stack).getName() + "|" + IHaftTool.getHaftMat(stack).getName() + "|" + IHandleTool.getHandleMat(stack).getName() + "|" + IAdornedTool.getAdornmentMat(stack).getName(); if (!model.cache.containsKey(key)) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.put("head", IHeadTool.getHeadMat(stack).getName()); builder.put("haft", IHaftTool.getHaftMat(stack).getName()); builder.put("handle", IHandleTool.getHandleMat(stack).getName()); if (IAdornedTool.getAdornmentMat(stack) != ModMaterials.ADORNMENT_NULL) { builder.put("adornment", IAdornedTool.getAdornmentMat(stack).getName()); } IModel parent = model.parent.retexture(builder.build()); Function<ResourceLocation, TextureAtlasSprite> textureGetter; textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() { public TextureAtlasSprite apply(ResourceLocation location) { return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()); } }; IBakedModel bakedModel = parent.bake(new SimpleModelState(model.transforms), model.format, textureGetter); model.cache.put(key, bakedModel); return bakedModel; } return model.cache.get(key); }
public AnimationItemOverrideList(IModel model, IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter, List<ItemOverride> overrides) { super(overrides); this.model = model; this.state = state; this.format = format; this.bakedTextureGetter = bakedTextureGetter; }
@SubscribeEvent(priority = EventPriority.LOWEST) @SideOnly(Side.CLIENT) public void onModelBake(ModelBakeEvent event) { if(!InteractionBWA.ARMOR_SHARD_RENDER) return; for (Item item : Item.REGISTRY) { if (!ItemUtil.isTool(item)) continue; for (String s : getVariantNames(event.getModelLoader(), item)) { ResourceLocation file = getItemLocation(s); ModelResourceLocation memory = ModelLoader.getInventoryVariant(s); IModel model = null; try { model = ModelLoaderRegistry.getModel(file); } catch (Exception e) { try { model = ModelLoaderRegistry.getModel(memory); } catch (Exception e1) { //e1.printStackTrace(); } } if(model == null) continue; IModel brokenmodel = new ModelToolShardInner(ImmutableList.copyOf(model.getTextures())); IBakedModel bakedbrokenmodel = brokenmodel.bake(brokenmodel.getDefaultState(), DefaultVertexFormats.ITEM, location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString())); ToolShardOverrideHandler.INSTANCE.addModel(item,bakedbrokenmodel); } } }
public IModel loadModel(ResourceLocation location) { assertState(ContextState.LoadingModels); try { return ModelLoaderRegistry.getModel(location); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity) { ItemStack food = ItemWrappedFood.getFood(stack); // not a crop item if (!ItemStackTools.isValid(food)) { return originalModel; } //BakedSeed model = (BakedSeed)originalModel; BakedItemModel model = (BakedItemModel)originalModel; String name = ItemUtil.getStringForItemStack(food, true, false); String cacheName = name+"v1"; if (!cache.containsKey(cacheName)) { IModel parent = model.parent.process(ImmutableMap.of("food", name)); Function<ResourceLocation, TextureAtlasSprite> textureGetter; textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() { @Override public TextureAtlasSprite apply(ResourceLocation location) { return RenderUtil.getSprite(location); } }; IBakedModel bakedModel = parent.bake(new SimpleModelState(model.transforms), model.format, textureGetter); cache.put(cacheName, bakedModel); return bakedModel; } return cache.get(cacheName); }
@Override public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity) { IMaterialCrop crop = ItemMaterialSeed.getCrop(stack); // not a crop item if (crop == null) { return originalModel; } //BakedSeed model = (BakedSeed)originalModel; BakedItemModel model = (BakedItemModel)originalModel; String name = crop.getUnlocalizedName(); String cacheName = name+"v11"; if (!cache.containsKey(cacheName)) { IModel parent = model.parent.process(ImmutableMap.of("crop", name)); Function<ResourceLocation, TextureAtlasSprite> textureGetter; textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() { @Override public TextureAtlasSprite apply(ResourceLocation location) { return RenderUtil.getSprite(location); } }; IBakedModel bakedModel = parent.bake(new SimpleModelState(model.transforms), model.format, textureGetter); cache.put(cacheName, bakedModel); return bakedModel; } return cache.get(cacheName); }
@Override public IModel loadModel( ResourceLocation modelLocation ) throws Exception { String loc = ""+modelLocation; if(loc.equals("crystalmod:models/block/pipe") || loc.equals("crystalmod:models/block/builtin/pipe"))return new ModelPipe(); //if(loc.contains("block/pipe") || loc.contains("builtin"))return new ModelPipe(); return builtInModels.get( modelLocation.getResourcePath() ); }
@Override public void onResourceManagerReload( IResourceManager resourceManager ) { for( IModel model : builtInModels.values() ) { if( model instanceof IResourceManagerReloadListener ) { ( (IResourceManagerReloadListener) model ).onResourceManagerReload( resourceManager ); } } }
@SuppressWarnings("unused") private void getBakedModels() { IModel model = null; if (modelJar == null) { try { model = ModelLoaderRegistry.getModel(new ResourceLocation(Wizardry.MODID, "block/jar")); } catch (Exception e) { e.printStackTrace(); } modelJar = model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString())); } }
@Override public IModel retexture(ImmutableMap<String, String> textures) { QBarOBJModel ret = new QBarOBJModel(this.getMatLib().makeLibWithReplacements(textures), getResourceLocation() , getCustomData()); return ret; }