net.minecraft.client.renderer.model.IBakedModel Java Examples

The following examples show how to use net.minecraft.client.renderer.model.IBakedModel. 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: CustomParticleHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public static void addLandingEffects(World world, BlockPos pos, BlockState state, Vector3 entityPos, int numParticles) {
    //Spoof a raytrace from the feet.
    BlockRayTraceResult traceResult = new BlockRayTraceResult(new Vec3d(entityPos.x, pos.getY() + 1, entityPos.z), Direction.UP, pos, false);
    ParticleManager manager = Minecraft.getInstance().particles;
    Random randy = new Random();
    BlockModelShapes modelShapes = Minecraft.getInstance().getBlockRendererDispatcher().getBlockModelShapes();
    IBakedModel model = modelShapes.getModel(state);
    if (model instanceof IModelParticleProvider) {
        IModelData modelData = ModelDataManager.getModelData(world, pos);
        List<TextureAtlasSprite> sprites = new ArrayList<>(((IModelParticleProvider) model).getHitEffects(traceResult, state, world, pos, modelData));

        double speed = 0.15000000596046448D;
        if (numParticles != 0) {
            for (int i = 0; i < numParticles; i++) {
                double mX = randy.nextGaussian() * speed;
                double mY = randy.nextGaussian() * speed;
                double mZ = randy.nextGaussian() * speed;
                manager.addEffect(CustomBreakingParticle.newLandingParticle(world, entityPos.x, entityPos.y, entityPos.z, mX, mY, mZ, sprites.get(randy.nextInt(sprites.size()))));
            }
        }
    }
}
 
Example #2
Source File: CustomParticleHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public static boolean handleRunningEffects(World world, BlockPos pos, BlockState state, Entity entity) {
    //Spoof a raytrace from the feet.
    BlockRayTraceResult traceResult = new BlockRayTraceResult(entity.getPositionVec().add(0, 1, 0), Direction.UP, pos, false);
    BlockModelShapes modelShapes = Minecraft.getInstance().getBlockRendererDispatcher().getBlockModelShapes();
    IBakedModel model = modelShapes.getModel(state);
    if (model instanceof IModelParticleProvider) {
        IModelData modelData = ModelDataManager.getModelData(world, pos);
        ParticleManager particleManager = Minecraft.getInstance().particles;
        List<TextureAtlasSprite> sprites = new ArrayList<>(((IModelParticleProvider) model).getHitEffects(traceResult, state, world, pos, modelData));
        TextureAtlasSprite rolledSprite = sprites.get(world.rand.nextInt(sprites.size()));
        double x = entity.getPosX() + (world.rand.nextFloat() - 0.5D) * entity.getWidth();
        double y = entity.getBoundingBox().minY + 0.1D;
        double z = entity.getPosZ() + (world.rand.nextFloat() - 0.5D) * entity.getWidth();
        particleManager.addEffect(new CustomBreakingParticle(world, x, y, z, -entity.getMotion().x * 4.0D, 1.5D, -entity.getMotion().z * 4.0D, rolledSprite));
        return true;
    }

    return false;
}
 
Example #3
Source File: ModelBakery.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static IBakedModel getCachedItemModel(ItemStack stack) {
    IBakedModel model;
    IItemStackKeyGenerator generator = getKeyGenerator(stack.getItem());
    String key = generator.generateKey(stack);
    model = keyModelCache.getIfPresent(key);
    if (model == null || FORCE_ITEM_REBAKE) {
        try {
            model = timeModelGeneration(ModelBakery::generateItemModel, stack, "ITEM: " + key);
        } catch (Throwable t) {
            LogUtils.errorOnce(logger, t, "ItemBaking", "Fatal exception thrown whilst baking item model for: " + stack);
            //                BakingVertexBuffer buffer = BakingVertexBuffer.create();
            //                if (buffer.isDrawing) {
            //                    buffer.finishDrawing();
            //                    buffer.reset();
            //                }
            return missingModel;
        }
        if (model != missingModel) {
            keyModelCache.put(key, model);
        }
    }
    return model;

}
 
Example #4
Source File: ModelBakery.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static IBakedModel generateItemModel(ItemStack stack) {
    Item item = stack.getItem();
    if (item instanceof IBakeryProvider) {

        IItemBakery bakery = (IItemBakery) ((IBakeryProvider) item).getBakery();

        List<BakedQuad> generalQuads = new LinkedList<>();
        Map<Direction, List<BakedQuad>> faceQuads = new HashMap<>();
        generalQuads.addAll(bakery.bakeItemQuads(null, stack));

        for (Direction face : Direction.BY_INDEX) {
            List<BakedQuad> quads = new LinkedList<>();

            quads.addAll(bakery.bakeItemQuads(face, stack));

            faceQuads.put(face, quads);
        }

        PerspectiveProperties properties = bakery.getModelProperties(stack);
        return new PerspectiveAwareBakedModel(faceQuads, generalQuads, properties);
    }
    return missingModel;
}
 
