Top.Mail.Ru
Ответы
Аватар пользователя
Аватар пользователя
Аватар пользователя
Аватар пользователя
Программирование
+3

Магия с ведрами | Minecraft Fabric

Я делаю один мод, и в нем при нажатии кнопки ведро с водой должно превратиться в ведро с вином, предмет из мода.

Но и мое ведро, и ведро с лавой ведут себя одинаково: при размещении жидкости она сразу превращается в воду. Более того, после перезахода ведро снова становится ведром с водой. Вот мой код, у меня уже закончились идеи как это исправить и я отчаялся обратиться сюда

12345678910111213141516171819202122232425262728293031323334353637383940414243
 public void onEndTick(MinecraftClient client) {  
 
    if (JesusClient.transformKey.wasPressed()) {  
 
        PlayerEntity player = client.player;  
 
        ItemStack itemStack = player.getMainHandStack();  
 
        ItemStack newWineStack;  
 
  
 
        if (itemStack.getItem() == Items.POTION && PotionUtil.getPotion(itemStack) == Potions.WATER) {  
 
            newWineStack = new ItemStack(Jesus.WINE_BOTTLE);  
 
        } else if (itemStack.getItem() == Items.WATER_BUCKET) {  
 
            // Место объявления ItemStack ведра  
 
            newWineStack = new ItemStack(Items.LAVA_BUCKET);  
 
        } else {  
 
            player.sendMessage(Text.translatable("message.transform_impossible").setStyle(Style.EMPTY.withColor(TextColor.fromRgb(0xFF5555))), false);  
 
            return;  
 
        }  
 
  
 
        itemStack.decrement(1);  
 
        if (!player.getInventory().insertStack(newWineStack)) {  
 
            player.dropStack(newWineStack);  
 
        }  
 
    }  
 
} 
По дате
По рейтингу
Аватар пользователя
Профи
10мес

попробуй

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
 // JesusMod.java 
public class JesusMod { 
    public static final WineBucketItem WINE_BUCKET_ITEM = new WineBucketItem(); 
 
    @Mod.Init 
    public void init(FMLInitializationEvent event) { 
        // Register the custom item 
        GameRegistry.registerItem(WINE_BUCKET_ITEM, "wine_bucket"); 
    } 
} 
 
// WineBucketItem.java 
public class WineBucketItem extends Item { 
    public WineBucketItem() { 
        super(new Item.Properties().group(ItemGroup.MISC)); 
    } 
 
    @Override 
    public ActionResult onItemUse(ItemStack stack, World world, PlayerEntity player, Hand hand) { 
        // Handle liquid placement and prevent default behavior 
        if (!world.isRemote) { 
            // Check if the player is trying to place a liquid in the bucket 
            if (player.isHandActive() && player.getActiveHand() == hand) { 
                // Get the liquid in the bucket 
                Fluid fluid = FluidRegistry.getFluid("water"); // or "lava" for lava bucket 
 
                // Check if the fluid is water or lava 
                if (fluid != null) { 
                    // Prevent the default behavior of turning the bucket into a water bucket 
                    return ActionResult.SUCCESS; 
                } 
            } 
        } 
        return super.onItemUse(stack, world, player, hand); 
    } 
 
    @Override 
    public boolean hasEffect(ItemStack stack) { 
        return true; 
    } 
 
    @Override 
    public void onCreated(ItemStack stack, World world, PlayerEntity player) { 
        // Add a custom NBT tag to mark it as a wine bucket 
        stack.getOrCreateTag().putBoolean("isWineBucket", true); 
    } 
} 
 
// JesusClient.java 
public class JesusClient { 
    public static final KeyBinding transformKey = new KeyBinding("key.transform", Keyboard.KEY_T, "category.jesus"); 
 
    @SubscribeEvent 
    public void onEndTick(TickEvent.ClientTickEvent event) { 
        if (event.phase == TickEvent.Phase.END) { 
            if (transformKey.wasPressed()) { 
                PlayerEntity player = Minecraft.getInstance().player; 
                ItemStack itemStack = player.getMainHandStack(); 
 
                if (itemStack.getItem() == Items.WATER_BUCKET) { 
                    // Create a custom wine bucket item instance 
                    ItemStack newWineStack = new ItemStack(JesusMod.WINE_BUCKET_ITEM); 
 
                    itemStack.decrement(1); 
                    if (!player.getInventory().insertStack(newWineStack)) { 
                        player.dropStack(newWineStack); 
                    } 
                } 
            } 
        } 
    } 
}