Search in sources :

Example 1 with ItemOverrideList

use of net.minecraft.client.renderer.block.model.ItemOverrideList in project Tropicraft by Tropicraft.

the class ClientProxy method onModelBake.

@SubscribeEvent
public void onModelBake(ModelBakeEvent event) {
    for (Entry<String, String[]> e : blockVariants.entrySet()) {
        for (String variant : e.getValue()) {
            ModelResourceLocation loc = new ModelResourceLocation(Info.MODID + ":" + e.getKey(), variant);
            IModel model = ModelLoaderRegistry.getModelOrLogError(loc, "Could not load arbitrary block variant " + variant + " for block " + e.getKey());
            event.getModelRegistry().putObject(loc, model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()));
        }
    }
    try {
        IModel waterTop = ModelLoaderRegistry.getModel(new ResourceLocation("tropicraft:block/tropics_water_top"));
        final IBakedModel waterTopBaked = waterTop.bake(waterTop.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
        Block[] fences = new Block[] { BlockRegistry.bambooFence, BlockRegistry.chunkFence, BlockRegistry.mahoganyFence, BlockRegistry.palmFence, BlockRegistry.thatchFence };
        for (Block block : fences) {
            ModelResourceLocation loc = new ModelResourceLocation(block.getRegistryName(), "normal");
            final IBakedModel fenceModel = event.getModelRegistry().getObject(loc);
            event.getModelRegistry().putObject(loc, new IBakedModel() {

                @Override
                @Nonnull
                public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
                    BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer();
                    if (layer == null || layer == BlockRenderLayer.SOLID) {
                        return fenceModel.getQuads(state, side, rand);
                    } else if (layer == BlockRenderLayer.TRANSLUCENT && state.getValue(BlockTropicraftFence.WATER) == WaterState.SURFACE) {
                        return waterTopBaked.getQuads(state, side, rand);
                    }
                    return Collections.emptyList();
                }

                @Override
                public boolean isGui3d() {
                    return true;
                }

                @Override
                public boolean isBuiltInRenderer() {
                    return false;
                }

                @Override
                public boolean isAmbientOcclusion() {
                    return true;
                }

                @Override
                @Nonnull
                public TextureAtlasSprite getParticleTexture() {
                    return fenceModel.getParticleTexture();
                }

                @Override
                @Nonnull
                public ItemOverrideList getOverrides() {
                    return fenceModel.getOverrides();
                }
            });
        }
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : IModel(net.minecraftforge.client.model.IModel) IBlockState(net.minecraft.block.state.IBlockState) Nonnull(javax.annotation.Nonnull) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EnumFacing(net.minecraft.util.EnumFacing) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ItemOverrideList(net.minecraft.client.renderer.block.model.ItemOverrideList) Block(net.minecraft.block.Block) ITropicraftBlock(net.tropicraft.core.common.block.ITropicraftBlock) ItemOverrideList(net.minecraft.client.renderer.block.model.ItemOverrideList) NonNullList(net.minecraft.util.NonNullList) List(java.util.List) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with ItemOverrideList

use of net.minecraft.client.renderer.block.model.ItemOverrideList in project FoamFix by asiekierka.

the class FoamyItemLayerModel method bakeStatic.

public static IBakedModel bakeStatic(ItemLayerModel parent, final IModelState state, final VertexFormat format, final Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> map = PerspectiveMapWrapper.getTransforms(state);
    TRSRTransformation guiTransform = map.get(ItemCameraTransforms.TransformType.GUI);
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    Optional<TRSRTransformation> transform = state.apply(Optional.empty());
    List<ResourceLocation> textures = (List<ResourceLocation>) parent.getTextures();
    ImmutableList.Builder<TextureAtlasSprite> textureAtlas = new ImmutableList.Builder<>();
    TextureAtlasSprite particle = bakedTextureGetter.apply(textures.isEmpty() ? MISSINGNO : textures.get(0));
    ItemOverrideList list;
    try {
        list = (ItemOverrideList) OVERRIDES_GET.invokeExact(parent);
    } catch (Throwable t) {
        throw new RuntimeException(t);
    }
    if (guiTransform != null && !guiTransform.isIdentity()) {
        // Have only 3D model
        return new Static3DItemModel(map, format, particle, list, textureAtlas.build(), transform);
    } else {
        if (BUILD_QUAD != null) {
            // Fast route!
            for (int i = 0; i < textures.size(); i++) {
                TextureAtlasSprite sprite = bakedTextureGetter.apply(textures.get(i));
                textureAtlas.add(sprite);
                try {
                    builder.add((BakedQuad) BUILD_QUAD.invokeExact(format, transform, EnumFacing.SOUTH, sprite, i, 0f, 0f, 8.5f / 16f, (float) sprite.getMinU(), (float) sprite.getMaxV(), 1f, 0f, 8.5f / 16f, (float) sprite.getMaxU(), (float) sprite.getMaxV(), 1f, 1f, 8.5f / 16f, (float) sprite.getMaxU(), (float) sprite.getMinV(), 0f, 1f, 8.5f / 16f, (float) sprite.getMinU(), (float) sprite.getMinV()));
                } catch (Throwable t) {
                    throw new RuntimeException(t);
                }
            }
        } else {
            // Slow fallback route :-(
            for (int i = 0; i < textures.size(); i++) {
                TextureAtlasSprite sprite = bakedTextureGetter.apply(textures.get(i));
                for (BakedQuad quad : ItemLayerModel.getQuadsForSprite(i, sprite, format, transform)) {
                    if (quad.getFace() == EnumFacing.SOUTH)
                        builder.add(quad);
                }
            }
        }
        // This returns otherModel because the 3D model is default
        return new DynamicItemModel(builder.build(), particle, map, list, textureAtlas.build(), format, transform).otherModel;
    }
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) ImmutableList(com.google.common.collect.ImmutableList) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ResourceLocation(net.minecraft.util.ResourceLocation) ItemOverrideList(net.minecraft.client.renderer.block.model.ItemOverrideList) ItemOverrideList(net.minecraft.client.renderer.block.model.ItemOverrideList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 3 with ItemOverrideList

use of net.minecraft.client.renderer.block.model.ItemOverrideList in project Random-Things by lumien231.

the class ModelCustomWorkbench method getOverrides.

@Override
public ItemOverrideList getOverrides() {
    return new ItemOverrideList(new ArrayList<ItemOverride>()) {

        @Override
        public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity) {
            checkDefault();
            NBTTagCompound compound;
            String woodName;
            int meta;
            if ((compound = stack.getTagCompound()) != null) {
                woodName = compound.getString("woodName");
                meta = compound.getInteger("woodMeta");
            } else {
                woodName = "minecraft:planks";
                meta = 0;
            }
            Block woodBlock = Block.getBlockFromName(woodName);
            if (woodBlock == null) {
                woodBlock = Blocks.PLANKS;
                meta = 0;
            }
            IBlockState woodState = woodBlock.getStateFromMeta(meta);
            if (woodState == null) {
                return defaultModel;
            }
            if (modelCache.containsKey(woodState)) {
                return modelCache.get(woodState);
            } else {
                modelCache.put(woodState, new ModelCubeOverlay(RenderUtils.getQuadFaceMapFromState(woodState), overlays, Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(Blocks.PLANKS.getDefaultState()).getParticleTexture(), true));
                return modelCache.get(woodState);
            }
        }
    };
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ItemOverride(net.minecraft.client.renderer.block.model.ItemOverride) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) World(net.minecraft.world.World) ItemOverrideList(net.minecraft.client.renderer.block.model.ItemOverrideList) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Block(net.minecraft.block.Block) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ItemStack(net.minecraft.item.ItemStack) ItemOverride(net.minecraft.client.renderer.block.model.ItemOverride)

Example 4 with ItemOverrideList

use of net.minecraft.client.renderer.block.model.ItemOverrideList in project LogisticsPipes by RS485.

the class LogisticsNewPipeModel method bake.

@Override
@SideOnly(Side.CLIENT)
@Nonnull
public IBakedModel bake(@Nonnull IModelState state, @Nonnull VertexFormat format, @Nonnull Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    return new IBakedModel() {

        private ArrayList<BakedQuad> quads = null;

        @Override
        @SideOnly(Side.CLIENT)
        @Nonnull
        public List<BakedQuad> getQuads(@Nullable IBlockState blockstate, @Nullable EnumFacing side, long rand) {
            BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer();
            ArrayList<BakedQuad> result;
            if (layer == BlockRenderLayer.CUTOUT || layer == null || blockstate == null) {
                result = getLPQuads(blockstate, side);
            } else {
                result = Lists.newArrayList();
            }
            addOtherQuads(result, blockstate, side, rand);
            return result;
        }

        private void addOtherQuads(@Nonnull List<BakedQuad> list, IBlockState blockstate, EnumFacing side, long rand) {
            if (blockstate != null) {
                SimpleServiceLocator.mcmpProxy.addQuads(list, blockstate, side, rand);
            }
        }

        private ArrayList<BakedQuad> getLPQuads(@Nullable IBlockState blockstate, @Nullable EnumFacing side) {
            if (blockstate != null) {
                if (side == null) {
                    IExtendedBlockState eState = (IExtendedBlockState) blockstate;
                    Cache<PipeRenderState.LocalCacheType, Object> objectCache = eState.getValue(LogisticsBlockGenericPipe.propertyCache);
                    if (objectCache != null) {
                        Object pipeQuads = objectCache.getIfPresent(PipeRenderState.LocalCacheType.QUADS);
                        if (pipeQuads instanceof Collection) {
                            // noinspection unchecked
                            return new ArrayList<>((Collection<? extends BakedQuad>) pipeQuads);
                        }
                    }
                    final ArrayList<BakedQuad> pipeQuads = LogisticsRenderPipe.secondRenderer.getQuadsFromRenderList(generatePipeRenderList(blockstate), format, true);
                    if (objectCache != null) {
                        objectCache.put(PipeRenderState.LocalCacheType.QUADS, new ArrayList<>(pipeQuads));
                    }
                    return pipeQuads;
                }
            } else {
                if (quads == null) {
                    quads = LogisticsRenderPipe.secondRenderer.getQuadsFromRenderList(generatePipeRenderList(), format, true);
                }
                return new ArrayList<>(quads);
            }
            return Lists.newArrayList();
        }

        @Override
        public boolean isAmbientOcclusion() {
            return false;
        }

        @Override
        public boolean isGui3d() {
            return true;
        }

        @Override
        public boolean isBuiltInRenderer() {
            return false;
        }

        @Override
        @Nonnull
        public TextureAtlasSprite getParticleTexture() {
            return BASE_TEXTURE_SPRITE;
        }

        @Override
        @Nonnull
        public ItemOverrideList getOverrides() {
            return ItemOverrideList.NONE;
        }

        @Override
        @Nonnull
        public org.apache.commons.lang3.tuple.Pair<? extends IBakedModel, Matrix4f> handlePerspective(@Nonnull ItemCameraTransforms.TransformType cameraTransformType) {
            return PerspectiveMapWrapper.handlePerspective(this, SimpleServiceLocator.cclProxy.getDefaultBlockState(), cameraTransformType);
        }
    };
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) Nonnull(javax.annotation.Nonnull) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) Matrix4f(javax.vecmath.Matrix4f) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) Collection(java.util.Collection) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) ItemOverrideList(net.minecraft.client.renderer.block.model.ItemOverrideList) List(java.util.List) LPUVTransformationList(logisticspipes.proxy.object3d.operation.LPUVTransformationList) ArrayList(java.util.ArrayList) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Nullable(javax.annotation.Nullable) Nonnull(javax.annotation.Nonnull) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

ItemOverrideList (net.minecraft.client.renderer.block.model.ItemOverrideList)4 List (java.util.List)3 IBlockState (net.minecraft.block.state.IBlockState)3 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)3 Nonnull (javax.annotation.Nonnull)2 Block (net.minecraft.block.Block)2 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)2 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)2 BlockRenderLayer (net.minecraft.util.BlockRenderLayer)2 EnumFacing (net.minecraft.util.EnumFacing)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Nullable (javax.annotation.Nullable)1 Matrix4f (javax.vecmath.Matrix4f)1 LPUVTransformationList (logisticspipes.proxy.object3d.operation.LPUVTransformationList)1 ItemOverride (net.minecraft.client.renderer.block.model.ItemOverride)1 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1