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 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);
    }
}

 

try commenting out 1st and 3rd registration and leave only the 2nd. i never did what you're trying but start with that.

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.