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

Hi,

I'm having trouble with making blocks that don't take up the full area of a block.

I've tried copying code from carpet blocks, but that doesn't seem to be working.

Here's an image showing the problem:

J5JAeZG.png

On the left is a block that's meant to be a coconut. On the right is a block that's meant to be a cutting board.

As the game mistakenly believes that they are full blocks, it does not render the grass blocks below them, resulting in an unintended x-ray effect.

Here's the code of the related files:

block/custom/CoconutBlock.java:

package com.realicraft.rckitchen.block.custom;

import net.minecraft.world.level.block.Block;

public class CoconutBlock extends Block {

    public CoconutBlock(Properties properties) {
        super(properties);
    }
}

block/custom/CuttingBoardBlock.java:

package com.realicraft.rckitchen.block.custom;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

public class CuttingBoardBlock extends Block {
    protected static final VoxelShape SHAPE = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D);

    public CuttingBoardBlock(BlockBehaviour.Properties properties) {
        super(properties);
    }

    public VoxelShape getShape(BlockState p_152917_, BlockGetter p_152918_, BlockPos p_152919_, CollisionContext p_152920_) {
        return SHAPE;
    }
}

(Some of this code has been copied from the java file for carpet blocks.)

block/ModBlocks.java:

package com.realicraft.rckitchen.block;

import com.realicraft.rckitchen.block.custom.CoconutBlock;
import com.realicraft.rckitchen.block.custom.CuttingBoardBlock;
import com.realicraft.rckitchen.item.ModCreativeModeTab;
import com.realicraft.rckitchen.item.ModItems;
import com.realicraft.rckitchen.rcKitchen;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

import java.util.function.Supplier;

public class ModBlocks {
    public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, rcKitchen.MODID);

    public static final RegistryObject<Block> COCONUT_BLOCK = registerBlock("coconut_block", () -> new CoconutBlock(BlockBehaviour.Properties.of(Material.WEB)), ModCreativeModeTab.KITCHEN_TAB);
    public static final RegistryObject<Block> CUTTING_BOARD = registerBlock("cutting_board", () -> new CuttingBoardBlock(BlockBehaviour.Properties.of(Material.WOOD)), ModCreativeModeTab.KITCHEN_TAB);

    private static <T extends Block>RegistryObject<T> registerBlock(String name, Supplier<T> block, CreativeModeTab tab) {
        RegistryObject<T> toReturn = BLOCKS.register(name, block);
        registerBlockItem(name, toReturn, tab);
        return toReturn;
    };

    private static <T extends Block>RegistryObject<Item> registerBlockItem(String name, RegistryObject<T> block, CreativeModeTab tab) {
        return ModItems.ITEMS.register(name, () -> new BlockItem(block.get(), new Item.Properties().tab(tab)));
    };

    public static void register(IEventBus eventBus) {
        BLOCKS.register(eventBus);
    }
}

 

Edited by realicraft
title update

1 hour ago, realicraft said:

I'm having trouble with making blocks that don't take up the full area of a block.

Try adding a call to '.noOcclusion()' on the BlockBehaviour.Properties when you create the block.

  • Author
23 minutes ago, vemerion said:

Try adding a call to '.noOcclusion()' on the BlockBehaviour.Properties when you create the block.

This seems to have fixed the x-ray issue. Thanks!

23 minutes ago, realicraft said:

This seems to have fixed the x-ray issue. Thanks!

Glad you were able to get it working! :)

  • realicraft changed the title to [Solved] [1.19.2] How to make non-full block

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.