Jump to content

blocks not droping


Recommended Posts

I am making a mod and am adding blocks, but when I break them, they don't drop anything! I don't know what's wrong.

The code of the block:

Spoiler

package flamepoint1544.flames_additions.block;

 

import net.minecraft.world.level.block.state.BlockState;

import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;

import net.minecraft.world.level.block.state.BlockBehaviour;

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

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

import net.minecraft.world.level.BlockGetter;

 

import net.minecraft.core.BlockPos;

 

public class UltimatiumOreBlock extends Block {

    public UltimatiumOreBlock() {

        super(BlockBehaviour.Properties.of().instrument(NoteBlockInstrument.BASEDRUM).sound(SoundType.STONE).strength(3f, 10f).requiresCorrectToolForDrops().speedFactor(1.1f).jumpFactor(1.1f).hasPostProcess((bs, br, bp) -> true)

                .emissiveRendering((bs, br, bp) -> true));

    }


 

    @Override

    public int getLightBlock(BlockState state, BlockGetter worldIn, BlockPos pos) {

        return 6;

    }

 

}

 

Link to comment
Share on other sites

Your block needs a loot table. Either write one manually as a datapack json file (see the vanilla wiki) or use data generation (recommended):

https://docs.minecraftforge.net/en/1.20.x/datagen/server/loottables/

Datagen explanation:

Spoiler


e.g. this class is the main provider and contains all your subproviders:

... extends LootTableProvider {

public ModLootTableProvider(PackOutput output) {
	super(output, Set.of(), List.of(
		new SubProviderEntry(ModBlockLoot::new, LootContextParamSets.BLOCK)
	));
}

And this one does the loot for blocks specifically

public class ModBlockLoot extends BlockLootSubProvider {
    
    protected ModBlockLoot() {
        super(Set.of(), FeatureFlags.REGISTRY.allFlags());
    }

    @Override
    protected Iterable<Block> getKnownBlocks() {
        return ModBlocks.BLOCKS // Get all registered entries
                .stream() // Stream the wrapped objects
                .flatMap(RegistryObject::stream) // Get the object if available
                ::iterator; // Create the iterable
    }

    @Override
    protected void generate() {
      	// some basic examples
        this.dropSelf(ModBlocks.SOMETHING_LIKE_DIRT.get());
        this.dropWhenSilkTouch(ModBlocks.SOMETHING_LIKE_GLASS.get());
      	// some other kinds use this format, see vanilla examples
        this.add(ModBlocks.SOMETHING_LIKE_VINES.get(), BlockLootSubProvider::createShearsOnlyDrop);
    }

Then add your provider:

in main mod constructor or something {
	...
	modEventBus.addListener(this::gatherData);
	...
}


public void gatherData(final GatherDataEvent event) {
        DataGenerator generator = event.getGenerator();
        PackOutput out = generator.getPackOutput();
  
  		generator.addProvider(event.includeServer(), new ModLootTableProvider(out));
 		// other providers can go here too.
    }

When you use the runData run configuration it'll generate the json files for you.

 

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.