Posted August 23, 20223 yr 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: 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 August 24, 20223 yr by realicraft title update
August 23, 20223 yr 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.
August 23, 20223 yr 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!
August 23, 20223 yr 23 minutes ago, realicraft said: This seems to have fixed the x-ray issue. Thanks! Glad you were able to get it working!
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.