Example #5
Source File: CCBakeryModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Set<TextureAtlasSprite> getHitEffects(BlockRayTraceResult traceResult, BlockState state, IBlockReader world, BlockPos pos, IModelData data) {
    IBakedModel model = ModelBakery.getCachedModel(state, data);
    if (model instanceof IModelParticleProvider) {
        return ((IModelParticleProvider) model).getHitEffects(traceResult, state, world, pos, data);
    }
    return Collections.emptySet();
}
 
Example #6
Source File: ModelProperties.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Builder copyFrom(IBakedModel model) {
    isAO = model.isAmbientOcclusion();
    isGui3D = model.isGui3d();
    isBuiltInRenderer = model.isBuiltInRenderer();
    particle = model.getParticleTexture();
    return this;
}
 
Example #7
Source File: WrappedItemModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void renderWrapped(ItemStack stack, TransformType transformType, MatrixStack mStack, IRenderTypeBuffer getter, int packedLight, int packedOverlay) {
    IBakedModel model = wrapped.getOverrides().getModelWithOverrides(wrapped, stack, world, entity);

    ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();
    RenderType rType = RenderTypeLookup.getRenderType(stack);
    if (transformType == TransformType.GUI && Objects.equals(rType, Atlases.getTranslucentBlockType())) {
        rType = Atlases.getTranslucentCullBlockType();
    }

    IVertexBuilder builder = ItemRenderer.getBuffer(getter, rType, true, stack.hasEffect());
    itemRenderer.renderModel(model, stack, packedLight, packedOverlay, mStack, builder);
}
 
Example #8
Source File: PerspectiveAwareMultiModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public List<BakedQuad> getQuads(BlockState state, Direction side, Random rand, IModelData data) {
    List<BakedQuad> quads = new LinkedList<>();
    if (baseModel != null) {
        quads.addAll(baseModel.getQuads(state, side, rand, data));
    }
    for (IBakedModel subModel : subModels) {
        quads.addAll(subModel.getQuads(state, side, rand, data));
    }
    return quads;
}
 
Example #9
Source File: TextureUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Deprecated
public static TextureAtlasSprite[] getIconsForBlock(BlockState state, Direction side) {
    IBakedModel model = Minecraft.getInstance().getBlockRendererDispatcher().getModelForState(state);
    if (model != null) {
        List<BakedQuad> quads = model.getQuads(state, side, new Random(0));
        if (quads != null && quads.size() > 0) {
            TextureAtlasSprite[] sprites = new TextureAtlasSprite[quads.size()];
            for (int i = 0; i < quads.size(); i++) {
                sprites[i] = quads.get(i).func_187508_a();
            }
            return sprites;
        }
    }
    return new TextureAtlasSprite[0];
}
 
Example #10
Source File: AbstractBakedPropertiesModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public IBakedModel handlePerspective(TransformType transformType, MatrixStack mat) {
    if (properties instanceof PerspectiveProperties) {
        ImmutableMap<TransformType, TransformationMatrix> transforms = ((PerspectiveProperties) properties).getTransforms();
        return PerspectiveMapWrapper.handlePerspective(this, transforms, transformType, mat);
    }
    return IModelParticleProvider.super.handlePerspective(transformType, mat);
}
 
Example #11
Source File: TextureUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Deprecated
public static TextureAtlasSprite getParticleIconForBlock(BlockState state) {
    IBakedModel model = Minecraft.getInstance().getBlockRendererDispatcher().getModelForState(state);
    if (model != null) {
        return model.getParticleTexture();
    }
    return null;
}
 
Example #12
Source File: CCBakeryModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public ItemOverrideList getOverrides() {
    return new ItemOverrideList() {
        @Override
        public IBakedModel getModelWithOverrides(IBakedModel originalModel, ItemStack stack, World world, LivingEntity entity) {
            IBakedModel model = ModelBakery.getCachedItemModel(stack);
            if (model == null) {
                return originalModel;
            }
            return model;
        }
    };
}
 
Example #13
Source File: CCBakeryModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Set<TextureAtlasSprite> getDestroyEffects(BlockState state, IBlockReader world, BlockPos pos, IModelData data) {
    //TODO, Destroy may need IModelData
    IBakedModel model = ModelBakery.getCachedModel(state, EmptyModelData.INSTANCE);
    if (model instanceof IModelParticleProvider) {
        return ((IModelParticleProvider) model).getDestroyEffects(state, world, pos, data);
    }
    return Collections.emptySet();
}
 
