Jump to content

[1.19] Overriding vanilla block and replace block states


NutronStar45

Recommended Posts

I'm making unlit torches, and I want to override the minecraft:torch block, but I get this error: `java.lang.RuntimeException: Invalid vanilla replacement`. Can I override vanilla blocks and block states? If so, how to do it?

Here's my `TorchBlock.java`:

package com.nutronstar45.chem.block.custom;

import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
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.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;

public class TorchBlock extends net.minecraft.world.level.block.TorchBlock {
    public static final BooleanProperty LIT = BlockStateProperties.LIT;

    public TorchBlock(BlockBehaviour.Properties properties, ParticleOptions particle) {
        super(properties, particle);
        this.registerDefaultState(this.stateDefinition.any().setValue(LIT, false));
    }

    @Override
    public void animateTick(BlockState blockState, Level level, BlockPos blockPos, RandomSource random) {
        double flameX = (double)blockPos.getX() + 0.5D;
        double flameY = (double)blockPos.getY() + 0.7D;
        double flameZ = (double)blockPos.getZ() + 0.5D;
        level.addParticle(ParticleTypes.SMOKE, flameX, flameY, flameZ, 0.0D, 0.0D, 0.0D);
        level.addParticle(this.flameParticle, flameX, flameY, flameZ, 0.0D, 0.0D, 0.0D);
    }

    @Override
    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
        builder.add(LIT);
    }
}

Here's my `ModBlocks.java`:

package com.nutronstar45.chem.block;

import com.nutronstar45.chem.Chem;
import com.nutronstar45.chem.block.custom.StickBlock;
import com.nutronstar45.chem.block.custom.TorchBlock;
import com.nutronstar45.chem.block.custom.WallStickBlock;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
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;

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

    public static final RegistryObject<Block> STICK = VANILLA_BLOCKS.register(
            "stick", () -> new StickBlock(
                    BlockBehaviour.Properties.of(Material.DECORATION).noCollission().instabreak().sound(SoundType.WOOD)));
    public static final RegistryObject<Block> TORCH = VANILLA_BLOCKS.register(
            "torch", () -> new TorchBlock(
                    BlockBehaviour.Properties.of(Material.DECORATION).noCollission().instabreak().lightLevel(
                            blockState -> 14
                    ).sound(SoundType.WOOD), ParticleTypes.FLAME));
    public static final RegistryObject<Block> WALL_STICK = VANILLA_BLOCKS.register(
            "wall_stick", () -> new WallStickBlock(
                    BlockBehaviour.Properties.of(Material.DECORATION).noCollission().instabreak().sound(SoundType.WOOD).lootFrom(STICK)));

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

Here's my `Chem.java`:

package com.nutronstar45.chem;

import com.nutronstar45.chem.block.ModBlocks;
import com.nutronstar45.chem.item.ModItems;
import com.nutronstar45.chem.sound.ModSoundEvents;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

@Mod(Chem.MODID)
public class Chem
{
    public static final String MODID = "chem";


    public Chem()
    {
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

        ModBlocks.register(modEventBus);
        ModItems.register(modEventBus);
        ModSoundEvents.register(modEventBus);

        MinecraftForge.EVENT_BUS.register(this);
    }
}

 

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.



×
×
  • Create New...

Important Information

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