Java Code Examples for net.minecraftforge.client.model.IModel#bake()
The following examples show how to use
net.minecraftforge.client.model.IModel#bake() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VariantModel.java From OpenModsLib with MIT License | 6 votes |
@Override public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { final Map<ResourceLocation, IBakedModel> bakedSubModels = Maps.newHashMap(); for (ResourceLocation subModel : modelData.getAllModels()) { IModel model = ModelLoaderRegistry.getModelOrLogError(subModel, "Couldn't load sub-model dependency: " + subModel); bakedSubModels.put(subModel, model.bake(new ModelStateComposition(state, model.getDefaultState()), format, bakedTextureGetter)); } final IModel baseModel; if (base.isPresent()) { ResourceLocation baseLocation = base.get(); baseModel = ModelLoaderRegistry.getModelOrLogError(baseLocation, "Couldn't load base-model dependency: " + baseLocation); } else { baseModel = ModelLoaderRegistry.getMissingModel(); } final IBakedModel bakedBaseModel = baseModel.bake(new ModelStateComposition(state, baseModel.getDefaultState()), format, bakedTextureGetter); return new BakedModel(bakedBaseModel, modelData, bakedSubModels, PerspectiveMapWrapper.getTransforms(state)); }
Example 2
Source File: PerspectiveAwareModel.java From OpenModsLib with MIT License | 6 votes |
@Override public IBakedModel bake(final IModelState state, final VertexFormat format, final Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { final Map<TransformType, IBakedModel> bakedModels = Maps.transformValues(models, location -> bakeModel(location, state, format, bakedTextureGetter)); IModel missing = ModelLoaderRegistry.getMissingModel(); IBakedModel bakedMissing = missing.bake(missing.getDefaultState(), format, bakedTextureGetter); final IBakedModel bakedBase; if (base.isPresent()) { bakedBase = bakeModel(base.get(), state, format, bakedTextureGetter); } else { bakedBase = bakedMissing; } return new PerspectiveAwareBakedModel( bakedModels, bakedBase, PerspectiveMapWrapper.getTransforms(state)); }
Example 3
Source File: ItemStateModel.java From OpenModsLib with MIT License | 6 votes |
@Override public IBakedModel bake(IModelState state, final VertexFormat format, final Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { final IModel defaultModel; if (this.defaultModel.isPresent()) { defaultModel = getModel(this.defaultModel.get()); } else if (!this.stateModels.isEmpty()) { final ResourceLocation first = this.stateModels.values().iterator().next(); defaultModel = getModel(first); } else { defaultModel = ModelLoaderRegistry.getMissingModel(); } final IBakedModel bakedDefaultModel = defaultModel.bake(defaultModel.getDefaultState(), format, bakedTextureGetter); final Map<State, IBakedModel> bakedStateModels = Maps.transformValues(stateModels, input -> { final IModel model = getModel(input); return model.bake(model.getDefaultState(), format, bakedTextureGetter); }); return new ItemStateOverrideList(bakedStateModels).wrapModel(bakedDefaultModel); }
Example 4
Source File: MultiLayerModel.java From OpenModsLib with MIT License | 6 votes |
@Override public IBakedModel bake(final IModelState state, final VertexFormat format, final Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { final Map<BlockRenderLayer, IBakedModel> bakedModels = Maps.transformValues(models, location -> bakeModel(location, state, format, bakedTextureGetter)); IModel missing = ModelLoaderRegistry.getMissingModel(); IBakedModel bakedMissing = missing.bake(missing.getDefaultState(), format, bakedTextureGetter); final IBakedModel bakedBase; if (base.isPresent()) { bakedBase = bakeModel(base.get(), state, format, bakedTextureGetter); } else { bakedBase = bakedMissing; } return new MultiLayerBakedModel( bakedModels, bakedBase, bakedMissing, PerspectiveMapWrapper.getTransforms(state)); }
Example 5
Source File: EventsClient.java From Valkyrien-Skies with Apache License 2.0 | 6 votes |
@SubscribeEvent public void onModelBake(ModelBakeEvent event) { GibsModelRegistry.onModelBakeEvent(event); ResourceLocation modelResourceLocation = new ResourceLocation(ValkyrienSkiesMod.MOD_ID, "item/infuser_core_main"); try { IModel model = ModelLoaderRegistry.getModel(modelResourceLocation); IBakedModel inventoryModel = model .bake(model.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()); IBakedModel handModel = event.getModelRegistry() .getObject(new ModelResourceLocation( ValkyrienSkiesMod.MOD_ID + ":" + ValkyrienSkiesMod.INSTANCE.physicsCore .getTranslationKey() .substring(5), "inventory")); event.getModelRegistry() .putObject( new ModelResourceLocation(ValkyrienSkiesMod.MOD_ID + ":testmodel", "inventory"), new InfuserCoreBakedModel(handModel, inventoryModel)); } catch (Exception e) { e.printStackTrace(); } }
Example 6
Source File: BakedModelCamouflageBlock.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
@Nullable public static IBakedModel getRotatedBakedModel(@Nullable IModel model, @Nullable IBakedModel bakedModelDefault, IBlockState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { if (model != null) { if (state.getPropertyKeys().contains(BlockEnderUtilities.FACING)) { return model.bake(TRSRTransformation.from(state.getValue(BlockEnderUtilities.FACING)), format, bakedTextureGetter); } else if (state.getPropertyKeys().contains(BlockEnderUtilities.FACING_H)) { return model.bake(TRSRTransformation.from(state.getValue(BlockEnderUtilities.FACING_H)), format, bakedTextureGetter); } } return bakedModelDefault; }
Example 7
Source File: ModelWithDependencies.java From OpenModsLib with MIT License | 5 votes |
@Override public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { final IModel model; if (base.isPresent()) { model = ModelLoaderRegistry.getModelOrLogError(base.get(), "Couldn't load MultiLayerModel dependency: " + base.get()); } else { model = ModelLoaderRegistry.getMissingModel(); } return model.bake(state, format, bakedTextureGetter); }
Example 8
Source File: BakedModelCamouflageBlock.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
public BakedModelCamouflageBlock(IModel baseModel, @Nullable IModel overlayModel, ImmutableMap<String, String> textures, IModelState modelState, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { this.baseModel = baseModel; this.overlayModel = overlayModel; this.modelState = modelState; this.format = format; this.bakedTextureGetter = bakedTextureGetter; this.bakedBaseModel = baseModel.bake(modelState, format, bakedTextureGetter); this.bakedOverlayModel = overlayModel != null ? overlayModel.bake(modelState, format, bakedTextureGetter) : null; this.itemQuads = buildItemModel(this.bakedBaseModel, this.bakedOverlayModel); }
Example 9
Source File: BakedEvalModel.java From OpenModsLib with MIT License | 5 votes |
public BakedEvalModel(IModel model, IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter, ITransformEvaluator evaluator) { super(model.bake(state, format, bakedTextureGetter), PerspectiveMapWrapper.getTransforms(state)); this.model = model; this.originalState = state; this.format = format; this.bakedTextureGetter = bakedTextureGetter; this.evaluator = evaluator; }
Example 10
Source File: TexturedItemModel.java From OpenModsLib with MIT License | 5 votes |
@Override public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { final IModel untexturedModel = getModel(this.untexturedModel); final IBakedModel untexturedBakedModel = untexturedModel.bake(new ModelStateComposition(state, untexturedModel.getDefaultState()), format, bakedTextureGetter); final IModel texturedModel = getModel(this.texturedModel); final IBakedModel texturedBakedModel = texturedModel.bake(new ModelStateComposition(state, texturedModel.getDefaultState()), format, bakedTextureGetter); final ItemOverrideList overrides = new TexturedItemOverrides(untexturedBakedModel, texturedModel, texturedBakedModel.getOverrides().getOverrides(), textures, state, format, bakedTextureGetter); return new BakedModel(untexturedBakedModel, PerspectiveMapWrapper.getTransforms(state), overrides); }
Example 11
Source File: ModelRocket.java From AdvancedRocketry with MIT License | 5 votes |
@Override public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { IModel subComponent; try { subComponent = ModelLoaderRegistry.getModel(resource); IBakedModel bakedModelCore = subComponent.bake(state, format, bakedTextureGetter); return bakedModelCore; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
Example 12
Source File: ModelEnderTools.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
@Override public IBakedModel handleItemState(IBakedModel originalModelIn, ItemStack stack, World world, EntityLivingBase entity) { boolean isTool = stack.getItem() == EnderUtilitiesItems.ENDER_TOOL; ItemLocationBoundModular item = (ItemLocationBoundModular)stack.getItem(); String core = String.valueOf(item.getSelectedModuleTier(stack, ModuleType.TYPE_ENDERCORE)); String cap = String.valueOf(item.getSelectedModuleTier(stack, ModuleType.TYPE_ENDERCAPACITOR)); String lc = String.valueOf(item.getSelectedModuleTier(stack, ModuleType.TYPE_LINKCRYSTAL)); String toolClass; String broken; String powered; String creative; String mode; String key; if (isTool) { ItemEnderTool itemTool = (ItemEnderTool)stack.getItem(); toolClass = ItemEnderTool.ToolType.fromStack(stack).getToolClass(); broken = String.valueOf(itemTool.isToolBroken(stack)); powered = String.valueOf(ItemEnderTool.PowerStatus.fromStack(stack) == ItemEnderTool.PowerStatus.POWERED); creative = String.valueOf(itemTool.isCreativeLikeBreakingEnabled(stack)); mode = String.valueOf(ItemEnderTool.DropsMode.fromStack(stack).ordinal()); key = toolClass + broken + powered + creative + mode + core + cap + lc; } else { ItemEnderSword itemSword = (ItemEnderSword)stack.getItem(); toolClass = "sword"; broken = String.valueOf(itemSword.isToolBroken(stack)); powered = "false"; creative = "false"; mode = String.valueOf(ItemEnderSword.SwordMode.fromStack(stack).ordinal()); key = broken + powered + creative + mode + core + cap + lc; } BakedEnderTool originalModel = (BakedEnderTool) originalModelIn; if (originalModel.cache.containsKey(key) == false) { ImmutableMap.Builder<String, String> map = ImmutableMap.builder(); map.put("toolClass", toolClass); map.put("broken", broken); map.put("powered", powered); map.put("creative", creative); map.put("mode", mode); map.put("core", core); map.put("capacitor", cap); map.put("lc", lc); IModel model = originalModel.parent.process(map.build()); Function<ResourceLocation, TextureAtlasSprite> textureGetter; textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() { public TextureAtlasSprite apply(ResourceLocation location) { return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()); } }; IBakedModel bakedModel = model.bake(new SimpleModelState(originalModel.transforms), originalModel.format, textureGetter); originalModel.cache.put(key, bakedModel); return bakedModel; } return originalModel.cache.get(key); }
Example 13
Source File: ModelNullifierBaked.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
private void addQuads(ModelNullifierBaked nullifierModel, boolean locked, ItemStack containedStack) { IBakedModel itemModel = null; IBakedModel textModel = null; if (containedStack.isEmpty() == false) { ItemType type = new ItemType(containedStack, true); itemModel = ITEM_MODEL_CACHE.get(type); if (itemModel == null) { IModel iModel = this.getItemModel(containedStack); if (iModel != null && iModel.getClass().getName().equals("net.minecraftforge.client.model.FancyMissingModel") == false) { TRSRTransformation trn = new TRSRTransformation(new javax.vecmath.Vector3f(-0.5f, -0.5f, -0.5f), null, null, null); TRSRTransformation trr = TRSRTransformation.from(ModelRotation.X0_Y180); TRSRTransformation trp = new TRSRTransformation(new javax.vecmath.Vector3f( 0.5f, 0.5f, 0.5f), null, null, null); TRSRTransformation trs = new TRSRTransformation(null, null, new javax.vecmath.Vector3f(0.6f, 0.6f, 0.6f), null); TRSRTransformation tr = trn.compose(trr).compose(trp).compose(trs); IModelState state = new ModelStateComposition(this.modelState, TRSRTransformation.blockCenterToCorner(tr)); itemModel = iModel.bake(state, this.format, this.bakedTextureGetter); } else { Minecraft mc = Minecraft.getMinecraft(); itemModel = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(containedStack); itemModel = itemModel.getOverrides().handleItemState(itemModel, containedStack, mc.world, mc.player); } ITEM_MODEL_CACHE.put(type, itemModel); } } this.addQuadsForSide(null, nullifierModel, itemModel, textModel, locked); for (EnumFacing side : EnumFacing.values()) { this.addQuadsForSide(side, nullifierModel, itemModel, textModel, locked); } }
Example 14
Source File: ProxyClient.java From WearableBackpacks with MIT License | 4 votes |
private static IBakedModel bakeBlockModel(String location) { IModel model = getModel(new ResourceLocation(location)); return model.bake(model.getDefaultState(), DefaultVertexFormats.BLOCK, loc -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(loc.toString())); }
Example 15
Source File: EvalExpandModel.java From OpenModsLib with MIT License | 4 votes |
public BakedEvalExpandModel(IModel model, IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter, IBlockState defaultBlockState, IVarExpander expander) { super(model.bake(state, format, bakedTextureGetter), PerspectiveMapWrapper.getTransforms(state)); this.expander = expander; this.defaultBlockState = defaultBlockState; }
Example 16
Source File: MultiLayerModel.java From OpenModsLib with MIT License | 4 votes |
private static IBakedModel bakeModel(ResourceLocation model, IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { IModel baseModel = ModelLoaderRegistry.getModelOrLogError(model, "Couldn't load MultiLayerModel dependency: " + model); return baseModel.bake(new ModelStateComposition(state, baseModel.getDefaultState()), format, bakedTextureGetter); }
Example 17
Source File: BakedModelBarrel.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
private IBakedModel getBakedBaseModel(IBlockState actualState) { IModel model = this.baseModel.retexture(this.getTexturesBaseModel(actualState, this.textures)); return model.bake(TRSRTransformation.from(actualState.getValue(BlockBarrel.FACING_H)), this.format, this.bakedTextureGetter); }
Example 18
Source File: ModelEnderBucket.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
@Override public IBakedModel handleItemState(IBakedModel originalModelIn, ItemStack stack, World world, EntityLivingBase entity) { if ((stack.getItem() instanceof ItemEnderBucket) == false) { return originalModelIn; } BakedEnderBucket originalModel = (BakedEnderBucket) originalModelIn; ItemEnderBucket item = (ItemEnderBucket)stack.getItem(); String linked = ItemEnderBucket.LinkMode.fromStack(stack) == ItemEnderBucket.LinkMode.ENABLED ? "true" : "false"; int capacity = item.getCapacityCached(stack, null); ItemEnderBucket.BucketMode mode = ItemEnderBucket.BucketMode.fromStack(stack); String modeStr = "none"; int amount = 0; FluidStack fluidStack = item.getFluidCached(stack); Fluid fluid = null; if (fluidStack != null) { amount = fluidStack.amount; fluid = fluidStack.getFluid(); } if (mode == ItemEnderBucket.BucketMode.DRAIN) { modeStr = "drain"; } else if (mode == ItemEnderBucket.BucketMode.FILL) { modeStr = "fill"; } else if (mode == ItemEnderBucket.BucketMode.BIND) { modeStr = "bind"; } String key = linked + "_" + modeStr + "_" + fluid + "_" + amount + "_" + capacity; if (originalModel.cache.containsKey(key) == false) { ImmutableMap.Builder<String, String> map = ImmutableMap.builder(); if (fluid != null) { map.put("fluid", fluid.getName()); } map.put("linked", linked); map.put("mode", modeStr); map.put("amount", String.valueOf(amount)); map.put("capacity", String.valueOf(capacity)); IModel parent = originalModel.parent.process(map.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(originalModel.transforms), originalModel.format, textureGetter); originalModel.cache.put(key, bakedModel); return bakedModel; } return originalModel.cache.get(key); }
Example 19
Source File: TexturedItemOverrides.java From OpenModsLib with MIT License | 4 votes |
@Override public IBakedModel load(Pair<ResourceLocation, Optional<ResourceLocation>> key) throws Exception { final IModel overrideModel = getOverrideModel(key.getRight()); final IModel retexturedModel = retextureModel(overrideModel, key.getKey()); return retexturedModel.bake(state, format, bakedTextureGetter); }
Example 20
Source File: PerspectiveAwareModel.java From OpenModsLib with MIT License | 4 votes |
private static IBakedModel bakeModel(ResourceLocation model, IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { IModel baseModel = ModelLoaderRegistry.getModelOrLogError(model, "Couldn't load MultiLayerModel dependency: " + model); return baseModel.bake(new ModelStateComposition(state, baseModel.getDefaultState()), format, bakedTextureGetter); }