Jump to content

[1.10.2] Render block at a different place


kajacx

Recommended Posts

I'm working on implementing custom airships for my mod, something like http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/1289952-archimedes-ships-v1-7-banking-ships but I'm stuck on how to render blocks at different position than they acctually are.

 

I have managed to locate code that is likely responsible for rendering blocks inside RenderChunk class, extend from that class, and have my own code executed. I have copied the original code, and tried to modify it so that each block gets rendered at a position 16 blocks higher than it should be, but with no effect.

 

I know that this is a difficult task, but if someone knows something of use, any help would be appriciated.

 

Here is my code so far:

 

    public void rebuildChunk1(float x, float y, float z, ChunkCompileTaskGenerator generator) {
        CompiledChunk compiledchunk = new CompiledChunk();
        int i = 1;
        //L.d("Getting position");
        BlockPos blockpos = Util.getField(thiz, "position");
        //L.d("Position get");
        BlockPos blockpos1 = blockpos.add(15, 15, 15);
        generator.getLock().lock();

        try {
            if (generator.getStatus() != ChunkCompileTaskGenerator.Status.COMPILING) {
                return;
            }

            generator.setCompiledChunk(compiledchunk);
        } finally {
            generator.getLock().unlock();
        }

        VisGraph lvt_9_1_ = new VisGraph();
        HashSet lvt_10_1_ = Sets.newHashSet();

        ChunkCache region = Util.getField(thiz, "region");

        if (!region.extendedLevelsInChunkCache()) {
            ++thiz.renderChunksUpdated;
            boolean[] aboolean = new boolean[blockRenderLayer.values().length];
            BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
            BlockPos.MutableBlockPos renderPos = new MutableBlockPos();
            BlockPos.MutableBlockPos renderPos0 = new MutableBlockPos(blockpos);
            renderPos0.add(0, 16, 0);

            for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(blockpos, blockpos1)) {
                renderPos.setPos(blockpos$mutableblockpos);
                //renderPos.add(0, 16, 0);
                //L.d("REndering in: " + blockpos$mutableblockpos);

                IBlockState iblockstate = region.getBlockState(blockpos$mutableblockpos);
                Block block = iblockstate.getBlock();

                if (block == Blocks.GOLD_ORE) {
                    L.d("Gold confirmed");
                }
                //L.s("block state: " + iblockstate);

                if (iblockstate.isOpaqueCube()) {
                    lvt_9_1_.setOpaqueCube(renderPos);
                }

                /*if (block.hasTileEntity(iblockstate)) {
                    TileEntity tileentity = region.func_190300_a(blockpos$mutableblockpos, Chunk.EnumCreateEntityType.CHECK);
                
                    if (tileentity != null) {
                        TileEntitySpecialRenderer<TileEntity> tileentityspecialrenderer = TileEntityRendererDispatcher.instance.<TileEntity>getSpecialRenderer(tileentity);
                
                        if (tileentityspecialrenderer != null) {
                            compiledchunk.addTileEntity(tileentity);
                
                            if (tileentityspecialrenderer.isGlobalRenderer(tileentity)) {
                                lvt_10_1_.add(tileentity);
                            }
                        }
                    }
                }*/

                for (BlockRenderLayer blockrenderlayer1 : BlockRenderLayer.values()) {
                    if (!block.canRenderInLayer(iblockstate, blockrenderlayer1))
                        continue;
                    net.minecraftforge.client.ForgeHooksClient.setRenderLayer(blockrenderlayer1);
                    int j = blockrenderlayer1.ordinal();

                    if (block.getDefaultState().getRenderType() != EnumBlockRenderType.INVISIBLE) {
                        net.minecraft.client.renderer.VertexBuffer vertexbuffer = generator.getRegionRenderCacheBuilder().getWorldRendererByLayerId(j);

                        if (!compiledchunk.isLayerStarted(blockrenderlayer1)) {
                            compiledchunk.setLayerStarted(blockrenderlayer1);
                            //thiz.preRenderBlocks(vertexbuffer, blockpos);
                            Util.callMethod1(thiz, "preRenderBlocks", vertexbuffer, renderPos0);
                        }

                        aboolean[j] |= blockrendererdispatcher.renderBlock(iblockstate, renderPos, region, vertexbuffer);
                    }
                }
                net.minecraftforge.client.ForgeHooksClient.setRenderLayer(null);
            }

            for (BlockRenderLayer blockrenderlayer : BlockRenderLayer.values()) {
                if (aboolean[blockrenderlayer.ordinal()]) {
                    //compiledchunk.setLayerUsed(blockrenderlayer);
                    Util.callMethod1(compiledchunk, "setLayerUsed", blockrenderlayer);
                }

                if (compiledchunk.isLayerStarted(blockrenderlayer)) {
                    //thiz.postRenderBlocks(blockrenderlayer, x, y, z, generator.getRegionRenderCacheBuilder().getWorldRendererByLayer(blockrenderlayer), compiledchunk);
                    Util.callMethod1(thiz, "postRenderBlocks", blockrenderlayer, x, y, z, generator.getRegionRenderCacheBuilder().getWorldRendererByLayer(blockrenderlayer), compiledchunk);
                }
            }
        }

        compiledchunk.setVisibility(lvt_9_1_.computeVisibility());

        ReentrantLock lockCompileTask = Util.getField(thiz, "lockCompileTask");
        Set<TileEntity> setTileEntities = Util.getField(thiz, "setTileEntities");
        RenderGlobal renderGlobal = Util.getField(thiz, "renderGlobal");

        lockCompileTask.lock();

        try {
            Set<TileEntity> set = Sets.newHashSet(lvt_10_1_);
            Set<TileEntity> set1 = Sets.newHashSet(setTileEntities);
            set.removeAll(setTileEntities);
            set1.removeAll(lvt_10_1_);
            setTileEntities.clear();
            setTileEntities.addAll(lvt_10_1_);
            renderGlobal.updateTileEntities(set1, set);
        } finally {
            lockCompileTask.unlock();
        }
    }

 

Note: the lines

 

if (block == Blocks.GOLD_ORE) {
    L.d("Gold confirmed");
}

 

Correctly detect when I place a gold block in the targeted area, so I got that going for me at least.

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



×
×
  • Create New...

Important Information

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