Jump to content

[Solved] [1.19.2] How to make non-full block


realicraft

Recommended Posts

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
Link to comment
Share on other sites

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

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



×
×
  • Create New...

Important Information

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