Nikita Mikhalkov

I want to do shorts about, i have to pay my heals to get inventory slots, i need russian language in mod, and cersion is 1.21.11

Kodari AI
KodariNov 4 at 6:54 pm 4
InventoryHealPayment
Adds a Minecraft Fabric mod for version 1.21.11 where players must pay health points to unlock additional inventory slots. The mod introduces a configurable system allowing players to sacrifice hearts in exchange for expanded storage capacity, with each slot purchase costing a set amount of health. Features include Russian language support, a user-friendly GUI for purchasing slots, health regeneration balancing, and configurable slot pricing and maximum slot limits. The mod integrates seamlessly with vanilla inventory mechanics and provides clear feedback to players about their current slot count and health costs.
  1. Заблокирую часть инвентаря и добавлю команду покупки слотов за максимальные сердца.

  2. Добавлю русские сообщения и сохранение прогресса игрока.

Создан мод для Fabric 1.21.11 с русским переводом.

  • В начале доступны 18 из 36 слотов.

  • /slots buy открывает следующий слот за полсердца максимального здоровья. Должно остаться хотя бы одно сердце.

  • /slots показывает прогресс. Купленные слоты сохраняются после смерти.

Для русских сообщений выберите русский язык в настройках Minecraft.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
11 226
src/main/java/dev/kodari/heartslots/HeartSlots.java
package dev.kodari.heartslots;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

public class HeartSlots implements ModInitializer {
    public static final Identifier COST = Identifier.of("heartslots", "slot_cost");

    public static int unlocked(PlayerEntity player) {
        EntityAttributeInstance health = player.getAttributeInstance(EntityAttributes.MAX_HEALTH);
        EntityAttributeModifier modifier = health == null ? null : health.getModifier(COST);
        return Math.max(18, Math.min(36, 18 + (modifier == null ? 0 : (int) -modifier.value())));
    }

    public static boolean locked(PlayerEntity player, int index) {
        return index >= unlocked(player) && index < 36;
    }

    @Override
    public void onInitialize() {
        CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(
            CommandManager.literal("slots")
                .executes(context -> {
                    ServerPlayerEntity player = context.getSource().getPlayerOrThrow();
                    context.getSource().sendFeedback(() -> Text.translatable("heartslots.status", unlocked(player)), false);
                    return 1;
                })
                .then(CommandManager.literal("buy").executes(context -> {
                    ServerPlayerEntity player = context.getSource().getPlayerOrThrow();
                    int count = unlocked(player);
                    if (count >= 36) {
                        context.getSource().sendError(Text.translatable("heartslots.full"));
                        return 0;
                    }
                    if (player.getMaxHealth() < 3.0f) {
                        context.getSource().sendError(Text.translatable("heartslots.health"));
                        return 0;
                    }
                    EntityAttributeInstance health = player.getAttributeInstance(EntityAttributes.MAX_HEALTH);
                    if (health == null) return 0;
                    health.removeModifier(COST);
                    health.addPersistentModifier(new EntityAttributeModifier(COST, -(count - 17), EntityAttributeModifier.Operation.ADD_VALUE));
                    player.setHealth(Math.min(player.getHealth(), player.getMaxHealth()));
                    context.getSource().sendFeedback(() -> Text.translatable("heartslots.bought", count + 1), false);
                    return 1;
                }))
        ));
    }
}