Posted January 8, 20241 yr 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; } }
January 10, 20241 yr 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.
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.