Andrea Rodriguez

haz un mod que cuando rompas objetos, bloques salga un item aleatorio

Kodari AI
KodariOct 22 at 6:33 pm 1
RandomDropMod
A Minecraft Fabric mod that makes every broken block or item drop a random item instead of its normal loot. When a player breaks any block or destroys an item, the mod replaces the standard drop with a completely random item from the game's item registry. The random selection includes all available items, creating unpredictable and exciting gameplay. The mod intercepts block break events and item destruction events, cancels the original drops, and spawns a random item at the break location. Compatible with all block types and works seamlessly with vanilla mechanics.
  1. Registraré una acción al romper bloques que genere un objeto aleatorio, solo en el servidor.

  2. Crearé desde cero los archivos de Gradle y la configuración del mod Fabric 26.3.

Listo: al romper cada bloque, además de sus drops normales, aparece un objeto aleatorio del juego en el suelo. No incluye aire y solo se genera en el servidor.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
5 115
src/main/java/com/kodari/randomdrops/RandomDrops.java
package com.kodari.randomdrops;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;

import java.util.List;

public class RandomDrops implements ModInitializer {
	private static final List<Item> RANDOM_ITEMS = BuiltInRegistries.ITEM.stream()
			.filter(item -> item != Items.AIR)
			.toList();

	@Override
	public void onInitialize() {
		PlayerBlockBreakEvents.AFTER.register((level, player, pos, state, blockEntity) -> {
			if (!(level instanceof ServerLevel serverLevel)) {
				return;
			}

			Item randomItem = RANDOM_ITEMS.get(RandomSource.create().nextInt(RANDOM_ITEMS.size()));
			ItemEntity droppedItem = new ItemEntity(
					serverLevel,
					pos.getX() + 0.5,
					pos.getY() + 0.5,
					pos.getZ() + 0.5,
					new ItemStack(randomItem)
			);
			serverLevel.addFreshEntity(droppedItem);
		});
	}
}