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

  • Author

I can render a Tile entity with special renderer (like a chest) anywhere I want (currently even from another dimension), but blocks are just so much more complicated it seems.

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.