Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

 

I am trying to make the model lighter and scale it. Registered ClientRegistry.bindTileEntityRenderer and in the render method I do the following:

public class ObjRenderer extends TileEntityRenderer<TileEntity> {

    public ObjRenderer(TileEntityRendererDispatcher tileEntityRendererDispatcher) {
        super(tileEntityRendererDispatcher);
    }

    @Override
    public void render(TileEntity tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {

        BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher();

        BlockState state = tileEntityIn.getBlockState();
        IBakedModel model = dispatcher.getModelForState(state);

        matrixStackIn.push();

        matrixStackIn.scale(2,2,2);

        IVertexBuilder vertexBuffer = bufferIn.getBuffer(RenderType.getSolid());

        float brightness = 0.87F;

        dispatcher.getBlockModelRenderer().renderModel(
                matrixStackIn.getLast(), vertexBuffer, state, model, brightness, brightness, brightness, combinedLightIn, combinedOverlayIn, EmptyModelData.INSTANCE
        );

        matrixStackIn.pop();

    }
}

 

After that, both the old and new model are rendered with the applied parameters on the new one, but I only need to change the main model. How to do this?

 

full code: https://github.com/alterland/almodels

Edited by Aviator737

  • Author

Here is the solution. Set the air model for block default state. Then, in the render method, take the state with the model and render it.
 

blockstate:

{
  "variants": {
    "model=true": {
      "model": "almodels:block/double_bed_1"
    },
    "model=false": {
      "model": "minecraft:block/air"
    }
  }
}

 

render method:

    @Override
    public void render(TileEntity tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {

        BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher();

        BlockState state = tileEntityIn.getBlockState().getBlock().getDefaultState().with(DoubleBed1Block.MODEL, true);
        IBakedModel model = dispatcher.getModelForState(state);

        Direction direction = tileEntityIn.getBlockState().get(HORIZONTAL_FACING);

        float angle = 0;

        matrixStackIn.push();

        IVertexBuilder vertexBuffer = bufferIn.getBuffer(RenderType.getSolid());

        float brightness = 0.87F;

        switch (direction) {
            default:
            case SOUTH:
                angle = 0;
                break;
            case NORTH:
                angle = 180;
                break;
            case EAST:
                angle = 90;
                break;
            case WEST:
                angle = 270;
                break;
        }

        matrixStackIn.rotate(Vector3f.YP.rotationDegrees(angle));

        dispatcher.getBlockModelRenderer().renderModel(
                matrixStackIn.getLast(), vertexBuffer, state, model, brightness, brightness, brightness, combinedLightIn, combinedOverlayIn, EmptyModelData.INSTANCE
        );

        matrixStackIn.pop();

    }

 

block:

    public DoubleBed1Block(final Properties properties) {
        super(properties);
        this.setDefaultState(this.getDefaultState().with(HORIZONTAL_FACING, Direction.NORTH).with(MODEL, false));
    }

 

Edited by Aviator737

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.