Example #14
Source File: ModelBakery.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static IBakedModel getCachedModel(BlockState state, IModelData data) {
    if (state == null) {
        return missingModel;
    }
    //        if (state.getUnlistedProperties().containsKey(ModelErrorStateProperty.ERROR_STATE)) {
    //            ErrorState errorState = state.getValue(ModelErrorStateProperty.ERROR_STATE);
    //            if (errorState == null) {
    //                CCLLog.logOncePerTick(Level.FATAL, "A CCL controlled model has been improperly handled by someone and will NOT be rendered. No more information available.");
    //                return missingModel;
    //            }
    //            if (errorState.hasErrored()) {
    //                CCLLog.logOncePerTick(Level.ERROR, "A CCL controlled model has reported an error and will NOT be rendered: \n" + errorState.getReason());
    //                return missingModel;
    //            }
    //        }
    IBakedModel model;
    IBlockStateKeyGenerator keyGenerator = getKeyGenerator(state.getBlock());
    String key = keyGenerator.generateKey(state, data);
    model = keyModelCache.getIfPresent(key);
    if (model == null || FORCE_BLOCK_REBAKE) {
        try {
            model = timeModelGeneration(ModelBakery::generateModel, state, data, "BLOCK: " + key);
        } catch (Throwable t) {
            LogUtils.errorOnce(logger, t, "BlockBaking", "Fatal exception thrown whilst baking block model for: " + state);
            //                BakingVertexBuffer buffer = BakingVertexBuffer.create();
            //                if (buffer.isDrawing) {
            //                    buffer.finishDrawing();
            //                    buffer.reset();
            //                }
            return missingModel;
        }
        if (model != missingModel) {
            keyModelCache.put(key, model);
        }
    }
    return model;
}
 
Example #15
Source File: ChoppingBlockRenderer.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void render(ChoppingBlockTileEntity te, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int p_225616_5_, int p_225616_6_)
{
    BlockState state = te.getWorld().getBlockState(te.getPos());
    if (!(state.getBlock() instanceof ChoppingBlock))
        return;

    //if (destroyStage < 0)
    {
        matrixStack.push();

        ItemRenderer itemRenderer = mc.getItemRenderer();

        LazyOptional<IItemHandler> linv = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
        linv.ifPresent((inv) -> {
            ItemStack stack = inv.getStackInSlot(0);
            if (stack.getCount() > 0)
            {
                matrixStack.push();
                matrixStack.translate(0.5, 0.5, 0.5);

                matrixStack.translate(0, -4.5 / 16.0f, 0);
                matrixStack.scale(2, 2, 2);

                IBakedModel ibakedmodel = itemRenderer.getItemModelWithOverrides(stack, te.getWorld(), (LivingEntity) null);
                itemRenderer.renderItem(stack, ItemCameraTransforms.TransformType.GROUND, true, matrixStack, buffer, p_225616_5_, p_225616_6_, ibakedmodel);
                /*int breakStage = te.getBreakStage();
                if (breakStage >= 0)
                {
                    renderItem(stack, ItemCameraTransforms.TransformType.GROUND, breakStage);
                }*/

                matrixStack.pop();
            }
        });

        matrixStack.pop();
    }
}
 
Example #16
Source File: CCRenderItem.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void renderItem(ItemStack stack, ItemCameraTransforms.TransformType transformType, boolean leftHand, MatrixStack mStack, IRenderTypeBuffer getter, int packedLight, int packedOverlay, IBakedModel modelIn) {
    if (modelIn instanceof IItemRenderer) {
        mStack.push();
        IBakedModel handled = ForgeHooksClient.handleCameraTransforms(mStack, modelIn, transformType, leftHand);
        mStack.translate(-0.5D, -0.5D, -0.5D);
        //If anyone doesnt return an IItemRenderer from here, your doing it wrong.
        ((IItemRenderer) handled).renderItem(stack, transformType, mStack, getter, packedLight, packedOverlay);
        mStack.pop();
    }
    super.renderItem(stack, transformType, leftHand, mStack, getter, packedLight, packedOverlay, modelIn);
}
 
