Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Stuck with block movement
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
iHamster

Stuck with block movement

By iHamster, January 6 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

iHamster    1

iHamster

iHamster    1

  • Tree Puncher
  • iHamster
  • Members
  • 1
  • 8 posts
Posted January 6 (edited)

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 January 8 by iHamster
Old code link removed
  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted January 6

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.

  • Quote

Share this post


Link to post
Share on other sites

iHamster    1

iHamster

iHamster    1

  • Tree Puncher
  • iHamster
  • Members
  • 1
  • 8 posts
Posted January 6

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. 

  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted January 6

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.

  • Quote

Share this post


Link to post
Share on other sites

iHamster    1

iHamster

iHamster    1

  • Tree Puncher
  • iHamster
  • Members
  • 1
  • 8 posts
Posted January 7 (edited)
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 January 8 by iHamster
Old code link removed
  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2417

Draco18s

Draco18s    2417

  • Reality Controller
  • Draco18s
  • Members
  • 2417
  • 16012 posts
Posted January 7
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.

  • Quote

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.

Share this post


Link to post
Share on other sites

iHamster    1

iHamster

iHamster    1

  • Tree Puncher
  • iHamster
  • Members
  • 1
  • 8 posts
Posted January 8
18 hours ago, Draco18s said:

This code says "draw nothing."

So it draws nothing.

And you are surprised.

Not anymore. I found out that Tile Entities are not created for some reason. I will rewrite everything from scratch, update github and get back for more help :) . ChampionAsh5357, Draco18s - thank you for your help! 

  • Quote

Share this post


Link to post
Share on other sites

iHamster    1

iHamster

iHamster    1

  • Tree Puncher
  • iHamster
  • Members
  • 1
  • 8 posts
Posted January 8

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();
    }
}

 

  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted January 9

That would make sense as 'windowTileEntityTileEntityType' seems to be null. Pass in your registry object instead.

  • Quote

Share this post


Link to post
Share on other sites

iHamster    1

iHamster

iHamster    1

  • Tree Puncher
  • iHamster
  • Members
  • 1
  • 8 posts
Posted January 9
14 hours ago, ChampionAsh5357 said:

That would make sense as 'windowTileEntityTileEntityType' seems to be null. Pass in your registry object instead.

You were right, thank you very much! 

  • Quote

Share this post


Link to post
Share on other sites

iHamster    1

iHamster

iHamster    1

  • Tree Puncher
  • iHamster
  • Members
  • 1
  • 8 posts
Posted January 21

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;
    }
}

 

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2417

Draco18s

Draco18s    2417

  • Reality Controller
  • Draco18s
  • Members
  • 2417
  • 16012 posts
Posted January 21

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
  • Quote

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.

Share this post


Link to post
Share on other sites

iHamster    1

iHamster

iHamster    1

  • Tree Puncher
  • iHamster
  • Members
  • 1
  • 8 posts
Posted January 21

I take it as a type of suggestion one can't decline :) 

  • Like 1
  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Aviator737
      [1.16.5] Apply transformation to obj model

      By Aviator737 · Posted 6 minutes ago

      Edited the post, made the question clearer as it seems to me.
    • GenElectrovise
      [Answered, not solved] Automated testing in Forge

      By GenElectrovise · Posted 35 minutes ago

      There'd also be a small startup time tradeoff but I don't know how much of a difference that would make. Interesting idea with running tests later on... I hadn't thought of that... Might try that out just to satisfy curiosity!
    • troublemaker_47
      Custom Ore Generation help

      By troublemaker_47 · Posted 58 minutes ago

      now i get it. Tank you so much you have really made my day  
    • samjviana
      Custom Ore Generation help

      By samjviana · Posted 59 minutes ago

      As from the integer "6" you asked ... it represent the vein size that the ore will try to generate.
    • troublemaker_47
      Custom Ore Generation help

      By troublemaker_47 · Posted 1 hour ago

      Thank you so much
  • Topics

    • Aviator737
      1
      [1.16.5] Apply transformation to obj model

      By Aviator737
      Started Friday at 02:43 PM

    • GenElectrovise
      3
      [Answered, not solved] Automated testing in Forge

      By GenElectrovise
      Started Thursday at 08:34 AM

    • troublemaker_47
      17
      Custom Ore Generation help

      By troublemaker_47
      Started Yesterday at 12:31 PM

    • CommandCore
      3
      Projectile Entity is Invisible

      By CommandCore
      Started February 26

    • ChocoCookies33
      1
      Description: Exception in server tick loop

      By ChocoCookies33
      Started 3 hours ago

  • Who's Online (See full list)

    • Aecht_Rob
    • Aviator737
    • samjviana
    • diesieben07
    • JDL
    • Luis_ST
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Stuck with block movement
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community