Jump to content

Stuck with block movement


iHamster

Recommended Posts

I'm trying to create garage doors mod, like garage doors from MalisisDoors, since it doesn't get updated. I got completely stuck trying to figure out how to make doors move. I'm going to store all data and logic of the door operation in NBT, it's not an issie. THE ISSUE is that I can't figure out what to do about rendering, which type of rendering to use, and on top of that wether I can use a .json model that I already have for this purposes, or I should create a new one in the code. I successfully failed to make either way work. Unfortunately, I'm not very clever, neither I am a Java expert, and, to make it even worse (who'd have thought it's possible?!) I can't find a tutorial that'd make any sense to me in regards of THE ISSUE. 

 

I've been experimenting with WindowTile for quite a while, but, like I said, I got completely stuck trying to make it move - in the end it should be able to "slide" and rotate. When I figure it out, everything else should be just a question of time. Any help, including useful links, is greately appreciated. Please, advise. 

 

 

Edited by iHamster
Old code link removed
Link to comment
Share on other sites

Is there a way to use a .json model with corresponding textures for tile entity rendering purposes? And I'd rather stick with idea of tile entities instead of blockstates, as in "open" position the model will have to have an offset from it's original position, which, in turn, will determine if it's time to close the whole door by checking redstone power. Unless I'm missing a way of rendering a stationary block with an offset. 

Link to comment
Share on other sites

Yes, you can just use the BlockModelRenderer or whatever the class is called.

6 minutes ago, iHamster said:

And I'd rather stick with idea of tile entities instead of blockstates, as in "open" position the model will have to have an offset from it's original position, which, in turn, will determine if it's time to close the whole door by checking redstone power

Well, I suggest blockstates to allow the use of cached baked models when its not moving, which is much more efficient than a renderer every tick.

Link to comment
Share on other sites

On 1/7/2021 at 1:46 AM, ChampionAsh5357 said:

Well, you would be using a TileEntityRenderer to determine how the doors are rendered during moving and then different blockstates to use a cached static model when not moving.

I'm missing something here. I've created a simple TE renderer, and registered it. Nothing changed at all. What am I doing wrong? 

 

public class GarageDoorWindowTileRenderer extends TileEntityRenderer<GarageDoorWindowTile> {


    public GarageDoorWindowTileRenderer(TileEntityRendererDispatcher rendererDispatcherIn) {
        super(rendererDispatcherIn);
    }

    @Override
    public void render(GarageDoorWindowTile tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {
        matrixStackIn.push();
        matrixStackIn.translate(1,5,1);
        matrixStackIn.pop();

    }
}
    @SubscribeEvent
    public static void onClientSetupEvent(FMLClientSetupEvent event) {

        RenderTypeLookup.setRenderLayer(RegistryHandler.GARAGEDOORWINDOW_BLOCK.get(), RenderType.getSolid());
        ClientRegistry.bindTileEntityRenderer(WindowTileEntity, GarageDoorWindowTileRenderer::new);
}

 

Edited by iHamster
Old code link removed
Link to comment
Share on other sites

8 hours ago, iHamster said:

    @Override
    public void render(GarageDoorWindowTile tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {
        matrixStackIn.push();
        matrixStackIn.translate(1,5,1);
        matrixStackIn.pop();

    }

This code says "draw nothing."

So it draws nothing.

And you are surprised.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Ok, as far as I can understand (I'm still not very smart though) this code should draw something. But it doesn't. I've changed a few things, so now tile entity is created for each block, but I can't get any further than that. I'm trying to render a baked model, and probably I'm doing it wrong. Please, advise. The link to the GitHub is here, the renderer code is below. Renderer should get registered, but it doesn't work. Please, advise. 

 

Renderer registration: 

 

    public static TileEntityType <WindowTileEntity> windowTileEntityTileEntityType;
    private void doClientStuff(final FMLClientSetupEvent event) {
            ClientRegistry.bindTileEntityRenderer(windowTileEntityTileEntityType, WindowTileEntityRenderer::new);
            System.out.println("renderer registered");
    }

 

public class WindowTileEntityRenderer extends TileEntityRenderer <WindowTileEntity> {
    public WindowTileEntityRenderer(TileEntityRendererDispatcher rendererDispatcherIn) {
        super(rendererDispatcherIn);
    }
    @Override
    public void render(WindowTileEntity tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {
        BlockState state = WINDOW_TILE.get().getDefaultState();
        System.out.println("state " + state.toString());
        matrixStackIn.push();
        matrixStackIn.translate(0,2,0);
        BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher();
        IBakedModel model = dispatcher.getModelForState(state);
        MatrixStack.Entry currentMatrix = matrixStackIn.getLast();
        float red = 5;
        float green = 5;
        float blue = 3;
        IVertexBuilder vertexBuffer = bufferIn.getBuffer(RenderType.getCutout());
        dispatcher.getBlockModelRenderer().renderModel(currentMatrix, vertexBuffer, state, model,
                red, green, blue, combinedLightIn, combinedOverlayIn, EmptyModelData.INSTANCE);
        matrixStackIn.pop();
    }
}

 

Link to comment
Share on other sites

  • 2 weeks later...

I need help once again. I came up with a "special block", which is supposed to "preserve empty space" while the door is open. It acts as it should - doesn't block movement and is transparent, when installed manually, but when it's put instead of a door element by the renderer, it blocks movement. Also, it seems like renderer doesn't unload on block replacement. Any ideas on what gould have gone wrong are appreciated. 

 

I know that removing block before placing a new one in not really necessery. 

 

"special block" : 

 

 

 

Renderer

public class SpecialBlock extends Block {
    private static final BooleanProperty POWERED = BlockStateProperties.POWERED;
    private static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;



    public SpecialBlock (){
        super(Block.Properties.create(Material.WOOD).doesNotBlockMovement());

    }

    @Override
    public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
        return VoxelShapes.empty();
    }


    @Nullable
    @Override
    public BlockState getStateForPlacement(BlockItemUseContext context){
        return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite());
    }

    @Override
    public boolean canDropFromExplosion (Explosion explosion) {return false;};

    @Override
    protected void fillStateContainer(StateContainer.Builder<net.minecraft.block.Block, BlockState> builder) {
        builder.add(FACING, POWERED);
    }

    @Override
    public BlockRenderType getRenderType(BlockState state) {
        return BlockRenderType.INVISIBLE;
    }

    @Override
    public boolean hasTileEntity(BlockState state) {
        return false;
    }
}

 

public class WindowTileEntityRenderer extends TileEntityRenderer <WindowTileEntity> {
    public WindowTileEntityRenderer(TileEntityRendererDispatcher rendererDispatcherIn) {
        super(rendererDispatcherIn);
    }
    IBakedModel model;
    Direction direction;
    BlockState state;
    private static DirectionProperty facing = BlockStateProperties.FACING;
    World world;
    BlockPos pos;
    boolean power;

    @Override
    public void render(WindowTileEntity tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {
        state = tileEntityIn.getBlockState();
        if (state.getBlock().equals(RegistryHandler.WINDOW_TILE.get().getDefaultState().getBlock())){
//        float a = tileEntityIn.turnAngle();

        pos = tileEntityIn.getPos();
        world = tileEntityIn.getWorld();
        direction = world.getBlockState(pos).get(facing);




        if (world.isBlockPowered(pos) == true) {power = true;} else {power = false;};
        BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher();
        if (power) {
            world = tileEntityIn.getWorld();
            world.removeTileEntity(pos);
            world.removeBlock(pos,false);
            System.out.println(state.toString());
            System.out.println(direction.toString());
            world.setBlockState(pos, RegistryHandler.SPECIAL_BLOCK.get().getDefaultState(),3);
            return;
            }
        model = dispatcher.getModelForState(world.getBlockState(pos));
        matrixStackIn.push();
        MatrixStack.Entry currentMatrix = matrixStackIn.getLast();
        float red = 1;
        float green = 1;
        float blue = 1;
        IVertexBuilder vertexBuffer = bufferIn.getBuffer(RenderType.getTranslucent());
        dispatcher.getBlockModelRenderer().renderModel(currentMatrix, vertexBuffer, null, model,
                red, green, blue, combinedLightIn, combinedOverlayIn, EmptyModelData.INSTANCE);

        matrixStackIn.pop();
    }
    }

    @Override
    public boolean isGlobalRenderer(WindowTileEntity windowTileEntity)
    {
        return false;
    }
}

 

Link to comment
Share on other sites

Why the fauk does your renderer change what blocks are in the world?

That's not the job of a renderer.

  • Like 1
  • Thanks 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I was just trying to play my modded world when i randomly got this crash for no reason. I sorted through like every mod and eventually I realized it was LLibrary but I can't seem to find a solution to fix the crashing. I can't lose the world that I have that uses this mod please help me. Here's the report: https://pastebin.com/0D00B79i If anyone has a solution please let me know.  
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Ligawin88 adalah bocoran slot rekomendasi gacor dari Ligawin88 yang bisa anda temukan di SLOT Ligawin88. Situs SLOT Ligawin88 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ligawin88 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ligawin88 merupakan SLOT Ligawin88 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Ligawin88. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ligawin88 hari ini yang telah disediakan SLOT Ligawin88. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ligawin88 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Ligawin88 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ligawin88 di link SLOT Ligawin88.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Asusslot adalah bocoran slot rekomendasi gacor dari Asusslot yang bisa anda temukan di SLOT Asusslot. Situs SLOT Asusslot hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Asusslot terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Asusslot merupakan SLOT Asusslot hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Asusslot. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Asusslot hari ini yang telah disediakan SLOT Asusslot. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Asusslot terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Asusslot terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Asusslot di link SLOT Asusslot.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Galeri555 adalah bocoran slot rekomendasi gacor dari Galeri555 yang bisa anda temukan di SLOT Galeri555. Situs SLOT Galeri555 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Galeri555 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Galeri555 merupakan SLOT Galeri555 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Galeri555. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Galeri555 hari ini yang telah disediakan SLOT Galeri555. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Galeri555 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Galeri555 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Galeri555 di link SLOT Galeri555.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Kocok303 adalah bocoran slot rekomendasi gacor dari Kocok303 yang bisa anda temukan di SLOT Kocok303. Situs SLOT Kocok303 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Kocok303 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Kocok303 merupakan SLOT Kocok303 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Kocok303. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Kocok303 hari ini yang telah disediakan SLOT Kocok303. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Kocok303 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Kocok303 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Kocok303 di link SLOT Kocok303.
  • Topics

×
×
  • Create New...

Important Information

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