Example #17
Source File: CustomParticleHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@link Block#addHitEffects}
 * Provided the model bound is an instance of IModelParticleProvider, you will have landing particles just handled for you.
 * Use the default PerspectiveModel implementations inside CCL, Destroy effects will just be handled for you.
 *
 * @param world   The world.
 * @param pos     The position of the block.
 * @param manager The ParticleManager.
 * @return True if particles were added, basically just return the result of this method inside {@link Block#addHitEffects}
 */
@OnlyIn (Dist.CLIENT)
public static boolean handleDestroyEffects(World world, BlockPos pos, BlockState state, ParticleManager manager) {
    BlockModelShapes modelShapes = Minecraft.getInstance().getBlockRendererDispatcher().getBlockModelShapes();
    IBakedModel model = modelShapes.getModel(state);
    if (model instanceof IModelParticleProvider) {
        IModelData modelData = ModelDataManager.getModelData(world, pos);
        Cuboid6 bounds = new Cuboid6(state.getShape(world, pos).getBoundingBox());
        addBlockDestroyEffects(world, bounds.add(pos), new ArrayList<>(((IModelParticleProvider) model).getDestroyEffects(state, world, pos, modelData)), manager);
        return true;
    }
    return false;
}
 
Example #18
Source File: DryingRackRenderer.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void render(DryingRackTileEntity te, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int combinedLightIn, int combinedOverlayIn)
{
    BlockState state = te.getWorld().getBlockState(te.getPos());
    if (state.getBlock() != SurvivalistBlocks.RACK.get())
        return;

    te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent((inv) -> {
        matrixStack.push(); // pushMatrix

        float angle = -state.get(DryingRackBlock.FACING).getHorizontalAngle();

        matrixStack.translate(0.5, 0.5, 0.5);    // translate
        matrixStack.rotate(Vector3f.YP.rotationDegrees(angle));        // rotate
        matrixStack.translate(-0.5, -0.5, -0.5); // translate
        //matrixStack.func_227863_a_(Vector3f.field_229183_f_.func_229187_a_(180));

        Minecraft mc = Minecraft.getInstance();

        ItemRenderer itemRenderer = mc.getItemRenderer();
        for (int i = 0; i < 4; i++)
        {
            ItemStack stack = inv.getStackInSlot(i);
            if (stack.getCount() > 0)
            {
                matrixStack.push(); // pushMatrix

                float zz = (i - 1.5f) * 0.1875f;

                matrixStack.translate(0, 0, zz); // translate

                matrixStack.scale(0.7f, 0.7f, 0.7f); // scale

                matrixStack.translate(0.715, 0.93, 0.635); // translate
                matrixStack.rotate(Vector3f.YP.rotationDegrees(180)); // rotate

                IBakedModel ibakedmodel = itemRenderer.getItemModelWithOverrides(stack, te.getWorld(), (LivingEntity) null);
                itemRenderer.renderItem(stack, ItemCameraTransforms.TransformType.FIXED, true, matrixStack, buffer, combinedLightIn, combinedOverlayIn, ibakedmodel); // renderItem

                matrixStack.pop(); // popMatrix
            }
        }

        matrixStack.pop(); // popMatrix
    });
}
 
Example #19
Source File: PerspectiveAwareMultiModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public PerspectiveAwareMultiModel(IBakedModel baseModel, List<IBakedModel> subModels, PerspectiveProperties properties) {
    super(properties);
    this.baseModel = baseModel;
    this.subModels = subModels;
}
 
Example #20
Source File: ModelProperties.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static ModelProperties createFromModel(IBakedModel model) {
    return new ModelProperties(model.isAmbientOcclusion(), model.isGui3d(), model.isBuiltInRenderer(), model.getParticleTexture());
}
 
Example #21
Source File: WrappedItemModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public WrappedItemModel(IBakedModel wrapped) {
    this.wrapped = wrapped;
}
 
Example #22
Source File: WrappedItemModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public IBakedModel getModelWithOverrides(IBakedModel originalModel, ItemStack stack, @Nullable World world, @Nullable LivingEntity entity) {
    WrappedItemModel.this.entity = entity;
    WrappedItemModel.this.world = world == null ? entity == null ? null : entity.world : null;
    return originalModel;
}
 
Example #23
Source File: PerspectiveAwareLayeredModelWrapper.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public PerspectiveAwareLayeredModelWrapper(Map<RenderType, IBakedModel> layerModelMap, PerspectiveProperties properties) {
    super(properties);
    this.layerModelMap = ImmutableMap.copyOf(layerModelMap);
}
 
Example #24
Source File: ModelRegistryHelper.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void register(ModelResourceLocation location, IBakedModel model) {
    registerModels.add(new ImmutablePair<>(location, model));
}
 
Example #25
Source File: IItemRenderer.java    From CodeChickenLib with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Called to handle this model's perspective. Either use {@link #getTransforms()}
 * Or add to the {@link MatrixStack} for the given {@link TransformType}.
 *
 * @param transformType Where we are handling perspective for.
 * @param mat           The {@link MatrixStack}.
 * @return The same model.
 */
@Override
default IBakedModel handlePerspective(TransformType transformType, MatrixStack mat) {
    return PerspectiveMapWrapper.handlePerspective(this, getTransforms(), transformType, mat);
}